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]

Re: Exit code of exited inferiors


On 05/22/2013 10:47 PM, Simon Marchi wrote:
> 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.

I've long wished that info threads would list the reason the
thread had last stopped.  E.g, with non-stop, say you're debugging
thread #1 and other threads stop for events (signals, breakpoints, etc.).
When you're done with whatever you were doing to thread #1, the only
option you have to see what happened to the other threads is to read
the back log, as with "info threads" you can see which threads are stopped,
but not what they stopped for.  There's also "info program", but that only
really works for all-stop.

I put getting at the inferiors' exit code post-mortem in the same
itch bucket.  :-)  So thanks for this little push in that direction.

> 
> 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 think that's fine.

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

Thanks.  As this includes a new MI attribute, it'll need to be documented
in the manual, mentioned in gdb/NEWS as well.

A new test case for the testsuite would be good too.

Lastly, pro forma: What's your copyright assignment status?  I don't see
your name in the copyright.list.  :-/  This patch as is is borderline
small enough, but the manual/NEWS/etc. changes would make it definitely
legally significant.

> 
> 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);

-- 
Pedro Alves


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