Skip to content

Commit

Permalink
Use RStr.splitList() instead of sscanf to parse /proc/pid/mem in gdb …
Browse files Browse the repository at this point in the history
…debug plugin ##debug

* Refs #21813
  • Loading branch information
radare committed Jun 7, 2023
1 parent 1b3d1df commit c08d1c2
Showing 1 changed file with 33 additions and 7 deletions.
40 changes: 33 additions & 7 deletions libr/debug/p/debug_gdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ typedef struct {
#define UNSUPPORTED 0
#define SUPPORTED 1

static RIOGdb ** origriogdb = NULL;
static libgdbr_t *desc = NULL;
static ut8* reg_buf = NULL;
static int buf_size = 0;
static int support_sw_bp = UNKNOWN;
static int support_hw_bp = UNKNOWN;
static R_TH_LOCAL RIOGdb ** origriogdb = NULL;
static R_TH_LOCAL libgdbr_t *desc = NULL;
static R_TH_LOCAL ut8* reg_buf = NULL;
static R_TH_LOCAL int buf_size = 0;
static R_TH_LOCAL int support_sw_bp = UNKNOWN;
static R_TH_LOCAL int support_hw_bp = UNKNOWN;

static bool r_debug_gdb_attach(RDebug *dbg, int pid);

static void check_connection(RDebug *dbg) {
if (!desc) {
r_debug_gdb_attach (dbg, -1);
Expand Down Expand Up @@ -97,7 +98,7 @@ static bool gdb_reg_read(RDebug *dbg, int type, ut8 *buf, int size) {
return true;
}

static RList *r_debug_gdb_map_get(RDebug* dbg) { //TODO
static RList *r_debug_gdb_map_get(RDebug* dbg) { // TODO
check_connection (dbg);
if (!desc || desc->pid <= 0) {
return NULL;
Expand Down Expand Up @@ -177,10 +178,34 @@ static RList *r_debug_gdb_map_get(RDebug* dbg) { //TODO
if (line_len == 0) {
break;
}
#if 1
RList *words = r_str_split_list (ptr, " ", 6);
int ret = r_list_length (words);
perms[0] = 0;
region1[2] = 0;
region2[2] = 0;
if (ret > 0) {
r_str_ncpy (region1 + 2, r_list_get_n (words, 0), sizeof (region1) - 2);
}
if (ret > 1) {
r_str_ncpy (perms, r_list_get_n (words, 1), sizeof (perms));
}
if (ret > 2) {
offset = r_num_get (NULL, r_list_get_n (words, 2));
}
if (ret > 4) {
const char *s = r_str_trim_head_ro (r_list_get_n (words, 5));
r_str_ncpy (name, s, sizeof (name));
}
r_list_free (words);
#else
// We assume Linux target, for now, so -
// 7ffff7dda000-7ffff7dfd000 r-xp 00000000 08:05 265428 /usr/lib/ld-2.25.so
// Android
// "12c00000-12c40000 rw-p 00000000 00:00 0 [anon:dalvik-main space (region space)]";
ret = sscanf (ptr, "%s %s %"PFMT64x" %*s %*s %[^\n]", &region1[2],
perms, &offset, name);
#endif
if (ret == 3) {
name[0] = '\0';
} else if (ret < 3) {
Expand Down Expand Up @@ -569,3 +594,4 @@ R_API RLibStruct radare_plugin = {
.version = R2_VERSION
};
#endif

0 comments on commit c08d1c2

Please sign in to comment.