aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorAndrew Stubbs <andrew.stubbs@st.com>2005-11-04 11:49:12 +0000
committerAndrew Stubbs <andrew.stubbs@st.com>2005-11-04 11:49:12 +0000
commit4b0ad76243714b959a63aa42649fa3cf6c886ef2 (patch)
tree510a04027769d4e032c7766378ed9475a363f296 /gdb
parentf6235d4cfac03962a505970ef92f231860c58517 (diff)
downloadfsf-binutils-gdb-4b0ad76243714b959a63aa42649fa3cf6c886ef2.zip
fsf-binutils-gdb-4b0ad76243714b959a63aa42649fa3cf6c886ef2.tar.gz
fsf-binutils-gdb-4b0ad76243714b959a63aa42649fa3cf6c886ef2.tar.bz2
2005-11-04 Andrew Stubbs <andrew.stubbs@st.com>
* 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. docs/ * gdb.texinfo (Choosing modes): Add --return-child-result.
Diffstat (limited to 'gdb')
-rw-r--r--gdb/ChangeLog10
-rw-r--r--gdb/doc/ChangeLog5
-rw-r--r--gdb/doc/gdb.texinfo21
-rw-r--r--gdb/infrun.c5
-rw-r--r--gdb/main.c18
-rw-r--r--gdb/top.c3
6 files changed, 54 insertions, 8 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 9be144f..67c8f01 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,13 @@
+2005-11-04 Andrew Stubbs <andrew.stubbs@st.com>
+
+ * 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.
+
2005-11-03 Wu Zhou <woodzltc@cn.ibm.com>
Checked in by Elena Zannoni <ezannoni@redhat.com>
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index f62c312..9f4234f 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,8 @@
+2005-11-04 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.
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 75ae4ef..5402d6a 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -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}
diff --git a/gdb/infrun.c b/gdb/infrun.c
index 4c2a78d..f1ebc3e 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -2931,6 +2931,11 @@ 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. */
+ 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
diff --git a/gdb/main.c b/gdb/main.c
index 5e91295..486b0ac 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -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\
diff --git a/gdb/top.c b/gdb/top.c
index 98ad51b..a8bba83 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -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;