Re: Timer

Marc Brünink <[email protected]>
Newsgroups gmane.comp.gdb.devel
Message-ID <[email protected]>
On May 7, 2013, at 4:48 PM, Pedro Alves wrote:

> On 05/07/2013 07:42 AM, Marc Brünink wrote:
>> 
>> On May 7, 2013, at 12:43 PM, Doug Evans wrote:
>> 
>>> On Mon, May 6, 2013 at 2:52 AM, Marc Brünink <[email protected]> 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
>>>> 4. Send SIGTRAP to debugged application
>>>> 5. continue
>>>> 
>>>> Actually, now that I think about it, I should have anticipated this behaviour.
>>>> Is there a better way to execute a piece of code at regular intervals?
> 
> You could also use another signal instead of SIGTRAP.

Yes, this is probably the way to go. However, I remember having some issues with different signals. Esp if an applications depends on the delivery of a signal and I use it to implement the timer interrupt. But I suppose using SIGPROF or something similar should be fine.

> 
>>> bash$ man setitimer
>> 
>> I suppose you are suggesting to modify either GDB or the application. This is exactly what I don't want. Any other way to accomplish this (using gdb)?
> 
> You could use LD_PRELOAD to inject a library that uses setitimer into your program.

Possible, but contradicts the gdb-only approach. 


> I guess you could do it with gdb python scripting too.

This would be nice but does not work. As far as I remember there is a sigsupend in linux-nat.c which will thwart using a simple threading.Timer. But I might be wrong here. Whatever the reason, it does not work.


Marc
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.