Fixes for winedbg:// and debug.io
This commit is contained in:
parent
a9b4bb76fb
commit
a1e24700e3
8 changed files with 78 additions and 57 deletions
|
|
@ -723,17 +723,20 @@ int main(int argc, char **argv, char **envp) {
|
|||
const char *src = haveRarunProfile? pfile: argv[optind];
|
||||
if (src && *src) {
|
||||
char *uri = strdup (src);
|
||||
char *p = strstr (uri, "://");
|
||||
if (p) {
|
||||
*p = 0;
|
||||
if (!strcmp (uri, "winedbg")) {
|
||||
debugbackend = "io";
|
||||
if (uri) {
|
||||
char *p = strstr (uri, "://");
|
||||
if (p) {
|
||||
*p = 0;
|
||||
// TODO: this must be specified by the io plugin, not hardcoded here
|
||||
if (!strcmp (uri, "winedbg")) {
|
||||
debugbackend = "io";
|
||||
} else {
|
||||
debugbackend = uri;
|
||||
}
|
||||
debug = 2;
|
||||
} else {
|
||||
debugbackend = uri;
|
||||
free (uri);
|
||||
}
|
||||
debug = 2;
|
||||
} else {
|
||||
free (uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -904,12 +907,6 @@ int main(int argc, char **argv, char **envp) {
|
|||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
if (fh) {
|
||||
r_core_bin_load (&r, pfile);
|
||||
r_debug_use (r.dbg, debugbackend);
|
||||
}
|
||||
*/
|
||||
}
|
||||
} else {
|
||||
const char *f = (haveRarunProfile && pfile)? pfile: argv[optind];
|
||||
|
|
|
|||
|
|
@ -3006,16 +3006,9 @@ static char *get_reg_profile(RAnal *anal) {
|
|||
break;
|
||||
#endif
|
||||
}
|
||||
if (p && *p) return strdup (p);
|
||||
return NULL;
|
||||
return (p && *p)? strdup (p): NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
static int set_reg_profile(RAnal *anal) {
|
||||
return r_reg_set_profile_string (anal->reg, p);
|
||||
}
|
||||
*/
|
||||
|
||||
static int archinfo(RAnal *anal, int q) {
|
||||
switch (q) {
|
||||
case R_ANAL_ARCHINFO_ALIGN:
|
||||
|
|
|
|||
|
|
@ -563,15 +563,11 @@ static int cb_asmbits(void *user, void *data) {
|
|||
core->print->bits = bits;
|
||||
}
|
||||
if (core->dbg && core->anal && core->anal->cur) {
|
||||
bool load_from_debug = false;
|
||||
r_debug_set_arch (core->dbg, core->anal->cur->arch, bits);
|
||||
if (r_config_get_i (core->config, "cfg.debug")) {
|
||||
load_from_debug = true;
|
||||
} else {
|
||||
(void)r_anal_set_reg_profile (core->anal);
|
||||
}
|
||||
bool load_from_debug = r_config_get_i (core->config, "cfg.debug");
|
||||
if (load_from_debug) {
|
||||
if (core->dbg->h && core->dbg->h->reg_profile) {
|
||||
// XXX. that should depend on the plugin, not the host os
|
||||
#if __WINDOWS__
|
||||
#if !defined(__MINGW64__) && !defined(_WIN64)
|
||||
core->dbg->bits = R_SYS_BITS_32;
|
||||
|
|
@ -584,6 +580,8 @@ static int cb_asmbits(void *user, void *data) {
|
|||
r_reg_set_profile_string (core->anal->reg, rp);
|
||||
free (rp);
|
||||
}
|
||||
} else {
|
||||
(void)r_anal_set_reg_profile (core->anal);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -602,11 +600,7 @@ static int cb_asmbits(void *user, void *data) {
|
|||
/* set pcalign */
|
||||
{
|
||||
int v = r_anal_archinfo (core->anal, R_ANAL_ARCHINFO_ALIGN);
|
||||
if (v != -1) {
|
||||
r_config_set_i (core->config, "asm.pcalign", v);
|
||||
} else {
|
||||
r_config_set_i (core->config, "asm.pcalign", 0);
|
||||
}
|
||||
r_config_set_i (core->config, "asm.pcalign", (v != -1)? v: 0);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -879,16 +873,15 @@ static int cb_cfgdebug(void *user, void *data) {
|
|||
if (!strcmp (r_config_get (core->config, "cmd.prompt"), "")) {
|
||||
r_config_set (core->config, "cmd.prompt", ".dr*");
|
||||
}
|
||||
if (!strcmp (dbgbackend, "bf"))
|
||||
if (!strcmp (dbgbackend, "bf")) {
|
||||
r_config_set (core->config, "asm.arch", "bf");
|
||||
}
|
||||
if (core->file) {
|
||||
r_debug_select (core->dbg, r_io_fd_get_pid (core->io, core->file->fd),
|
||||
r_io_fd_get_tid (core->io, core->file->fd));
|
||||
}
|
||||
} else {
|
||||
if (core->dbg) {
|
||||
r_debug_use (core->dbg, NULL);
|
||||
}
|
||||
r_debug_use (core->dbg, NULL);
|
||||
core->bin->is_debugger = false;
|
||||
}
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -685,7 +685,6 @@ R_API RDebugReasonType r_debug_wait(RDebug *dbg, RBreakpointItem **bp) {
|
|||
dbg->reason.type = reason;
|
||||
if (reason == R_DEBUG_REASON_SIGNAL && dbg->reason.signum != -1) {
|
||||
/* handle signal on continuations here */
|
||||
eprintf ("got signal...\n");
|
||||
int what = r_debug_signal_what (dbg, dbg->reason.signum);
|
||||
const char *name = r_signal_to_string (dbg->reason.signum);
|
||||
if (name && strcmp ("SIGTRAP", name)) {
|
||||
|
|
|
|||
|
|
@ -41,11 +41,12 @@ R_API void r_debug_map_list(RDebug *dbg, ut64 addr, int rad) {
|
|||
break;
|
||||
case '*':
|
||||
r_list_foreach (dbg->maps, iter, map) {
|
||||
char *name = r_str_newf ("%s.%s", map->name,
|
||||
r_str_rwx_i (map->perm));
|
||||
char *name = (map->name && *map->name)
|
||||
? r_str_newf ("%s.%s", map->name, r_str_rwx_i (map->perm))
|
||||
: r_str_newf ("%08"PFMT64x".%s", map->addr, r_str_rwx_i (map->perm));
|
||||
r_name_filter (name, 0);
|
||||
dbg->cb_printf ("f map.%s 0x%08"PFMT64x" 0x%08"PFMT64x"\n",
|
||||
name, map->addr_end - map->addr, map->addr);
|
||||
name, map->addr_end - map->addr + 1, map->addr);
|
||||
free (name);
|
||||
}
|
||||
r_list_foreach (dbg->maps_user, iter, map) {
|
||||
|
|
|
|||
|
|
@ -5,29 +5,27 @@
|
|||
#include <r_debug.h>
|
||||
|
||||
static int __io_step(RDebug *dbg) {
|
||||
dbg->iob.system (dbg->iob.io, "ds");
|
||||
free (dbg->iob.system (dbg->iob.io, "ds"));
|
||||
return true;
|
||||
}
|
||||
|
||||
static int __io_step_over(RDebug *dbg) {
|
||||
dbg->iob.system (dbg->iob.io, "dso");
|
||||
free (dbg->iob.system (dbg->iob.io, "dso"));
|
||||
return true;
|
||||
}
|
||||
|
||||
static RList *__io_maps(RDebug *dbg) {
|
||||
RList *list = r_list_new ();
|
||||
dbg->iob.system (dbg->iob.io, "dm");
|
||||
const char *consdata = r_cons_get_buffer ();
|
||||
if (!consdata) {
|
||||
char *str = dbg->iob.system (dbg->iob.io, "dm");
|
||||
if (!str) {
|
||||
r_list_free (list);
|
||||
return NULL;
|
||||
}
|
||||
char *ostr, *str = strdup (consdata);
|
||||
char *ostr = str;
|
||||
ut64 map_start, map_end;
|
||||
char perm[32];
|
||||
char name[512];
|
||||
ostr = str;
|
||||
while (true) {
|
||||
for (;;) {
|
||||
char *nl = strchr (str, '\n');
|
||||
if (nl) {
|
||||
*nl = 0;
|
||||
|
|
@ -80,7 +78,10 @@ static int __io_attach(RDebug *dbg, int pid) {
|
|||
// "drp" register profile
|
||||
static char *__io_reg_profile(RDebug *dbg) {
|
||||
r_cons_push ();
|
||||
dbg->iob.system (dbg->iob.io, "drp");
|
||||
char *drp = dbg->iob.system (dbg->iob.io, "drp");
|
||||
if (drp) {
|
||||
return drp;
|
||||
}
|
||||
const char *buf = r_cons_get_buffer ();
|
||||
if (buf && *buf) {
|
||||
char *ret = strdup (buf);
|
||||
|
|
|
|||
|
|
@ -134,7 +134,7 @@ static void printcmd (RIO *io, const char *cmd) {
|
|||
free (res);
|
||||
}
|
||||
|
||||
struct winedbg_x86_32 { // __attribute__((__packed__)) {
|
||||
struct __attribute__((packed)) winedbg_x86_32 {
|
||||
ut16 cs, ss, ds, es, fs, gs;
|
||||
ut32 eip, esp, ebp, eflags;
|
||||
ut32 eax, ebx, ecx, edx;
|
||||
|
|
@ -147,15 +147,28 @@ static struct winedbg_x86_32 regState() {
|
|||
if (res) {
|
||||
char *line = strstr (res, "EIP:");
|
||||
if (line) {
|
||||
ut32 eip, esp, ebp, eflags;
|
||||
(void)sscanf (line, "EIP:%08x ESP:%08x EBP:%08x EFLAGS:%08x",
|
||||
&r.eip, &r.esp, &r.ebp, &r.eflags);
|
||||
&eip, &esp, &ebp, &eflags);
|
||||
r.eip = eip;
|
||||
r.esp = esp;
|
||||
r.ebp = ebp;
|
||||
r.eflags = eflags;
|
||||
line = strstr (line, "EAX:");
|
||||
if (line) {
|
||||
ut32 eax, ebx, ecx, edx;
|
||||
(void)sscanf (line, "EAX:%08x EBX:%08x ECX:%08x EDX:%08x",
|
||||
&r.eax, &r.ebx, &r.ecx, &r.edx);
|
||||
&eax, &ebx, &ecx, &edx);
|
||||
r.eax = eax;
|
||||
r.ebx = ebx;
|
||||
r.ecx = ecx;
|
||||
r.edx = edx;
|
||||
line = strstr (line, "ESI:");
|
||||
if (line) {
|
||||
(void)sscanf (line, "ESI:%08x EDI:%08x", &r.esi, &r.edi);
|
||||
ut32 esi, edi;
|
||||
(void)sscanf (line, "ESI:%08x EDI:%08x", &esi, &edi);
|
||||
r.esi = esi;
|
||||
r.edi = edi;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -242,7 +255,32 @@ const char *msg =
|
|||
} else if (!strncmp (cmd, "dp", 3)) {
|
||||
printcmd (io, "info thread");
|
||||
} else if (!strncmp (cmd, "dm", 3)) {
|
||||
printcmd (io, "info maps");
|
||||
char *wineDbgMaps = runcmd ("info maps");
|
||||
char *res = NULL;
|
||||
if (wineDbgMaps) {
|
||||
const char *perm;
|
||||
char *ptr = wineDbgMaps;
|
||||
for (;;) {
|
||||
char *nl = strchr (ptr, '\n');
|
||||
if (!nl) {
|
||||
break;
|
||||
}
|
||||
*nl++ = 0;
|
||||
perm = "r-x";
|
||||
ut64 from = 0, to = 0;
|
||||
if (strstr (ptr, " commit ")) {
|
||||
if (strstr (ptr, "RW")) {
|
||||
perm = "rw-";
|
||||
}
|
||||
sscanf (ptr, "%08"PFMT64x" %08"PFMT64x, &from, &to);
|
||||
}
|
||||
char *row = r_str_newf ("0x%08"PFMT64x" - 0x%08" PFMT64x" %s %s\n", from, to, perm, "");
|
||||
ptr = nl + 1;
|
||||
res = r_str_append (res, row);
|
||||
}
|
||||
free (wineDbgMaps);
|
||||
return res;
|
||||
}
|
||||
} else if (!strncmp (cmd, "pid", 3)) {
|
||||
return r_str_newf ("%d", fd->fd);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -716,7 +716,6 @@ R_API int r_run_config_env(RRunProfile *p) {
|
|||
eprintf ("Cannot connect\n");
|
||||
return 1;
|
||||
}
|
||||
eprintf ("connected\n");
|
||||
if (p->_pty) {
|
||||
if (redirect_socket_to_pty (fd) != 0) {
|
||||
eprintf ("socket redirection failed\n");
|
||||
|
|
|
|||
Loading…
Reference in a new issue