首页 >后端开发 >C++ >使用gdb快速调试

使用gdb快速调试

Mary-Kate Olsen
Mary-Kate Olsen原创
2024-12-29 19:48:11197浏览

Quick debugging with gdb

这是我在 cli 上调试快速内容的例程:

$ gcc myprogram.c -g -o myprogram

$ gdb -tui myprogram

(gdb) break main

(gdb) run

您将使程序运行并在 main 处停止。之后,这是我最常用的命令:

Command Short version Description
step s Step in
next n Step over
until 123 unt 123 Run until line 123
info locals i lo Prints local variables
print myvar p myvar Prints myvar value once
display myvar disp myvar Displays myvar value on every execution
undisplay myvar und myvar Stops displaying myvar value
set myvar = 0 s myvar = 0 Sets the value of myvar to 0
break 456 b 456 Adds a breakpoint on line 456
info breakpoints i b Lists all breakpoints
delete d Delete all breakpoints
list main l main Go to function main
list foo.c:789 l foo.c:789 Go to file foo.c on line 789
where whe Prints where the execution is at right now
kill k Kills the current execution

如果需要,Ctrl-l 会刷新屏幕。 focus cmd 使箭头键在命令行上工作,focus src 使其滚动显示的源代码。

以上是使用gdb快速调试的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn