From: Kevin Pouget Date: Tue, 4 Oct 2011 08:04:13 +0000 (+0000) Subject: 2011-10-04 Kevin Pouget X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=cb6be26b8b0a1bf6bb4da1eb5841119d73220fd5;p=binutils-gdb.git 2011-10-04 Kevin Pouget 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-10-04 Kevin Pouget 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-10-04 Kevin Pouget PR python/12691: Add the inferior to Python exited event * gdb.texinfo (Events In Python): Describe exited inferior attribute. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 191ac2f9af0..5ea2c05f67d 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,11 @@ +2011-10-04 Kevin Pouget + + 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-10-03 Joel Brobecker * ada-tasks.c (print_ada_task_info): Add "thread-id" field diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog index 262c656a83b..4ccd64ca196 100644 --- a/gdb/doc/ChangeLog +++ b/gdb/doc/ChangeLog @@ -1,3 +1,8 @@ +2011-10-04 Kevin Pouget + + PR python/12691: Add the inferior to Python exited event + * gdb.texinfo (Events In Python): Describe exited inferior attribute. + 2011-10-03 Joel Brobecker * gdb.texinfo (GDB/MI Miscellaneous Commands): Minor diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index aa7cdca457f..dd0f7f61c0d 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -22306,12 +22306,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 f4b3ee25696..49d7b6a78ac 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 08150e567f9..85ea2e2a81b 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 8ed3ea5ef55..275caea8ba7 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/ChangeLog b/gdb/testsuite/ChangeLog index 9b5ff14c394..125316eaa0c 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2011-10-04 Kevin Pouget + + 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-10-03 Edjunior Machado * gdb.base/jit.exp: Add testcase name to log message diff --git a/gdb/testsuite/gdb.python/py-events.c b/gdb/testsuite/gdb.python/py-events.c index ceb697ea279..665ca51ec54 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 2d2139d1fd2..18419fae1fa 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 10aea4f5d21..6bdd935f3a5 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)):