为什么为x86汇编函数将GDB断点设置在错误的地址? [英] Why is GDB breakpoint set at the wrong address for an x86 assembly function?
问题描述
我遇到一个问题,其中gdb在添加断点时将行号映射到错误的内存地址.
I am experiencing an issue where gdb is mapping a line number to the wrong memory address when adding a breakpoint.
以下x86 Linux汇编程序打印"hello".
The following x86 Linux assembly program prints "hello".
/* hello.s */
.section .data
str:
.ascii "hello\n"
strlen = . - str
.section .text
print:
pushl %ebp
movl %esp, %ebp
pushl %ebx
movl $4, %eax
movl $1, %ebx
movl $str, %ecx
movl $strlen, %edx
int $0x80
popl %ebx
movl %ebp, %esp
popl %ebp
ret
.globl _start
_start:
call print
movl $1, %eax
movl $0, %ebx
int $0x80
我用调试信息编译它,然后链接.
I compile it with debugging information, and then link.
$ as -g --32 -o hello.o hello.s
$ ld -m elf_i386 -o hello hello.o
接下来,在gdb中,我尝试在打印功能的第一行( pushl%ebp
)的第11行上设置断点.
Next, in gdb, I try to set a breakpoint on line 11, the first line of the print function (pushl %ebp
).
$ gdb ./hello
(gdb) break hello.s:11
断点3位于0x8048078:文件hello.s,第11行.
Breakpoint 3 at 0x8048078: file hello.s, line 11.
如输出所示,断点设置在地址0x8048078上.但是,这是错误的地址.当我在gdb中运行程序时,它在第14行中断.第11行的地址是0x8048074,已使用gdb的info命令进行了确认.
As shown in the output, the breakpoint is set at address 0x8048078. However, that is the wrong address. When I run my program in gdb, it breaks at line 14. The address of line 11 is 0x8048074, confirmed using gdb's info command.
(gdb) info line hello.s:11
"hello.s"的第11行开始于地址0x8048074,结束于0x8048075.
Line 11 of "hello.s" starts at address 0x8048074 and ends at 0x8048075 .
直接在打印指令上设置断点即可(将断点设置为第11行的地址,0x8048074).
Setting a breakpoint on the print instruction directly works (the break point is set for the address of line 11, 0x8048074).
当我为第11行添加一个断点时,gdb不会使用与使用上述info命令输出的地址相同的地址?这是我要中断的内存地址.
How come when I add a breakpoint for line 11, gdb does not use the same address as output by using the info command above? This is the memory address I am trying to break on.
我在gdb 7.11.1和8.0.1上都遇到相同的行为.我尝试添加 .type print,@ function
批注,但这并不能解决我的问题.
I am experiencing the same behavior on both gdb 7.11.1 and 8.0.1. I have tried adding a .type print,@function
annotation, but that did not solve my issue.
推荐答案
怎么来
默认情况下,当您在函数或函数启动的行上设置断点时,GDB会尝试跳过函数序言.
By default, GDB tries to skip past function prolog, when you set a breakpoint on a function, or a line on which the function starts.
这往往是 C
开发人员想要的,因为他们通常对参数设置不感兴趣.
This tends to be what C
developers want, since they usually aren't interested in parameter setup.
如果您需要其他功能,请使用 b *地址
或 b& print
阻止GDB正常运行.
If you want something else, use b *address
or b &print
to prevent GDB from doing its usual thing.
这篇关于为什么为x86汇编函数将GDB断点设置在错误的地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!