old-cross-binutils/gdb/testsuite/gdb.python/py-events.py
Doug Evans dc6c87175b New python events: infcall, 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 10:59:08 -08:00

118 lines
4.4 KiB
Python

# Copyright (C) 2010-2014 Free Software Foundation, Inc.
# 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)):
print ("event type: stop")
if (isinstance (event, gdb.SignalEvent)):
print ("stop reason: signal")
print ("stop signal: %s" % (event.stop_signal))
if ( event.inferior_thread is not None) :
print ("thread num: %s" % (event.inferior_thread.num))
def breakpoint_stop_handler (event):
if (isinstance (event, gdb.StopEvent)):
print ("event type: stop")
if (isinstance (event, gdb.BreakpointEvent)):
print ("stop reason: breakpoint")
print ("first breakpoint number: %s" % (event.breakpoint.number))
for bp in event.breakpoints:
print ("breakpoint number: %s" % (bp.number))
if ( event.inferior_thread is not None) :
print ("thread num: %s" % (event.inferior_thread.num))
else:
print ("all threads stopped")
def exit_handler (event):
assert (isinstance (event, gdb.ExitedEvent))
print ("event type: exit")
print ("exit code: %d" % (event.exit_code))
print ("exit inf: %d" % (event.inferior.num))
print ("dir ok: %s" % str('exit_code' in dir(event)))
def continue_handler (event):
assert (isinstance (event, gdb.ContinueEvent))
print ("event type: continue")
if ( event.inferior_thread is not None) :
print ("thread num: %s" % (event.inferior_thread.num))
def new_objfile_handler (event):
assert (isinstance (event, gdb.NewObjFileEvent))
print ("event type: new_objfile")
print ("new objfile name: %s" % (event.new_objfile.filename))
def clear_objfiles_handler (event):
assert (isinstance (event, gdb.ClearObjFilesEvent))
print ("event type: clear_objfiles")
print ("progspace: %s" % (event.progspace.filename))
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))
class test_events (gdb.Command):
"""Test events."""
def __init__ (self):
gdb.Command.__init__ (self, "test-events", gdb.COMMAND_STACK)
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)
gdb.events.inferior_call.connect (inferior_call_handler)
gdb.events.memory_changed.connect (memory_changed_handler)
gdb.events.register_changed.connect (register_changed_handler)
print ("Event testers registered.")
test_events ()
class test_newobj_events (gdb.Command):
"""NewObj events."""
def __init__ (self):
gdb.Command.__init__ (self, "test-objfile-events", gdb.COMMAND_STACK)
def invoke (self, arg, from_tty):
gdb.events.new_objfile.connect (new_objfile_handler)
gdb.events.clear_objfiles.connect (clear_objfiles_handler)
print ("Object file events registered.")
test_newobj_events ()