gdb print< filename.c>:执行的每个语句的行号 [英] gdb print <filename.c>:line number of every statement executed

查看:1347
本文介绍了gdb print< filename.c>:执行的每个语句的行号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个确定性停止)程序,其中无IO ,我希望以gdb运行并打印出每一个被执行的c语句:(例如filename:line-num)

 < main.c> ;: 27 
< main.c>:29
< foo.c>:14
//等等

有没有合理的方式来处理这个问题?我不介意一些人的努力,但我不能在每一个c文件的每一行添加断点。
任何帮助都非常感谢,谢谢。



编辑

看来, libc遇到的函数使输出过于冗长。有没有办法阻止gdb进入malloc等libc函数?感谢!

解决方案

您可以在无限循环中 step 该程序或直到您按下Ctrl + C。每进入一个新函数,每一个 step 命令都会打印行号和文件名。要调用循环,请在gdb shell中执行以下操作:

 (gdb)while 1 
> step
> end

假设您只对从 main 您可以将所有命令放在一个文件中 gdbCommands.txt

  break main 
run
while 1
step
end

并使用执行它> gdb -x gdbCommands.txt --args程序arg1 arg2 arg3



如果您想另外跳过特定libc文件中的函数,您可以添加:

  skip -file / path / to / some / filename 

给命令,如下所示:

 设置登录
break main
skip -file exit.c
skip -file malloc.c
skip -file strops.c
skip -file ../sysdeps/x86_64/multiarch/strchr-avx2.S
skip -file ../sysdeps/x86_64/multiarch/strlen-avx2.S
skip -file。 ./sysdeps/x86_64/multiarch/memchr-avx2.S
skip -file ../sysdeps/x86_64/multiarch/strcmp-sse42.S
skip -file ../sysdeps/x86_64/multiarch/ strstr-sse2-unaligned.S
skip -file ../sysdeps/x86_64/multiarch/strcpy-sse2-unaligned.S
skip -file ../sysdeps/x86_64/multiarch/strcmp-sse2- unaligned.S
skip -file ../sysdeps/x86_64/multiarch/memset-vec-unaligned-erms.S
skip -file ../sysdeps/x86_64/multiarch/memmove-vec-unaligned- erms.S
运行
而1
步骤
结束



set logging on 命令会将所有gdb输出重定向到一个名为 gdb.txt 的文件,您可以稍后检查。


I have a deterministic (halting) program with no IO, that I want to run with gdb and have it print every c statement that gets executed: (say filename:line-num)

<main.c>:27
<main.c>:29
<foo.c>:14
// etc. 

Is there any reasonable way to instrument this? I don't mind some human effort, but I can't add breakpoints in every single line of every single c file. Any help is very much appreciated, thanks.

EDIT

It seems that stepping into all libc encountered functions makes the output far too verbose. Is there any way to prevent gdb from stepping into libc functions like malloc? Thanks!

解决方案

You can step in infinite loop till the end of the program or until you press Ctrl+C. Every step command will print the line number and also filename when stepping into a new function. To invoke the loop do this in gdb shell:

(gdb) while 1
 >step
 >end

Assuming you are only interested in statements executed starting from the beginning of main you can put all commands in a file gdbCommands.txt:

break main
run
while 1
step
end

and execute it with gdb -x gdbCommands.txt --args program arg1 arg2 arg3.

If you want to additionally skip functions in specific libc files, you can add:

skip -file /path/to/some/filename

to the commands, like that:

set logging on
break main
skip -file exit.c
skip -file malloc.c
skip -file strops.c
skip -file ../sysdeps/x86_64/multiarch/strchr-avx2.S
skip -file ../sysdeps/x86_64/multiarch/strlen-avx2.S
skip -file ../sysdeps/x86_64/multiarch/memchr-avx2.S
skip -file ../sysdeps/x86_64/multiarch/strcmp-sse42.S
skip -file ../sysdeps/x86_64/multiarch/strstr-sse2-unaligned.S
skip -file ../sysdeps/x86_64/multiarch/strcpy-sse2-unaligned.S
skip -file ../sysdeps/x86_64/multiarch/strcmp-sse2-unaligned.S
skip -file ../sysdeps/x86_64/multiarch/memset-vec-unaligned-erms.S
skip -file ../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S
run
while 1
step
end

the set logging on command will redirect all gdb output to a file called gdb.txt you can later inspect.

这篇关于gdb print&lt; filename.c&gt;:执行的每个语句的行号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆