Re: Timer

Marc Brünink
2013-05-07T10:18:24Z

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 <marc@nus.edu.sg> 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
From gdb-return-42109-listarch-gdb=sources.redhat.com@sourceware.org Tue May 07 10:19:00 2013
Return-Path: <gdb-return-42109-listarch-gdb=sources.redhat.com@sourceware.org>
Delivered-To: listarch-gdb@sources.redhat.com
Received: (qmail 7725 invoked by alias); 7 May 2013 10:19:00 -0000
Mailing-List: contact gdb-help@sourceware.org; run by ezmlm
Precedence: bulk
List-Id: <gdb.sourceware.org>
List-Subscribe: <mailto:gdb-subscribe@sourceware.org>
List-Archive: <http://sourceware.org/ml/gdb/>
List-Post: <mailto:gdb@sourceware.org>
List-Help: <mailto:gdb-help@sourceware.org>, <http://sourceware.org/ml/#faqs>
Sender: gdb-owner@sourceware.org
Delivered-To: mailing list gdb@sourceware.org
Received: (qmail 7714 invoked by uid 89); 7 May 2013 10:18:59 -0000
X-Spam-SWARE-Status: No, score=-1.3 required=5.0 tests=AWL,BAYES_00,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,KHOP_THREADED,RCVD_IN_DNSWL_LOW,RCVD_IN_HOSTKARMA_YE,SPF_PASS,TW_NX autolearn=ham version=3.3.1
Received: from mail-da0-f43.google.com (HELO mail-da0-f43.google.com) (209.85.210.43) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Tue, 07 May 2013 10:18:58 +0000
Received: by mail-da0-f43.google.com with SMTP id u7so253039dae.30 for <gdb@sourceware.org>; Tue, 07 May 2013 03:18:57 -0700 (PDT)
X-Received: by 10.66.8.69 with SMTP id p5mr1910944paa.57.1367917970512; Tue, 07 May 2013 02:12:50 -0700 (PDT)
Received: from [192.168.0.104] ([112.233.222.117]) by mx.google.com with ESMTPSA id aa8sm29572136pad.14.2013.05.07.02.12.46 for <multiple recipients> (version=TLSv1 cipherìDHE-RSA-RC4-SHA bits\x128/128); Tue, 07 May 2013 02:12:48 -0700 (PDT)
Message-ID: <5188C586.6010201@gmail.com>
Date: Tue, 07 May 2013 10:19:00 -0000
From: xunxun <xunxun1982@gmail.com>
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64; rv:17.0) Gecko/20130328 Thunderbird/17.0.5
MIME-Version: 1.0
To: John Martin <jmartin@larraioz.com>
CC: gdb@sourceware.org
Subject: Re: Doubt with gdb
References: <5188C0F5.2010306@larraioz.com> <5188C241.9000209@larraioz.com> <5188C2D9.2020503@gmail.com> <5188C421.3060102@larraioz.com>
In-Reply-To: <5188C421.3060102@larraioz.com>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-SW-Source: 2013-05/txt/msg00036.txt.bz2
Content-length: 674

Ã¤ÂºÂŽ 2013/5/7 Ã¦Â˜ÂŸÃ¦ÂœÂŸÃ¤ÂºÂŒ 17:06, John Martin Ã¥Â†Â™Ã©ÂÂ“:
> Hello,
>
> And, is it possible to extract only variables of a function?
>
> info variables return me all variables of program.
>
> info variables "function" ????
>
>
> El 07/05/13 11:01, xunxun escribiÃƒÂ³:
>> Ã¤ÂºÂŽ 2013/5/7 Ã¦Â˜ÂŸÃ¦ÂœÂŸÃ¤ÂºÂŒ 16:58, John Martin Ã¥Â†Â™Ã©ÂÂ“:
>>> Hello,
>>> is there any way to tell GDB that return all static variables of a
>>> function?
>>> best regards.
>>>
>>>
>> |info variables |
>> ||
>> <http://sourceware.org/gdb/current/onlinedocs/gdb/Symbols.html#index-info-variables-918>
>> --
>> Best Regards,
>> xunxun
>
Maybe you need the local variables?

info local
>
> --

--
Best Regards,
xunxun