From 486c88954f7fc6679500010c6677c8774aec35e3 Mon Sep 17 00:00:00 2001 From: pancake Date: Tue, 22 Sep 2015 02:28:04 +0200 Subject: [PATCH] Darwin: start debugging suspended. Fixes in lm32 --- libr/asm/p/asm_lm32.c | 53 ++++++++++++++++------------- libr/debug/p/native/xnu/xnu_debug.c | 2 ++ libr/io/p/io_debug.c | 13 +++---- 3 files changed, 39 insertions(+), 29 deletions(-) diff --git a/libr/asm/p/asm_lm32.c b/libr/asm/p/asm_lm32.c index bbf92f8788..7aacf8a012 100644 --- a/libr/asm/p/asm_lm32.c +++ b/libr/asm/p/asm_lm32.c @@ -8,6 +8,8 @@ #include #include "../arch/lm32/lm32_isa.h" +#define LM32_UNUSED 0 + //str has to be at least 8 chars elements long static int reg_number_to_string(ut8 reg, char *str) { ut8 match_idx = 0xff; @@ -24,6 +26,7 @@ static int reg_number_to_string(ut8 reg, char *str) { return 0; } +#if LM32_UNUSED static int string_to_reg_number(const char *str, ut8 *num) { ut8 match_idx = 0xff; int i; @@ -39,22 +42,6 @@ static int string_to_reg_number(const char *str, ut8 *num) { return 0; } -//str has to be at least 8 chars elements long -static int csr_number_to_string(ut8 csr, char *str) { - ut8 match_idx = 0xff; - int i; - for (i = 0; i < RAsmLm32CsrNumber; i++) { - if (RAsmLm32Csrs[i].number == csr) { - match_idx = i; - break; - } - } - //csr number not found in array - if (match_idx == 0xff) return -1; - strcpy (str, RAsmLm32Csrs[match_idx].name); - return 0; -} - static int string_to_csr_number(const char *str, ut8 *num) { ut8 match_idx = 0xff; int i; @@ -83,6 +70,23 @@ static int string_to_opcode(const char *str, ut8 *num) { *num = tmp_num; return 0; } +#endif + +//str has to be at least 8 chars elements long +static int csr_number_to_string(ut8 csr, char *str) { + ut8 match_idx = 0xff; + int i; + for (i = 0; i < RAsmLm32CsrNumber; i++) { + if (RAsmLm32Csrs[i].number == csr) { + match_idx = i; + break; + } + } + //csr number not found in array + if (match_idx == 0xff) return -1; + strcpy (str, RAsmLm32Csrs[match_idx].name); + return 0; +} //sign_loc is the location of the sign bit before the shift static st32 shift_and_signextend(ut8 shift, ut8 sign_loc, ut32 val) { @@ -363,6 +367,8 @@ static int r_asm_lm32_stringify(RAsmLm32Instruction *instr, char *str) { return 0; } +#if 0 + static int r_asm_lm32_destringify(const char *string, RAsmLm32Instruction *instr) { //TODO return -1; @@ -373,8 +379,14 @@ static int r_asm_lm32_encode(RAsmLm32Instruction *instr, ut32 *val) { return -1; } +static int assemble(RAsm *a, RAsmOp *ao, const char *str) { + //TODO + return -1; +} -static int disassemble(RAsm *a, RAsmOp *op, ut8 *buf, ut64 len) { +#endif + +static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { RAsmLm32Instruction instr; //lm32 is big endian a->big_endian = 1; @@ -394,18 +406,13 @@ static int disassemble(RAsm *a, RAsmOp *op, ut8 *buf, ut64 len) { return 4; } -static int assemble(RAsm *a, RAsmOp *ao, const char *str) { - //TODO - return -1; -} - RAsmPlugin r_asm_plugin_lm32 = { .name = "lm32", .arch = "lm32", .desc = "disassembly plugin for Lattice Micro 32 ISA", .license = "BSD", .bits = 32, - .disassemble = &disassemble, + .disassemble = disassemble, //.assemble = &assemble, TODO }; diff --git a/libr/debug/p/native/xnu/xnu_debug.c b/libr/debug/p/native/xnu/xnu_debug.c index 849ef389ad..c3b000f5e8 100644 --- a/libr/debug/p/native/xnu/xnu_debug.c +++ b/libr/debug/p/native/xnu/xnu_debug.c @@ -57,6 +57,7 @@ bool xnu_step(RDebug *dbg) { //debug_arch_x86_trap_set (dbg, 1); // TODO: not supported in all platforms. need dbg.swstep= + task_resume (pid_to_task (pid)); #if __arm__ || __arm64__ || __aarch64__ ios_hwstep_enable (dbg, true); ret = ptrace (PT_STEP, pid, (caddr_t)1, 0); //SIGINT @@ -98,6 +99,7 @@ int xnu_continue(RDebug *dbg, int pid, int tid, int sig) { #else //ut64 rip = r_debug_reg_get (dbg, "pc"); void *data = (void*)(size_t)((sig != -1) ? sig : dbg->reason.signum); + task_resume (pid_to_task (pid)); return ptrace (PT_CONTINUE, pid, (void*)(size_t)1, (int)(size_t)data) == 0; #endif diff --git a/libr/io/p/io_debug.c b/libr/io/p/io_debug.c index 284e877e9f..e0a0d32d48 100644 --- a/libr/io/p/io_debug.c +++ b/libr/io/p/io_debug.c @@ -279,13 +279,15 @@ static int fork_and_ptraceme(RIO *io, int bits, const char *cmd) { { #define _POSIX_SPAWN_DISABLE_ASLR 0x0100 posix_spawn_file_actions_t fileActions; - ut32 ps_flags = POSIX_SPAWN_SETEXEC; + //ut32 ps_flags = POSIX_SPAWN_SETEXEC; + ut32 ps_flags = POSIX_SPAWN_SETEXEC | \ + POSIX_SPAWN_SETSIGDEF | \ + POSIX_SPAWN_SETSIGMASK; posix_spawnattr_t attr = {0}; size_t copied = 1; cpu_type_t cpu; pid_t p = -1; - int ret; - int useASLR = io->aslr; + int ret, useASLR = io->aslr; posix_spawnattr_init (&attr); if (useASLR != -1) { if (useASLR) { @@ -301,6 +303,7 @@ static int fork_and_ptraceme(RIO *io, int bits, const char *cmd) { posix_spawn_file_actions_addinherit_np (&fileActions, STDOUT_FILENO); posix_spawn_file_actions_addinherit_np (&fileActions, STDERR_FILENO); ps_flags |= POSIX_SPAWN_CLOEXEC_DEFAULT; + ps_flags |= POSIX_SPAWN_START_SUSPENDED; (void)posix_spawnattr_setflags (&attr, ps_flags); #if __i386__ || __x86_64__ @@ -373,9 +376,7 @@ static int fork_and_ptraceme(RIO *io, int bits, const char *cmd) { #endif static int __plugin_open(RIO *io, const char *file, ut8 many) { - if (!strncmp (file, "dbg://", 6) && file[6]) - return true; - return false; + return (!strncmp (file, "dbg://", 6) && file[6]); } static RIODesc *__open(RIO *io, const char *file, int rw, int mode) {