Mic*_*eld 10 debugging macos assembly
我希望能够使用Sierra 10.12.4在我的Mac上编写和调试x64程序集.人们会认为这不是一个特别困难或模糊的愿望,但尽管经过了数小时的努力和大量的在线搜索,我还没有成功,我也没有找到任何其他人.
我更喜欢使用NASM汇编程序,但如果必须,我会使用GAS或任何具有Intel语法的东西.(顺便说一句,请注意gdb和lldb都可以正常使用gcc编译的C文件.)
这是我的情况和我尝试过的:
NASM不起作用
我可以组装和链接文件并验证它是否有效.
$ nasm -f macho64 -g -F dwarf hello2.s -o hello2.o
$ gcc hello2.o -o hello2
$ ./hello2
Hello, world!
Run Code Online (Sandbox Code Playgroud)
但我不能用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.
Run Code Online (Sandbox Code Playgroud)
我无法用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.
Run Code Online (Sandbox Code Playgroud)
GAS不起作用
我可以组装,链接和运行:
$ gcc -g hello.s -o hello
$ ./hello
Hello, world!
Run Code Online (Sandbox Code Playgroud)
但我不能用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]
Run Code Online (Sandbox Code Playgroud)
(所以它只是运行并忽略了断点.)
我无法用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.
Run Code Online (Sandbox Code Playgroud)
我在网上找到的东西
这是一篇关于gdb不使用新版Mac OS 的博客文章.
有一些旧的相关StackOverflow问题,两者都没有提供足够的答案.
还有这种方式可以使用Xcode,它奇迹般地起作用......但它实际上并没有做我想要的.调试器实际上并不知道我的源文件; 它只是单步执行指令并显示反汇编代码或其他内容.另外我不想使用XCode.
几个月前我在NASM邮件列表上询问过这个问题,没有人回复过.
所以...
因此,目前不可能做一个人可能想要使用Mac 的计算机做的最基本的事情之一?
如果有人有办法这样做,请告诉我完全必要的命令.
奇迹中的奇迹,看来我可以用 clang 做到这一点:
$ 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
Run Code Online (Sandbox Code Playgroud)
不幸的是,据我所知,clang 的 x64 程序集支持完全没有记录,我只能通过实验找出正确的咒语来做到这一点。但我想这确实是一件事。
| 归档时间: |
|
| 查看次数: |
1854 次 |
| 最近记录: |