gpt4 book ai didi

macos - 是否可以在 Mac OS 上调试 x64 程序集?

转载 作者:行者123 更新时间:2023-12-02 18:04:33 30 4
gpt4 key购买 nike

我希望能够在我的 Mac 上使用 Sierra 10.12.4 编写和调试 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!

但我无法使用 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 做到这一点:

$ 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 程序集支持完全没有文档记录,我只能通过实验找出正确的咒语来做到这一点。但我想这确实是个事。

关于macos - 是否可以在 Mac OS 上调试 x64 程序集?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44493487/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com