Chinaunix首页 | 论坛 | 博客
  • 博客访问: 334127
  • 博文数量: 78
  • 博客积分: 2536
  • 博客等级: 少校
  • 技术积分: 600
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-29 01:50
文章分类

全部博文(78)

文章存档

2011年(1)

2010年(17)

2009年(52)

2008年(8)

我的朋友

分类: LINUX

2009-09-21 22:37:08

在gdb中不输入,直接回车,默认执行上次的命令。输入命令时,可以输入命令开头的一个或者几个字母,在没有歧义的情况下,gdb会自动补齐命令的。例如:i lo = info locals。

例如调试文件 eg1.c;

编译,编译时要打开调试选项 -g,例如: gcc -g eg1.c -o eg1。

启动gdb:gdb eg1,或者是输入gdb,然后在输入 file eg1。

help / h:帮助

run / r:使用run来运行程序。如果没有错误,程序会一直运行完,如果有错误出现,gdb会获得控制权,并中断程序。

list / l :使用list命令来查源代码。
List specified function or line.
With no argument, lists ten more lines after or around previous listing.
"list -" lists the ten lines before a previous ten-line listing.
One argument specifies a line, and ten lines are listed around that line.
Two arguments with comma between specify starting and ending lines to list.
Lines can be specified in these ways:
LINENUM, to list around that line in current file,
FILE:LINENUM, to list around that line in that file,
FUNCTION, to list around beginning of that function,
FILE:FUNCTION, to distinguish among like-named static functions.
*ADDRESS, to list around the line containing that address.
With two args if one is empty it stands for ten lines away from the other arg.

print / p:查看指定变量。输入 'print no1' 和 'print diff',可以相应看到变量 "no1" 和 "diff" 的值。

continue / c:告诉gdb 继续执行。

break / b:设置断点。使用方式:'break 函数名' ,'break linenumber’ help
"break if " 设置中断条件。
如果已经在某行行中设置了断点,如 1 号断点,则可以使用
'condition' 命令来代替在断点上设置条件:
(gdb) condition 1 value==div
info break 见info命令。

info / i:
info locals 显示所有的局部变量。
'info break':查看当前定义了什么断点及其条件
info break 除了显示所有条件和已经遇到断点多少次之外,断点信息还在 'Enb' 列中指定了是否启用该断点。可以使用命令 'disable '、'enable ' 或 'delete ' 来禁用、启用和彻底删除断点,例如 'disable 1' 将阻止在 1 号断点处中断。
info watch 命令将列出已定义的监视点和断点(此命令等价于 'info break'),而且可以使用与断点相同的语法来启用、禁用和删除监视点。

help info
Generic command for showing things about the program being debugged.

List of info subcommands:

info address -- Describe where symbol SYM is stored
info all-registers -- List of all registers and their contents
info args -- Argument variables of current stack frame
info breakpoints -- Status of user-settable breakpoints
info catch -- Exceptions that can be caught in the current stack frame
info common -- Print out the values contained in a Fortran COMMON block
info copying -- Conditions for redistributing copies of GDB
info dcache -- Print information on the dcache performance
info display -- Expressions to display when program stops
info extensions -- All filename extensions associated with a source language
info files -- Names of targets and files being debugged
info float -- Print the status of the floating point unit
info frame -- All about selected stack frame
info functions -- All function names
info handle -- What debugger does when program gets various signals
info line -- Core addresses of the code for a source line
info locals -- Local variables of current stack frame
info macro -- Show the definition of MACRO
info mem -- Memory region attributes
info proc -- Show /proc process information about any running process
info program -- Execution status of the program
info registers -- List of integer registers and their contents
info remote-process -- Query the remote system for process info
info scope -- List the variables local to a scope
info set -- Show all GDB settings
info sharedlibrary -- Status of loaded shared object libraries
info signals -- What debugger does when program gets various signals
info source -- Information about the current source file
info sources -- Source files in the program
info stack -- Backtrace of the stack
info symbol -- Describe what symbol is at location ADDR
info target -- Names of targets and files being debugged
info terminal -- Print inferior's saved terminal status
info threads -- IDs of currently known threads
info tracepoints -- Status of tracepoints
info types -- All type names
info udot -- Print contents of kernel ``struct user'' for current child
info variables -- All global and static variable names
info vector -- Print the status of the vector unit
info warranty -- Various kinds of warranty you do not have
info watchpoints -- Synonym for ``info breakpoints''

next / n:单步调试程序。'next' 将跳过函数调用。

step / s:也是单步调试程序,进入函数体。

watch :如果我们对 "value" 什么时候变得与 "div" 相等更感兴趣,那么可以使用另一种断点,称作监视。当指定表达式的值改变时,监视点将中断程序执行,但必须在表达式中所使用的变量在作用域中时设置监视点。
(gdb) watch div==value
info watch 命令将列出已定义的监视点和断点(此命令等价于 'info break'),而且可以使用与断点相同的语法来启用、禁用和删除监视点。

阅读(1347) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~