免费注册 查看新帖 |

Chinaunix

广告
  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1857 | 回复: 1
打印 上一主题 下一主题

The gdb Command - more advanced commands(Z) [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2003-05-15 13:49 |只看该作者 |倒序浏览
(gdb) b 36              - break at line number 36 of current source file  
(gdb) b 36 if i==3      - break at line 36 of current source file if the
                          variable i is equal to 3   
                          (A condition such as if "i==3"  can be added after
                          any breakpoint definition )     
(gdb) b fn.c:22         - break at line number 22 of source file fn.c which
                          is compiled into this executable  
(gdb) b func            - break at function "func" entry point (or in
                          source  file  fn.c:  b fn.c:func)   
(gdb) i b               - info breakpoints. Lists all breakpoints now set up.
(gdb) d                 - delete all breakpoints (d 1 for just #1).

An executable file (a.out if the -o option is not used) can be compiled from a number of source files in C, and the   will know about these source files and the lines they contain. To find source line numbers so you can set breakpoints, use the following commands:

(gdb) l 23              - list to terminal screen 10 lines of current source
                          centered at line 23
(gdb) l fn.c:22         - print 10 lines from source file in fn.c centered
                          at line 22
(gdb) l func            - print 10 lines around function "func" entry point
                          (or l fn.c:func)
(gdb) l                 - print 10 or more lines after lines last printed
(gdb) l fn.c:1          - print all lines starting from line 1 in source
                          file fn.fc

Some other commands for examining memory and program information are:

(gdb) i sources         - info on sources - print the names of all source files
(gdb) i lo              - info locals: values of all local vars, current
                          function
(gdb) i var             - info variables: values of global/static vars
(gdb) i s               - info stack:calls made to get to this execution
                          point.
(gdb) bt                - same as i s
(gdb) where               same as i s
(gdb) up                - go up one stack level (to caller)
(gdb) down              - go down one stack level (to called function)
(gdb) x 0x20034   - examine memory address 0x20034
(gdb) x/s 0x20034 - examine memory, addr 0x20034, as a string  (also x/f
(gdb) display x   - prints x each time program stops
(gdb) whatis  x   - prints type information for x

bf NOTE: While running, CTRL-C brings you back to the (gdb) prompt to examine the program state. This is useful for programs that are in an infinite loop or hung and for debugging performance problems

To begin running a program again after a break (including the first break at main) type:

(gdb) c                 - continue running program from stopped point
(gdb) c 22              - continue, don't stop at this breakpoint again
                          until it is encountered 22 times

In setting a breakpoint we were allowed to give a condition (b 36 if i==3). In a counted continue (c 22), the condition is not checked until the breakpoint has been encountered 22 times. To find out what breakpoints exist and delete them:

(gdb) i b               - info on breakpoints - returns list of breaknumbers  
(gdb) d 3               - delete break number 3
(gdb) d                 - delete all breakpoints

You can create an array starting at any position to print out values all with the same type:

(gdb) p array[3]@12     - will print out values starting at array position
                          3 for 12 positions

You can also call your own function from within the debugger:

(gdb)  p my_function ()               - calls a function
(gdb)  call my_function ()            - same as p
(gdb)  p my_function (10, ``Boston'') - call function with values
(gdb)  p my_function (x, p->;name)     - call  using variable values

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
2 [报告]
发表于 2003-05-15 13:55 |只看该作者

The gdb Command - more advanced commands(Z)

http://www.chinaunix.net/forum/viewtopic.php?t=64604&start=15
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP