2017-04-09 21:41:32 +00:00
|
|
|
/* radare - LGPL - Copyright 2009-2017 - pancake */
|
2009-04-01 22:44:43 +00:00
|
|
|
|
|
|
|
#include <r_debug.h>
|
|
|
|
|
2017-04-09 21:41:32 +00:00
|
|
|
R_API RDebugPid *r_debug_pid_new(const char *path, int pid, int uid, char status, ut64 pc) {
|
2015-08-29 12:01:38 +00:00
|
|
|
RDebugPid *p = R_NEW0 (RDebugPid);
|
2017-04-09 21:41:32 +00:00
|
|
|
if (!p) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-03-05 00:49:12 +00:00
|
|
|
p->path = strdup (path);
|
|
|
|
p->pid = pid;
|
2017-04-09 21:41:32 +00:00
|
|
|
p->uid = uid;
|
2010-03-05 00:49:12 +00:00
|
|
|
p->status = status;
|
2015-09-14 00:08:31 +00:00
|
|
|
p->runnable = true;
|
2010-11-11 03:12:09 +00:00
|
|
|
p->pc = pc;
|
2010-03-05 00:49:12 +00:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
R_API RDebugPid *r_debug_pid_free(RDebugPid *pid) {
|
2015-08-29 12:01:38 +00:00
|
|
|
free (pid->path);
|
|
|
|
free (pid);
|
2010-03-05 00:49:12 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-12-22 00:23:35 +00:00
|
|
|
R_API RList *r_debug_pids(RDebug *dbg, int pid) {
|
2016-12-09 17:07:06 +00:00
|
|
|
if (dbg && dbg->h && dbg->h->pids) {
|
|
|
|
return dbg->h->pids (dbg, pid);
|
|
|
|
}
|
2010-12-22 00:23:35 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-10-01 19:39:28 +00:00
|
|
|
// TODO: deprecate list/iterate functions from core apis? keep them for easiness?
|
|
|
|
R_API int r_debug_pid_list(RDebug *dbg, int pid, char fmt) {
|
2010-03-05 00:49:12 +00:00
|
|
|
RList *list;
|
|
|
|
RListIter *iter;
|
2012-02-14 17:19:16 +00:00
|
|
|
RDebugPid *p;
|
2010-03-05 00:49:12 +00:00
|
|
|
if (dbg && dbg->h && dbg->h->pids) {
|
2016-12-09 17:07:06 +00:00
|
|
|
list = dbg->h->pids (dbg, R_MAX (0, pid));
|
|
|
|
if (!list) {
|
2015-09-14 00:08:31 +00:00
|
|
|
return false;
|
2016-12-09 17:07:06 +00:00
|
|
|
}
|
2019-03-18 18:16:08 +00:00
|
|
|
PJ *j = pj_new ();
|
|
|
|
pj_a (j);
|
2014-10-01 19:39:28 +00:00
|
|
|
r_list_foreach (list, iter, p) {
|
|
|
|
switch (fmt) {
|
|
|
|
case 'j':
|
2019-03-18 18:16:08 +00:00
|
|
|
pj_o (j);
|
|
|
|
pj_ki (j, "pid", p->pid);
|
|
|
|
pj_ki (j, "uid", p->uid);
|
|
|
|
pj_ks (j, "status", &p->status);
|
|
|
|
pj_ks (j, "path", p->path);
|
|
|
|
pj_end (j);
|
2014-10-01 19:39:28 +00:00
|
|
|
break;
|
|
|
|
default:
|
2017-04-09 21:41:32 +00:00
|
|
|
dbg->cb_printf (" %c %d uid:%d %c %s\n",
|
|
|
|
dbg->pid == p->pid? '*': '-',
|
|
|
|
p->pid, p->uid, p->status, p->path);
|
2014-10-01 19:39:28 +00:00
|
|
|
break;
|
2014-08-29 23:12:12 +00:00
|
|
|
}
|
2010-03-05 00:49:12 +00:00
|
|
|
}
|
2019-03-18 18:16:08 +00:00
|
|
|
pj_end (j);
|
2017-04-09 21:41:32 +00:00
|
|
|
if (fmt == 'j') {
|
2019-03-18 18:16:08 +00:00
|
|
|
dbg->cb_printf (pj_string (j));
|
2017-04-09 21:41:32 +00:00
|
|
|
}
|
2019-03-18 18:16:08 +00:00
|
|
|
pj_free (j);
|
2010-03-05 00:49:12 +00:00
|
|
|
r_list_free (list);
|
|
|
|
}
|
2015-09-14 00:08:31 +00:00
|
|
|
return false;
|
2009-04-01 22:44:43 +00:00
|
|
|
}
|
|
|
|
|
2014-08-29 23:12:12 +00:00
|
|
|
R_API int r_debug_thread_list(RDebug *dbg, int pid) {
|
2010-03-10 23:29:36 +00:00
|
|
|
RList *list;
|
|
|
|
RListIter *iter;
|
2012-02-14 17:19:16 +00:00
|
|
|
RDebugPid *p;
|
2016-04-21 13:21:56 +00:00
|
|
|
if (pid == -1) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-12-04 23:18:51 +00:00
|
|
|
if (dbg && dbg->h && dbg->h->threads) {
|
2012-06-07 01:41:21 +00:00
|
|
|
list = dbg->h->threads (dbg, pid);
|
2018-09-13 08:17:26 +00:00
|
|
|
if (!list) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-08-29 12:01:38 +00:00
|
|
|
if (pid == -'j') {
|
2019-03-18 18:16:08 +00:00
|
|
|
PJ *j = pj_new ();
|
|
|
|
pj_a (j);
|
2014-08-29 23:12:12 +00:00
|
|
|
r_list_foreach (list, iter, p) {
|
2019-03-18 18:16:08 +00:00
|
|
|
pj_o (j);
|
|
|
|
pj_ki (j, "pid", p->pid);
|
|
|
|
pj_ks (j, "status", &p->status);
|
|
|
|
pj_ks (j, "path", p->path);
|
|
|
|
pj_end (j);
|
2014-08-29 23:12:12 +00:00
|
|
|
}
|
2019-03-18 18:16:08 +00:00
|
|
|
pj_end (j);
|
|
|
|
dbg->cb_printf (pj_string (j));
|
|
|
|
pj_free (j);
|
2014-08-29 23:12:12 +00:00
|
|
|
} else {
|
|
|
|
r_list_foreach (list, iter, p) {
|
2015-08-08 18:15:13 +00:00
|
|
|
dbg->cb_printf (" %c %d %c %s\n",
|
2015-08-29 12:01:38 +00:00
|
|
|
dbg->tid == p->pid ? '*' : '-',
|
|
|
|
p->pid, p->status, p->path);
|
2014-08-29 23:12:12 +00:00
|
|
|
}
|
2010-03-10 23:29:36 +00:00
|
|
|
}
|
|
|
|
r_list_free (list);
|
|
|
|
}
|
2015-09-14 00:08:31 +00:00
|
|
|
return false;
|
2010-03-10 23:29:36 +00:00
|
|
|
}
|
|
|
|
|
2009-04-01 22:44:43 +00:00
|
|
|
/* processes */
|
2010-03-02 10:18:49 +00:00
|
|
|
R_API int r_debug_pid_parent(RDebugPid *pid) {
|
2009-09-10 20:51:34 +00:00
|
|
|
// fork in child
|
|
|
|
return 0;
|
2009-04-01 22:44:43 +00:00
|
|
|
}
|
|
|
|
|
2010-03-05 00:49:12 +00:00
|
|
|
#if 0
|
2010-03-02 10:18:49 +00:00
|
|
|
R_API int r_debug_pid_del(struct r_debug_t *dbg) {
|
2009-09-10 20:51:34 +00:00
|
|
|
// kill da child
|
2015-09-14 00:08:31 +00:00
|
|
|
return true;
|
2009-04-01 22:44:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* threads */
|
2010-03-02 10:18:49 +00:00
|
|
|
R_API int r_debug_pid_add_thread(struct r_debug_t *dbg) {
|
2009-09-10 20:51:34 +00:00
|
|
|
// create a thread in process
|
2015-09-14 00:08:31 +00:00
|
|
|
return true;
|
2009-04-01 22:44:43 +00:00
|
|
|
}
|
|
|
|
|
2010-03-02 10:18:49 +00:00
|
|
|
R_API int r_debug_pid_del_thread(struct r_debug_t *dbg) {
|
2009-09-10 20:51:34 +00:00
|
|
|
// kill a thread in process
|
2015-09-14 00:08:31 +00:00
|
|
|
return true;
|
2009-04-01 22:44:43 +00:00
|
|
|
}
|
2010-03-05 00:49:12 +00:00
|
|
|
#endif
|
2009-04-01 22:44:43 +00:00
|
|
|
|
|
|
|
/* status */
|
2010-03-02 10:18:49 +00:00
|
|
|
R_API int r_debug_pid_set_state(struct r_debug_t *dbg, int status) {
|
2015-09-14 00:08:31 +00:00
|
|
|
return true;
|
2009-04-01 22:44:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* status */
|
2010-03-02 10:18:49 +00:00
|
|
|
R_API struct r_debug_pid_t *r_debug_pid_get_status(struct r_debug_t *dbg, int pid) {
|
2009-04-01 22:44:43 +00:00
|
|
|
return NULL;
|
|
|
|
}
|