2. next和step next简写成n,当执行到某一行我们想要继续往下一行代码走时就可以用该命令; step简写成s,它也是单步执行,与next不同的是1,如果当前代码行是调用了某个函数,那么step会进入该被调用的函数里面,一般比较接近我们的问题相关的代码时,就可以用step进入函数内部,再单步调试。
如果你在没有 调试符号 (debugging sysbols) 的情况下进行编译(LCTT 译注:即在使用 gcc 编译程序时没有写 -g 选项),然后在 bar 上设置一个断点,然后尝试在这个函数内使用 step 来单步执行语句。GDB 会给出一个 没有行号信息 (no line number information) 的错误信息。 gccexmp.c-o exmp gdb./exmp (...
Choosing the right debugging tool depends on your specific needs. GDB is a versatile and powerful debugger, and it’s a great choice for most debugging tasks. However, if you’re working with LLVM/Clang toolchain, you might find LLDB more suitable. If you’re dealing with memory leaks or ...
准备老规矩,先准备一个示例程序如下:/*gdbStep.c*/#include<stdio.h>/*计算简单乘法,这里没有考虑溢出*/int add(int a, int b){ int c = a + b; return c;}/*打印从 0 到 num-1 的数*/int count(int num){ int i = 0; if(0 > num) return 0; while(i < num)...
如果没有调试信息,会提示no debugging symbols found。如果是下面的提示: 代码语言:javascript 代码运行次数:0 运行 AI代码解释 Reading symbols from helloWorld...done. 则可以进行调试。 readelf查看段信息 例如: 代码语言:javascript 代码运行次数:0 运行 AI代码解释 $ readelf -S helloWorld|grep debug [] ....
[Thread debuggingusinglibthread_db enabled] Using host libthread_db library "/lib64/libthread_db.so.1". Breakpoint 1,main()at test.cc:27 (gdb)c Continuing. 3 [New Thread 0x7ffff6fd2700(LWP44996)] in fun_int n=1 [New Thread0x7ffff67d1700(LWP44997)] ...
a=1,b=19return0;(gdb)quitAdebugging session is active.Inferior1[process22935]will be killed.Quit anyway?(y or n)y root@iZ2zeeailqvwws5dcuivdbZ:~/2/02# 在start命令后,每输入一个n就能够单步执行一条语句(输入一个命令后,直接回车表示最近输入命令的含义)。当程序执行完时,可以输入quit命令来退...
[Thread debugging using libthread_db enabled] Using host libthread_db library "/lib64/libthread_db.so.1". Breakpoint 1, main () at test.cc:27 (gdb) c Continuing. 3 [New Thread 0x7ffff6fd2700 (LWP 44996)] in fun_int n = 1 ...
2.8 单步运行 (Step Execution - step) 2.9 继续执行 (Continuing Execution - continue) 2.10 退出GDB (Exiting GDB - quit) 3. 断点调试 (Breakpoint Debugging) 3.1 设置断点 (Setting Breakpoints) 3.2 条件断点 (Conditional Breakpoints) 3.3 查看断点 (Inspecting Breakpoints) 3.4 清除断点 (Clearing Breakpoi...
如果想知道程序现在运行到了哪里,同样可以使用“backtrace”命令。当然也可以使用“step”命令对程序进行单步调试。 在完成调试之后,不要忘记用detach命令断开连接,让被调试的进程可以继续正常运行。 #./debugme Enter a string to count words: 1. 面临问题:一般情况下,如果被gdb调试的程序中调用fork派生出一个新的...