Rizin
unix-like reverse engineering framework and cli tools
pid.c File Reference
#include <rz_debug.h>

Go to the source code of this file.

Functions

RZ_API RzDebugPidrz_debug_pid_new (const char *path, int pid, int uid, char status, ut64 pc)
 
RZ_API RzDebugPidrz_debug_pid_free (RzDebugPid *pid)
 
RZ_API RzListrz_debug_pids (RzDebug *dbg, int pid)
 
RZ_API int rz_debug_pid_list (RzDebug *dbg, int pid, char fmt)
 
RZ_API int rz_debug_thread_list (RzDebug *dbg, int pid, char fmt)
 
RZ_API int rz_debug_pid_parent (RzDebugPid *pid)
 
RZ_API int rz_debug_pid_set_state (struct rz_debug_t *dbg, int status)
 
RZ_API struct rz_debug_pid_trz_debug_pid_get_status (struct rz_debug_t *dbg, int pid)
 

Function Documentation

◆ rz_debug_pid_free()

RZ_API RzDebugPid* rz_debug_pid_free ( RzDebugPid pid)

Definition at line 20 of file pid.c.

20  {
21  free(pid->path);
22  free(pid);
23  return NULL;
24 }
#define NULL
Definition: cris-opc.c:27
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc pid
Definition: sflib.h:64

References free(), NULL, and pid.

Referenced by linux_pid_list(), linux_thread_list(), rz_debug_dmp_pids(), rz_debug_gdb_pids(), rz_debug_gdb_threads(), rz_debug_winkd_pids(), windbg_pids(), windbg_threads(), and xnu_thread_list().

◆ rz_debug_pid_get_status()

RZ_API struct rz_debug_pid_t* rz_debug_pid_get_status ( struct rz_debug_t dbg,
int  pid 
)

Definition at line 180 of file pid.c.

180  {
181  return NULL;
182 }

References NULL.

◆ rz_debug_pid_list()

RZ_API int rz_debug_pid_list ( RzDebug dbg,
int  pid,
char  fmt 
)

Definition at line 34 of file pid.c.

34  {
35  RzList *list;
37  RzDebugPid *p;
38  if (dbg && dbg->cur && dbg->cur->pids) {
39  list = dbg->cur->pids(dbg, RZ_MAX(0, pid));
40  if (!list) {
41  return false;
42  }
43  PJ *j = pj_new();
44  pj_a(j);
45  rz_list_foreach (list, iter, p) {
46  switch (fmt) {
47  case 'j':
48  pj_o(j);
49  pj_kb(j, "current", dbg->pid == p->pid);
50  pj_ki(j, "ppid", p->ppid);
51  pj_ki(j, "pid", p->pid);
52  pj_ki(j, "uid", p->uid);
53  pj_ks(j, "status", &p->status);
54  pj_ks(j, "path", p->path);
55  pj_end(j);
56  break;
57  default:
58  dbg->cb_printf(" %c %d ppid:%d uid:%d %c %s\n",
59  dbg->pid == p->pid ? '*' : '-',
60  p->pid, p->ppid, p->uid, p->status, p->path);
61  break;
62  }
63  }
64  pj_end(j);
65  if (fmt == 'j') {
66  dbg->cb_printf("%s", pj_string(j));
67  }
68  pj_free(j);
70  }
71  return false;
72 }
RzDebug * dbg
Definition: desil.c:30
void * p
Definition: libc.cpp:67
static void list(RzEgg *egg)
Definition: rz-gg.c:52
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137
RZ_API PJ * pj_new(void)
Definition: pj.c:25
RZ_API PJ * pj_kb(PJ *j, const char *k, bool v)
Definition: pj.c:177
RZ_API PJ * pj_ki(PJ *j, const char *k, int d)
Definition: pj.c:149
RZ_API PJ * pj_end(PJ *j)
Definition: pj.c:87
RZ_API const char * pj_string(PJ *pj)
Definition: pj.c:57
RZ_API void pj_free(PJ *j)
Definition: pj.c:34
RZ_API PJ * pj_o(PJ *j)
Definition: pj.c:75
RZ_API PJ * pj_ks(PJ *j, const char *k, const char *v)
Definition: pj.c:170
RZ_API PJ * pj_a(PJ *j)
Definition: pj.c:81
#define RZ_MAX(x, y)
Definition: rz_pj.h:12
RzList *(* pids)(RzDebug *dbg, int pid)
Definition: rz_debug.h:376
PrintfCallback cb_printf
Definition: rz_debug.h:292
struct rz_debug_plugin_t * cur
Definition: rz_debug.h:295

References rz_debug_t::cb_printf, rz_debug_t::cur, dbg, list(), p, rz_debug_t::pid, pid, rz_debug_plugin_t::pids, pj_a(), pj_end(), pj_free(), pj_kb(), pj_ki(), pj_ks(), pj_new(), pj_o(), pj_string(), rz_list_free(), and RZ_MAX.

Referenced by cmd_debug_pid().

◆ rz_debug_pid_new()

RZ_API RzDebugPid* rz_debug_pid_new ( const char *  path,
int  pid,
int  uid,
char  status,
ut64  pc 
)

Definition at line 6 of file pid.c.

6  {
8  if (!p) {
9  return NULL;
10  }
11  p->path = strdup(path);
12  p->pid = pid;
13  p->uid = uid;
14  p->status = status;
15  p->runnable = true;
16  p->pc = pc;
17  return p;
18 }
static static fork const void static count static fd const char const char static newpath const char static path const char path
Definition: sflib.h:35
return strdup("=SP r13\n" "=LR r14\n" "=PC r15\n" "=A0 r0\n" "=A1 r1\n" "=A2 r2\n" "=A3 r3\n" "=ZF zf\n" "=SF nf\n" "=OF vf\n" "=CF cf\n" "=SN or0\n" "gpr lr .32 56 0\n" "gpr pc .32 60 0\n" "gpr cpsr .32 64 0 ____tfiae_________________qvczn\n" "gpr or0 .32 68 0\n" "gpr tf .1 64.5 0 thumb\n" "gpr ef .1 64.9 0 endian\n" "gpr jf .1 64.24 0 java\n" "gpr qf .1 64.27 0 sticky_overflow\n" "gpr vf .1 64.28 0 overflow\n" "gpr cf .1 64.29 0 carry\n" "gpr zf .1 64.30 0 zero\n" "gpr nf .1 64.31 0 negative\n" "gpr itc .4 64.10 0 if_then_count\n" "gpr gef .4 64.16 0 great_or_equal\n" "gpr r0 .32 0 0\n" "gpr r1 .32 4 0\n" "gpr r2 .32 8 0\n" "gpr r3 .32 12 0\n" "gpr r4 .32 16 0\n" "gpr r5 .32 20 0\n" "gpr r6 .32 24 0\n" "gpr r7 .32 28 0\n" "gpr r8 .32 32 0\n" "gpr r9 .32 36 0\n" "gpr r10 .32 40 0\n" "gpr r11 .32 44 0\n" "gpr r12 .32 48 0\n" "gpr r13 .32 52 0\n" "gpr r14 .32 56 0\n" "gpr r15 .32 60 0\n" "gpr r16 .32 64 0\n" "gpr r17 .32 68 0\n")
static const char struct stat static buf struct stat static buf static vhangup int status
Definition: sflib.h:145
#define RZ_NEW0(x)
Definition: rz_types.h:284

References NULL, p, path, pc, pid, RZ_NEW0, status, and strdup().

Referenced by bsd_pid_list(), bsd_thread_list(), build_debug_pid(), linux_add_new_thread(), linux_pid_list(), linux_thread_list(), w32_thread_list(), windbg_pids(), windbg_threads(), xnu_get_pid(), and xnu_thread_list().

◆ rz_debug_pid_parent()

RZ_API int rz_debug_pid_parent ( RzDebugPid pid)

Definition at line 151 of file pid.c.

151  {
152  // fork in child
153  return 0;
154 }

◆ rz_debug_pid_set_state()

RZ_API int rz_debug_pid_set_state ( struct rz_debug_t dbg,
int  status 
)

Definition at line 175 of file pid.c.

175  {
176  return true;
177 }

◆ rz_debug_pids()

RZ_API RzList* rz_debug_pids ( RzDebug dbg,
int  pid 
)

Definition at line 26 of file pid.c.

26  {
27  if (dbg && dbg->cur && dbg->cur->pids) {
28  return dbg->cur->pids(dbg, pid);
29  }
30  return NULL;
31 }

References rz_debug_t::cur, dbg, NULL, pid, and rz_debug_plugin_t::pids.

◆ rz_debug_thread_list()

RZ_API int rz_debug_thread_list ( RzDebug dbg,
int  pid,
char  fmt 
)

Definition at line 74 of file pid.c.

74  {
75  RzList *list;
77  RzDebugPid *p;
78  RzAnalysisFunction *fcn = NULL;
79  RzDebugMap *map = NULL;
80  RzStrBuf *path = NULL;
81  if (pid == -1) {
82  return false;
83  }
84  if (dbg && dbg->cur && dbg->cur->threads) {
85  list = dbg->cur->threads(dbg, pid);
86  if (!list) {
87  return false;
88  }
89  PJ *j = pj_new();
90  pj_a(j);
91  rz_list_foreach (list, iter, p) {
92  path = rz_strbuf_new("");
93  if (p->pc != 0) {
94  map = rz_debug_map_get(dbg, p->pc);
95  if (map && map->name && map->name[0]) {
96  rz_strbuf_appendf(path, "%s ", map->name);
97  }
98 
99  rz_strbuf_appendf(path, "(0x%" PFMT64x ")", p->pc);
100 
101  fcn = rz_analysis_get_fcn_in(dbg->analysis, p->pc, 0);
102  if (fcn) {
103  if (p->pc == fcn->addr) {
104  rz_strbuf_appendf(path, " at %s", fcn->name);
105  } else {
106  st64 delta = p->pc - fcn->addr;
107  char sign = delta >= 0 ? '+' : '-';
108  rz_strbuf_appendf(path, " in %s%c%" PFMT64u, fcn->name, sign, RZ_ABS(delta));
109  }
110  } else {
111  const char *flag_name = dbg->corebind.getName(dbg->corebind.core, p->pc);
112  if (flag_name) {
113  rz_strbuf_appendf(path, " at %s", flag_name);
114  } else {
115  char *name_delta = dbg->corebind.getNameDelta(dbg->corebind.core, p->pc);
116  if (name_delta) {
117  rz_strbuf_appendf(path, " in %s", name_delta);
118  free(name_delta);
119  }
120  }
121  }
122  }
123  switch (fmt) {
124  case 'j':
125  pj_o(j);
126  pj_kb(j, "current", dbg->tid == p->pid);
127  pj_ki(j, "pid", p->pid);
128  pj_ks(j, "status", &p->status);
129  pj_ks(j, "path", rz_strbuf_get(path));
130  pj_end(j);
131  break;
132  default:
133  dbg->cb_printf(" %c %d %c %s\n",
134  dbg->tid == p->pid ? '*' : '-',
135  p->pid, p->status, rz_strbuf_get(path));
136  break;
137  }
139  }
140  pj_end(j);
141  if (fmt == 'j') {
142  dbg->cb_printf("%s", pj_string(j));
143  }
144  pj_free(j);
146  }
147  return false;
148 }
RZ_API RzDebugMap * rz_debug_map_get(RzDebug *dbg, ut64 addr)
Definition: dmap.c:65
size_t map(int syms, int left, int len)
Definition: enough.c:237
RZ_DEPRECATE RZ_API RzAnalysisFunction * rz_analysis_get_fcn_in(RzAnalysis *analysis, ut64 addr, int type)
Definition: fcn.c:1687
@ RZ_ABS
RZ_API char * rz_strbuf_get(RzStrBuf *sb)
Definition: strbuf.c:321
RZ_API RzStrBuf * rz_strbuf_new(const char *s)
Definition: strbuf.c:8
RZ_API void rz_strbuf_free(RzStrBuf *sb)
Definition: strbuf.c:358
RZ_API bool rz_strbuf_appendf(RzStrBuf *sb, const char *fmt,...) RZ_PRINTF_CHECK(2
#define PFMT64u
Definition: rz_types.h:395
#define PFMT64x
Definition: rz_types.h:393
#define st64
Definition: rz_types_base.h:10
void * core
Definition: rz_bind.h:31
RzCoreGetNameDelta getNameDelta
Definition: rz_bind.h:41
RzCoreGetName getName
Definition: rz_bind.h:40
RzList *(* threads)(RzDebug *dbg, int pid)
Definition: rz_debug.h:375
RzCoreBind corebind
Definition: rz_debug.h:314
RzAnalysis * analysis
Definition: rz_debug.h:305
static st64 delta
Definition: vmenus.c:2425

References rz_analysis_function_t::addr, rz_debug_t::analysis, rz_debug_t::cb_printf, rz_core_bind_t::core, rz_debug_t::corebind, rz_debug_t::cur, dbg, delta, free(), rz_core_bind_t::getName, rz_core_bind_t::getNameDelta, list(), map(), rz_analysis_function_t::name, NULL, p, path, PFMT64u, PFMT64x, pid, pj_a(), pj_end(), pj_free(), pj_kb(), pj_ki(), pj_ks(), pj_new(), pj_o(), pj_string(), RZ_ABS, rz_analysis_get_fcn_in(), rz_debug_map_get(), rz_list_free(), rz_strbuf_appendf(), rz_strbuf_free(), rz_strbuf_get(), rz_strbuf_new(), st64, rz_debug_plugin_t::threads, and rz_debug_t::tid.

Referenced by cmd_debug_pid().