This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
Re: [PATCH] specify arguments to debugee from commandline (second try)
- To: gdb-patches at sources dot redhat dot com
- Subject: Re: [PATCH] specify arguments to debugee from commandline (second try)
- From: David Deephanphongs <deephan at erols dot com>
- Date: Fri, 30 Mar 2001 16:36:03 -0500
- References: <20010330005457.A21793@llamedos.org>
- Reply-To: deephan at erols dot com
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<argc; i++)
! {
! arg_len += strlen (argv[i]);
! arg_len += 1; /* for the space that comes after the argument */
! }
! cmdline_inf_args = xmalloc( arg_len );
! for (; optind < argc; optind++)
! {
! switch (++count)
! {
! case 1:
! symarg = argv[optind];
! execarg = argv[optind];
! break;
! case 2:
! strcpy( cmdline_inf_args, argv[optind] );
! break;
! default:
! strcat (cmdline_inf_args, " ");
! strcat (cmdline_inf_args, argv[optind]);
! break;
! }
! }
! }
! else
! {
! 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;
}
*************** extern int gdbtk_test (char *);
*** 669,678 ****
catch_command_errors (source_command, cmdarg[i], !batch, RETURN_MASK_ALL);
}
xfree (cmdarg);
!
/* Read in the old history after all the command files have been read. */
init_history ();
if (batch)
{
/* We have hit the end of the batch file. */
--- 717,732 ----
catch_command_errors (source_command, cmdarg[i], !batch, RETURN_MASK_ALL);
}
xfree (cmdarg);
!
/* Read in the old history after all the command files have been read. */
init_history ();
+ if (cmdline_inf_args_flag)
+ {
+ /* Set the inferior arguments now, so we can override the command file. */
+ set_inferior_args (cmdline_inf_args);
+ }
+
if (batch)
{
/* We have hit the end of the batch file. */