2016-01-01 04:33:14 +00:00
|
|
|
# Copyright (C) 2010-2016 Free Software Foundation, Inc.
|
2011-02-05 05:27:23 +00:00
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
# This file is part of the GDB testsuite. It tests python pretty
|
|
|
|
# printers.
|
|
|
|
import gdb
|
|
|
|
|
|
|
|
def signal_stop_handler (event):
|
|
|
|
if (isinstance (event, gdb.StopEvent)):
|
2012-12-10 21:22:21 +00:00
|
|
|
print ("event type: stop")
|
2011-02-05 05:27:23 +00:00
|
|
|
if (isinstance (event, gdb.SignalEvent)):
|
2012-12-10 21:22:21 +00:00
|
|
|
print ("stop reason: signal")
|
|
|
|
print ("stop signal: %s" % (event.stop_signal))
|
2011-02-05 05:27:23 +00:00
|
|
|
if ( event.inferior_thread is not None) :
|
2012-12-10 21:22:21 +00:00
|
|
|
print ("thread num: %s" % (event.inferior_thread.num))
|
2011-02-05 05:27:23 +00:00
|
|
|
|
|
|
|
def breakpoint_stop_handler (event):
|
|
|
|
if (isinstance (event, gdb.StopEvent)):
|
2012-12-10 21:22:21 +00:00
|
|
|
print ("event type: stop")
|
2011-02-05 05:27:23 +00:00
|
|
|
if (isinstance (event, gdb.BreakpointEvent)):
|
2012-12-10 21:22:21 +00:00
|
|
|
print ("stop reason: breakpoint")
|
|
|
|
print ("first breakpoint number: %s" % (event.breakpoint.number))
|
2011-09-15 12:27:20 +00:00
|
|
|
for bp in event.breakpoints:
|
2012-12-10 21:22:21 +00:00
|
|
|
print ("breakpoint number: %s" % (bp.number))
|
2011-02-05 05:27:23 +00:00
|
|
|
if ( event.inferior_thread is not None) :
|
2012-12-10 21:22:21 +00:00
|
|
|
print ("thread num: %s" % (event.inferior_thread.num))
|
2011-02-05 05:27:23 +00:00
|
|
|
else:
|
2012-12-10 21:22:21 +00:00
|
|
|
print ("all threads stopped")
|
2011-02-05 05:27:23 +00:00
|
|
|
|
|
|
|
def exit_handler (event):
|
2013-09-04 23:49:21 +00:00
|
|
|
assert (isinstance (event, gdb.ExitedEvent))
|
|
|
|
print ("event type: exit")
|
2012-12-10 21:22:21 +00:00
|
|
|
print ("exit code: %d" % (event.exit_code))
|
|
|
|
print ("exit inf: %d" % (event.inferior.num))
|
|
|
|
print ("dir ok: %s" % str('exit_code' in dir(event)))
|
2011-02-05 05:27:23 +00:00
|
|
|
|
|
|
|
def continue_handler (event):
|
2013-09-04 23:49:21 +00:00
|
|
|
assert (isinstance (event, gdb.ContinueEvent))
|
|
|
|
print ("event type: continue")
|
2011-02-05 05:27:23 +00:00
|
|
|
if ( event.inferior_thread is not None) :
|
2012-12-10 21:22:21 +00:00
|
|
|
print ("thread num: %s" % (event.inferior_thread.num))
|
2011-02-05 05:27:23 +00:00
|
|
|
|
2011-10-07 07:38:30 +00:00
|
|
|
def new_objfile_handler (event):
|
2013-09-04 23:49:21 +00:00
|
|
|
assert (isinstance (event, gdb.NewObjFileEvent))
|
|
|
|
print ("event type: new_objfile")
|
|
|
|
print ("new objfile name: %s" % (event.new_objfile.filename))
|
2011-10-07 07:38:30 +00:00
|
|
|
|
2014-10-17 18:12:17 +00:00
|
|
|
def clear_objfiles_handler (event):
|
|
|
|
assert (isinstance (event, gdb.ClearObjFilesEvent))
|
|
|
|
print ("event type: clear_objfiles")
|
|
|
|
print ("progspace: %s" % (event.progspace.filename))
|
|
|
|
|
New python events: inferior call, register/memory changed.
gdb/ChangeLog:
* NEWS: Mention new Python events.
* Makefile.in (SUBDIR_PYTHON_OBS): Add py-infevents.o.
(SUBDIR_PYTHON_SRCS): Add py-infevents.c.
(py-infevents.o): New rule.
* doc/observer.texi (inferior_call_pre, inferior_call_post)
(memory_changed, register_changed): New observers.
* infcall.c (call_function_by_hand): Notify observer before and
after inferior call.
* python/py-event.h (inferior_call_kind): New enum.
(emit_inferior_call_event): New prototype.
(emit_register_changed_event): New prototype.
(emit_memory_changed_event): New prototype.
* python/py-events.h (events_object): New registries
inferior_call, memory_changed and register_changed.
* python/py-evts.c (gdbpy_initialize_py_events): Add the
inferior_call, memory_changed and register_changed registries.
* python/py-infevents.c: New.
* python/py-inferior.c (python_on_inferior_call_pre)
(python_on_inferior_call_post, python_on_register_change)
(python_on_memory_change): New functions.
(gdbpy_initialize_inferior): Attach python handler to new
observers.
* python/py-infthread.c(gdbpy_create_ptid_object): New.
(thpy_get_ptid) Use gdbpy_create_ptid_object.
* python/python-internal.h:
(gdbpy_create_ptid_object)
(gdbpy_initialize_inferior_call_pre_event)
(gdbpy_initialize_inferior_call_post_event)
(gdbpy_initialize_register_changed_event)
(gdbpy_initialize_memory_changed_event): New prototypes.
* python/python.c (_initialize_python): Initialize new events.
* valops.c (value_assign): Notify register_changed observer.
gdb/doc/ChangeLog:
* python.texi (Events In Python): Document new events
InferiorCallPreEvent, InferiorCallPostEvent, MemoryChangedEvent
and RegisterChangedEvent.
gdb/testsuite/ChangeLog:
* gdb.python/py-events.py (inferior_call_handler): New.
(register_changed_handler, memory_changed_handler): New.
(test_events.invoke): Register new handlers.
* gdb.python/py-events.exp: Add tests for inferior call,
memory_changed and register_changed events.
2014-12-02 19:15:29 +00:00
|
|
|
def inferior_call_handler (event):
|
|
|
|
if (isinstance (event, gdb.InferiorCallPreEvent)):
|
|
|
|
print ("event type: pre-call")
|
|
|
|
elif (isinstance (event, gdb.InferiorCallPostEvent)):
|
|
|
|
print ("event type: post-call")
|
|
|
|
else:
|
|
|
|
assert False
|
|
|
|
print ("ptid: %s" % (event.ptid,))
|
|
|
|
print ("address: 0x%x" % (event.address))
|
|
|
|
|
|
|
|
def register_changed_handler (event):
|
|
|
|
assert (isinstance (event, gdb.RegisterChangedEvent))
|
|
|
|
print ("event type: register-changed")
|
|
|
|
assert (isinstance (event.frame, gdb.Frame))
|
|
|
|
print ("frame: %s" % (event.frame))
|
|
|
|
print ("num: %s" % (event.regnum))
|
|
|
|
|
|
|
|
def memory_changed_handler (event):
|
|
|
|
assert (isinstance (event, gdb.MemoryChangedEvent))
|
|
|
|
print ("event type: memory-changed")
|
|
|
|
print ("address: %s" % (event.address))
|
|
|
|
print ("length: %s" % (event.length))
|
|
|
|
|
|
|
|
|
2011-02-05 05:27:23 +00:00
|
|
|
class test_events (gdb.Command):
|
|
|
|
"""Test events."""
|
|
|
|
|
|
|
|
def __init__ (self):
|
2013-09-04 23:49:21 +00:00
|
|
|
gdb.Command.__init__ (self, "test-events", gdb.COMMAND_STACK)
|
2011-02-05 05:27:23 +00:00
|
|
|
|
|
|
|
def invoke (self, arg, from_tty):
|
|
|
|
gdb.events.stop.connect (signal_stop_handler)
|
|
|
|
gdb.events.stop.connect (breakpoint_stop_handler)
|
|
|
|
gdb.events.exited.connect (exit_handler)
|
|
|
|
gdb.events.cont.connect (continue_handler)
|
New python events: inferior call, register/memory changed.
gdb/ChangeLog:
* NEWS: Mention new Python events.
* Makefile.in (SUBDIR_PYTHON_OBS): Add py-infevents.o.
(SUBDIR_PYTHON_SRCS): Add py-infevents.c.
(py-infevents.o): New rule.
* doc/observer.texi (inferior_call_pre, inferior_call_post)
(memory_changed, register_changed): New observers.
* infcall.c (call_function_by_hand): Notify observer before and
after inferior call.
* python/py-event.h (inferior_call_kind): New enum.
(emit_inferior_call_event): New prototype.
(emit_register_changed_event): New prototype.
(emit_memory_changed_event): New prototype.
* python/py-events.h (events_object): New registries
inferior_call, memory_changed and register_changed.
* python/py-evts.c (gdbpy_initialize_py_events): Add the
inferior_call, memory_changed and register_changed registries.
* python/py-infevents.c: New.
* python/py-inferior.c (python_on_inferior_call_pre)
(python_on_inferior_call_post, python_on_register_change)
(python_on_memory_change): New functions.
(gdbpy_initialize_inferior): Attach python handler to new
observers.
* python/py-infthread.c(gdbpy_create_ptid_object): New.
(thpy_get_ptid) Use gdbpy_create_ptid_object.
* python/python-internal.h:
(gdbpy_create_ptid_object)
(gdbpy_initialize_inferior_call_pre_event)
(gdbpy_initialize_inferior_call_post_event)
(gdbpy_initialize_register_changed_event)
(gdbpy_initialize_memory_changed_event): New prototypes.
* python/python.c (_initialize_python): Initialize new events.
* valops.c (value_assign): Notify register_changed observer.
gdb/doc/ChangeLog:
* python.texi (Events In Python): Document new events
InferiorCallPreEvent, InferiorCallPostEvent, MemoryChangedEvent
and RegisterChangedEvent.
gdb/testsuite/ChangeLog:
* gdb.python/py-events.py (inferior_call_handler): New.
(register_changed_handler, memory_changed_handler): New.
(test_events.invoke): Register new handlers.
* gdb.python/py-events.exp: Add tests for inferior call,
memory_changed and register_changed events.
2014-12-02 19:15:29 +00:00
|
|
|
gdb.events.inferior_call.connect (inferior_call_handler)
|
|
|
|
gdb.events.memory_changed.connect (memory_changed_handler)
|
|
|
|
gdb.events.register_changed.connect (register_changed_handler)
|
2012-12-10 21:22:21 +00:00
|
|
|
print ("Event testers registered.")
|
2011-02-05 05:27:23 +00:00
|
|
|
|
|
|
|
test_events ()
|
2011-10-07 07:38:30 +00:00
|
|
|
|
|
|
|
class test_newobj_events (gdb.Command):
|
|
|
|
"""NewObj events."""
|
|
|
|
|
|
|
|
def __init__ (self):
|
2013-09-04 23:49:21 +00:00
|
|
|
gdb.Command.__init__ (self, "test-objfile-events", gdb.COMMAND_STACK)
|
2011-10-07 07:38:30 +00:00
|
|
|
|
|
|
|
def invoke (self, arg, from_tty):
|
|
|
|
gdb.events.new_objfile.connect (new_objfile_handler)
|
2014-10-17 18:12:17 +00:00
|
|
|
gdb.events.clear_objfiles.connect (clear_objfiles_handler)
|
2013-09-04 23:49:21 +00:00
|
|
|
print ("Object file events registered.")
|
2011-10-07 07:38:30 +00:00
|
|
|
|
|
|
|
test_newobj_events ()
|