From d89274c8a5090d5a70e72af95abf29e4aab445ef Mon Sep 17 00:00:00 2001 From: pancake Date: Fri, 10 Nov 2023 19:54:32 +0100 Subject: [PATCH] Minor code cleanup in the gdb code --- libr/core/cmd_debug.inc.c | 3 +- libr/include/r_reg.h | 2 -- libr/reg/arena.c | 4 +-- libr/reg/profile.c | 4 +-- shlr/gdb/src/gdbclient/core.c | 67 +++++++++-------------------------- 5 files changed, 22 insertions(+), 58 deletions(-) diff --git a/libr/core/cmd_debug.inc.c b/libr/core/cmd_debug.inc.c index 0dc978028f..cf9b011a52 100644 --- a/libr/core/cmd_debug.inc.c +++ b/libr/core/cmd_debug.inc.c @@ -374,7 +374,6 @@ static RCoreHelpMessage help_msg_dr = { "drrj", "", "show registers references (telescoping) in JSON format", // TODO: 'drs' to swap register arenas and display old register valuez "drs", "[?]", "stack register states", - "drS", "", "show the size of the register profile", "drt", "[?]", "show all register types", "drw"," ", "set contents of the register arena", "drx", "[?]", "show debug registers", @@ -393,7 +392,7 @@ static RCoreHelpMessage help_msg_drp = { "drpi", "", "show internal representation of the register profile", "drp.", "", "show the current fake size", "drpj", "", "show the current register profile (JSON)", - "drps", " [new fake size]", "set the fake size", + "drps", " [new fake size]", "get or set the register profile size", "drpg", "", "show register profile comments", "NOTE:", "", "this help will show arp if you run drp? when cfg.debug=0", NULL diff --git a/libr/include/r_reg.h b/libr/include/r_reg.h index 43ed771da7..cccdd46059 100644 --- a/libr/include/r_reg.h +++ b/libr/include/r_reg.h @@ -7,8 +7,6 @@ #include #include -#define R_REG_USE_VEC 1 - #ifdef __cplusplus extern "C" { #endif diff --git a/libr/reg/arena.c b/libr/reg/arena.c index b52d5ed160..c0f98016a7 100644 --- a/libr/reg/arena.c +++ b/libr/reg/arena.c @@ -357,11 +357,11 @@ R_API int r_reg_arena_set_bytes(RReg *reg, const char *str) { R_API void r_reg_arena_shrink(RReg *reg) { r_return_if_fail (reg); - RListIter *iter; - RRegArena *a; int i; const size_t bytes_size = 1024; for (i = 0; i < R_REG_TYPE_LAST; i++) { + RRegArena *a; + RListIter *iter; r_list_foreach (reg->regset[i].pool, iter, a) { free (a->bytes); /* ha ha ha */ diff --git a/libr/reg/profile.c b/libr/reg/profile.c index 96ecccb10a..e3464dfce5 100644 --- a/libr/reg/profile.c +++ b/libr/reg/profile.c @@ -432,8 +432,8 @@ static char *gdb_to_r2_profile(const char *gdb) { } R_API char *r_reg_parse_gdb_profile(const char *profile_file) { - char *str = NULL; - if (!(str = r_file_slurp (profile_file, NULL))) { + char *str = r_file_slurp (profile_file, NULL); + if (!str) { char *base = r_sys_getenv (R_LIB_ENV); if (base) { char *file = r_str_appendf (base, R_SYS_DIR "%s", profile_file); diff --git a/shlr/gdb/src/gdbclient/core.c b/shlr/gdb/src/gdbclient/core.c index edbeb87398..8de258dbf2 100644 --- a/shlr/gdb/src/gdbclient/core.c +++ b/shlr/gdb/src/gdbclient/core.c @@ -489,9 +489,7 @@ int gdbr_attach(libgdbr_t *g, int pid) { ret = handle_attach (g); end: - if (cmd) { - free (cmd); - } + free (cmd); gdbr_lock_leave (g); return ret; } @@ -566,9 +564,7 @@ int gdbr_detach_pid(libgdbr_t *g, int pid) { ret = 0; end: - if (cmd) { - free (cmd); - } + free (cmd); gdbr_lock_leave (g); return ret; } @@ -647,9 +643,7 @@ int gdbr_kill_pid(libgdbr_t *g, int pid) { } end: - if (cmd) { - free (cmd); - } + free (cmd); gdbr_lock_leave (g); return ret; } @@ -925,9 +919,7 @@ int gdbr_write_memory(libgdbr_t *g, ut64 address, const uint8_t *data, ut64 len) ret = 0; end: gdbr_lock_leave (g); - if (tmp) { - free (tmp); - } + free (tmp); return ret; } @@ -964,7 +956,7 @@ int gdbr_continue(libgdbr_t *g, int pid, int tid, int sig) { } if (sig <= 0) { - strncpy (command, CMD_C_CONT, sizeof (command) - 1); + r_str_ncpy (command, CMD_C_CONT, sizeof (command)); } else { snprintf (command, sizeof (command) - 1, "%s%02x", CMD_C_CONT_SIG, sig); } @@ -1017,9 +1009,7 @@ int gdbr_write_bin_registers(libgdbr_t *g, const char *regs, int len) { ret = 0; end: gdbr_lock_leave (g); - if (command) { - free (command); - } + free (command); return ret; } @@ -1186,15 +1176,9 @@ int gdbr_write_registers(libgdbr_t *g, char *registers) { ret = 0; end: - if (command) { - free (command); - } - if (buff) { - free (buff); - } - if (value) { - free (value); - } + free (command); + free (buff); + free (value); gdbr_lock_leave (g); return ret; } @@ -1610,9 +1594,7 @@ int gdbr_send_qRcmd(libgdbr_t *g, const char *cmd, PrintfCallback cb_printf) { ret = 0; end: - if (buf) { - free (buf); - } + free (buf); gdbr_lock_leave (g); return ret; } @@ -1671,15 +1653,13 @@ char* gdbr_exec_file_read(libgdbr_t *g, int pid) { end: gdbr_lock_leave (g); if (ret != 0) { - if (path) { - free (path); - } + free (path); return NULL; } return path; } -bool gdbr_is_thread_dead (libgdbr_t *g, int pid, int tid) { +bool gdbr_is_thread_dead(libgdbr_t *g, int pid, int tid) { bool ret = false; if (!g) { @@ -1703,12 +1683,7 @@ bool gdbr_is_thread_dead (libgdbr_t *g, int pid, int tid) { if (send_msg (g, msg) < 0 || read_packet (g, false) < 0 || send_ack (g) < 0) { goto end; } - if (g->data_len == 3 && g->data[0] == 'E') { - ret = true; - } else { - ret = false; - } - + ret = (g->data_len == 3 && g->data[0] == 'E'); end: gdbr_lock_leave (g); return ret; @@ -1802,15 +1777,11 @@ RList* gdbr_pids_list(libgdbr_t *g, int pid) { end: gdbr_lock_leave (g); if (ret != 0) { - if (dpid) { - free (dpid); - } + free (dpid); // We can't use r_debug_pid_free here if (list) { r_list_foreach (list, iter, dpid) { - if (dpid->path) { - free (dpid->path); - } + free (dpid->path); free (dpid); } r_list_free (list); @@ -1904,15 +1875,11 @@ RList* gdbr_threads_list(libgdbr_t *g, int pid) { end: gdbr_lock_leave (g); if (ret != 0) { - if (dpid) { - free (dpid); - } + free (dpid); // We can't use r_debug_pid_free here if (list) { r_list_foreach (list, iter, dpid) { - if (dpid->path) { - free (dpid->path); - } + free (dpid->path); free (dpid); } r_list_free (list);