如何在GNU GAS ELF输出中创建GDB可以中断但不能算作功能的局部标签? [英] How to make local labels in GNU GAS ELF output that GDB can break on but not count as functions?
问题描述
当使用GNU GAS手动编写程序集时,在一个函数中,我要设置一个标签,以便:
When writing assembly manually with GNU GAS, within a function, I want to set a label such that:
- GDB不会将该标签视为函数名称
- 我可以使用
b mylabel
破坏标签
- GDB won't treat that label as the function name
- I can use
b mylabel
to break on the label
在
A similar question for nasm
has been asked at: Break at local label using GDB for NASM assembly but I wanted to make it more precise here that I want GNU GAS and ELF output.
例如如果我将普通标签mylabel
定义为:
E.g. if I defined a normal label mylabel
as in:
main.S
.text
.global _start
_start:
/* exit */
mov $60, %rax
mylabel:
mov $0, %rdi
syscall
不能满足我的要求,因为当GDB到达mov $0, %rdi
时,bt
将mylabel
显示为函数名称,而我希望它是_start
.特别是,这可能会破坏回溯,因为GDB找不到堆栈框架: gdb如何重建是C ++的stacktrace吗?
that does not satisfy me because when GDB reaches the mov $0, %rdi
, bt
shows mylabel
as the function name, and I would like it to be _start
instead. In particular, this can break backtraces because GDB can't find the stack frame: How gdb reconstructs stacktrace for C++?
但是,如果我将mylabel
替换为.Lmylabel
,如以下说明所示:
However, if I replace mylabel
with .Lmylabel
as explained at: Local labels in GNU assembler; gdb printing backtrace as though labels are functions then _start
is the function name as desired, but b .Lmylabel
fails. nm
does not show the symbol at all either.
ELF/DWARF格式是否支持任何可以使用的格式,是否可以通过GNU GAS公开呢?
Does the ELF / DWARF formats support anything that could be used, and is there any way to expose that though GNU GAS?
在Ubuntu 18.10,GDB 8.2,GNU GAS 2.31.1中进行了测试.
Tested in Ubuntu 18.10, GDB 8.2, GNU GAS 2.31.1.
推荐答案
我不确定这是否满足您的需求,但是您可以执行此操作(对于非PIE二进制文件,请与-no-pie
链接):
I'm not sure if this fits your needs, but you can do this (for a non-PIE binary, so link with -no-pie
):
.text
.global _start
_start:
/* exit */
mov $60, %rax
.Lmylabel:
mov $0, %rdi
syscall
.section .rodata
mylabel:
.long .Lmylabel
然后,您可以使用break *mylabel
(请注意*
)设置断点:
Then, you can set a breakpoint using break *mylabel
(note the *
):
(gdb) break *mylabel
Breakpoint 2 at 0x401007: file t.S, line 7.
由于mylabel
或多或少是一个函数指针,因此GDB对此一无所知,并将忽略它:
Since mylabel
is more or less a function pointer, GDB does not know anything about it and will ignore it:
Breakpoint 1, _start () at t.S:5
5 mov $60, %rax
(gdb) si
7 mov $0, %rdi
使用链接程序脚本,应该可以将mylabel
符号放在未加载的部分中,以减少运行时开销.
With a linker script, it should be possible to put the mylabel
symbol into a section which is not loaded, to reduce run-time overhead.
这篇关于如何在GNU GAS ELF输出中创建GDB可以中断但不能算作功能的局部标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!