gdb - GDB 无法创建断点
问题描述
我正在实现一个简单的堆栈溢出,我正在使用 gdb 进行检查。我不断提出的一个问题是 gdb 不接受我的断点。我的 c 代码很简单:
void function(int a, int b, int c) {
...//stuff
}
void main() {
int x;
x = 0;
function(1,2,3);
x = 1;
printf("%d\n",x);
}
我正在使用 gcc -m32 -fno-stack-protector -o example3test example3test.c 来编译它。
我尝试在 <+42> 行上设置一个简单的断点,只是为了测试它是否有效。
(gdb) disass main
Dump of assembler code for function main:
0x000005d1 <+0>: lea 0x4(%esp),%ecx
0x000005d5 <+4>: and $0xfffffff0,%esp
0x000005d8 <+7>: pushl -0x4(%ecx)
0x000005db <+10>: push %ebp
0x000005dc <+11>: mov %esp,%ebp
0x000005de <+13>: push %ebx
0x000005df <+14>: push %ecx
0x000005e0 <+15>: sub $0x10,%esp
0x000005e3 <+18>: call 0x470 <__x86.get_pc_thunk.bx>
0x000005e8 <+23>: add $0x1a18,%ebx
0x000005ee <+29>: movl $0x0,-0xc(%ebp)
0x000005f5 <+36>: push $0x3
0x000005f7 <+38>: push $0x2
0x000005f9 <+40>: push $0x1
0x000005fb <+42>: call 0x5a0 <function>
0x00000600 <+47>: add $0xc,%esp
0x00000603 <+50>: movl $0x1,-0xc(%ebp)
0x0000060a <+57>: sub $0x8,%esp
0x0000060d <+60>: pushl -0xc(%ebp)
0x00000610 <+63>: lea -0x1950(%ebx),%eax
0x00000616 <+69>: push %eax
0x00000617 <+70>: call 0x400 <printf@plt>
0x0000061c <+75>: add $0x10,%esp
0x0000061f <+78>: nop
0x00000620 <+79>: lea -0x8(%ebp),%esp
0x00000623 <+82>: pop %ecx
0x00000624 <+83>: pop %ebx
0x00000625 <+84>: pop %ebp
0x00000626 <+85>: lea -0x4(%ecx),%esp
0x00000629 <+88>: ret
End of assembler dump.
(gdb) break *0x000005fb
Breakpoint 1 at 0x5fb
(gdb) run
Starting program: /home/jasmine/tutorials/smashingTheStackForFun/example3test
Warning:
Cannot insert breakpoint 1.
Cannot access memory at address 0x5fb
我不知道为什么它不接受这个断点。这里的大多数答案都涉及不使用 * 或使用错误的符号,据我所见,我的看起来是正确的,但我可能是错的。
解决方案
我不知道为什么它不接受这个断点。
您有一个与位置无关的可执行文件,它在运行时被重定位到不同的地址。
这将起作用:
(gdb) start
# GDB stops at main
(gdb) break *&main+42
(gdb) continue
另请参阅此答案。
推荐阅读
- r - R 多列的频率表,按第三个变量分组
- google-maps-api-3 - 谷歌距离矩阵和 OR 工具
- python - 嵌套序列化程序 Django REST Framework 时排除字段
- javascript - 在 React 从多个相等的输入中获取信息并保存信息
- git - 如何告诉我的 git 工具不要转换行尾?
- postgresql - 如何通过 AIRFLOW 将 GCP Postgres sql 中的数据导出到 GCS 中的 csv 文件?
- loops - 是否可以在使用批处理文件运行循环时检查按键?
- python - 将列表列表转换为元组的元组
- sql - 按递归深度有限的前任排序
- python - 根据条件将列表中的值设置为 0