【问题标题】:assembly - lldb can't find correct debug information on macOS程序集 - lldb 在 macOS 上找不到正确的调试信息
【发布时间】:2019-07-17 05:23:48
【问题描述】:

我在macOS 10.14上学习汇编语言,我的汇编器nasm的版本是2.14.02,链接器ld的版本是ld64-409.12,调试器lldb的版本是lldb-1000.11.38.2。

我有一个名为test.asm的源代码文件,我使用

nasm -f macho64 -F dwarf -g test.asm
ld -e _start -o test test.o -lSystem

我使用lldb进行调试:

lldb test

当我想在某行设置断点时:

(lldb)b test.asm:3

事实证明:

error: parsing line table prologue at 0x00000000 (parsing ended around 0x00000006
Breakpoint 1: no locations (pending).
WARNING:  Unable to resolve breakpoint to any actual locations.

我用

nm -pa test

查看调试信息,结果:

0000000000000000 - 00 0000    SO xxxx(the directory)
0000000000000000 - 00 0000    SO test.asm
000000005c70cdfd - 03 0001   OSO xxxx/test.o
0000000000001f88 - 01 0000 BNSYM
0000000000001f88 - 01 0000   FUN _start
0000000000000078 - 00 0000   FUN
0000000000000078 - 01 0000 ENSYM
0000000000002000 - 02 0000 STSYM query_string
0000000000002014 - 02 0000 STSYM out_string
0000000000002025 - 03 0000 STSYM in_char
0000000000000000 - 01 0000    SO
0000000000002000 d query_string
0000000000002014 d out_string
0000000000000011 a out_string_len
0000000000000014 a query_string_len
0000000000002025 b in_char
0000000000001000 T __mh_execute_header
0000000000001f88 T _start
                 U dyld_stub_binder

如果我使用

dsymutil -dump-debug-map test

事实证明

---
triple:          'x86_64-apple-darwin'
binary-path:     test
objects:
  - filename:        xxxx/test.o
    timestamp:       1550896637
    symbols:
      - { sym: in_char, objAddr: 0x000000000000009D, binAddr: 0x0000000000002025, size: 0x00000000 }
      - { sym: query_string, objAddr: 0x0000000000000078, binAddr: 0x0000000000002000, size: 0x00000000 }
      - { sym: _start, objAddr: 0x0000000000000000, binAddr: 0x0000000000001F88, size: 0x00000078 }
      - { sym: out_string, objAddr: 0x000000000000008C, binAddr: 0x0000000000002014, size: 0x00000000 }
...

如果我使用dsymutil 来打包调试信息,例如:

dsymutil test

再试试lldb test,结果是:

warning: (x86_64) xxxx/test empty dSYM file detected, dSYM was created with an executable with no debug info.

【问题讨论】:

  • test.o 是目标文件,而不是源文件。 test.asm 是您的源文件,它有一个有趣的第 3 行。但是您也可以在没有源代码的情况下很好地调试 asm。如果 lldb 命令类似于 GDB,您可以 b *0x12345678 在数字地址处设置断点,或者只需 b 在您单步执行的当前行上设置 BP。 (但从反汇编窗口复制/粘贴地址不太方便。)同样,如果它像 GDB,您可以在启动程序时使用starti 在第一条指令处设置一次性断点。
  • @PeterCordes 感谢您的评论!但即使我改成 b test.asm:3,它仍然会出错。我编辑问题以显示当前错误。不幸的是,lldb 没有名为“starti”的命令
  • 我忘记了ld -g 是否有什么不同。它与 Linux 上的 GNU binutils 中的 ld 无关(出于兼容性考虑,它被忽略了),但我想知道调试信息是否将其放入二进制文件中。
  • b _start 有效吗?这应该基于简单的符号,而不是调试信息。
  • @PeterCordes ld:未知选项:-g。而b _start 仍然不起作用,结果显示“断点 1:没有位置(待定)。警告:无法将断点解析到任何实际位置。”

标签: assembly nasm lldb


【解决方案1】:

最后,我锻炼了。 LLDB 支持由 GAS 汇编的程序,其源代码使用 AT&T 语法。如果你真的想在 macOS 上使用 intel 语法调试 NASM 汇编的程序,只需使用 GDB。

【讨论】:

    猜你喜欢
    • 2015-03-23
    • 1970-01-01
    • 2017-12-16
    • 2018-12-18
    • 2019-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多