]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
2005-11-14 Andrew Stubbs <andrew.stubbs@st.com>
authorAndrew Stubbs <andrew.stubbs@st.com>
Mon, 14 Nov 2005 15:35:16 +0000 (15:35 +0000)
committerAndrew Stubbs <andrew.stubbs@st.com>
Mon, 14 Nov 2005 15:35:16 +0000 (15:35 +0000)
* infrun.c: Include main.h.
(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: Include main.h.
(quit_force): Return child result if appropriate.
* main.h (return_child_result, return_child_result_value): Declare.
* Makefile.in (top.o, infrun.o): Add main.h to dependencies.

doc/
* gdb.texinfo (Choosing modes): Add --return-child-result.

gdb/ChangeLog
gdb/Makefile.in
gdb/doc/ChangeLog
gdb/doc/gdb.texinfo
gdb/infrun.c
gdb/main.c
gdb/main.h
gdb/top.c

index a05c19758fd05d8c8e1cc566725b17a036c36dc1..7b124bc67ea2d37ad1839368eb629c73fe33cabb 100644 (file)
@@ -1,3 +1,17 @@
+2005-11-14  Andrew Stubbs  <andrew.stubbs@st.com>
+
+       * infrun.c: Include main.h.
+       (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: Include main.h.
+       (quit_force): Return child result if appropriate.
+       * main.h (return_child_result, return_child_result_value): Declare.
+       * Makefile.in (top.o, infrun.o): Add main.h to dependencies.
+
 2005-11-13  Daniel Jacobowitz  <dan@codesourcery.com>
 
        Merge from mainline:
index 73eb906cf49bd4abee01d459f40da36235b205a7..64c6b229a32d65c467f39e9094cd9b4bb5f61853 100644 (file)
@@ -2133,7 +2133,7 @@ infrun.o: infrun.c $(defs_h) $(gdb_string_h) $(symtab_h) $(frame_h) \
        $(gdbcore_h) $(gdbcmd_h) $(cli_script_h) $(target_h) $(gdbthread_h) \
        $(annotate_h) $(symfile_h) $(top_h) $(inf_loop_h) $(regcache_h) \
        $(value_h) $(observer_h) $(language_h) $(solib_h) $(gdb_assert_h) \
-       $(mi_common_h)
+       $(mi_common_h) $(main_h)
 inftarg.o: inftarg.c $(defs_h) $(frame_h) $(inferior_h) $(target_h) \
        $(gdbcore_h) $(command_h) $(gdb_stat_h) $(observer_h) $(gdb_wait_h) \
        $(inflow_h)
@@ -2689,7 +2689,7 @@ top.o: top.c $(defs_h) $(gdbcmd_h) $(call_cmds_h) $(cli_cmds_h) \
        $(annotate_h) $(completer_h) $(top_h) $(version_h) $(serial_h) \
        $(doublest_h) $(gdb_assert_h) $(readline_h) $(readline_history_h) \
        $(event_top_h) $(gdb_string_h) $(gdb_stat_h) $(ui_out_h) \
-       $(cli_out_h)
+       $(cli_out_h) $(main_h)
 tracepoint.o: tracepoint.c $(defs_h) $(symtab_h) $(frame_h) $(gdbtypes_h) \
        $(expression_h) $(gdbcmd_h) $(value_h) $(target_h) $(language_h) \
        $(gdb_string_h) $(inferior_h) $(tracepoint_h) $(remote_h) \
index f62c31230cf923d0089799c1b43d01efd6a77afc..c85c991f4ab74deda6ae850f97a39c8abb1e1a5b 100644 (file)
@@ -1,3 +1,7 @@
+2005-11-14  Andrew Stubbs  <andrew.stubbs@st.com>
+
+       * gdb.texinfo (Choosing modes): Add --return-child-result.
+
 2005-11-01  Andrew Stubbs  <andrew.stubbs@st.com>
 
        * gdb.texinfo (Choosing modes): Add --batch-silent.
index 75ae4ef7f07df0925acd947fed481eaacea2f2eb..5402d6a697aa8efe41b1dfd80797d1198fb3ead4 100644 (file)
@@ -1007,6 +1007,27 @@ messages, for example.
 Note that targets that give their output via @value{GDBN}, as opposed to
 writing directly to @code{stdout}, will also be made silent.
 
+@item -return-child-result
+@cindex @code{--return-child-result}
+The return code from @value{GDBN} will be the return code from the child
+process (the process being debugged), with the following exceptions:
+
+@itemize @bullet
+@item
+@value{GDBN} exits abnormally.  E.g., due to an incorrect argument or an
+internal error.  In this case the exit code is the same as it would have been
+without @samp{-return-child-result}.
+@item
+The user quits with an explicit value.  E.g., @samp{quit 1}.
+@item
+The child process never runs, or is not allowed to terminate, in which case
+the exit code will be -1.
+@end itemize
+
+This option is useful in conjunction with @samp{-batch} or @samp{-batch-silent},
+when @value{GDBN} is being used as a remote program loader or simulator
+interface.
+
 @item -nowindows
 @itemx -nw
 @cindex @code{--nowindows}
index 4c2a78d2dbc33cbefd374edae41d8478809eb586..fab0a962adeea0012c0cf72c5caebbf03e97afd5 100644 (file)
@@ -46,6 +46,7 @@
 #include "observer.h"
 #include "language.h"
 #include "solib.h"
+#include "main.h"
 
 #include "gdb_assert.h"
 #include "mi/mi-common.h"
@@ -2931,6 +2932,8 @@ print_stop_reason (enum inferior_stop_reason stop_reason, int stop_info)
               async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY));
          ui_out_text (uiout, "\nProgram exited normally.\n");
        }
+      /* Support the --return-child-result option.  */
+      return_child_result_value = stop_info;
       break;
     case SIGNAL_RECEIVED:
       /* Signal received. The signal table tells us to print about
index 5e912953da3bdb6cf1771d3a0d7cd1a933d0c23d..486b0ac5782ba122f56c8828703d461d64e9a946 100644 (file)
@@ -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}
     };
 
@@ -730,15 +737,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
@@ -838,6 +838,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 1c91d0770f87cbcdf89d025ed0bc4f48c933ae25..2f5e90cd67fb5788c8823f7040f7b4c1f49649c5 100644 (file)
@@ -32,4 +32,8 @@ struct captured_main_args
 
 extern int gdb_main (struct captured_main_args *);
 
+/* From main.c.  */
+extern int return_child_result;
+extern int return_child_result_value;
+
 #endif
index 98ad51b7f8ec1c4be604cf8a9efc40639050c7b5..e4fb84519d10d9ee146e8f416d0ae6ae6d0d34b3 100644 (file)
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -46,6 +46,7 @@
 #include "serial.h"
 #include "doublest.h"
 #include "gdb_assert.h"
+#include "main.h"
 
 /* readline include files */
 #include "readline/readline.h"
@@ -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;