From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27829 invoked by alias); 3 Jun 2011 15:26:26 -0000 Received: (qmail 27784 invoked by uid 22791); 3 Jun 2011 15:26:24 -0000 X-SWARE-Spam-Status: No, hits=-6.9 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 03 Jun 2011 15:26:09 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p53FPxHH014169 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 3 Jun 2011 11:25:59 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p53FPxet026851; Fri, 3 Jun 2011 11:25:59 -0400 Received: from opsy.redhat.com (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id p53FPwDX028352; Fri, 3 Jun 2011 11:25:58 -0400 Received: by opsy.redhat.com (Postfix, from userid 500) id BDA4E37817D; Fri, 3 Jun 2011 09:25:57 -0600 (MDT) From: Tom Tromey To: Eli Zaretskii Cc: pedro@codesourcery.com, gdb-patches@sourceware.org Subject: Re: RFA: fix PR mi/12661 References: <201104271926.30493.pedro@codesourcery.com> <201106021834.58440.pedro@codesourcery.com> <831uzceyzr.fsf@gnu.org> <83wrh4dj0a.fsf@gnu.org> Date: Fri, 03 Jun 2011 15:26:00 -0000 In-Reply-To: <83wrh4dj0a.fsf@gnu.org> (Eli Zaretskii's message of "Fri, 03 Jun 2011 00:24:21 +0300") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2011-06/txt/msg00054.txt.bz2 >>>>> "Eli" == Eli Zaretskii writes: Eli> Yes, that'd be good. Alternatively, you could say Eli> The value of the @code{exit-code} field is the exit code of the inferior Here is what I am checking in. Tom 2011-06-03 Tom Tromey * python/py-inferior.c (python_inferior_exit): Use inferior's exit code fields. * python/py-exitedevent.c (create_exited_event_object): Change type of 'exit_code'. Optionally add exit_code attribute. (emit_exited_event): Change type of 'exit_code'. * python/py-event.h (emit_exited_event): Update. * mi/mi-interp.c (mi_inferior_exit): Print exit code. * infrun.c (handle_inferior_event): Set exit code fields on inferior. * inferior.h (struct inferior) : New fields. * inferior.c (exit_inferior_1): Initialize new fields. 2011-06-03 Tom Tromey * gdb.texinfo (GDB/MI Async Records): Document 'exit-code' field. (Events In Python): Note that exit_code is optional. Index: inferior.c =================================================================== RCS file: /cvs/src/src/gdb/inferior.c,v retrieving revision 1.28 diff -u -r1.28 inferior.c --- inferior.c 27 May 2011 18:26:19 -0000 1.28 +++ inferior.c 3 Jun 2011 15:17:42 -0000 @@ -281,6 +281,9 @@ inf->vfork_parent->vfork_child = NULL; inf->vfork_parent = NULL; } + + inf->has_exit_code = 0; + inf->exit_code = 0; } void Index: inferior.h =================================================================== RCS file: /cvs/src/src/gdb/inferior.h,v retrieving revision 1.159 diff -u -r1.159 inferior.h --- inferior.h 26 May 2011 18:23:31 -0000 1.159 +++ inferior.h 3 Jun 2011 15:17:42 -0000 @@ -517,6 +517,11 @@ /* Private data used by the target vector implementation. */ struct private_inferior *private; + /* HAS_EXIT_CODE is true if the inferior exited with an exit code. + In this case, the EXIT_CODE field is also valid. */ + int has_exit_code; + LONGEST exit_code; + /* We keep a count of the number of times the user has requested a particular syscall to be tracked, and pass this information to the target. This lets capable targets implement filtering directly. */ Index: infrun.c =================================================================== RCS file: /cvs/src/src/gdb/infrun.c,v retrieving revision 1.490 diff -u -r1.490 infrun.c --- infrun.c 30 May 2011 18:04:32 -0000 1.490 +++ infrun.c 3 Jun 2011 15:17:43 -0000 @@ -3308,6 +3308,11 @@ that the user can inspect this again later. */ set_internalvar_integer (lookup_internalvar ("_exitcode"), (LONGEST) ecs->ws.value.integer); + + /* Also record this in the inferior itself. */ + current_inferior ()->has_exit_code = 1; + current_inferior ()->exit_code = (LONGEST) ecs->ws.value.integer; + gdb_flush (gdb_stdout); target_mourn_inferior (); singlestep_breakpoints_inserted_p = 0; Index: doc/gdb.texinfo =================================================================== RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v retrieving revision 1.840 diff -u -r1.840 gdb.texinfo --- doc/gdb.texinfo 17 May 2011 13:29:38 -0000 1.840 +++ doc/gdb.texinfo 3 Jun 2011 15:17:48 -0000 @@ -22127,7 +22127,9 @@ @item events.exited Emits @code{events.ExitedEvent} which indicates that the inferior has exited. -@code{events.ExitedEvent} has one attribute: +@code{events.ExitedEvent} has one optional attribute. This attribute +will exist only in the case that the inferior exited with some +status. @table @code @defivar ExitedEvent exit_code An integer representing the exit code which the inferior has returned. @@ -25199,11 +25201,12 @@ @value{GDBN} identifier of the thread group. The @var{pid} field contains process identifier, specific to the operating system. -@itemx =thread-group-exited,id="@var{id}" +@item =thread-group-exited,id="@var{id}"[,exit-code="@var{code}"] A thread group is no longer associated with a running program, either because the program has exited, or because it was detached from. The @var{id} field contains the @value{GDBN} identifier of the -thread group. +thread group. @var{code} is the exit code of the inferior; it exists +only when the inferior exited with some code. @item =thread-created,id="@var{id}",group-id="@var{gid}" @itemx =thread-exited,id="@var{id}",group-id="@var{gid}" Index: mi/mi-interp.c =================================================================== RCS file: /cvs/src/src/gdb/mi/mi-interp.c,v retrieving revision 1.64 diff -u -r1.64 mi-interp.c --- mi/mi-interp.c 27 Apr 2011 10:17:37 -0000 1.64 +++ mi/mi-interp.c 3 Jun 2011 15:17:48 -0000 @@ -366,8 +366,14 @@ struct mi_interp *mi = top_level_interpreter_data (); target_terminal_ours (); - fprintf_unfiltered (mi->event_channel, "thread-group-exited,id=\"i%d\"", - inf->num); + if (inf->has_exit_code) + fprintf_unfiltered (mi->event_channel, + "thread-group-exited,id=\"i%d\",exit-code=\"%s\"", + inf->num, int_string (inf->exit_code, 8, 0, 0, 1)); + else + fprintf_unfiltered (mi->event_channel, + "thread-group-exited,id=\"i%d\"", inf->num); + gdb_flush (mi->event_channel); } Index: python/py-event.h =================================================================== RCS file: /cvs/src/src/gdb/python/py-event.h,v retrieving revision 1.1 diff -u -r1.1 py-event.h --- python/py-event.h 5 Feb 2011 05:27:23 -0000 1.1 +++ python/py-event.h 3 Jun 2011 15:17:48 -0000 @@ -104,7 +104,7 @@ } event_object; extern int emit_continue_event (ptid_t ptid); -extern int emit_exited_event (LONGEST exit_code); +extern int emit_exited_event (const LONGEST *exit_code); extern int evpy_emit_event (PyObject *event, eventregistry_object *registry); Index: python/py-exitedevent.c =================================================================== RCS file: /cvs/src/src/gdb/python/py-exitedevent.c,v retrieving revision 1.1 diff -u -r1.1 py-exitedevent.c --- python/py-exitedevent.c 5 Feb 2011 05:27:23 -0000 1.1 +++ python/py-exitedevent.c 3 Jun 2011 15:17:48 -0000 @@ -21,8 +21,8 @@ static PyTypeObject exited_event_object_type; -PyObject * -create_exited_event_object (LONGEST exit_code) +static PyObject * +create_exited_event_object (const LONGEST *exit_code) { PyObject *exited_event; @@ -31,9 +31,10 @@ if (!exited_event) goto fail; - if (evpy_add_attribute (exited_event, - "exit_code", - PyLong_FromLongLong (exit_code)) < 0) + if (exit_code + && evpy_add_attribute (exited_event, + "exit_code", + PyLong_FromLongLong (*exit_code)) < 0) goto fail; return exited_event; @@ -47,7 +48,7 @@ will create a new Python exited event object. */ int -emit_exited_event (LONGEST exit_code) +emit_exited_event (const LONGEST *exit_code) { PyObject *event; Index: python/py-inferior.c =================================================================== RCS file: /cvs/src/src/gdb/python/py-inferior.c,v retrieving revision 1.8 diff -u -r1.8 py-inferior.c --- python/py-inferior.c 19 May 2011 18:41:23 -0000 1.8 +++ python/py-inferior.c 3 Jun 2011 15:17:48 -0000 @@ -112,18 +112,14 @@ python_inferior_exit (struct inferior *inf) { struct cleanup *cleanup; - LONGEST exit_code = -1; - ptid_t ptidp; - struct target_waitstatus status; + const LONGEST *exit_code = NULL; cleanup = ensure_python_env (target_gdbarch, current_language); - get_last_target_status (&ptidp, &status); + if (inf->has_exit_code) + exit_code = &inf->exit_code; - exit_code = status.value.integer; - - if (exit_code >= 0 - && emit_exited_event (exit_code) < 0) + if (emit_exited_event (exit_code) < 0) gdbpy_print_stack (); do_cleanups (cleanup);