From: Andrew STUBBS <andrew.stubbs@st.com>
To: gdb@sources.redhat.com
Subject: RFC: GDB as a loader 3/3: --eval-command option
Date: Tue, 18 Oct 2005 11:33:00 -0000 [thread overview]
Message-ID: <4354DD31.3020809@st.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 905 bytes --]
Hi all,
The attached patch implements a new option --eval-command (-ex for
short) which works similarly to the --command option except that it
passes the command itself, rather than a file name containing commands.
In most cases, this eliminates the need for temporary files or messing
around with stdin when running programs via the debugger.
For example:
gdb hello.exe --batch -ex 'target sim' -ex load -ex run
This option may be used in conjunction with the existing --command (-x)
command and the order of the options is honoured.
It is still necessary to use a script file if define/if/while, or any
other nested construct, is required. Suggestions on how to deal with
this would be welcome.
Note that the patch assumes that the batch-silent and
return-child-result patches have already been applied (although the
implementation in no way depends on those features).
Thanks
Andrew Stubbs
[-- Attachment #2: eval-command.patch --]
[-- Type: text/plain, Size: 3536 bytes --]
2005-10-18 Andrew Stubbs <andrew.stubbs@st.com>
* main.c (captured_main): Define struct cmdarg. Change type of cmdarg.
Add new options --eval-command and alias -ex.
Adjust --command to use the new struct cmdarg.
Execute commands given with --eval-command.
(print_gdb_help): Add new options --eval-command, -ex and mention -x.
Index: src/gdb/main.c
===================================================================
--- src.orig/gdb/main.c 2005-10-18 09:57:29.000000000 +0100
+++ src/gdb/main.c 2005-10-18 10:14:27.000000000 +0100
@@ -138,7 +138,13 @@ captured_main (void *data)
static int print_version;
/* Pointers to all arguments of --command option. */
- char **cmdarg;
+ struct cmdarg {
+ enum {
+ CMDARG_FILE,
+ CMDARG_COMMAND
+ } type;
+ char *string;
+ } *cmdarg;
/* Allocated size of cmdarg. */
int cmdsize;
/* Number of elements of cmdarg used. */
@@ -178,7 +184,7 @@ captured_main (void *data)
#endif
cmdsize = 1;
- cmdarg = (char **) xmalloc (cmdsize * sizeof (*cmdarg));
+ cmdarg = (struct cmdarg *) xmalloc (cmdsize * sizeof (*cmdarg));
ncmd = 0;
dirsize = 1;
dirarg = (char **) xmalloc (dirsize * sizeof (*dirarg));
@@ -285,8 +291,10 @@ captured_main (void *data)
{"pid", required_argument, 0, 'p'},
{"p", required_argument, 0, 'p'},
{"command", required_argument, 0, 'x'},
+ {"eval-command", required_argument, 0, 'X'},
{"version", no_argument, &print_version, 1},
{"x", required_argument, 0, 'x'},
+ {"ex", required_argument, 0, 'X'},
#ifdef GDBTK
{"tclcommand", required_argument, 0, 'z'},
{"enable-external-editor", no_argument, 0, 'y'},
@@ -387,12 +395,23 @@ captured_main (void *data)
corearg = optarg;
break;
case 'x':
- cmdarg[ncmd++] = optarg;
+ cmdarg[ncmd].type = CMDARG_FILE;
+ cmdarg[ncmd++].string = optarg;
+ if (ncmd >= cmdsize)
+ {
+ cmdsize *= 2;
+ cmdarg = xrealloc ((char *) cmdarg,
+ cmdsize * sizeof (*cmdarg));
+ }
+ break;
+ case 'X':
+ cmdarg[ncmd].type = CMDARG_COMMAND;
+ cmdarg[ncmd++].string = optarg;
if (ncmd >= cmdsize)
{
cmdsize *= 2;
- cmdarg = (char **) xrealloc ((char *) cmdarg,
- cmdsize * sizeof (*cmdarg));
+ cmdarg = xrealloc ((char *) cmdarg,
+ cmdsize * sizeof (*cmdarg));
}
break;
case 'B':
@@ -733,7 +752,12 @@ extern int gdbtk_test (char *);
do_cleanups (ALL_CLEANUPS);
}
#endif
- catch_command_errors (source_command, cmdarg[i], !batch, RETURN_MASK_ALL);
+ if (cmdarg[i].type == CMDARG_FILE)
+ catch_command_errors (source_command, cmdarg[i].string,
+ !batch, RETURN_MASK_ALL);
+ else /* cmdarg[i].type == CMDARG_COMMAND */
+ catch_command_errors (execute_command, cmdarg[i].string,
+ !batch, RETURN_MASK_ALL);
}
xfree (cmdarg);
@@ -846,7 +870,11 @@ Options:\n\n\
--return-child-result\n\
GDB exit code will be the child's exit code.\n\
--cd=DIR Change current directory to DIR.\n\
- --command=FILE Execute GDB commands from FILE.\n\
+ --command=FILE, -x Execute GDB commands from FILE.\n\
+ --eval-command=COMMAND, -ex\n\
+ Execute a single GDB command.\n\
+ May be used multiple times and in conjunction\n\
+ with --command.\n\
--core=COREFILE Analyze the core dump COREFILE.\n\
--pid=PID Attach to running process PID.\n\
"), stream);
next reply other threads:[~2005-10-18 11:33 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-10-18 11:33 Andrew STUBBS [this message]
2005-10-28 11:10 ` Andrew STUBBS
2005-10-28 13:04 ` Eli Zaretskii
2005-10-28 14:03 ` Andrew STUBBS
2005-10-28 17:05 ` Eli Zaretskii
2005-11-04 11:54 ` Andrew STUBBS
2005-11-05 2:51 ` Daniel Jacobowitz
2005-11-05 10:01 ` Eli Zaretskii
2005-11-07 14:01 ` Andrew STUBBS
2005-11-07 14:16 ` Andrew STUBBS
2005-11-07 17:27 ` Joel Brobecker
2005-11-07 18:06 ` Andrew STUBBS
2005-11-07 20:54 ` Eli Zaretskii
2005-11-07 20:46 ` Eli Zaretskii
2005-11-08 11:05 ` Andrew STUBBS
2005-11-13 17:38 ` Daniel Jacobowitz
2005-11-14 11:45 ` Andrew STUBBS
[not found] ` <20051114134816.GA21373@nevyn.them.org>
2005-11-14 15:57 ` Andrew STUBBS
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=4354DD31.3020809@st.com \
--to=andrew.stubbs@st.com \
--cc=gdb@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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).