This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Exit code of exited inferiors


Hi,

The current behaviour in Eclipse's CDT when a debugged process exits normally
is to remove it from the list. We would like to change it so that they stay in
the process list after they exit, probably showing them as "Exited" and
displaying the exit code.

The problem is there is no way to query GDB for the exit code of an exited
inferior. One way to do it would be to catch the thread-group-exited MI event,
which contains the exit code. It means that the CDT view would be required to
keep a state and could not be reconstructed from scratch, simply by querying
GDB. The current design seems to avoid keeping information in the view that GDB
can't give us.

For this reason, I suggest adding an exit-code field in the -list-thread-group
response when appropriate. Appropriate meaning after an inferior process has
exited, and before it is run again. This field would contain the exit code for
the last run of the inferior. Doing so would require a little modification, as
the exit_code and has_exit_code fields in struct inferior are wiped in
exit_inferior_1. I think it would be reasonable to keep them around until the
inferior is started again.

Is there any problem with this? There might be some cases where it does not
make sense. For example, after the inferior exits, if you change the executable
(using the "file" command), you have a state where the exit code does not match
the executable anymore. Not sure if this is an issue.

I am sending this patch to illustrate the proposed change. Thanks for your
comments!

Simon

2013-05-22  Simon Marchi  <simon.marchi@ericsson.com>

	* gdb/inferior.c (exit_inferior_1): Remove exit code clear.
	(inferior_appeared): Add exit code clear.
	* gdb/mi/mi-main.c (print_one_inferior): Add printing of the exit code.

---
 gdb/inferior.c   |    4 ++--
 gdb/mi/mi-main.c |    2 ++
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/gdb/inferior.c b/gdb/inferior.c
index ed6b626..a145780 100644
--- a/gdb/inferior.c
+++ b/gdb/inferior.c
@@ -275,8 +275,6 @@ exit_inferior_1 (struct inferior *inftoex, int silent)
       inf->vfork_child = NULL;
     }
 
-  inf->has_exit_code = 0;
-  inf->exit_code = 0;
   inf->pending_detach = 0;
 }
 
@@ -322,6 +320,8 @@ void
 inferior_appeared (struct inferior *inf, int pid)
 {
   inf->pid = pid;
+  inf->has_exit_code = 0;
+  inf->exit_code = 0;
 
   observer_notify_inferior_appeared (inf);
 }
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index 94fda8f..204ba34 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -568,6 +568,8 @@ print_one_inferior (struct inferior *inferior, void *xdata)
 
       ui_out_field_fmt (uiout, "id", "i%d", inferior->num);
       ui_out_field_string (uiout, "type", "process");
+      if (inferior->has_exit_code)
+	ui_out_field_int (uiout, "exit-code", inferior->exit_code);
       if (inferior->pid != 0)
 	ui_out_field_int (uiout, "pid", inferior->pid);
 
-- 
1.7.9.5


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]