【发布时间】:2022-12-04 01:36:25
【问题描述】:
首次尝试 ARM64 (apple M1) 汇编编码。具有可以正确组装和运行的基本“hello world”代码,但是当我在 lldb 中运行它时,只有前三行以完整的源代码格式显示,如下所示:
Abenaki:hello jiml$ ~/llvm/clang+llvm-15.0.2-arm64-apple-darwin21.0/bin/lldb hello
(lldb) target create "hello"
Current executable set to '/Users/jiml/Projects/GitRepos/ARM/hello/hello/hello/hello' (arm64).
(lldb) b main
Breakpoint 1: where = hello`main + 4, address = 0x0000000100003f7c
(lldb) r
Process 5017 launched: '/Users/jiml/Projects/GitRepos/ARM/hello/hello/hello/hello' (arm64)
Process 5017 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
frame #0: 0x0000000100003f7c hello`main at hello.s:19
16
17 _main:
18 mov x0, #0x0 // stdout
-> 19 adrp x1, msg@PAGE // pointer to string
20 add x1, x1, msg@PAGEOFF
21 ldr x2, =msg_len // bytes to output
22 mov x16, #0x04 // sys_write
warning: This version of LLDB has no plugin for the language "assembler". Inspection of frame variables will be limited.
(lldb)
三步之后,显示恢复为裸对象代码,如下所示:
(lldb) s
Process 5017 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = step in
frame #0: 0x0000000100003f88 hello`main + 16
hello`main:
-> 0x100003f88 <+16>: mov x16, #0x4
0x100003f8c <+20>: svc #0x80
0x100003f90 <+24>: adrp x1, 1
0x100003f94 <+28>: mov x2, #0x0
dwarfdump -a 显示所有源代码行都存在于 .o 中; .dSYM 程序集的行为相同。但是,在 lldb 中使用“list”命令可以正确显示所有源代码行。
这是 LLVM(clang、lldb)开发的已知问题吗?任何帮助表示赞赏...
我已经尝试过 LLVM 版本 14 和 15,同样的行为,搜索过类似的问题但没有帮助。
我确实找到了这个 https://stackoverflow.com/questions/73778648/why-is-it-that-assembling-linking-in-one-step-loses-debug-info-for-my-assembly-s 但确实如此不能解决我的问题。
【问题讨论】:
-
源代码行可能都存在,但它们的范围可能不会涵盖所有主要部分,因为某些代码只是编译器生成但未与特定源代码行相关联,或者因为编译器错误 - 特别是如果您不构建在 - O0。您可以使用
source info -f hello.s查看包含所有范围的源映射。您可以使用image lookup -va <address>询问 lldb 它对特定地址的了解。这可能会让您深入了解为什么此代码没有关联的源代码行号。 -
如果这仍然看起来不对,最好向 llvm 错误报告者提交报告:github.com/llvm/llvm-project/issues。请务必包括您的输入 .s 文件和您的编译行以及您正在使用的 clang 和 lldb 的版本。