MacOS debugger not working on Apple Sillicon
TLDR; While it is possible to run an x86_64 version of Hashlink through Apple's Rosetta 2 (on MacOS 12.0) emulation layer, debugging currently is broken.
The debugger fails at properly attaching to the debugee's process using ptrace(PT_ATTACHEXC). No error is returned, but the hl process being debugged enters an odd state and no mach-exception is received on the tracing process. On Intel Mac (also with older MacOS version) this still works as expected.
Any hints are welcome.
does it work with lldb -o run path/to/hl in a rosetta shell?
It seems to work with lldb. I'm not sure what the issue is here, as there is hardly any documentation on these topics. I have a few wild ideas:
- Some weird timing issue with receiving the mach exception (should be a system queue however, so that would be odd)
- Some codesigning issue.
hlexecutable is codesigned "properly". I also tried codsigning thenodeexec with the same entitlements, as it runs the debugger (via Node FFI) –- no succes - Tried giving the debugee's
hlprogramm aptrace(PT_TRACE_ME), but after adding that theptrace(PT_ATTACHEXC)on the debugger process fails
I tried looking the lldb source code, but it's a big bloat and hard to see what it does differently.
Is lldb running as x86 or arm?
@rcstuber Any luck? I tried to look into it myself, but the mach signaling intricacies are beyond me atm.
Nope, sorry. My last attempt was over a year ago. Still hoping for the Haxe community to make Hashlink ARM compatible as to skip Rosetta completely...
That would be awesome, but I consider it highly unlikely.
Still hoping for the Haxe community to make Hashlink ARM compatible as to skip Rosetta completely...
Does anyone know what's involved in this? It looks like there are some hardcoded x86_64 types in mdbg.c/h that error when I try to compile for ARM but I'm not sure if that's just the tip of the iceberg.
Presumably a port will have to happen at some point, unless hashlink is forever relegated to "Intel Mac only" which would be a shame for a crossplatform project.
The entire VM needs to be re-written for ARM. Try talking to Zeta on the Discord, iirc he worked on a ARM version a while back already. Good luck!
Is it possible to get debugging working with HL/C?