gdb tracepoint 使用demo

这篇博客详细介绍了如何使用gdb的tracepoint功能进行调试。通过一个名为'demo'的实例,包括了'i.tracepoint.c'源代码,'Makefile'构建文件和具体的命令操作。博主还进行了测试,通过运行'./tracepoint',配合'gdbserver'和'gdb'客户端。然而,目前在tracepoint中查看局部变量存在一些问题,博主尚未找出解决办法。
部署运行你感兴趣的模型镜像

gdb对tracepoint的描述

In some applications, it is not feasible for the debugger to interrupt
the program's execution long enough for the developer to learn anything
helpful about its behavior.  If the program's correctness depends on
its real-time behavior, delays introduced by a debugger might cause the
program to change its behavior drastically, or perhaps fail, even when
the code itself is correct.  It is useful to be able to observe the
program's behavior without interrupting it.


I.demo
i.tracepoint.c

#include <stdio.h>
#include <unistd.h>

int indx;

int main(int argc, char *argv[])
{
    int res;

    indx = 0;
    while ( indx < 10000 ) {
        res = indx * 2;
        printf("%d\n", res);
        sleep(1);
        indx++;
    }

    return 0;
}


ii.Makefile

all:
	gcc -g tracepoint.c -o tracepoint


iii.command

file tracepoint
target remote 127.0.0.1:1234
trace tracepoint.c:15
actions
collect indx
end
tstart
break tracepoint.c:14
continue
continue 10
tstop
tstatus
tfind start
while($trace_frame != -1)
printf "Frame %d : indx = %d\n", $trace_frame, indx
tfind
end


II 测试
i ./tracepoint

[redhat@localhost test]$ ./tracepoint 
0
2
4


ii gdbserver

[redhat@localhost src]$ gdbserver --attach 127.0.0.1:1234 `pidof tracepoint`
Attached; pid = 18812
Listening on port 1234
Remote debugging from host 127.0.0.1


iii gdb

[redhat@localhost test]$ gdb --command=command
GNU gdb (GDB) Red Hat Enterprise Linux (7.2-50.el6)
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
0x00000038d8aaab80 in __nanosleep_nocancel () from /lib64/libc.so.6
Created trace state variable $trace_timestamp for target's variable 1.
Tracepoint 1 at 0x40054b: file tracepoint.c, line 15.
Breakpoint 2 at 0x400541: file tracepoint.c, line 14.

Breakpoint 2, main (argc=1, argv=0x7fff716cb1c8) at tracepoint.c:14
14	        sleep(1);

Breakpoint 2, main (argc=1, argv=0x7fff716cb1c8) at tracepoint.c:14
14	        sleep(1);
Trace stopped by a tstop command.
Collected 11 trace frames.
Trace buffer has 5242649 bytes of 5242880 bytes free (0% full).
Trace will stop if GDB disconnects.
Not looking at any trace frame.
Found trace frame 0, tracepoint 1
Frame 0 : indx = 325
Found trace frame 1, tracepoint 1
Frame 1 : indx = 326
Found trace frame 2, tracepoint 1
Frame 2 : indx = 327
Found trace frame 3, tracepoint 1
Frame 3 : indx = 328
Found trace frame 4, tracepoint 1
Frame 4 : indx = 329
Found trace frame 5, tracepoint 1
Frame 5 : indx = 330
Found trace frame 6, tracepoint 1
Frame 6 : indx = 331
Found trace frame 7, tracepoint 1
Frame 7 : indx = 332
Found trace frame 8, tracepoint 1
Frame 8 : indx = 333
Found trace frame 9, tracepoint 1
Frame 9 : indx = 334
Found trace frame 10, tracepoint 1
Frame 10 : indx = 335
No trace frame found
Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.47.el6.x86_64
(gdb) 


III.locals

局部变量目前有问题,暂未找到原因

(gdb) actions
Enter actions for tracepoint 1, one per line.
End with a line saying just "end".
>collect res
DWARF operator DW_OP_call_frame_cfa cannot be translated to an agent expression
(gdb) actions
Enter actions for tracepoint 1, one per line.
End with a line saying just "end".
>collect $locals
>end
(gdb) tstart
DWARF operator DW_OP_call_frame_cfa cannot be translated to an agent expression
(gdb) 


 

您可能感兴趣的与本文相关的镜像

ACE-Step

ACE-Step

音乐合成
ACE-Step

ACE-Step是由中国团队阶跃星辰(StepFun)与ACE Studio联手打造的开源音乐生成模型。 它拥有3.5B参数量,支持快速高质量生成、强可控性和易于拓展的特点。 最厉害的是,它可以生成多种语言的歌曲,包括但不限于中文、英文、日文等19种语言

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值