mirror of
https://github.com/radareorg/radare2.git
synced 2024-11-24 05:40:10 +00:00
added =!detach, and replaced eprintfs with io->cb_printf (#8125)
* added =!detach, and replaced eprintfs with io->cb_printf * keep error in eprintf
This commit is contained in:
parent
261675ef3b
commit
b9695773ce
@ -347,6 +347,9 @@ static int r_debug_gdb_attach(RDebug *dbg, int pid) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int r_debug_gdb_detach(RDebug *dbg, int pid) {
|
static int r_debug_gdb_detach(RDebug *dbg, int pid) {
|
||||||
|
if (pid <= 0 || !desc->stub_features.multiprocess) {
|
||||||
|
return gdbr_detach (desc);
|
||||||
|
}
|
||||||
return gdbr_detach_pid (desc, pid);
|
return gdbr_detach_pid (desc, pid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,6 +202,7 @@ static int __system(RIO *io, RIODesc *fd, const char *cmd) {
|
|||||||
" =!pkt s - send packet 's'\n"
|
" =!pkt s - send packet 's'\n"
|
||||||
" =!monitor cmd - hex-encode monitor command and pass"
|
" =!monitor cmd - hex-encode monitor command and pass"
|
||||||
" to target interpreter\n"
|
" to target interpreter\n"
|
||||||
|
" =!detach [pid] - detach from remote/detach specific pid\n"
|
||||||
" =!inv.reg - invalidate reg cache\n"
|
" =!inv.reg - invalidate reg cache\n"
|
||||||
" =!pktsz - get max packet size used\n"
|
" =!pktsz - get max packet size used\n"
|
||||||
" =!pktsz bytes - set max. packet size as 'bytes' bytes\n"
|
" =!pktsz bytes - set max. packet size as 'bytes' bytes\n"
|
||||||
@ -212,8 +213,8 @@ static int __system(RIO *io, RIODesc *fd, const char *cmd) {
|
|||||||
if (!strncmp (cmd, "pktsz", 5)) {
|
if (!strncmp (cmd, "pktsz", 5)) {
|
||||||
const char *ptr = r_str_chop_ro (cmd + 5);
|
const char *ptr = r_str_chop_ro (cmd + 5);
|
||||||
if (!isdigit (*ptr)) {
|
if (!isdigit (*ptr)) {
|
||||||
eprintf ("packet size: %u bytes\n",
|
io->cb_printf ("packet size: %u bytes\n",
|
||||||
desc->stub_features.pkt_sz);
|
desc->stub_features.pkt_sz);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
ut32 pktsz;
|
ut32 pktsz;
|
||||||
@ -224,13 +225,24 @@ static int __system(RIO *io, RIODesc *fd, const char *cmd) {
|
|||||||
desc->stub_features.pkt_sz = R_MAX (pktsz, 64); // min = 64
|
desc->stub_features.pkt_sz = R_MAX (pktsz, 64); // min = 64
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (!strncmp (cmd, "detach", 6)) {
|
||||||
|
int pid;
|
||||||
|
if (!isspace (cmd[6]) || !desc->stub_features.multiprocess) {
|
||||||
|
return gdbr_detach (desc) >= 0;
|
||||||
|
}
|
||||||
|
cmd = r_str_chop_ro (cmd + 6);
|
||||||
|
if (!*cmd || !(pid = strtoul (cmd, NULL, 10))) {
|
||||||
|
return gdbr_detach (desc) >= 0;
|
||||||
|
}
|
||||||
|
return gdbr_detach_pid (desc, pid) >= 0;
|
||||||
|
}
|
||||||
if (!strncmp (cmd, "pkt ", 4)) {
|
if (!strncmp (cmd, "pkt ", 4)) {
|
||||||
if (send_msg (desc, cmd + 4) == -1) {
|
if (send_msg (desc, cmd + 4) == -1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
int r = read_packet (desc);
|
int r = read_packet (desc);
|
||||||
desc->data[desc->data_len] = '\0';
|
desc->data[desc->data_len] = '\0';
|
||||||
eprintf ("reply:\n\n%s\n", desc->data);
|
io->cb_printf ("reply:\n%s\n", desc->data);
|
||||||
if (!desc->no_ack) {
|
if (!desc->no_ack) {
|
||||||
eprintf ("[waiting for ack]\n");
|
eprintf ("[waiting for ack]\n");
|
||||||
}
|
}
|
||||||
@ -248,7 +260,7 @@ static int __system(RIO *io, RIODesc *fd, const char *cmd) {
|
|||||||
if (!isspace (cmd[8])) {
|
if (!isspace (cmd[8])) {
|
||||||
qrcmd = "help";
|
qrcmd = "help";
|
||||||
}
|
}
|
||||||
if (gdbr_send_qRcmd (desc, qrcmd) < 0) {
|
if (gdbr_send_qRcmd (desc, qrcmd, io->cb_printf) < 0) {
|
||||||
eprintf ("remote error\n");
|
eprintf ("remote error\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -281,7 +293,7 @@ static int __system(RIO *io, RIODesc *fd, const char *cmd) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
eprintf ("%s\n", file);
|
io->cb_printf ("%s\n", file);
|
||||||
free (file);
|
free (file);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ int gdbr_check_vcont(libgdbr_t *g);
|
|||||||
* remote target's interpreter.
|
* remote target's interpreter.
|
||||||
* \returns 0 on success and -1 on failure
|
* \returns 0 on success and -1 on failure
|
||||||
*/
|
*/
|
||||||
int gdbr_send_qRcmd(libgdbr_t *g, const char *cmd);
|
int gdbr_send_qRcmd(libgdbr_t *g, const char *cmd, void (*cb_printf) (const char *, ...));
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief attaches to a process
|
* \brief attaches to a process
|
||||||
|
@ -337,19 +337,12 @@ int gdbr_detach(libgdbr_t *g) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
reg_cache.valid = false;
|
reg_cache.valid = false;
|
||||||
|
|
||||||
if (g->stub_features.multiprocess) {
|
|
||||||
if (g->pid <= 0) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return gdbr_detach_pid (g, g->pid);
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = send_msg (g, "D");
|
ret = send_msg (g, "D");
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return 0;
|
// Disconnect
|
||||||
|
return gdbr_disconnect (g);
|
||||||
}
|
}
|
||||||
|
|
||||||
int gdbr_detach_pid(libgdbr_t *g, int pid) {
|
int gdbr_detach_pid(libgdbr_t *g, int pid) {
|
||||||
@ -1055,7 +1048,7 @@ void gdbr_invalidate_reg_cache() {
|
|||||||
reg_cache.valid = false;
|
reg_cache.valid = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int gdbr_send_qRcmd(libgdbr_t *g, const char *cmd) {
|
int gdbr_send_qRcmd(libgdbr_t *g, const char *cmd, void (*cb_printf) (const char *fmt, ...)) {
|
||||||
if (!g || !cmd) {
|
if (!g || !cmd) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -1096,7 +1089,7 @@ int gdbr_send_qRcmd(libgdbr_t *g, const char *cmd) {
|
|||||||
// Console output from gdbserver
|
// Console output from gdbserver
|
||||||
unpack_hex (g->data + 1, g->data_len - 1, g->data + 1);
|
unpack_hex (g->data + 1, g->data_len - 1, g->data + 1);
|
||||||
g->data[g->data_len - 1] = '\0';
|
g->data[g->data_len - 1] = '\0';
|
||||||
eprintf ("%s", g->data + 1);
|
cb_printf ("%s", g->data + 1);
|
||||||
}
|
}
|
||||||
if (read_packet (g) < 0) {
|
if (read_packet (g) < 0) {
|
||||||
free (buf);
|
free (buf);
|
||||||
|
Loading…
Reference in New Issue
Block a user