GNU 汇编器中的本地标签;gdb 打印回溯,就好像标签是函数一样 [英] Local labels in GNU assembler; gdb printing backtrace as though labels are functions

查看:22
本文介绍了GNU 汇编器中的本地标签;gdb 打印回溯,就好像标签是函数一样的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Two pieces of example code; first some C++ code calling into assembly:

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

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

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()上设置断点,然后查看回溯:

Run it under gdb, set a breakpoint on stuff(), then look at the backtrace:

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 & 为前缀的标签.后缀 $ 看看它是否会阻止标签被导出,但它不起作用.

After sifting through [edit an older copy of] the GNU assembler documentation, I tried labels prefixed with L & postfixed with $ to see if it would prevent the labels from being exported, but it didn't work.

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

If I make the labels numeric the backtrace looks normal, but I'm not overly fond of the notion of using numeric labels.

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

Could someone point me in the right direction, please?

推荐答案

我找到了答案 在 GNU 汇编器手册中;引用该文档:

I found an answer in the GNU assembler manual; quoting from that doc:

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

A local symbol is any symbol beginning with certain local label prefixes. By default, the local label prefix is ‘.L’ for ELF systems or ‘L’ for traditional a.out systems, but each target may have its own set of local label prefixes.

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

Sure enough, as soon as I put .L on there, it worked.

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

.L labels don't appear as symbols in the object file.

这篇关于GNU 汇编器中的本地标签;gdb 打印回溯,就好像标签是函数一样的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆