20145212——GDB调试汇编堆栈过程分析
GDB调试汇编堆栈过程分析
测试代码
#include <stdio.h>
short val = 1;
int vv = 2;
int g(int xxx)
{
return xxx + vv;
}
static const int f(int xx)
{
return g(xx);
}
int main(void)
{
return f(9)+ val;
}
分析过程
通过
gcc - g gdb.c -o gdb -m32
指令在64位的机器上产生32位汇编进入gdb调试,先在main函数处设置一个断点,再run一下,使用disassemble指令获取汇编代码
main函数汇编代码:
g函数汇编代码:
f函数汇编代码:
通过
info registers
列出使用的寄存器.
此时主函数的栈基址为
0xffffd028
,用x(examine)
指令查看内存地址中的值,目前%esp
所指堆栈内容为0,%ebp
所指内容也为0
结合
display
命令和寄存器或pc内部变量,做如下设置:display /i $pc
,其中$pc
代表当前汇编指令,/i
表示以十六进行显示。这样在每次执行下一条汇编语句时,都会显示出当前执行的语句。
使用
si
执行下一条指令、%esp、%ebpinfo registers
和堆栈内容的变化x/na %esp
1.call将下一条指令的所在地址(即当时程序计数器PC的内容)入栈
2.将上一个函数的基址入栈,将当前%esp作为新基址
3.准备传参
4.call指令将下一条指令的地址入栈,此时%esp,%ebp和堆栈的值为:
6.执行g函数,g初始化栈指针
7.计算short+int
8.pop %ebp
指令将栈顶弹到%ebp中
9.ret返回g中call的调用位置
10.leave返回准备栈
11.ret结束main函数
12.%esp加立即数4
指令 | %eip | %esp | %ebp | %eax | 堆栈 |
---|---|---|---|---|---|
push $0x9 | 0x8048400 | 0xffffd024 | 0xffffd028 | 0xf7fb7dbc | 0x0 |
call 0x80483eb | 0x8048400 | 0xffffd020 | 0xffffd028 | 0xf7fb7dbc | 0x9 0x0 |
push %ebp | 0x80483eb | 0xffffd020 | 0xffffd028 | 0xf7fb7dbc | 0x8048405 0x9 0x0 |
mov %esp,%ebp | 0x80483ec | 0xffffd01c | 0xffffd028 | 0xf7fb7dbc | 0xffffd028 0x8048405 0x9 0x0 |
pushl 0x8(%ebp) | 0x80483ee | 0xffffd01c | 0xffffd01c | 0xf7fb8dbc | 0xffffd028 0x8048405 0x9 0x0 |
call 0x80483db | 0x80483f1 | 0xffffd018 | 0xffffd01c | 0xf7fb8dbc | 0x9 0xffffd028 0x8048405 0x9 0x0 |
push %ebp | 0x80483db | 0xffffd014 | 0xffffd01c | 0xf7fb8dbc | 0x80483f6 0x9 0xffffd028 0x8048405 0x9 0x0 |
mov %esp,%ebp | 0x80483dc | 0xffffd010 | 0xffffd01c | 0xf7fb8dbc | 0xffffd01c 0x80483f6 0x9 0xffffd028 0x8048405 0x9 0x0 |
mov 0x804a01c,%edx | 0x80483de | 0xffffd010 | 0xffffd010 | 0xf7fb7dbc | 0xffffd01c 0x80483f6 0x9 0xffffd028 0x8048405 0x9 0x0 |
mov 0x8(%ebp),%eax | 0x80483e4 | 0xffffd010 | 0xffffd010 | 0xf7fb7dbc | 0xffffd01c 0x80483f6 0x9 0xffffd028 0x8048405 0x9 0x0 |
add %edx,%eax | 0x80483e7 | 0xffffd010 | 0xffffd010 | 0x9 | 0xffffd01c 0x80483f6 0x9 0xffffd028 0x8048405 0x9 0x0 |
pop %ebp | 0x80483e9 | 0xffffd010 | 0xffffd010 | 0xb | 0xffffd01c 0x80483f6 0x9 0xffffd028 0x8048405 0x9 0x0 |
ret | 0x80483ea | 0xffffd014 | 0xffffd01c | 0xb | 0x80483f6 0x9 0xffffd028 0x8048405 0x9 0x0 |
add $0x4,%esp | 0x80483f6 | 0xffffd018 | 0xffffd01c | 0xb | 0x9 0xffffd028 0x8048405 0x9 0x0 |
leave | 0x80483f9 | 0xffffd01c | 0xffffd01c | 0xb | 0xffffd028 0x8048405 0x9 0x0 |
ret | 0x80483fa | 0xffffd020 | 0xffffd028 | 0xb | 0x8048405 0x9 0x0 |
add $0x4,%esp | 0x8048405 | 0xffffd024 | 0xffffd028 | 0xb | 0x9 0x0 |
mov %eax,%edx | 0x8048405 | 0xffffd028 | 0xffffd028 | 0xb | 0x0 |
20145212——GDB调试汇编堆栈过程分析的更多相关文章
- GDB调试汇编堆栈过程分析
GDB调试汇编堆栈过程分析 分析过程 这是我的C源文件:click here 使用gcc - g example.c -o example -m32指令在64位的机器上产生32位汇编,然后使用gdb ...
- 20145223《信息安全系统设计基础》 GDB调试汇编堆栈过程分析
20145223<信息安全系统设计基础> GDB调试汇编堆栈过程分析 分析的c语言源码 生成汇编代码--命令:gcc -g example.c -o example -m32 进入gdb调 ...
- 赵文豪 GDB调试汇编堆栈过程分析
GDB调试汇编堆栈过程分析 使用gcc - g example.c -o example -m32指令在64位的机器上产生32位汇编,然后使用gdb example指令进入gdb调试器: 使用gdb调 ...
- 20145337 GDB调试汇编堆栈过程分析
20145337 GDB调试汇编堆栈过程分析 测试代码 #include<stdio.h> short addend1 = 1; static int addend2 = 2; const ...
- 20145208 GDB调试汇编堆栈过程分析
20145208 GDB调试汇编堆栈过程分析 测试代码 #include<stdio.h> short addend1 = 1; static int addend2 = 2; const ...
- 20145218 GDB调试汇编堆栈过程分析
GDB调试汇编堆栈过程分析 虚拟机中分析过程 输入gcc - g example.c -o example -m32指令在64位机器上产生32位汇编,但出现以下错误: 这时需要使用sudo apt-g ...
- 20145236 GDB调试汇编堆栈过程分析
GDB调试汇编堆栈过程分析 首先需要输入sudo apt-get install libc6-dev-i386安装一个库才能产生汇编代码,然后输入gcc - g example.c -o exampl ...
- 20145312 GDB调试汇编堆栈过程分析
20145312 GDB调试汇编堆栈过程分析 参考资料 卢肖明同学的博客:<GDB调试汇编堆栈过程分析>: http://www.cnblogs.com/lxm20145215----/p ...
- 20145240 GDB调试汇编堆栈过程分析
20145240 GDB调试汇编堆栈过程分析 测试代码 #include<stdio.h> short addend1 = 1; static int addend2 = 2; const ...
随机推荐
- 16-static和extern关键字2-对变量的作用
上一讲介绍了static和extern对函数的作用,static用来定义一个内部函数,不允许其他文件访问:extern用来定义和声明一个外部函数,允许其他文件访问.static和extern对变量也有 ...
- 树莓派:raspberry pi 3b - NOOBS
NOOBS - 多操作系统安装器,可以将不同支持树莓派的流行操作系统安装在一张SD卡中并提供一个启动管理工具,安装的不同操作系统相互独立,互不影响,是一种比较有意思的玩法. 从版本1.3.1开始到1. ...
- sql 优化
1.选择最有效率的表名顺序(只在基于规则的优化器中有效): oracle的解析器按照从右到左的顺序处理 from 子句中的表名,from子句中写在最后的表(基础表driving table)将被最先处 ...
- bitmap解码
#include <stdio.h> #include <stdlib.h> #include <string.h> #define BYTE unsigned c ...
- 前端之ajax
前端之ajax 本节内容 ajax介绍 原生js实现ajax jquery实现ajax json 跨域请求 1. ajax介绍 AJAX(Asynchronous Javascript And XML ...
- [LeetCode] Kth Smallest Element in a BST 二叉搜索树中的第K小的元素
Given a binary search tree, write a function kthSmallest to find the kth smallest element in it. Not ...
- [LeetCode] Combination Sum III 组合之和之三
Find all possible combinations of k numbers that add up to a number n, given that only numbers from ...
- JQuery Ajax调用asp.net后台方法
利用JQuery的$.ajax()可以很方便的调用asp.net的后台方法. 先来个简单的实例热热身吧. 1.无参数的方法调用 asp.net code: using System.Web.Scrip ...
- IO操作工具类
package com.imooc.io; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; impor ...
- log4j+mybatis打印数据库日志
参考文献:一:http://blog.csdn.net/rangqiwei/article/details/50825090 二:http://www.mybatis.org/mybatis-3/zh ...