是否可以在Mac OS上调试x64程序集? [英] Is it possible to debug x64 assembly on Mac OS?

查看:109
本文介绍了是否可以在Mac OS上调试x64程序集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够使用Sierra 10.12.4在Mac上编写和调试x64程序集.有人会认为这不是一个特别困难或晦涩的愿望,但是尽管付出了许多时间和大量的在线搜索,但我还是没有成功,也没有找到其他任何一个人.

I would like to be able to write and debug x64 assembly on my Mac with Sierra 10.12.4. One would think this would not be a particularly difficult or obscure desire, but despite many hours of effort and a lot of searching online I have not succeeded and I haven't found anyone else who has either.

我更喜欢使用NASM汇编器,但如果需要的话,将使用GAS或任何具有Intel语法的东西. (顺便说一下,请注意gdb和lldb都可以与使用gcc编译的C文件一起正常工作.)

I would prefer to use the NASM assembler, but will use GAS or anything with Intel syntax if I have to. (By the way, note that both gdb and lldb work fine with C files compiled with gcc.)

这是我的处境以及我尝试过的事情:

Here's my situation and what I've tried:

NASM不起作用

我可以汇编并链接文件并验证其是否有效.

I can assemble and link a file and verify it works.

$ nasm -f macho64 -g -F dwarf hello2.s -o hello2.o
$ gcc hello2.o -o hello2
$ ./hello2
Hello, world!

但是我无法使用gdb对其进行调试(请注意,我确实做了所有必要的代码签名废话):

But I can't debug it with gdb (note that I did do all the necessary codesigning nonsense):

$ 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对其进行调试:

And I can't debug it with 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不起作用

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

I can assemble, link, and run:

$ gcc -g hello.s -o hello
$ ./hello
Hello, world!

但是我无法使用gdb进行调试:

But I can't debug with 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]

(因此它只是运行而忽略了断点.)

(So it just ran and ignored the breakpoint.)

我无法使用lldb对其进行调试:

And I can't debug it with 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.

我在网上找到的东西

此处是有关gdb在新版本的Mac OS上不起作用的博客文章.

Here is a blog post about gdb not working on new versions of Mac OS.

有一些旧的与StackOverflow相关的问题,都没有一个足够的答案.

There are a couple old related StackOverflow questions, neither of which provide an adequate answer.

还有使用Xcode的方法,似乎奇迹般地起作用了……但实际上并没有满足我的要求.调试器实际上并不知道我的源文件.它只是逐步执行说明并显示反汇编的代码或其他内容.另外我也不想使用XCode.

There's also this way to use Xcode, which miraculously seems to work... but it doesn't actually do what I want. The debugger is not actually aware of my source file; it's just stepping through the instructions and displaying disassembled code or something. Also I don't want to use XCode.

几个月前,我在NASM邮件列表上问了这个问题,但没人回应.

I asked about this on the NASM mailing list a couple months ago and nobody ever responded.

所以...

那么,当前是否可能无法使用Mac使用计算机完成人们可能想做的最基本的事情之一??

So is it currently impossible to do one of the most basic things a person might want to do with a computer using a Mac?

如果有人可以做到这一点,请向我确切显示必要的命令.

If someone has a way to do this, please show me exactly the necessary commands.

推荐答案

奇迹出现了,看来我可以用c来做到这一点:

Miracle of miracles, it seems I can do this with 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程序集支持是完全没有文献记载的,而我仅通过实验就得出了实现此目的的正确方法.但这是我想的.

Unfortunately as far as I can tell clang's x64 assembly support is completely undocumented, and I figured out the correct incantations to do this only by experimenting. But it's something, I guess.

这篇关于是否可以在Mac OS上调试x64程序集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆