From: David Deephanphongs <deephan@erols.com>
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 [thread overview]
Message-ID: <20010330163603.A27435@llamedos.org> (raw)
In-Reply-To: <20010330005457.A21793@llamedos.org>
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. */
next prev parent reply other threads:[~2001-03-30 13:28 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20010330005457.A21793@llamedos.org>
2001-03-29 23:13 ` [PATCH] specify arguments to debugee from commandline Eli Zaretskii
2001-03-30 0:26 ` David Deephanphongs
2001-03-30 1:32 ` Eli Zaretskii
2001-03-30 3:00 ` Alexandre Oliva
2001-03-30 3:47 ` Pierre Muller
2001-03-30 8:01 ` David Deephanphongs
2001-03-30 12:37 ` Andrew Cagney
2001-03-30 5:06 ` Fernando Nasser
2001-03-30 5:20 ` Fernando Nasser
2001-03-30 13:28 ` David Deephanphongs [this message]
2001-04-02 22:27 ` [PATCH] specify arguments to debugee from commandline (second try) David Deephanphongs
2001-04-02 22:48 ` Alexandre Oliva
2001-04-05 21:27 ` Tom Tromey
2001-04-05 21:47 ` Alexandre Oliva
2001-04-05 21:21 ` Tom Tromey
2001-04-06 1:32 ` Eli Zaretskii
[not found] ` <87vgoi58lr.fsf@creche.redhat.com>
2001-04-06 9:26 ` Eli Zaretskii
2001-04-06 9:35 ` Pierre Muller
2001-04-06 11:00 ` Tom Tromey
2001-04-17 10:38 ` Andrew Cagney
2001-04-20 2:39 ` David Deephanphongs
2001-06-06 23:40 ` David Deephanphongs
2001-06-07 0:00 ` Eli Zaretskii
2001-04-06 11:03 ` Tom Tromey
2001-04-06 13:13 ` Eli Zaretskii
2001-04-10 22:27 ` David Deephanphongs
2001-04-11 1:55 ` Eli Zaretskii
2001-04-11 19:05 ` David Deephanphongs
2001-04-12 8:26 ` Tom Tromey
2001-04-12 14:13 ` David Deephanphongs
2001-04-12 17:21 ` Tom Tromey
2001-04-13 1:30 ` Todd Whitesel
2001-04-06 22:46 ` David Deephanphongs
2001-04-05 21:12 ` Tom Tromey
2001-04-06 1:36 ` Eli Zaretskii
2001-06-22 12:26 Deephanphongs, David
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20010330163603.A27435@llamedos.org \
--to=deephan@erols.com \
--cc=gdb-patches@sources.redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox