2017-05-26 00:43:26 +00:00
|
|
|
/* radare - LGPL - Copyright 2009-2017 pancake */
|
2009-02-05 21:08:46 +00:00
|
|
|
|
|
|
|
#include <r_debug.h>
|
2017-05-26 00:43:26 +00:00
|
|
|
#include <config.h>
|
2009-08-22 01:54:24 +00:00
|
|
|
|
2016-10-27 11:33:27 +00:00
|
|
|
static RDebugPlugin *debug_static_plugins[] = {
|
|
|
|
R_DEBUG_STATIC_PLUGINS
|
|
|
|
};
|
2009-02-05 21:08:46 +00:00
|
|
|
|
2015-12-04 01:57:56 +00:00
|
|
|
R_API void r_debug_plugin_init(RDebug *dbg) {
|
2009-08-22 01:54:24 +00:00
|
|
|
int i;
|
2016-12-01 08:09:59 +00:00
|
|
|
dbg->plugins = r_list_newf (free);
|
2016-10-27 11:33:27 +00:00
|
|
|
for (i = 0; debug_static_plugins[i]; i++) {
|
2017-07-21 07:37:49 +00:00
|
|
|
r_debug_plugin_add (dbg, debug_static_plugins[i]);
|
2010-05-28 00:44:51 +00:00
|
|
|
}
|
2009-02-05 21:08:46 +00:00
|
|
|
}
|
|
|
|
|
2015-12-04 01:57:56 +00:00
|
|
|
R_API bool r_debug_use(RDebug *dbg, const char *str) {
|
|
|
|
if (str) {
|
2016-10-27 11:33:27 +00:00
|
|
|
RDebugPlugin *h;
|
|
|
|
RListIter *iter;
|
|
|
|
r_list_foreach (dbg->plugins, iter, h) {
|
2015-12-04 01:57:56 +00:00
|
|
|
if (h->name && !strcmp (str, h->name)) {
|
|
|
|
dbg->h = h;
|
2017-01-22 00:08:48 +00:00
|
|
|
if (dbg->anal && dbg->anal->cur) {
|
2015-12-04 01:57:56 +00:00
|
|
|
r_debug_set_arch (dbg, dbg->anal->cur->arch, dbg->bits);
|
2017-01-22 00:08:48 +00:00
|
|
|
}
|
2015-12-04 01:57:56 +00:00
|
|
|
dbg->bp->breakpoint = dbg->h->breakpoint;
|
|
|
|
dbg->bp->user = dbg;
|
|
|
|
}
|
2009-02-05 21:08:46 +00:00
|
|
|
}
|
|
|
|
}
|
2011-03-24 10:03:23 +00:00
|
|
|
if (dbg->h && dbg->h->reg_profile) {
|
2011-05-07 16:19:16 +00:00
|
|
|
char *p = dbg->h->reg_profile (dbg);
|
2015-12-04 01:57:56 +00:00
|
|
|
if (p) {
|
2011-11-11 16:14:09 +00:00
|
|
|
r_reg_set_profile_string (dbg->reg, p);
|
2016-12-01 08:09:59 +00:00
|
|
|
if (dbg->anal && dbg->reg != dbg->anal->reg) {
|
|
|
|
r_reg_free (dbg->anal->reg);
|
2011-04-02 16:55:47 +00:00
|
|
|
dbg->anal->reg = dbg->reg;
|
2016-04-13 11:54:23 +00:00
|
|
|
}
|
2011-04-02 16:55:47 +00:00
|
|
|
if (dbg->h->init)
|
|
|
|
dbg->h->init (dbg);
|
|
|
|
r_reg_set_profile_string (dbg->reg, p);
|
2014-09-10 00:21:10 +00:00
|
|
|
free (p);
|
2015-12-04 01:57:56 +00:00
|
|
|
} else {
|
|
|
|
eprintf ("Cannot retrieve reg profile from debug plugin (%s)\n", dbg->h->name);
|
2011-04-02 16:55:47 +00:00
|
|
|
}
|
2011-03-24 10:03:23 +00:00
|
|
|
}
|
|
|
|
return (dbg->h != NULL);
|
2009-02-05 21:08:46 +00:00
|
|
|
}
|
|
|
|
|
2016-10-04 12:34:06 +00:00
|
|
|
R_API int r_debug_plugin_list(RDebug *dbg, int mode) {
|
2015-06-12 01:04:09 +00:00
|
|
|
char spaces[16];
|
2009-02-18 00:43:57 +00:00
|
|
|
int count = 0;
|
2015-06-12 01:04:09 +00:00
|
|
|
memset (spaces, ' ', 15);
|
|
|
|
spaces[15] = 0;
|
2016-10-27 11:33:27 +00:00
|
|
|
RDebugPlugin *h;
|
|
|
|
RListIter *iter;
|
|
|
|
r_list_foreach (dbg->plugins, iter, h) {
|
2015-06-12 01:04:09 +00:00
|
|
|
int sp = 8-strlen (h->name);
|
|
|
|
spaces[sp] = 0;
|
2016-10-04 12:34:06 +00:00
|
|
|
if (mode == 'q') {
|
|
|
|
dbg->cb_printf ("%s\n", h->name);
|
|
|
|
} else {
|
|
|
|
dbg->cb_printf ("%d %s %s %s%s\n",
|
|
|
|
count, (h == dbg->h)? "dbg": "---",
|
|
|
|
h->name, spaces, h->license);
|
|
|
|
}
|
2015-06-12 01:04:09 +00:00
|
|
|
spaces[sp] = ' ';
|
2009-02-18 00:43:57 +00:00
|
|
|
count++;
|
|
|
|
}
|
2015-12-04 01:57:56 +00:00
|
|
|
return false;
|
2009-02-18 00:43:57 +00:00
|
|
|
}
|
|
|
|
|
2015-12-04 01:57:56 +00:00
|
|
|
R_API bool r_debug_plugin_add(RDebug *dbg, RDebugPlugin *foo) {
|
2016-10-27 11:33:27 +00:00
|
|
|
if (!dbg || !foo || !foo->name) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-01-22 00:08:48 +00:00
|
|
|
RDebugPlugin *dp = R_NEW (RDebugPlugin);
|
|
|
|
memcpy (dp, foo, sizeof (RDebugPlugin));
|
|
|
|
r_list_append (dbg->plugins, dp);
|
2015-12-04 01:57:56 +00:00
|
|
|
return true;
|
2009-02-05 21:08:46 +00:00
|
|
|
}
|