没有合适的资源?快使用搜索试试~ 我知道了~
gdb调试实例.pdf
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 71 浏览量
2022-01-13
04:27:04
上传
评论
收藏 451KB PDF 举报
温馨提示
试读
16页
gdb调试实例.pdf
资源推荐
资源详情
资源评论
1. 查看 gdb 命令 ..................................................................................................... 2
2. 程序堆栈布局 ...................................................................................................... 3
3. 调试演示 ............................................................................................................ 5
a) 堆栈信息 ...................................................................................................... 5
b) 调试多进程 .................................................................................................. 6
c) 无效的内存地址 ............................................................................................ 7
d) 不对齐的内存地址 ......................................................................................... 8
e) 缓冲区溢出 .................................................................................................. 9
f) 堆栈溢出 .................................................................................................... 10
4. 调试原理 & 调试信息 ........................................................................................ 14
a) 调试原理 .................................................................................................... 14
b) 调试信息 .................................................................................................... 14
1. 查看 gdb 命令
(gdb) help
List of classes of commands:
STM -- STMicroelectronics specific target commands
aliases -- Aliases of other commands
breakpoints -- Making program stop at certain points
data -- Examining data
files -- Specifying and examining files
internals -- Maintenance commands
obscure -- Obscure features
running -- Running the program
stack -- Examining the stack
status -- Status inquiries
support -- Support facilities
tracepoints -- Tracing of program execution without stopping the program
user-defined -- User-defined commands
Type "help" followed by a class name for a list of commands in that class.
Type "help all" for the list of all commands.
Type "help" followed by command name for full documentation.
Type "apropos word" to search for commands related to "word".
Command name abbreviations are allowed if unambiguous.
(gdb) help stack
Examining the stack.
The stack is made up of stack frames. Gdb assigns numbers to stack frames
counting from zero for the innermost (currently executing) frame.
At any time gdb identifies one frame as the "selected" frame.
Variable lookups are done with respect to the selected frame.
When the program being debugged stops, gdb selects the innermost frame.
The commands below can be used to select other frames by number or address.
List of commands:
backtrace -- Print backtrace of all stack frames
bt -- Print backtrace of all stack frames
down -- Select and print stack frame called by this one
frame -- Select and print a stack frame
return -- Make selected stack frame return to its caller
select-frame -- Select a stack frame without printing anything
up -- Select and print stack frame that called this one
Type "help" followed by command name for full documentation.
Type "apropos word" to search for commands related to "word".
Command name abbreviations are allowed if unambiguous.
(gdb) help bt
Print backtrace of all stack frames, or innermost COUNT frames.
With a negative argument, print outermost -COUNT frames.
Use of the 'full' qualifier also prints the values of the local variables.
(gdb) help frame
Select and print a stack frame.
With no argument, print the selected stack frame. (See also "info frame").
An argument specifies the frame to select.
It can be a stack frame number or the address of the frame.
With argument, nothing is printed if input is coming from
a command file or a user-defined command.
2. 程序堆栈布局
frame 是函数调用时,在堆栈上记录的数据信息,包括寄存器,局部变量,函数参数等,
每个函数被调用都会在堆栈上记录自己的信息,于是形成了如图显示的 frame stack:
frame 的组成:在函数的入口处,首先保存那些在本函数里被使用的寄存器(D),函数退出
时,恢复它们,其中就包含函数调用的返回地址,然后给函数内的局部变量分配空间(C),
再然后给 alloca 调用或者动态数组分配空间(B),如果有调用子函数,而且子函数的参数个
数过多,无法完全通过寄存器传递,那么就需要借助堆栈传递(A)。
函数出口处,堆栈释放是分配的逆过程,A-->B-->C-->D,在 D 中得到函数的返回地址,于
是当前函数调用完成,返回到调用它的上一级函数体内。
补充说明:不是每个函数的 frame 都包含 ABCD,可能只包含一部分,比如只有 CD,分配
的时候 D-->C,释放的时候 C-->D,这个过程是完全对称的。
pop A
pop B
pop C
pop D, get ret addr
then ret to parent
jump to child
ret addr
jump to child
ret addr
jump to child
ret addr
push D, save ret addr
push C
push B
push A
run
push D, save ret addr
push C
push B
push A
run
push D, save ret addr
push C
push B
push A
run
pop A
pop B
pop C
pop D, get ret addr
then ret to parent
pop A
pop B
pop C
pop D, get ret addr
then ret to parent
剩余15页未读,继续阅读
资源评论
念广隶
- 粉丝: 3w+
- 资源: 6万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功