Re: [PATCH] PR/12691 Add the inferior to Python exited event

Kevin Pouget
2011-09-19T10:16:37Z

[-- Attachment #1: Type: text/plain, Size: 2454 bytes --]

On Wed, Aug 31, 2011 at 5:50 PM, Tom Tromey <tromey@redhat.com> wrote:
>>>>>> "Kevin" == Kevin Pouget <kevin.pouget@gmail.com> writes:
>
> Kevin> this patch was not explicitly accepted, could you please review this
> Kevin> version updated against the last trunk?
>
> Code bits are ok.  Thanks.
>
> Tom

Hello,

There was a discrepancy between the version of the patch you approved
(http://sourceware.org/ml/gdb-patches/2011-08/msg00659/0001-PR-12691-Add-the-inferior-to-Python-exited-event)
and the one I originally submitted (I certainly missed a step during
the April->August update in the git tree):

gdb/doc/gdb.texinfo | 10 ++++++----
gdb/python/py-exitedevent.c | 6 ++++++
gdb/testsuite/gdb.python/py-events.c | 1 +
gdb/testsuite/gdb.python/py-events.exp | 11 ++++++++++-
gdb/testsuite/gdb.python/py-events.py | 1 +
5 files changed, 24 insertions(+), 5 deletions(-)

and

> gdb/doc/gdb.texinfo | 12 ++++++++----
> gdb/python/py-event.h | 2 +-
> gdb/python/py-exitedevent.c | 13 ++++++++++---
> gdb/python/py-inferior.c | 2 +-

gdb/testsuite/gdb.python/py-events.c | 1 +
gdb/testsuite/gdb.python/py-events.exp | 11 ++++++++++-
gdb/testsuite/gdb.python/py-events.py | 1 +

so I think it has to be re-approved.
There is no regression on x86_64 against the up-to-date GIT tree and
the generated PDF looks as expected.

Thanks,

Kevin

(I can't build the CVS tree because of missing ".deps/*.Po" files from
GDB/binutils, don't know where the problem comes from)

2011-09-20 Kevin Pouget <kevin.pouget@st.com>

PR python/12691: Add the inferior to Python exited event
* python/py-exitedevent.c (create_exited_event_object): Add inferior
to exited_event.
* python/py-event.h (emit_exited_event): Likewise
* python/-inferior.c (python_inferior_exit): Likewise

2011-09-01 Kevin Pouget <kevin.pouget@st.com>

PR python/12691: Add the inferior to Python exited event
* gdb.python/py-events.exp: Test the inferior attribute of exited
event with a fork.
* gdb.python/py-events.py: Print inferior number on exit.
* gdb.python/py-events.c: Fork the inferior.

2011-09-01 Kevin Pouget <kevin.pouget@st.com>

PR python/12691: Add the inferior to Python exited event
* gdb.texinfo (Events In Python): Describe exited inferior attribute.

[-- Attachment #2: 0001-PR-12691-Add-the-inferior-to-Python-exited-event.patch --]
[-- Type: text/x-patch, Size: 5631 bytes --]

From e3a5558105530ba0c95ae0f5af1c98bc6f04e08a Mon Sep 17 00:00:00 2001
From: Kevin Pouget <kevin.pouget@st.com>
Date: Mon, 19 Sep 2011 11:31:02 +0200
Subject: [PATCH] PR/12691 Add the inferior to Python exited event

---
gdb/doc/gdb.texinfo | 12 ++++++++----
gdb/python/py-event.h | 2 +-
gdb/python/py-exitedevent.c | 13 ++++++++++---
gdb/python/py-inferior.c | 2 +-
gdb/testsuite/gdb.python/py-events.c | 1 +
gdb/testsuite/gdb.python/py-events.exp | 11 ++++++++++-
gdb/testsuite/gdb.python/py-events.py | 1 +
7 files changed, 32 insertions(+), 10 deletions(-)

diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 051377d..e55efb1 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -22289,12 +22289,16 @@ inherited attribute refer to @code{gdb.ThreadEvent} above.

@item events.exited
Emits @code{events.ExitedEvent} which indicates that the inferior has exited.
-@code{events.ExitedEvent} has one optional attribute. This attribute
-will exist only in the case that the inferior exited with some
-status.
+@code{events.ExitedEvent} has two attributes:
@table @code
@defvar ExitedEvent.exit_code
-An integer representing the exit code which the inferior has returned.
+An integer representing the exit code, if available, which the inferior
+has returned. (The exit code could be unavailable if, for example,
+@value{GDBN} detaches from the inferior.) If the exit code is unavailable,
+the attribute does not exist.
+@end defvar
+@defvar ExitedEvent inferior
+A reference to the inferior which triggered the @code{exited} event.
@end defvar
@end table

diff --git a/gdb/python/py-event.h b/gdb/python/py-event.h
index f4b3ee2..49d7b6a 100644
--- a/gdb/python/py-event.h
+++ b/gdb/python/py-event.h
@@ -104,7 +104,7 @@ typedef struct
} event_object;

extern int emit_continue_event (ptid_t ptid);
-extern int emit_exited_event (const LONGEST *exit_code);
+extern int emit_exited_event (const LONGEST *exit_code, struct inferior *inf);

extern int evpy_emit_event (PyObject *event,
eventregistry_object *registry);
diff --git a/gdb/python/py-exitedevent.c b/gdb/python/py-exitedevent.c
index 08150e5..85ea2e2 100644
--- a/gdb/python/py-exitedevent.c
+++ b/gdb/python/py-exitedevent.c
@@ -22,9 +22,10 @@
static PyTypeObject exited_event_object_type;

static PyObject *
-create_exited_event_object (const LONGEST *exit_code)
+create_exited_event_object (const LONGEST *exit_code, struct inferior *inf)
{
PyObject *exited_event;
+ PyObject *inf_obj;

exited_event = create_event_object (&exited_event_object_type);

@@ -37,6 +38,12 @@ create_exited_event_object (const LONGEST *exit_code)
PyLong_FromLongLong (*exit_code)) < 0)
goto fail;

+ inf_obj = inferior_to_inferior_object (inf);
+ if (!inf_obj || evpy_add_attribute (exited_event,
+ "inferior",
+ inf_obj) < 0)
+ goto fail;
+
return exited_event;

fail:
@@ -48,14 +55,14 @@ create_exited_event_object (const LONGEST *exit_code)
will create a new Python exited event object. */

int
-emit_exited_event (const LONGEST *exit_code)
+emit_exited_event (const LONGEST *exit_code, struct inferior *inf)
{
PyObject *event;

if (evregpy_no_listeners_p (gdb_py_events.exited))
return 0;

- event = create_exited_event_object (exit_code);
+ event = create_exited_event_object (exit_code, inf);

if (event)
return evpy_emit_event (event, gdb_py_events.exited);
diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c
index 8ed3ea5..275caea 100644
--- a/gdb/python/py-inferior.c
+++ b/gdb/python/py-inferior.c
@@ -119,7 +119,7 @@ python_inferior_exit (struct inferior *inf)
if (inf->has_exit_code)
exit_code = &inf->exit_code;

- if (emit_exited_event (exit_code) < 0)
+ if (emit_exited_event (exit_code, inf) < 0)
gdbpy_print_stack ();

do_cleanups (cleanup);
diff --git a/gdb/testsuite/gdb.python/py-events.c b/gdb/testsuite/gdb.python/py-events.c
index ceb697e..665ca51 100644
--- a/gdb/testsuite/gdb.python/py-events.c
+++ b/gdb/testsuite/gdb.python/py-events.c
@@ -17,6 +17,7 @@
*/

int second(){
+ fork() ;
return 12;
}

diff --git a/gdb/testsuite/gdb.python/py-events.exp b/gdb/testsuite/gdb.python/py-events.exp
index 2d2139d..18419fa 100644
--- a/gdb/testsuite/gdb.python/py-events.exp
+++ b/gdb/testsuite/gdb.python/py-events.exp
@@ -37,6 +37,8 @@ if ![runto_main ] then {
return -1
}

+gdb_test_no_output "set detach-on-fork off" ""
+
gdb_test "Test_Events" "Event testers registered."

gdb_breakpoint "first"
@@ -54,4 +56,11 @@ all threads stopped"
#test exited event.
gdb_test "continue" ".*event type: continue.*
.*event type: exit.*
-.*exit code: 12.*"
+.*exit code: 12.*
+.*exit inf: 1.*" "Inferior 1 terminated."
+
+gdb_test "inferior 2" ".*Switching to inferior 2.*"
+gdb_test "continue" ".*event type: continue.*
+.*event type: exit.*
+.*exit code: 12.*
+.*exit inf: 2.*" "Inferior 2 terminated."
diff --git a/gdb/testsuite/gdb.python/py-events.py b/gdb/testsuite/gdb.python/py-events.py
index 10aea4f..6bdd935 100644
--- a/gdb/testsuite/gdb.python/py-events.py
+++ b/gdb/testsuite/gdb.python/py-events.py
@@ -43,6 +43,7 @@ def exit_handler (event):
if (isinstance (event, gdb.ExitedEvent)):
print "event type: exit"
print "exit code: %d" % (event.exit_code)
+ print "exit inf: %d" % (event.inferior.num)

def continue_handler (event):
if (isinstance (event, gdb.ContinueEvent)):
--
1.7.6