Linux debugger improvements

This commit is contained in:
pancake 2021-04-19 17:28:42 -07:00
parent c04ae7dd64
commit b5e262a6b9
8 changed files with 31 additions and 24 deletions

View File

@ -1,4 +1,4 @@
/* radare2 - LGPL - Copyright 2008-2020 - pancake, Jody Frankowski */
/* radare2 - LGPL - Copyright 2008-2021 - pancake, Jody Frankowski */
#include <r_cons.h>
#include <r_util.h>

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009-2019 - pancake */
/* radare - LGPL - Copyright 2009-2021 - pancake */
#include <r_userconf.h>
#include <r_debug.h>
@ -667,7 +667,7 @@ static int bsd_reg_read (RDebug *dbg, int type, ut8* buf, int size) {
case R_REG_TYPE_GPR:
{
R_DEBUG_REG_T regs;
memset (&regs, 0, sizeof(regs));
memset (&regs, 0, sizeof (regs));
memset (buf, 0, size);
#if __NetBSD__ || __OpenBSD__
ret = ptrace (PTRACE_GETREGS, pid, (caddr_t)&regs, sizeof (regs));
@ -681,8 +681,12 @@ static int bsd_reg_read (RDebug *dbg, int type, ut8* buf, int size) {
// process exists still.. is because there's a
// missing call to 'wait'. and the process is not
// yet available to accept more ptrace queries.
if (ret != 0) return false;
if (sizeof(regs) < size) size = sizeof(regs);
if (ret != 0) {
return false;
}
if (sizeof (regs) < size) {
size = sizeof (regs);
}
memcpy (buf, &regs, size);
return sizeof(regs);
}

View File

@ -1176,10 +1176,6 @@ int linux_reg_read(RDebug *dbg, int type, ut8 *buf, int size) {
};
ret = r_debug_ptrace (dbg, PTRACE_GETREGSET, pid, 1, &io);
// ret = ptrace (PTRACE_GETREGSET, pid, (void*)(size_t)(NT_PRSTATUS), NULL); // &io);
if (ret != 0) {
r_sys_perror("PTRACE_GETREGSET");
return false;
}
#elif __BSD__ && (__POWERPC__ || __sparc__)
ret = r_debug_ptrace (dbg, PTRACE_GETREGS, pid, &regs, NULL);
#else
@ -1227,8 +1223,8 @@ int linux_reg_read(RDebug *dbg, int type, ut8 *buf, int size) {
ymm_space[ri*8+rj] = xstate.fpstate._xmm[ri].element[rj];
#endif
}
for (rj=0; rj < 4; rj++) {
ymm_space[ri*8+(rj+4)] = xstate.ymmh.ymmh_space[ri*4+rj];
for (rj = 0; rj < 4; rj++) {
ymm_space[ri * 8 + (rj + 4)] = xstate.ymmh.ymmh_space[ri * 4 + rj];
}
}
size = R_MIN (sizeof (ymm_space), size);

View File

@ -25,7 +25,7 @@
#ifdef __GLIBC__
typedef enum __ptrace_request ptrace_wrap_ptrace_request;
#else
typedef int ptrace_wrap_ptrace_request;
typedef size_t ptrace_wrap_ptrace_request;
#endif
typedef enum {

View File

@ -117,16 +117,16 @@ typedef struct r_io_t {
SdbList *plugins;
char *runprofile;
char *envprofile;
#if USE_PTRACE_WRAP
struct ptrace_wrap_instance_t *ptrace_wrap;
#endif
#if __WINDOWS__
struct w32dbg_wrap_instance_t *w32dbg_wrap;
#endif
char *args;
REvent *event;
PrintfCallback cb_printf;
RCoreBind corebind;
#if __WINDOWS__
struct w32dbg_wrap_instance_t *w32dbg_wrap;
#endif
#if USE_PTRACE_WRAP
struct ptrace_wrap_instance_t *ptrace_wrap;
#endif
} RIO;
typedef struct r_io_desc_t {

View File

@ -292,6 +292,14 @@ static int __close(RIODesc *desc) {
return ret;
}
static void show_help(void) {
eprintf ("Usage: =!cmd args\n"
" =!ptrace - use ptrace io\n"
" =!mem - use /proc/pid/mem io if possible\n"
" =!pid - show targeted pid\n"
" =!pid <#> - select new pid\n");
}
static char *__system(RIO *io, RIODesc *fd, const char *cmd) {
RIOPtrace *iop = (RIOPtrace*)fd->data;
//printf("ptrace io command (%s)\n", cmd);
@ -300,11 +308,7 @@ static char *__system(RIO *io, RIODesc *fd, const char *cmd) {
return NULL;
}
if (!strcmp (cmd, "help")) {
eprintf ("Usage: =!cmd args\n"
" =!ptrace - use ptrace io\n"
" =!mem - use /proc/pid/mem io if possible\n"
" =!pid - show targeted pid\n"
" =!pid <#> - select new pid\n");
show_help ();
} else
if (!strcmp (cmd, "ptrace")) {
close_pidmem (iop);
@ -327,7 +331,7 @@ static char *__system(RIO *io, RIODesc *fd, const char *cmd) {
return r_str_newf ("%d", iop->pid);
}
} else {
eprintf ("Try: '=!pid'\n");
show_help ();
}
return NULL;
}

View File

@ -81,6 +81,7 @@ static void wrap_func(ptrace_wrap_instance *inst) {
static void *th_run(ptrace_wrap_instance *inst) {
while (1) {
sem_wait (&inst->request_sem);
switch (inst->request.type) {
case PTRACE_WRAP_REQUEST_TYPE_STOP:
goto stop;
@ -94,6 +95,7 @@ static void *th_run(ptrace_wrap_instance *inst) {
wrap_func (inst);
break;
}
sem_post (&inst->result_sem);
}
stop:

View File

@ -9,6 +9,7 @@ printf "\033[33m"
echo "Sanitize build script can be configured with the SANITIZE environment variable."
echo "Use one of the following words to specify which sanitizers to use:"
echo " - address - detect memory errors"
echo " - thread - detect thread racing issues"
echo " - leak - find memory leaks"
echo " - memory - detect uninitialized reads"
echo " - undefined - find undefined behaviour"