是否可以在Mac OS上调试x64程序集?
我希望能够使用Sierra 10.12.4在我的Mac上编写和调试x64程序集。有人会认为这不会是一个特别困难或模糊的愿望,但尽管经过了许多小时的努力和大量的在线搜索,我还没有成功,我还没有找到任何其他人。是否可以在Mac OS上调试x64程序集?
我宁愿使用NASM汇编程序,但如果必须使用GAS或任何带有Intel语法的程序。 (顺便说一句,注意,这两个GDB和LLDB做工精细用的C文件用gcc编译。)
这里是我的情况,我已经试过:
NASM不起作用
我可以组装并链接一个文件并验证它是否有效。
$ nasm -f macho64 -g -F dwarf hello2.s -o hello2.o
$ gcc hello2.o -o hello2
$ ./hello2
Hello, world!
但我不能用gdb(请注意,我做所有必要的代码签名废话)进行调试:
$ gdb hello2
GNU gdb (GDB) 8.0
<snip>
Reading symbols from hello2...done.
(gdb) list
1 section .data
2
3 msg: db "Hello, world!", 0
4
5 section .text
6 global _main
7 extern _puts
8
9 _main:
10 push rbp
(gdb) break 10
Breakpoint 1 at 0x0: file hello2.s, line 10.
(gdb) run
Starting program: /Users/mike/GoogleDrive/Projects/Sort/hello2
[New Thread 0x1403 of process 38022]
warning: unhandled dyld version (15)
Warning:
Cannot insert breakpoint 1.
Cannot access memory at address 0x0
Command aborted.
我不能LLDB调试它:
$ lldb hello2
(lldb) target create "hello2"
Current executable set to 'hello2' (x86_64).
(lldb) b hello2.s:10
Breakpoint 1: no locations (pending).
WARNING: Unable to resolve breakpoint to any actual locations.
GAS不起作用
我可以汇编,链接,并运行:
$ gcc -g hello.s -o hello
$ ./hello
Hello, world!
但我不能使用gdb调试:
$ gdb hello
GNU gdb (GDB) 8.0
<snip>
Reading symbols from hello...Reading symbols from /Users/mike/GoogleDrive/Projects/Sort/hello.dSYM/Contents/Resources/DWARF/hello...done.
done.
(gdb) list
1 .intel_syntax
2 .text
3 .globl _main
4
5 _main:
6 push rbp
7 mov rbp, rsp
8 lea rdi, [rip + _main.S_0]
9 call _puts
10 mov rax, 0
(gdb) break 6
No line 6 in the current file.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (6) pending.
(gdb) run
Starting program: /Users/mike/GoogleDrive/Projects/Sort/hello
[New Thread 0x1403 of process 38063]
warning: unhandled dyld version (15)
Hello, world!
[Inferior 1 (process 38063) exited normally]
(所以它只是跑而忽略了断点)
我不能LLDB调试它:
$ lldb hello
(lldb) target create "hello"
Current executable set to 'hello' (x86_64).
(lldb) b hello.s:6
Breakpoint 1: no locations (pending).
WARNING: Unable to resolve breakpoint to any actual locations.
我在网上找到的东西
Here是关于gdb
的博客文章,不适用于新版本的Mac OS。
有几个老相关的StackOverflow问题,都没有提供足够的答案。
还有this way to use Xcode,奇迹似乎工作...但它并没有真正做我想要的。调试器实际上并不知道我的源文件;它只是单步执行指令并显示反汇编代码或其他内容。我也不想使用XCode。
几个月前我在NASM邮件列表上询问过这个问题,但没有人回复。
所以...
因此,它是目前不可能做到的最基本的东西的人可能会希望使用的是Mac电脑做一个?
如果有人有办法做到这一点,请告诉我确切的必要命令。奇迹
奇迹,看来我可以用铿锵做到这一点:
$ clang -g -c -x assembler hello.s
$ clang hello.o -o hello
$ ./hello
Hello, world!
$ lldb hello
(lldb) target create "hello"
Current executable set to 'hello' (x86_64).
(lldb) b hello.s:10
Breakpoint 1: where = hello`main + 16, address = 0x0000000100000f7c
(lldb) run
Process 40460 launched: '/Users/mike/GoogleDrive/Projects/Sort/hello' (x86_64)
Hello, world!
Process 40460 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
frame #0: 0x0000000100000f7c hello`main at hello.s:10
7 mov rbp, rsp
8 lea rdi, [rip + _main.S_0]
9 call _puts
-> 10 mov rax, 0
11 mov rsp, rbp
12 pop rbp
13 ret
不幸的是,据我可以告诉铛的x64组件的支持完全是无证的,我想通了正确的咒语,要做到这一点只通过实验。但是,我猜是这样。
我不知道在哪里可以找到clang汇编程序的文档,但Xcode有一个选项来显示llvm汇编源代码C/C++/ObjC源文件(Product-> Perform Action-> Assemble)。这可能会让你得到类似的操作的例子,你可以为你的目的进行婴儿床。 –
什么版本的'nasm'?什么版本的'gdb','llvm'? –
我已经试过了nasm版本2.13.01和2.14rc0,以及gdb版本7.12.1和8.0。 LLDB-370.0.42。 Apple llvm版本8.1.0。无论版本如何,我都会得到相同的结果。您是否暗示您已经开始调试以使用该软件的某个版本? –
我指的是nasm 2.13发行说明:“macho对象格式现在支持矮工具调试格式,正如新工具链所要求的那样。”但你已经表示你是最新的。你在nasm论坛上问过吗? –