public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* Question about GDB event mechanism
@ 2012-05-03 18:42 Siva Chandra
  2012-05-09 20:34 ` Tom Tromey
  0 siblings, 1 reply; 2+ messages in thread
From: Siva Chandra @ 2012-05-03 18:42 UTC (permalink / raw)
  To: gdb

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Question about GDB event mechanism
  2012-05-03 18:42 Question about GDB event mechanism Siva Chandra
@ 2012-05-09 20:34 ` Tom Tromey
  0 siblings, 0 replies; 2+ messages in thread
From: Tom Tromey @ 2012-05-09 20:34 UTC (permalink / raw)
  To: Siva Chandra; +Cc: gdb

>>>>> "Siva" == Siva Chandra <sivachandra@google.com> writes:

Siva> I am trying to understand the event mechanism when used in Python
Siva> code.

I'm sorry about the delay in my reply.
I was away.

Siva> I would expect "Hello, Breakpoint!" to be printed, but it is not being
Siva> printed as 'run' is executed via 'execute_command_to_string' which
Siva> will reset gdb_stdout only after 'execute_command' returns.  The
Siva> notification of the breakpoint event is sent via 'normal_stop' before
Siva> 'execute_command' returns.
[...]
Siva> Hence, should the current behavior be documented or fixed?

I think it is a bug.
In my view, the events should trigger for all stops, regardless of where
the command originated.

Tom

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-05-09 20:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-03 18:42 Question about GDB event mechanism Siva Chandra
2012-05-09 20:34 ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).