Macos 可以在Mac OS上调试x64程序集吗?

Macos 可以在Mac OS上调试x64程序集吗?,macos,debugging,assembly,Macos,Debugging,Assembly,我希望能够使用Sierra 10.12.4在Mac上编写和调试x64程序集。有人会认为这不是一个特别困难或模糊的愿望,但尽管我花了很多时间在网上搜索,但我没有成功,也没有找到任何其他人 我更喜欢使用NASM汇编程序,但如果有必要,我会使用GAS或任何带有英特尔语法的东西。(顺便说一句,注意gdb和lldb在使用gcc编译的C文件中都可以正常工作。) 以下是我的情况和我的尝试: NASM不起作用 我可以组装和链接一个文件,并验证它是否有效 $ nasm -f macho64 -g -F dwarf

我希望能够使用Sierra 10.12.4在Mac上编写和调试x64程序集。有人会认为这不是一个特别困难或模糊的愿望,但尽管我花了很多时间在网上搜索,但我没有成功,也没有找到任何其他人

我更喜欢使用NASM汇编程序,但如果有必要,我会使用GAS或任何带有英特尔语法的东西。(顺便说一句,注意gdb和lldb在使用gcc编译的C文件中都可以正常工作。)

以下是我的情况和我的尝试:

NASM不起作用

我可以组装和链接一个文件,并验证它是否有效

$ nasm -f macho64 -g -F dwarf hello2.s -o hello2.o
$ gcc hello2.o -o hello2
$ ./hello2
Hello, world!
但是我不能用gdb调试它(注意,我确实做了所有必要的代码设计工作):

气体不起作用

我可以组装、链接和运行:

$ 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]
我在网上找到的东西

是一篇关于gdb不能在新版本Mac OS上运行的博客文章

有两个老的相关问题,都没有提供充分的答案

还有,这似乎奇迹般地起作用了。。。但它实际上并不能满足我的要求。调试器实际上不知道我的源文件;它只是一步一步地浏览指令并显示反汇编代码或其他东西。我也不想使用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

不幸的是,据我所知,clang的x64组装支持完全没有文档记录,我只是通过实验才找到了正确的咒语。但我想这是个问题。

nasm的哪个版本?什么版本的
gdb
llvm
?我试过nasm版本2.13.01和2.14rc0,以及gdb版本7.12.1和8.0。lldb-370.0.42。苹果llvm版本8.1.0。无论版本如何,我都会得到相同的结果。你是说你已经开始调试这个软件的某个版本了吗?我指的是nasm 2.13发行说明:“macho对象格式现在支持dwarf调试格式,这是更新的工具链所要求的。”但你已经表示你是最新版本的。你是在nasm论坛上问的吗?我是在nasm邮件列表上问的,但不是在论坛上问的……我不能回答你的问题,因为我从未在Mac上使用过GDB,但你反对使用Xcode似乎有点不同寻常。“调试器实际上并不知道我的源文件;它只是单步执行指令并显示反汇编代码或其他东西。”你是在汇编中编写的,兄弟。反汇编的代码看起来与源文件完全相同!我不知道在哪里可以找到clang assembler的文档,但是Xcode有一个选项可以显示C/C++/ObjC源文件的llvm汇编源代码(产品->执行操作->汇编)。这可能会让您获得类似操作的示例,您可以根据自己的目的进行复制。
$ 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 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.
$ 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