Skip to content

Commit

Permalink
Slight improvement (exception translation, wait function), comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dd86k committed Jan 17, 2024
1 parent c94b856 commit f5d645c
Show file tree
Hide file tree
Showing 7 changed files with 289 additions and 178 deletions.
60 changes: 60 additions & 0 deletions src/adbg/include/posix/sys/wait.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/// Fixing improper sys/wait.h definitions.
///
/// This is due to extern (D) tricking the compiler the function that is
/// external dispite the defined body.
///
/// Authors: dd86k <dd@dax.moe>
/// Copyright: © dd86k <dd@dax.moe>
/// License: BSD-3-Clause
module adbg.include.posix.sys.wait;

version (Posix):

public import core.sys.posix.sys.wait;

pragma(inline, true):

// Source:
// gdb/gdbsupport/gdb_wait.h

bool WIFEXITED(int status) {
version (MinGW) // (((w) & 0xC0000000) == 0)
return (status & 0xC0000000) == 0;
else // (((w)&0377) == 0)
return cast(ubyte)status == 0;
}

bool WIFSIGNALED(int status) {
version (MinGW) // (((w) & 0xC0000000) == 0xC0000000)
return ((status) & 0xC0000000) == 0xC0000000;
else // (((w)&0377) != 0177 && ((w)&~0377) == 0)
return cast(ubyte)status != 0x7f && cast(ubyte)(status >> 8) == 0;
}

bool WIFSTOPPED(int status) {
version (RS6000) // ((w)&0x40)
return (status & 0x40) != 0;
else // (((w)&0377) == 0177)
return cast(ubyte)status == 0x7f;
}

version (CRuntime_Glibc)
bool WIFCONTINUED(int status) {
// ((s) == 0xffff)
return cast(short)status == 0xffff;
}

int WEXITSTATUS(int status) {
version (MinGW) // ((w) & ~0xC0000000)
return status & ~0xC0000000;
else // (((w) >> 8) & 0377) /* same as WRETCODE */
return cast(ubyte)(status >> 8);
}

int WTERMSIG(int status) {
// MinGW: extern int windows_status_to_termsig (unsigned long);
return status & 0x7f;
}

// #define WSTOPSIG WEXITSTATUS
alias WSTOPSIG = WEXITSTATUS;
3 changes: 3 additions & 0 deletions src/adbg/v2/debugger/breakpoint.d
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import adbg.error;

extern (C):

// NOTE: When a breakpoint is hit by the debugger, the address should
// be checked against the process' breakpoint list.

version (X86) {
private alias ubyte opcode_t;
private enum opcode_t BREAKPOINT = 0xCC; // INT3
Expand Down
7 changes: 6 additions & 1 deletion src/adbg/v2/debugger/context.d
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,12 @@ int adbg_context_fill(adbg_process_t *tracee, adbg_thread_context_t *ctx) {
adbg_context_fill_win(ctx, &winctx);
}
} else version (Posix) {
//TODO: PTRACE_GETFPREGS
//TODO: PT_GETFPREGS
// PT_GETWMMXREGS
// PT_GET_THREAD_AREA
// PT_GETCRUNCHREGS
// PT_GETVFPREGS
// PT_GETHBPREGS
user_regs_struct u = void;
if (ptrace(PT_GETREGS, tracee.pid, null, &u) < 0) {
ctx.count = 0;
Expand Down
Loading

0 comments on commit f5d645c

Please sign in to comment.