This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Question about GDB event mechanism
- From: Siva Chandra <sivachandra at google dot com>
- To: gdb at sourceware dot org
- Date: Fri, 4 May 2012 00:12:04 +0530
- Subject: Question about GDB event mechanism
Hi all,
I am trying to understand the event mechanism when used in Python
code. For example, set a breakpoint at main and run 'tcmd' after
sourcing the following Python script:
<CODE>
import gdb
def bp_handler(bp_event):
print "Hello, BreakPoint!"
gdb.events.stop.connect(bp_handler)
class Cmd(gdb.Command):
def __init__(self):
super(Cmd, self).__init__("tcmd", gdb.COMMAND_OBSCURE)
def invoke(self, arg, from_tty):
gdb.execute("run", to_string=True)
print "End of 'tcmd'"
Cmd()
</CODE>
I would expect "Hello, Breakpoint!" to be printed, but it is not being
printed as 'run' is executed via 'execute_command_to_string' which
will reset gdb_stdout only after 'execute_command' returns. The
notification of the breakpoint event is sent via 'normal_stop' before
'execute_command' returns.
Above was a simple example, but consider a case where a user is trying
to execute commands like 'step' or 'up' as part of the stop event
callback: For a long time, I didn't understand what was going when I
did such things (I of course had a very different expectations).
Hence, should the current behavior be documented or fixed?
Thanks,
Siva Chandra