GDB:在NASM汇编文件中找不到符号文件。

3

请原谅我,因为我在这里还是个新手,但我正在尝试使用 gdb 调试 x86 汇编。

ex10.asm

global main
extern printf

section .data
        msg db "Testing %i...", 0x0a, 0x00

main:
        push ebp
        mov ebp, esp
        push 123
        push msg
        call printf
        mov eax, 0
        mov esp, ebp
        pop ebp
        ret

编译并链接以下内容:

nasm -f elf32 -F dwarf -g ex10.asm -o ex10.o

gcc -m32 -gdwarf ex10.o -o ex10

ex10.o 看起来带有调试符号

$ objdump --syms ./ex10.o | grep debug
00000000 l    d  .debug_info    00000000 .debug_info
00000000 l    d  .debug_abbrev  00000000 .debug_abbrev
00000000 l    d  .debug_line    00000000 .debug_line

ex10似乎没有调试符号

$ objdump --syms ./ex10 | grep debug
  ----returns nothing----

运行 gdb ./ex10 的结果如下:

$ gdb ./ex10
GNU gdb (Ubuntu 9.2-0ubuntu1~20.04.1) 9.2
This GDB was configured as "x86_64-linux-gnu".
Reading symbols from ./ex10...
(No debugging symbols found in ./ex10)

在这之后,我不太确定该如何查看。有任何建议或需要提供的信息吗?

此外,还有nasm版本。

$ apt list --installed | grep nasm
nasm/focal,now 2.14.02-1 amd64 [installed]

4
main: 前面加上 section .text 行。 - ssbssa
谢谢你的提示。我听说过那个,但是现在正试图看看调试是如何工作的。 - jakechowder
1个回答

3

本文使用 NASM版本2.15.05 进行复制。

未使用 section .text(ssbssa建议):

readelf -w ex10.o

Section '.debug_aranges' has no debugging data.
Section '.debug_pubnames' has no debugging data.
Section '.debug_info' has no debugging data.
Section '.debug_abbrev' has no debugging data.
Section '.debug_line' has no debugging data.
Section '.debug_frame' has no debugging data.
Section '.debug_loc' has no debugging data.

因此,最终链接输出中自然什么也得不到。

main 之前添加 section .text 可以解决这个问题。

注意:你期望从 objdump --syms ./ex10 | grep debug 中获得输出,但这是错误的期望:

  1. 你的文件中没有名为 *debug* 的符号
  2. ~永远不应该使用 objdump 查看 ELF 文件。应该使用 readelf

如果你坚持要使用 objdump,请按照以下操作:

objdump -g ex10 | grep debug

Contents of the .debug_aranges section (loaded from ex10):
  Offset into .debug_info:  0x0
Contents of the .debug_info section (loaded from ex10):
Contents of the .debug_abbrev section (loaded from ex10):
Raw dump of debug contents of section .debug_line (loaded from ex10):

感谢您的解释和有用的链接。再见! - jakechowder

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接