aboutsummaryrefslogtreecommitdiff
path: root/gdb/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/main.c')
-rw-r--r--gdb/main.c75
1 files changed, 58 insertions, 17 deletions
diff --git a/gdb/main.c b/gdb/main.c
index bb8ddc3..3d56a31 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -19,6 +19,7 @@
#include "annotate.h"
#include "exceptions.h"
+#include "gdbsupport/common-inferior.h"
#include "top.h"
#include "ui.h"
#include "target.h"
@@ -29,7 +30,6 @@
#include <sys/types.h>
#include <sys/stat.h>
-#include <ctype.h>
#include "gdbsupport/event-loop.h"
#include "ui-out.h"
@@ -59,6 +59,7 @@
#include "serial.h"
#include "cli-out.h"
#include "bt-utils.h"
+#include "terminal.h"
/* The selected interpreter. */
std::string interpreter_p;
@@ -617,9 +618,20 @@ captured_main_1 (struct captured_main_args *context)
char **argv = context->argv;
static int quiet = 0;
- static int set_args = 0;
static int inhibit_home_gdbinit = 0;
+ /* Has the user passed inferior arguments on the command line. */
+ enum {
+ /* No arguments passed. */
+ NO_ARGS,
+
+ /* Arguments passed with --args. */
+ SET_ESC_ARGS,
+
+ /* Arguments passed with --no-escape-args. */
+ SET_NO_ESC_ARGS
+ } set_args = NO_ARGS;
+
/* Pointers to various arguments from command line. */
char *symarg = NULL;
char *execarg = NULL;
@@ -769,7 +781,12 @@ captured_main_1 (struct captured_main_args *context)
OPT_EIX,
OPT_EIEX,
OPT_READNOW,
- OPT_READNEVER
+ OPT_READNEVER,
+ OPT_SET_ESC_ARGS,
+ OPT_SET_NO_ESC_ARGS,
+#ifdef USE_WIN32API
+ OPT_BINARY_OUTPUT,
+#endif
};
/* This struct requires int* in the struct, but write_files is a bool.
So use this temporary int that we write back after argument parsing. */
@@ -842,9 +859,13 @@ captured_main_1 (struct captured_main_args *context)
{"windows", no_argument, NULL, OPT_WINDOWS},
{"statistics", no_argument, 0, OPT_STATISTICS},
{"write", no_argument, &write_files_1, 1},
- {"args", no_argument, &set_args, 1},
+ {"args", no_argument, nullptr, OPT_SET_ESC_ARGS},
+ {"no-escape-args", no_argument, nullptr, OPT_SET_NO_ESC_ARGS},
{"l", required_argument, 0, 'l'},
{"return-child-result", no_argument, &return_child_result, 1},
+#ifdef USE_WIN32API
+ {"binary-output", no_argument, 0, OPT_BINARY_OUTPUT},
+#endif
{0, no_argument, 0, 0}
};
@@ -852,9 +873,14 @@ captured_main_1 (struct captured_main_args *context)
{
int option_index;
+ /* If the previous argument was --args or --no-escape-args, then
+ stop argument processing. */
+ if (set_args != NO_ARGS)
+ break;
+
c = getopt_long_only (argc, argv, "",
long_options, &option_index);
- if (c == EOF || set_args)
+ if (c == EOF)
break;
/* Long option that takes an argument. */
@@ -935,6 +961,12 @@ captured_main_1 (struct captured_main_args *context)
case OPT_EIEX:
cmdarg_vec.emplace_back (CMDARG_EARLYINIT_COMMAND, optarg);
break;
+ case OPT_SET_ESC_ARGS:
+ set_args = SET_ESC_ARGS;
+ break;
+ case OPT_SET_NO_ESC_ARGS:
+ set_args = SET_NO_ESC_ARGS;
+ break;
case 'B':
batch_flag = batch_silent = 1;
gdb_stdout = new null_file ();
@@ -1018,6 +1050,12 @@ captured_main_1 (struct captured_main_args *context)
}
break;
+#ifdef USE_WIN32API
+ case OPT_BINARY_OUTPUT:
+ set_output_translation_mode_binary ();
+ break;
+#endif
+
case '?':
error (_("Use `%s --help' for a complete list of options."),
gdb_program_name);
@@ -1068,7 +1106,7 @@ captured_main_1 (struct captured_main_args *context)
/* Now that gdb_init has created the initial inferior, we're in
position to set args for that inferior. */
- if (set_args)
+ if (set_args != NO_ARGS)
{
/* The remaining options are the command-line options for the
inferior. The first one is the sym/exec file, and the rest
@@ -1080,10 +1118,9 @@ captured_main_1 (struct captured_main_args *context)
symarg = argv[optind];
execarg = argv[optind];
++optind;
- current_inferior ()->set_args
- (gdb::array_view<char * const> (&argv[optind], argc - optind),
- startup_with_shell);
- }
+ gdb::array_view<char * const> arg_view (&argv[optind], argc - optind);
+ current_inferior ()->set_args (arg_view, (set_args == SET_ESC_ARGS));
+ }
else
{
/* OK, that's all the options. */
@@ -1253,7 +1290,7 @@ captured_main_1 (struct captured_main_args *context)
If pid_or_core_arg's first character is a digit, try attach
first and then corefile. Otherwise try just corefile. */
- if (isdigit (pid_or_core_arg[0]))
+ if (c_isdigit (pid_or_core_arg[0]))
{
ret = catch_command_errors (attach_command, pid_or_core_arg,
!batch_flag);
@@ -1330,10 +1367,8 @@ captured_main_1 (struct captured_main_args *context)
}
static void
-captured_main (void *data)
+captured_main (captured_main_args *context)
{
- struct captured_main_args *context = (struct captured_main_args *) data;
-
captured_main_1 (context);
/* NOTE: cagney/1999-11-07: There is probably no reason for not
@@ -1402,7 +1437,8 @@ This is the GNU debugger. Usage:\n\n\
gdb_puts (_("\
Selection of debuggee and its files:\n\n\
--args Arguments after executable-file are passed to inferior.\n\
- --core=COREFILE Analyze the core dump COREFILE.\n\
+ --no-escape-args Like --args, but arguments are not escaped.\n \
+ --core=COREFILE Analyze the core dump COREFILE.\n \
--exec=EXECFILE Use EXECFILE as the executable.\n\
--pid=PID Attach to running process PID.\n\
--directory=DIR Search for source files in DIR.\n\
@@ -1459,8 +1495,13 @@ Remote debugging options:\n\n\
Other options:\n\n\
--cd=DIR Change current directory to DIR.\n\
--data-directory=DIR, -D\n\
- Set GDB's data-directory to DIR.\n\
-"), stream);
+ Set GDB's data-directory to DIR.\n"
+#ifdef USE_WIN32API
+"\
+ --binary-output Set the translation mode of stdout/stderr to binary,\n\
+ disabling CRLF translation.\n"
+#endif
+), stream);
gdb_puts (_("\n\
At startup, GDB reads the following early init files and executes their\n\
commands:\n\