gdb tips

file ex1
用file命令加载调试时所需的符号表,然后再通过“attach”命令进行连接:
(gdb) at 2412

show args
run
b 8
info break(i b)
run(r)
continue(c)
step(s)
break(b)
gcc -gdwarf-2 -g3 sample.c -o sample
-gdwarf-version 默认的level值是2, level 3包含更多的信息,当使用 -g3 选项时,调度器支持宏扩展。

info source -- Information about the current source file
info args -- Argument variables of current stack frame
set args -- Set argument list to give program being debugged when it is started

-ggdb
Produce debugging information for use by GDB.  This means to use the most expressive format available (DWARF 2, stabs, or the native format if neither of those are supported), including GDB extensions if at all possible.
With g++, this is accomplished using the -g command line argument. For even more information, the -ggdb switch can be used which includes debugging symbols which are specific to gdb.

-gdwarf-version
Produce debugging information in DWARF format (if that is supported).  This is the format used by DBX on IRIX 6.  The value of version may be either 2,3 or 4; the default version is 2.
Note that with DWARF version 2 some ports require, and will always use, some non-conflicting DWARF 3 extensions in the unwind tables.
Version 4 may require GDB 7.0 and -fvar-tracking-assignments for maximum benefit.


GUI调试器可以同时打开多个小窗口,分别显示寄存器、汇编和源代码等。在gdb里也可以做到,但同时最多只能显示两个窗口,试了一下也很方便的。基本命令如下:
a)         `layout src' 仅显示源代码窗口。
b)        `layout asm' 仅显示汇编代码窗口。
c)        `layout split' 显示源代码和汇编代码窗口。
d)        `layout regs' 显示寄存器和源代码窗口,或者寄存器和汇编代码窗口。
e)         `layout next` 和 `layout prev' 切换窗口。
f)         ctrl + L 刷新屏幕。
g)        `C-x 1' 单窗口模式。
h)        `C-x 2' 双窗口模式。
i)          `C-x a' 回到传统模式。

gdb program 11146 #11146 为irb 的进程ID。

你可能感兴趣的:(tips)