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

Kevin Pouget
2011-08-31T14:34:33Z

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

On Tue, Apr 26, 2011 at 10:22 AM, Kevin Pouget <kevin.pouget@gmail.com> wrote:
> On Mon, Apr 25, 2011 at 2:19 PM, Tom Tromey <tromey@redhat.com> wrote:
>>
>> >>>>> "Kevin" == Kevin Pouget <kevin.pouget@gmail.com> writes:
>>
>> Kevin> Following Tom's advise
>> Kevin> (http://sourceware.org/ml/gdb/2011-04/msg00116.html), here is a patch
>> Kevin> which hooks the inferior to the `exited' event object
>> Kevin> let me know what you think about it
>>
>> It looks pretty good, but I think it needs a couple small changes.
>>
>> Kevin> +  if (evpy_add_attribute (exited_event,
>> Kevin> +                          "inferior",
>> Kevin> +                          inferior_to_inferior_object (inf)) < 0)
>> Kevin> +    goto fail;
>>
>> This does not account for the possibility that
>> inferior_to_inferior_object could fail.  I think there has
>> to be a temporary object that is explicitly checked against NULL.
>
>
> done, it should only fail when the process runs out of space, so GDB
> must handle it somewhere else
>
>> Kevin> +gdb_test "continue" ".*event type: continue.*
>> Kevin> +.*event type: exit.*
>> Kevin> +.*exit code: 12.*
>> Kevin> +.*exit inf: 2.*"
>>
>> Pass a test name to gdb_test.
>
> right

Hello,

this patch was not explicitly accepted, could you please review this
version updated against the last trunk?
The doc was accepted, but I had to reshape the paragraph during the
update, Eli, could you please tell me what you think about it?

Cordially,

Kevin

2011-04-21 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-04-21 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-04-21 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 --]
[-- Type: application/octet-stream, Size: 3653 bytes --]

From 9caa3edc65ec1bef5ac54d676365c5595674ce7e Mon Sep 17 00:00:00 2001
From: Kevin Pouget <kevin.pouget@st.com>
Date: Wed, 31 Aug 2011 16:32:45 +0200
Subject: [PATCH] PR/12691 Add the inferior to Python exited event

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

diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 23b2a98..bbc7a7d 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -22285,12 +22285,14 @@ 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
@defivar ExitedEvent exit_code
-An integer representing the exit code which the inferior has returned.
+An integer representing the exit code which the inferior has returned. (Optional,
+will exist only in the case that the inferior exited with some status.)
+@end defivar
+@defivar ExitedEvent inferior
+A reference to the inferior which triggered the exited event.
@end defivar
@end table

diff --git a/gdb/python/py-exitedevent.c b/gdb/python/py-exitedevent.c
index 08150e5..5ee6eb8 100644
--- a/gdb/python/py-exitedevent.c
+++ b/gdb/python/py-exitedevent.c
@@ -37,6 +37,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:
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 e5d6daf..cdf4ae6 100644
--- a/gdb/testsuite/gdb.python/py-events.exp
+++ b/gdb/testsuite/gdb.python/py-events.exp
@@ -42,6 +42,8 @@ if ![runto_main ] then {
return -1
}

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

gdb_breakpoint "first"
@@ -56,4 +58,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 1 terminated."
diff --git a/gdb/testsuite/gdb.python/py-events.py b/gdb/testsuite/gdb.python/py-events.py
index 9f05b9f..b40f074 100644
--- a/gdb/testsuite/gdb.python/py-events.py
+++ b/gdb/testsuite/gdb.python/py-events.py
@@ -41,6 +41,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