From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Deephanphongs To: gdb-patches@sources.redhat.com Subject: Re: [PATCH] specify arguments to debugee from commandline (second try) Date: Wed, 06 Jun 2001 23:40:00 -0000 Message-id: <20010607024045.A25325@llamedos.org> References: <20010420031059.A516@llamedos.org> X-SW-Source: 2001-06/msg00116.html Ok, here's the latest revision of the command-line args patch. Syntax: gdb [various options] --args GDB will escape the following characters within an inferior argument: ^|&#<>\"'`$*?[](); \{} ^----space One thing I'm a little confused about - I thought that GNU getopt (and getopt_long_only) moved arguments to the beginning of argv, but that doesn't seem to be the case. with an argv that looks like this: {"gdb", "ls", "--args", "-l"} I expect it to look like this (after getopt is called): {"gdb", "--args", "ls", "-l"} That doesn't happen, though. Is it being forced into compatability mode somehow? Anyway, that's why it's 'gdb --args ...' instead of 'gdb --args ...' This isn't a proper patch - there's indentation issues with some of the old argument parsing code. I'm leaving the indentation alone right now so I don't obscure the actual changed code (I had to put an 'if' around all the old program-name/corearg code). ---- Begin patch ---- *** gdb/main.c Thu Jun 7 00:56:39 2001 --- cmdline_arg_gdb/main.c Thu Jun 7 00:58:56 2001 *************** captured_main (void *data) *** 168,173 **** --- 168,177 ---- long time_at_startup = get_run_time (); + /* Arguments for the inferior program from the commandline. */ + char *cmdline_inf_args = 0; + int cmdline_inf_args_flag = 0; + START_PROGRESS (argv[0], 0); #ifdef MPW *************** captured_main (void *data) *** 281,286 **** --- 285,291 ---- {"windows", no_argument, &use_windows, 1}, {"statistics", no_argument, 0, 13}, {"write", no_argument, &write_files, 1}, + {"args", no_argument, 0, 14}, /* Allow machine descriptions to add more options... */ #ifdef ADDITIONAL_OPTIONS ADDITIONAL_OPTIONS *************** captured_main (void *data) *** 297,302 **** --- 302,314 ---- if (c == EOF) break; + /* We stop argument processing instantly if we get a -args option. */ + if (c == 14) + { + cmdline_inf_args_flag = 1; + break; + } + /* Long option that takes an argument. */ if (c == 0 && long_options[option_index].flag == 0) c = long_options[option_index].val; *************** extern int gdbtk_test (char *); *** 463,470 **** use_windows = 0; #endif - /* OK, that's all the options. The other arguments are filenames. */ count = 0; for (; optind < argc; optind++) switch (++count) { --- 475,522 ---- use_windows = 0; #endif count = 0; + /* If we have commandline arguments, then we expect the next argument + to be the program name, and the following arguments to be arguments + to the inferior process. */ + if (cmdline_inf_args_flag) + { + int arg_len = 1; /* EOS */ + int i; + char *cmdline_end; /* points to end of cmdline_inf_args. */ + + /* Run through all the arguments to determine what size buffer + we need. */ + for (i=optind+1; i