radare2/libr/debug/plugin.c

84 lines
1.9 KiB
C
Raw Normal View History

/* radare - LGPL - Copyright 2009-2017 pancake */
#include <r_debug.h>
#include <config.h>
static RDebugPlugin *debug_static_plugins[] = {
R_DEBUG_STATIC_PLUGINS
};
2015-12-04 01:57:56 +00:00
R_API void r_debug_plugin_init(RDebug *dbg) {
int i;
dbg->plugins = r_list_newf (free);
for (i = 0; debug_static_plugins[i]; i++) {
r_debug_plugin_add (dbg, debug_static_plugins[i]);
}
}
2015-12-04 01:57:56 +00:00
R_API bool r_debug_use(RDebug *dbg, const char *str) {
if (str) {
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;
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);
}
2015-12-04 01:57:56 +00:00
dbg->bp->breakpoint = dbg->h->breakpoint;
dbg->bp->user = dbg;
}
}
}
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) {
r_reg_set_profile_string (dbg->reg, p);
if (dbg->anal && dbg->reg != dbg->anal->reg) {
r_reg_free (dbg->anal->reg);
dbg->anal->reg = dbg->reg;
2016-04-13 11:54:23 +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);
}
}
return (dbg->h != NULL);
}
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];
int count = 0;
2015-06-12 01:04:09 +00:00
memset (spaces, ' ', 15);
spaces[15] = 0;
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] = ' ';
count++;
}
2015-12-04 01:57:56 +00:00
return false;
}
2015-12-04 01:57:56 +00:00
R_API bool r_debug_plugin_add(RDebug *dbg, RDebugPlugin *foo) {
if (!dbg || !foo || !foo->name) {
return false;
}
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;
}