hashlink icon indicating copy to clipboard operation
hashlink copied to clipboard

MacOS debugger not working on Apple Sillicon

Open rcstuber opened this issue 4 years ago • 9 comments

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.

rcstuber avatar Dec 16 '21 13:12 rcstuber

does it work with lldb -o run path/to/hl in a rosetta shell?

shakesoda avatar Dec 16 '21 23:12 shakesoda

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. hl executable is codesigned "properly". I also tried codsigning the node exec with the same entitlements, as it runs the debugger (via Node FFI) –- no succes
  • Tried giving the debugee's hl programm a ptrace(PT_TRACE_ME), but after adding that the ptrace(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.

rcstuber avatar Dec 20 '21 11:12 rcstuber

Is lldb running as x86 or arm?

onehundredfeet avatar Jan 03 '23 20:01 onehundredfeet

@rcstuber Any luck? I tried to look into it myself, but the mach signaling intricacies are beyond me atm.

onehundredfeet avatar Apr 18 '23 04:04 onehundredfeet

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...

rcstuber avatar Apr 18 '23 04:04 rcstuber

That would be awesome, but I consider it highly unlikely.

onehundredfeet avatar Apr 18 '23 17:04 onehundredfeet

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.

AesteroidBlues avatar Apr 18 '23 19:04 AesteroidBlues

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!

rcstuber avatar Apr 18 '23 19:04 rcstuber

Is it possible to get debugging working with HL/C?

onehundredfeet avatar Mar 26 '24 18:03 onehundredfeet