The Art of Debbugging 笔记 (gdb)
来源:互联网 发布:mysql查询结果中文乱码 编辑:程序博客网 时间:2024/06/10 03:15
-tui,打开TUI模式,Ctrl-X-A返回non-TUI模式。
在TUI模式下,上下箭头,PgUp/PgDn 用于滚动代码,Crtl+P/N 用于查看历史命令;
断点显示在代码右侧,B+表示当前有效,B-表示disable了:
gdb 命令:
断点
break: 2.4节;
tbreak: temporary break,单次有效;
delete/clear/disable/enable: 2.7节;
info breakpoints: 输出格式 2.8.1;
条件断点:
break break-args if (condition): (2.10.1)
单步
step: step into a function
next: step over a function 2.9.1.1
finish: 结束当前stack frame,即从当前函数返回,比如:step 进入一个函数,finish可以从这个函数返回;2.9.1.3
continue [n]: 继续执行,可选参数参数n,表示忽略接下来遇到的n个断点;2.9.1.2
until: 参数和break一样,可以执行到希望的位置;没有参数,默认是调出循环;2.9.1.4
查看堆栈信息:1.5.4
backtrace (bt): 打印所有调用函数堆栈信息;
bt n: 打印栈顶n层信息;
bt -n: 打印栈底n层信息;
frame: 打印当前栈顶;(每一层称为一个frame)
frame n: n从0开始,0表示栈顶,依次类推;
up/down n: 向栈底/顶移动n层;
info fram/f: 打印更详细的当前栈的信息;
info命令:
info breakpoints
info args
attatching to a running process:
$gdb /path/to/the/executable/of/running/process pid-of-running-process
进入gdb之后,可以用attatch命令
(gdb) attatch pid
参考:Using GNU's GDB Debugger, chapter 6 Debugging A Running Process
watch 命令:
(gdb) watch 表达式 当表达式的值发生改变时,程序中止。注意:只有在程序运行过程中才可以设置观察点,因此只有在设置断点之后运行程序再设置观察点才是有意义的
(gdb)awatch 表达式 当表达式被读取或者写入时,程序终止。
可以配合display应用。
display 命令:
(gdb) display 表达式 每运行到断点时显示该表达式的值,程序运行后起作用
(gdb) info display 显示所有display的表达式
查看内存信息:
x (examine)命令
x/nfu addr
x addr
n, the repeat count
- The repeat count is a decimal integer; the default is 1. It specifieshow much memory (counting by unitsu) to display.
- f, the display format
- The display format is one of the formats used by
x
or- u, the unit size
- The unit size is any of
b
- Bytes.
h
- Halfwords (two bytes).
w
- Words (four bytes). This is the initial default.
g
- Giant words (eight bytes).
Each time you specify a unit size with
x
, that size becomes thedefault unit the next time you usex
. (For the`s' and`i' formats, the unit size is ignored and is normally not written.)- addr, starting display address
- addr is the address where you want GDB to begin displayingmemory. The expression need not have a pointer value (though it may);it is always interpreted as an integer address of a byte of memory.See sectionExpressions, for more information on expressions. The default foraddr is usually just after the last address examined--but severalother commands also set the default address:
info breakpoints
(tothe address of the last breakpoint listed),info line
(to thestarting address of a line), andFor example, `x/3uh 0x54320' (addr也可以使用程序中的符号)is a request to display three halfwords(
h
) of memory, formatted as unsigned decimal integers (`u'),starting at address0x54320
. `x/4xw $sp' prints the fourwords (`w') of memory above the stack pointer in hexadecimal (`x').
具体查看 Debug with GDB, 8.5 Examining Memory
打印指针指向的数组
p *array@len:array 是指针,len希望打印的元素个数,元素类型为*array的类型;
调试 core
$ gdb executable-file core // executable-file 为可执行文件,core 是可执行文件运行崩溃时dump的core文件;
进入gdb后,也可以用core-file命令指定core file
(gdb) core-file core
参考资料:
1. GNU GDB Debugger Command Cheat Sheet
- The Art of Debbugging 笔记 (gdb)
- The Art of Debugging with GDB
- The Art of Java
- The Art of C++
- The Art of SQL
- The Art of Rails
- the art of conclusion
- The art of deception
- the Art of Life
- The Art of Debugging
- State-of-the-art
- The art of report
- The Art of Logging
- The art of software testing 阅读笔记(一)
- The art of software testing 阅读笔记(二)
- the art of unix programming--笔记(chap1)
- the art of unix programming--笔记(chap4)
- the art of unix programming--笔记(chap12)
- TCP/IP、Http、Socket的区别
- 结合DataGrid控件ASP.NET上传并读取Excel文件数据
- GridView 和DataGrid区别
- jquery随记(事件)----键盘事件2011.08.18
- Javascript常用定义方法
- The Art of Debbugging 笔记 (gdb)
- Telnet命令
- javaScript 计算器
- ASP.NET网络编程中常用到的27个函数集
- JavaScript 常用对象[日期和时间对象]
- 用javascript操纵GridView中CheckBox的两个常用技巧
- hive 执行过程源码分析
- 几种排序算法(面试时经常要考的)
- javaScript 不会随滚动条滚动的层