From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20963 invoked by alias); 18 Oct 2005 11:33:38 -0000 Mailing-List: contact gdb-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sources.redhat.com Received: (qmail 20947 invoked by uid 22791); 18 Oct 2005 11:33:34 -0000 Received: from lon-del-03.spheriq.net (HELO lon-del-03.spheriq.net) (195.46.50.99) by sourceware.org (qpsmtpd/0.30-dev) with ESMTP; Tue, 18 Oct 2005 11:33:34 +0000 Received: from lon-out-03.spheriq.net ([195.46.50.131]) by lon-del-03.spheriq.net with ESMTP id j9IBXVl1012722 for ; Tue, 18 Oct 2005 11:33:31 GMT Received: from lon-cus-02.spheriq.net (lon-cus-02.spheriq.net [195.46.50.38]) by lon-out-03.spheriq.net with ESMTP id j9IBXUvB021401 for ; Tue, 18 Oct 2005 11:33:30 GMT Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by lon-cus-02.spheriq.net with ESMTP id j9IBXRKV007152 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=OK) for ; Tue, 18 Oct 2005 11:33:28 GMT Received: from zeta.dmz-eu.st.com (ns2.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 72580DA45 for ; Tue, 18 Oct 2005 11:33:27 +0000 (GMT) Received: by zeta.dmz-eu.st.com (STMicroelectronics, from userid 60012) id D926E473CF; Tue, 18 Oct 2005 11:36:12 +0000 (GMT) Received: from zeta.dmz-eu.st.com (localhost [127.0.0.1]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id A3A4675969 for ; Tue, 18 Oct 2005 11:36:12 +0000 (UTC) Received: from mail1.bri.st.com (mail1.bri.st.com [164.129.8.218]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 32754473CF for ; Tue, 18 Oct 2005 11:36:12 +0000 (GMT) Received: from [164.129.15.13] (terrorhawk.bri.st.com [164.129.15.13]) by mail1.bri.st.com (MOS 3.5.8-GR) with ESMTP id CDA01457 (AUTH "andrew stubbs"); Tue, 18 Oct 2005 12:33:25 +0100 (BST) Message-ID: <4354DD31.3020809@st.com> Date: Tue, 18 Oct 2005 11:33:00 -0000 From: Andrew STUBBS User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317) MIME-Version: 1.0 To: gdb@sources.redhat.com Subject: RFC: GDB as a loader 3/3: --eval-command option Content-Type: multipart/mixed; boundary="------------050902010700080908020704" X-O-Spoofed: Not Scanned X-O-General-Status: No X-O-Spam1-Status: Not Scanned X-O-Spam2-Status: Not Scanned X-O-URL-Status: Not Scanned X-O-Virus1-Status: No X-O-Virus2-Status: Not Scanned X-O-Virus3-Status: No X-O-Virus4-Status: No X-O-Virus5-Status: Not Scanned X-O-Image-Status: Not Scanned X-O-Attach-Status: Not Scanned X-SpheriQ-Ver: 2.3.0 X-SW-Source: 2005-10/txt/msg00097.txt.bz2 This is a multi-part message in MIME format. --------------050902010700080908020704 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 905 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 --------------050902010700080908020704 Content-Type: text/plain; name="eval-command.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="eval-command.patch" Content-length: 3536 2005-10-18 Andrew Stubbs * 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); --------------050902010700080908020704--