【问题标题】:Local labels in GNU assembler; gdb printing backtrace as though labels are functionsGNU 汇编器中的本地标签; gdb 打印回溯,就好像标签是函数一样
【发布时间】:2014-11-21 19:00:54
【问题描述】:

两段示例代码;首先将一些 C++ 代码调用到程序集中:

/* test1.cc */
#include <stdio.h>

extern "C" void blah();
extern "C" void stuff() {
  printf( "This is a test\n" );
}

int main( int argc, char *argv[] ) {
  blah();

  return 0;
}

...然后是程序集:

.file "test2.s"
.text
.globl blah, stuff
.type blah,@function
.type stuff,@function
.align 16

blah:
  /* normal function preamble */
  pushl %ebp
  movl %esp, %ebp

label1:
  call stuff

  leave
  retn

内置:

as -g --32 test2.s -o test2.o
clang++ -m32 -g test1.cc -c
clang++ -m32 -g test*.o -o test

在gdb下运行,在stuff()上设置断点,然后查看回溯:

gdb test
(gdb) break stuff
(gdb) run
(gdb) back
     #0  stuff () at test1.cc:5
---> #1  0x08048458 in label1 () at test2.s:12
---> #2  0xffffc998 in ?? ()
     #3  0x0804843e in main (argc=1, argv=0xffffca44) at test1.cc:9

在筛选 [edit GNU 汇编器文档的旧副本后,我尝试了以L 为前缀和以$ 为后缀的标签,看看它是否会阻止标签被导出,但是没有用。

如果我将标签设为数字,则回溯看起来很正常,但我并不太喜欢使用数字标签的概念。

请有人指出我正确的方向吗?

【问题讨论】:

  • 本地标签应以.L (dot L) 开头。例如,.Llabel1 有效。

标签: assembly gdb debug-symbols gnu-assembler backtrace


【解决方案1】:

我找到了答案in the GNU assembler manual;引用该文档:

本地符号是任何以某些本地标签前缀开头的符号。默认情况下, 本地标签前缀对于 ELF 系统是“.L”,对于传统 a.out 系统是“L”,但每个目标 可能有自己的一组本地标签前缀。

果然,只要我把.L放在那里,它就起作用了。

.L 标签不会在目标文件中显示为符号。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-26
相关资源
最近更新 更多