static void PrintHelp();
-static void ParseDebugOpt(const char* arg) {
- const char *p = 0;
+static bool ParseDebugOpt(const char* arg) {
+ const char* port = NULL;
- if (strstr(arg, "--debug-port=") == arg) {
- p = 1 + strchr(arg, '=');
- debug_port = atoi(p);
- } else {
+ if (!strcmp(arg, "--debug")) {
use_debug_agent = true;
- if (!strcmp(arg, "--debug-brk")) {
- debug_wait_connect = true;
- return;
- } else if (!strcmp(arg, "--debug")) {
- return;
- } else if (strstr(arg, "--debug-brk=") == arg) {
- debug_wait_connect = true;
- p = 1 + strchr(arg, '=');
- debug_port = atoi(p);
- } else if (strstr(arg, "--debug=") == arg) {
- p = 1 + strchr(arg, '=');
- debug_port = atoi(p);
- }
+ } else if (!strncmp(arg, "--debug=", sizeof("--debug=") - 1)) {
+ use_debug_agent = true;
+ port = arg + sizeof("--debug=") - 1;
+ } else if (!strcmp(arg, "--debug-brk")) {
+ use_debug_agent = true;
+ debug_wait_connect = true;
+ } else if (!strncmp(arg, "--debug-brk=", sizeof("--debug-brk=") - 1)) {
+ use_debug_agent = true;
+ debug_wait_connect = true;
+ port = arg + sizeof("--debug-brk=") - 1;
+ } else if (!strncmp(arg, "--debug-port=", sizeof("--debug-port=") - 1)) {
+ port = arg + sizeof("--debug-port=") - 1;
+ } else {
+ return false;
}
- if (p && debug_port > 1024 && debug_port < 65536)
- return;
- fprintf(stderr, "Bad debug option.\n");
- if (p)
- fprintf(stderr, "Debug port must be in range 1025 to 65535.\n");
+ if (port != NULL) {
+ debug_port = atoi(port);
+ if (debug_port < 1024 || debug_port > 65535) {
+ fprintf(stderr, "Debug port must be in range 1024 to 65535.\n");
+ PrintHelp();
+ exit(12);
+ }
+ }
- PrintHelp();
- exit(12);
+ return true;
}
static void PrintHelp() {
const char* const arg = argv[index];
unsigned int args_consumed = 1;
- if (strstr(arg, "--debug") == arg) {
- ParseDebugOpt(arg);
+ if (ParseDebugOpt(arg)) {
+ // Done, consumed by ParseDebugOpt().
} else if (strcmp(arg, "--version") == 0 || strcmp(arg, "-v") == 0) {
printf("%s\n", NODE_VERSION);
exit(0);
--- /dev/null
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+// Flags: --debugger
+
+var common = require('../common');
+var assert = require('assert');
+
+assert.notEqual(process.execArgv.indexOf('--debugger'), -1);