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: Fri, 30 Mar 2001 13:28:00 -0000 Message-id: <20010330163603.A27435@llamedos.org> References: <20010330005457.A21793@llamedos.org> X-SW-Source: 2001-03/msg00562.html This patch allows the user to pass the arguments to the program to be debugged on the command line. When the option -run is encountered, gdb stops processing options. It treats the first argument after -run as the program name, and everything that follows is treated as the arguments to the debuggee. This patch is sans a formal changelog and documentation fixes, I'll add them if the patch is accepted. Changes (from gdb+dejagnu-20010327): inferior.h: change get/set_inferior_arg prototypes to get/set_inferior_args prototypes. get/set_inferior_arg do not appear anywhere in the code. main.c: process the -run argument. I do this in two passes - the first pass calculates the length of the argument string, the second pass strcpy and strcat's the arguments into the buffer. I do the actual assignment of the inferior_argument variable after the command file is processed - this will allow the commandline to override the command file. ===== PATCH ===== diff -c3p gdb-orig/inferior.h gdb/inferior.h *** gdb-orig/inferior.h Tue Mar 13 18:31:13 2001 --- gdb/inferior.h Fri Mar 30 12:12:51 2001 *************** extern void tty_command (char *, int); *** 267,275 **** extern void attach_command (char *, int); ! extern char *get_inferior_arg (void); ! extern char *set_inferior_arg (char *); /* Last signal that the inferior received (why it stopped). */ --- 267,275 ---- extern void attach_command (char *, int); ! extern char *get_inferior_args (void); ! extern char *set_inferior_args (char *); /* Last signal that the inferior received (why it stopped). */ diff -c3p gdb-orig/main.c gdb/main.c *** gdb-orig/main.c Tue Mar 6 03:21:10 2001 --- gdb/main.c Fri Mar 30 16:10:46 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) *** 284,289 **** --- 288,294 ---- {"windows", no_argument, &use_windows, 1}, {"statistics", no_argument, 0, 13}, {"write", no_argument, &write_files, 1}, + {"run", no_argument, 0, 14}, /* Allow machine descriptions to add more options... */ #ifdef ADDITIONAL_OPTIONS ADDITIONAL_OPTIONS *************** captured_main (void *data) *** 300,305 **** --- 305,318 ---- if (c == EOF) break; + /* A -run argument stops the option processing + immediately. */ + 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 *); *** 468,490 **** /* OK, that's all the options. The other arguments are filenames. */ count = 0; ! for (; optind < argc; optind++) ! switch (++count) ! { ! case 1: ! symarg = argv[optind]; ! execarg = argv[optind]; ! break; ! case 2: ! /* FIXME: The documentation says this can be a "ProcID". as well. */ ! corearg = argv[optind]; ! break; ! case 3: ! fprintf_unfiltered (gdb_stderr, "Excess command line arguments ignored. (%s%s)\n", argv[optind], (optind == argc - 1) ? "" : " ..."); ! break; ! } if (batch) quiet = 1; } --- 481,538 ---- /* OK, that's all the options. The other arguments are filenames. */ count = 0; ! if (cmdline_inf_args_flag) ! { ! int arg_len = 1; /* \0 */ ! int i; ! ! /* Run through all the arguments to find out how long of a buffer ! we need. */ ! for (i=optind+1; i