From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19657 invoked by alias); 18 Oct 2005 11:30:14 -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 19638 invoked by uid 22791); 18 Oct 2005 11:30:11 -0000 Received: from fra-del-04.spheriq.net (HELO fra-del-04.spheriq.net) (195.46.51.100) by sourceware.org (qpsmtpd/0.30-dev) with ESMTP; Tue, 18 Oct 2005 11:30:11 +0000 Received: from fra-out-03.spheriq.net (fra-out-03.spheriq.net [195.46.51.131]) by fra-del-04.spheriq.net with ESMTP id j9IBTxeb031781 for ; Tue, 18 Oct 2005 11:29:59 GMT Received: from fra-cus-01.spheriq.net (fra-cus-01.spheriq.net [195.46.51.37]) by fra-out-03.spheriq.net with ESMTP id j9IBTuZ6021146 for ; Tue, 18 Oct 2005 11:29:58 GMT Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by fra-cus-01.spheriq.net with ESMTP id j9IBTqGA018989 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=OK) for ; Tue, 18 Oct 2005 11:29:53 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 E7D65DA44 for ; Tue, 18 Oct 2005 11:29:46 +0000 (GMT) Received: by zeta.dmz-eu.st.com (STMicroelectronics, from userid 60012) id 62BCD473CA; Tue, 18 Oct 2005 11:32:32 +0000 (GMT) Received: from zeta.dmz-eu.st.com (localhost [127.0.0.1]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 2604075994 for ; Tue, 18 Oct 2005 11:32:32 +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 ABCC6473C4 for ; Tue, 18 Oct 2005 11:32:31 +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 CDA01411 (AUTH "andrew stubbs"); Tue, 18 Oct 2005 12:29:45 +0100 (BST) Message-ID: <4354DC55.4090706@st.com> Date: Tue, 18 Oct 2005 11:30: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 2/3: return child result Content-Type: multipart/mixed; boundary="------------020706000308050408050309" 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/msg00096.txt.bz2 This is a multi-part message in MIME format. --------------020706000308050408050309 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 833 Hi all, The attached patch implements a new option --return-child-result. This option causes GDB to return the return value of the last child (inferior) program to run. The patch assumes that the batch-silent patch has already been applied. Note that 'quit ' still works as expected. Also, any exit through a mechanism other than quit_force (i.e. errors) gives the same exit code as it did before. Batch mode has been adjusted to exit through quit_force in order to ensure it give the right result. I am not sure that this has been implemented in the best way. The declaration of extern variables probably ought to be moved to a header file somewhere, but I'm not sure which is best. It has also been suggested that it ought to use the value stored in the existing $_exitcode convenience variable. Thanks Andrew Stubbs --------------020706000308050408050309 Content-Type: text/plain; name="return-child-result.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="return-child-result.patch" Content-length: 3826 2005-10-18 Andrew Stubbs * infrun.c (print_stop_reason): Set return_child_result_value on exit. * main.c (return_child_result): New variable. (return_child_result_value): Likewise. (captured_main): Add option --return-child-result. Replace call to target_detach and exit (in batch mode) with quit_force. (print_gdb_help): Add option --return-child-result. * top.c (quit_force): Return child result if appropriate. Index: src/gdb/infrun.c =================================================================== --- src.orig/gdb/infrun.c 2005-09-29 21:41:27.000000000 +0100 +++ src/gdb/infrun.c 2005-10-17 18:00:23.000000000 +0100 @@ -2931,6 +2931,11 @@ print_stop_reason (enum inferior_stop_re async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY)); ui_out_text (uiout, "\nProgram exited normally.\n"); } + { + /* Support the --return-child-result option. */ + extern int return_child_result_value; + return_child_result_value = stop_info; + } break; case SIGNAL_RECEIVED: /* Signal received. The signal table tells us to print about Index: src/gdb/main.c =================================================================== --- src.orig/gdb/main.c 2005-10-17 17:44:35.000000000 +0100 +++ src/gdb/main.c 2005-10-17 18:19:31.000000000 +0100 @@ -76,6 +76,12 @@ struct ui_file *gdb_stdtargerr; /* Support for the --batch-silent option. */ int batch_silent = 0; +/* Support for --return-child-result option. + Set the default to -1 to return error in the case + that the program does not run or does not complete. */ +int return_child_result = 0; +int return_child_result_value = -1; + /* Whether to enable writing into executable and core files */ extern int write_files; @@ -303,6 +309,7 @@ captured_main (void *data) {"write", no_argument, &write_files, 1}, {"args", no_argument, &set_args, 1}, {"l", required_argument, 0, 'l'}, + {"return-child-result", no_argument, &return_child_result, 1}, {0, no_argument, 0, 0} }; @@ -735,15 +742,8 @@ extern int gdbtk_test (char *); if (batch) { - if (attach_flag) - /* Either there was a problem executing the command in the - batch file aborted early, or the batch file forgot to do an - explicit detach. Explicitly detach the inferior ensuring - that there are no zombies. */ - target_detach (NULL, 0); - /* We have hit the end of the batch file. */ - exit (0); + quit_force (NULL, 0); } /* Do any host- or target-specific hacks. This is used for i960 targets @@ -843,6 +843,8 @@ Options:\n\n\ -b BAUDRATE Set serial port baud rate used for remote debugging.\n\ --batch Exit after processing options.\n\ --batch-silent As for --batch, but suppress all gdb stdout output.\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\ --core=COREFILE Analyze the core dump COREFILE.\n\ Index: src/gdb/top.c =================================================================== --- src.orig/gdb/top.c 2005-07-04 14:29:12.000000000 +0100 +++ src/gdb/top.c 2005-10-17 18:00:23.000000000 +0100 @@ -1177,6 +1177,7 @@ quit_force (char *args, int from_tty) { int exit_code = 0; struct qt_args qt; + extern int return_child_result, return_child_result_value; /* An optional expression may be used to cause gdb to terminate with the value of that expression. */ @@ -1186,6 +1187,8 @@ quit_force (char *args, int from_tty) exit_code = (int) value_as_long (val); } + else if (return_child_result) + exit_code = return_child_result_value; qt.args = args; qt.from_tty = from_tty; --------------020706000308050408050309--