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