From: Phil Muldoon <pmuldoon@redhat.com>
To: "Marc Brünink" <marc@nus.edu.sg>
Cc: gdb <gdb@sourceware.org>
Subject: Re: Timer
Date: Tue, 07 May 2013 13:28:00 -0000 [thread overview]
Message-ID: <51890165.3070701@redhat.com> (raw)
In-Reply-To: <A941B6D9-B0CA-4EC2-AEFE-476014555337@nus.edu.sg>
On 06/05/13 10:52, Marc Brünink wrote:
> I want to execute a piece of code at regular intervals. Actually I'm sampling $pc.
> (let's not go into detail why I use gdb)
>
> My current solution just starts another process that sends a SIGTRAP to the debugged application. Using a simple script I can print the $pc.
>
> However, I just realised that this approach does not work too well. If gdb is stopped due to a breakpoint it will interpret the received SIGTRAP as another hit of the very same breakpoint.
>
> Reproduce:
> 1. Attach to any program
> 2. Create any breakpoint
> 3. Wait until breakpoint is hit
> 5. continue
You can a little of this right now with the GDB Python API by writing a
breakpoint in Python that implements the "stop" callback. I know you
mentioned only within the confines of GDB, but the Python API is
provided as standard (of course, you have to have Python installed on
the system).
From:
http://sourceware.org/gdb/current/onlinedocs/gdb/Breakpoints-In-Python.html#Breakpoints-In-Python
class MyBreakpoint(gdb.Breakpoint):
def stop(self):
pc = gdb.parse_and_eval("(long) $pc")
print "0x"+long(pc).__format__("x")
return False
b = MyBreakpoint("foo.c:42")
In the "stop" callback, if the callback returns "False", the inferior
is continued (if "True", the inferior is stopped). If you wanted to
make the breakpoint depend on the state of the inferior, you can use
the Breakpoint.condition string to insert a condition.
> 4. Send SIGTRAP to debugged application
But I am not sure what this relates to a timer event, so I am probably
not fully understanding what you want. There are two other areas of
the Python API which may interest you:
Events in GDB/Python:
http://sourceware.org/gdb/current/onlinedocs/gdb/Events-In-Python.html#Events-In-Python
And inserting objects into GDB's event loop
gdb.post_event()
http://sourceware.org/gdb/current/onlinedocs/gdb/Basic-Python.html#Basic-Python
Unfortunately post_event() is not deterministic. The callable object
is called when GDB gets around to processing that event in the queue.
There is no way to arbitrarily run an event according to a timer, at
least in the Python API; it is event based only (right now).
Cheers,
Phil
prev parent reply other threads:[~2013-05-07 13:28 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-06 9:52 Timer Marc Brünink
2013-05-07 4:43 ` Timer Doug Evans
2013-05-07 6:42 ` Timer Marc Brünink
2013-05-07 8:48 ` Timer Pedro Alves
2013-05-07 10:18 ` Timer Marc Brünink
2013-05-07 10:51 ` Timer Pedro Alves
2013-05-07 13:44 ` Timer Tom Tromey
2013-05-07 13:28 ` Phil Muldoon [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=51890165.3070701@redhat.com \
--to=pmuldoon@redhat.com \
--cc=gdb@sourceware.org \
--cc=marc@nus.edu.sg \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox