Blog

finish and until

Content #

The finish command completes execution of the current function without further pauses within the fucntion (except at any intervening breakpoints).

Similarly, the Until command (abbreviated simply as u) is typically used to complete an executing loop, without further pauses within the loop, except at any intervening breakpoints within the loop.

From #

until(gdb command)

Content #

GDB的until命令的作用是什么?

Execute until the program reaches a source line greater than the current [one].

From #

finish(gdb command)

Content #

GDB的finish命令的作用是什么?

让GDB恢复执行,在当前栈帧完成之后停止。

GDB调试时,如果不小心单步进入了原本希望越过的函数时,使用 finish 命令可以回到越过函数命令(next)到达的位置。

From #

x命令与print命令的区别

Content #

gdb中x命令与print命令有何区别?

print命令打印的是表达式的值。 x命令是用来查看内存地址上的内容的。

From #

向进程发送一个信号

Content #

所谓“向进程发送一个信号”只是形象地说法,从代码的层面来看它究竟是怎么回事呢?

操作系统将信号记录到进程表中,接到收信号的进程在下次CPU时间里执行相应的信号处理程序。

From #

Breakpoint Command Lists

Content #

要让GDB每次到达同一个断点时都自动执行一组命令,该如何操作?

使用Breakpoint Command Lists

(gdb) command 1
Type commands for when breakpoint 1 is hit, one per line.
End with a line saying just "end".
>silent
>printf "fibonacci was passed %d.\n", n
>continue
>end

From #

软件调试的艺术

错误的内存访问并不一定会导致段错误

Content #

为什么说程序中错误的内存访问并不一定会导致段错误?

分页机制下,只需要2.2个内存页的程序会得到3个内存页,访问这些多分配的内存就不会导致段错误。

From #

convenience variable(gdb)

Content #

现在有指针指向链表中不同的节点,用GDB调试时,想到把某个节点的地址记录下来,以备将来使用,请问该如何操作?

使用convenience variable

set $q = p

在后面再访问该变量:

p *$q

From #

在断点处自动执行打印函数

Content #

现在要调试二叉树代码,大体结构如下:

struct node {...};
typedef struct node *nsp;
nsp root;
nsp makenode(int x){...}
void insert(nsp *btp, int x){...}
void printtree(nsp bt){...}
int main(){...}

主要的功能都在insert函数中,printtree函数实现了打印二叉树的功能,请问在GDB中如何设置可以最方便来调试二叉树程序?

在insert函数的结束位置设置断点,在该断点自动执行如下代码:

commands 2
>printf "****** current tree ******\n"
>call printtree(root)
>end

From #

breakpoint的三种Disposition

Content #

  1. keep - 下次到达断点后不改变断点,默认。
  2. del - 下次到达到删除该断点。(tbreak)
  3. dis - 下次到达到会禁用该断点。(enable once)

From #