Skip to content

Commit

Permalink
Fix compilation on Musl targets.
Browse files Browse the repository at this point in the history
  • Loading branch information
dd86k committed Oct 20, 2023
1 parent 3bf615e commit 9eb63af
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 18 deletions.
10 changes: 3 additions & 7 deletions src/adbg/v1/debugger/debugger.d
Original file line number Diff line number Diff line change
Expand Up @@ -568,15 +568,11 @@ L_DEBUG_LOOP:
// - gdbserver and lldb never attempt to do such thing anyway
case SIGILL, SIGSEGV, SIGFPE, SIGBUS:
siginfo_t sig = void;
if (ptrace(PT_GETSIGINFO, g_debuggee.pid, null, &sig) >= 0) {
version (CRuntime_Glibc)
e.fault.raw = sig._sifields._sigfault.si_addr;
else version (CRuntime_Musl)
e.fault.raw = sig.__si_fields.__sigfault.si_addr;
else static assert(0, "hack me");
} else {
if (ptrace(PT_GETSIGINFO, g_debuggee.pid, null, &sig) < 0) {
e.fault.raw = null;
break;
}
e.fault.raw = sig._sifields._sigfault.si_addr;
break;
// case SIGINT, SIGTERM, SIGABRT: //TODO: Kill?
default:
Expand Down
4 changes: 2 additions & 2 deletions src/adbg/v1/debugger/seh/posix.d
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ void adbg_seh_action(int sig, siginfo_t *si, void *p) {

mexception.oscode = sig;
// HACK: Missing ref'd D bindings to Musl
version (CRuntime_Glibc)
/*version (CRuntime_Glibc)
mexception.fault.raw = si._sifields._sigfault.si_addr;
else version (CRuntime_Musl)
mexception.fault.raw = si.__si_fields.__sigfault.si_addr;
else static assert(0, "hack me");
else static assert(0, "hack me");*/

/+mexception.pid = mexception.tid = 0;
adbg_ctx_init(&mexception.registers);
Expand Down
12 changes: 7 additions & 5 deletions src/adbg/v2/debugger/process.d
Original file line number Diff line number Diff line change
Expand Up @@ -675,17 +675,19 @@ L_DEBUG_LOOP:
// - First SIGTRAP does NOT contain int3
// - Windows does, though, and points to it
// - gdbserver and lldb never attempt to do such thing anyway
// NOTE: Newer D compilers fixed siginfo_t as a whole
// for version (linux). Noticed on DMD 2.103.1.
// Old glibc: ._sifields._sigfault.si_addr
// Old musl: .__si_fields.__sigfault.si_addr
// New: ._sifields._sigfault.si_addr & .si_addr()
// NOTE: .si_addr() emits linker errors on Musl platforms.
case SIGILL, SIGSEGV, SIGFPE, SIGBUS:
siginfo_t sig = void;
if (ptrace(PT_GETSIGINFO, tracee.pid, null, &sig) < 0) {
exception.fault_address = 0;
break;
}
version (CRuntime_Glibc)
exception.fault_address = cast(ulong)sig._sifields._sigfault.si_addr;
else version (CRuntime_Musl)
exception.fault_address = cast(ulong)sig.__si_fields.__sigfault.si_addr;
else static assert(0, "hack me");
exception.fault_address = cast(size_t)sig._sifields._sigfault.si_addr;
break;
// case SIGINT, SIGTERM, SIGABRT: //TODO: Killed?
default:
Expand Down
8 changes: 4 additions & 4 deletions src/adbg/v2/debugger/seh.d
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// (Incomplete module) Structued Exception Handling wrapper.
/// (Work in progress) Structued Exception Handling wrapper.
///
/// Authors: dd86k <[email protected]>
/// Copyright: © dd86k <[email protected]>
Expand Down Expand Up @@ -48,7 +48,7 @@ version (Windows) {

extern (C):

version (none)
version (none) // Disabled until setjmp works on Win64
public int adbg_seh_enable(int function(adbg_exception_t*) func) {
if (func == null)
return adbg_oops(AdbgError.nullArgument);
Expand Down Expand Up @@ -134,11 +134,11 @@ void adbg_seh_catch(int sig, siginfo_t *si, void *p) {

checkpoint.exception.oscode = sig;
// HACK: Missing ref'd D bindings to Musl
version (CRuntime_Glibc)
/*version (CRuntime_Glibc)
checkpoint.exception.fault_address = cast(ulong)si._sifields._sigfault.si_addr;
else version (CRuntime_Musl)
checkpoint.exception.fault_address = cast(ulong)si.__si_fields.__sigfault.si_addr;
else static assert(0, "hack me");
else static assert(0, "hack me");*/

/+mexception.pid = mexception.tid = 0;
adbg_ctx_init(&mexception.registers);
Expand Down

0 comments on commit 9eb63af

Please sign in to comment.