mirror of
https://github.com/radareorg/radare2.git
synced 2025-01-31 10:22:37 +00:00
Add support non-numeric signal numbers in RRunProfile (#6558)
* Add support non-numeric signal numbers in RRunProfile * Add signal util module * Remove old `signal_resolve` implementation
This commit is contained in:
parent
edd97e44c6
commit
249532bf53
@ -2848,11 +2848,11 @@ static void r_core_debug_kill (RCore *core, const char *input) {
|
||||
const char *signame, *arg = input + 1;
|
||||
int signum = atoi (arg);
|
||||
if (signum > 0) {
|
||||
signame = r_debug_signal_resolve_i (core->dbg, signum);
|
||||
signame = r_signal_to_string (signum);
|
||||
if (signame)
|
||||
r_cons_println (signame);
|
||||
} else {
|
||||
signum = r_debug_signal_resolve (core->dbg, arg);
|
||||
signum = r_signal_from_string (arg);
|
||||
if (signum > 0) {
|
||||
r_cons_printf ("%d\n", signum);
|
||||
}
|
||||
@ -2886,7 +2886,7 @@ static void r_core_debug_kill (RCore *core, const char *input) {
|
||||
// - pass
|
||||
// - trace
|
||||
// - stop
|
||||
if (signum<1) signum = r_debug_signal_resolve (core->dbg, name);
|
||||
if (signum<1) signum = r_signal_from_string (name);
|
||||
if (signum>0) {
|
||||
if (!p || !p[0]) { // stop (the usual)
|
||||
r_debug_signal_setup (core->dbg, signum, 0);
|
||||
@ -3583,7 +3583,7 @@ static int cmd_debug(void *data, const char *input) {
|
||||
#define P r_cons_printf
|
||||
#define PS(X, Y) {escaped_str = r_str_escape (Y);r_cons_printf(X, escaped_str);free(escaped_str);}
|
||||
if (rdi) {
|
||||
const char *s = r_debug_signal_resolve_i (core->dbg, core->dbg->reason.signum);
|
||||
const char *s = r_signal_to_string (core->dbg->reason.signum);
|
||||
P ("type=%s\n", r_debug_reason_to_string (core->dbg->reason.type));
|
||||
P ("signal=%s\n", s? s: "none");
|
||||
P ("signum=%d\n", core->dbg->reason.signum);
|
||||
@ -3609,7 +3609,7 @@ static int cmd_debug(void *data, const char *input) {
|
||||
case 'j':
|
||||
P ("{");
|
||||
if (rdi) {
|
||||
const char *s = r_debug_signal_resolve_i (core->dbg, core->dbg->reason.signum);
|
||||
const char *s = r_signal_to_string (core->dbg->reason.signum);
|
||||
P ("\"type\":\"%s\",", r_debug_reason_to_string (core->dbg->reason.type));
|
||||
P ("\"signal\":\"%s\",", s? s: "none");
|
||||
P ("\"signum\":%d,", core->dbg->reason.signum);
|
||||
|
@ -643,7 +643,7 @@ R_API RDebugReasonType r_debug_wait(RDebug *dbg, RBreakpointItem **bp) {
|
||||
/* handle signal on continuations here */
|
||||
eprintf ("got signal...\n");
|
||||
int what = r_debug_signal_what (dbg, dbg->reason.signum);
|
||||
const char *name = r_debug_signal_resolve_i (dbg, dbg->reason.signum);
|
||||
const char *name = r_signal_to_string (dbg->reason.signum);
|
||||
if (name && strcmp ("SIGTRAP", name)) {
|
||||
r_cons_printf ("[+] signal %d aka %s received %d\n",
|
||||
dbg->reason.signum, name, what);
|
||||
@ -1001,7 +1001,7 @@ repeat:
|
||||
dbg->iob.read_at (dbg->iob.io, pc, buf, sizeof (buf));
|
||||
r_anal_op (dbg->anal, &op, pc, buf, sizeof (buf));
|
||||
if (op.size > 0) {
|
||||
const char *signame = r_debug_signal_resolve_i (dbg, dbg->reason.signum);
|
||||
const char *signame = r_signal_to_string (dbg->reason.signum);
|
||||
r_debug_reg_set (dbg, "PC", pc+op.size);
|
||||
eprintf ("Skip signal %d handler %s\n",
|
||||
dbg->reason.signum, signame);
|
||||
|
@ -126,27 +126,6 @@ R_API void r_debug_signal_list(RDebug *dbg, int mode) {
|
||||
dbg->_mode = 0;
|
||||
}
|
||||
|
||||
R_API int r_debug_signal_resolve(RDebug *dbg, const char *signame) {
|
||||
int ret;
|
||||
char *name;
|
||||
if (strchr (signame, '.'))
|
||||
return 0;
|
||||
name = strdup (signame);
|
||||
if (!name) return 0;
|
||||
r_str_case (name, true);
|
||||
if (strncmp (name, "SIG", 3))
|
||||
name = r_str_prefix (name, "SIG");
|
||||
ret = (int)sdb_num_get (DB, name, 0);
|
||||
free (name);
|
||||
return ret;
|
||||
}
|
||||
|
||||
R_API const char *r_debug_signal_resolve_i(RDebug *dbg, int signum) {
|
||||
char k[32];
|
||||
snprintf (k, sizeof (k), "%d", signum);
|
||||
return sdb_const_get (DB, k, 0);
|
||||
}
|
||||
|
||||
R_API int r_debug_signal_send(RDebug *dbg, int num) {
|
||||
return r_sandbox_kill (dbg->pid, num);
|
||||
}
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include "r_util/r_queue.h"
|
||||
#include "r_util/r_range.h"
|
||||
#include "r_util/r_sandbox.h"
|
||||
#include "r_util/r_signal.h"
|
||||
#include "r_util/r_spaces.h"
|
||||
#include "r_util/r_stack.h"
|
||||
#include "r_util/r_str.h"
|
||||
|
10
libr/include/r_util/r_signal.h
Normal file
10
libr/include/r_util/r_signal.h
Normal file
@ -0,0 +1,10 @@
|
||||
#ifndef R_SIGNAL_H
|
||||
#define R_SIGNAL_H
|
||||
|
||||
/* Returns atoi(str) if signal with `str` name not found. */
|
||||
R_API int r_signal_from_string (const char *str);
|
||||
|
||||
/* Return NULL if signal with `code` not found. */
|
||||
R_API const char* r_signal_to_string (int code);
|
||||
|
||||
#endif // R_SIGNAL_H
|
@ -34,7 +34,6 @@
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/resource.h>
|
||||
#include <termios.h>
|
||||
#include <signal.h>
|
||||
#include <grp.h>
|
||||
#include <errno.h>
|
||||
#if defined(__sun)
|
||||
@ -405,16 +404,15 @@ R_API int r_run_parseline (RRunProfile *p, char *b) {
|
||||
else if (!strcmp (b, "setgid")) p->_setgid = strdup (e);
|
||||
else if (!strcmp (b, "setegid")) p->_setegid = strdup (e);
|
||||
else if (!strcmp (b, "nice")) p->_nice = atoi (e);
|
||||
else if (!strcmp (b, "timeout")) p->_timeout = atoi (e);
|
||||
else if (!strcmp (b, "timeoutsig")) p->_timeout_sig = r_signal_from_string (e);
|
||||
else if (!memcmp (b, "arg", 3)) {
|
||||
int n = atoi (b + 3);
|
||||
if (n >= 0 && n < R_RUN_PROFILE_NARGS) {
|
||||
p->_args[n] = getstr (e);
|
||||
} else eprintf ("Out of bounds args index: %d\n", n);
|
||||
} else if (!strcmp (b, "timeout")) {
|
||||
p->_timeout = atoi (e);
|
||||
} else if (!strcmp (b, "timeoutsig")) {
|
||||
// TODO: support non-numeric signal numbers here
|
||||
p->_timeout_sig = atoi (e);
|
||||
} else {
|
||||
eprintf ("Out of bounds args index: %d\n", n);
|
||||
}
|
||||
} else if (!strcmp (b, "envfile")) {
|
||||
char *p, buf[1024];
|
||||
FILE *fd = fopen (e, "r");
|
||||
@ -468,6 +466,7 @@ R_API const char *r_run_help() {
|
||||
"# clearenv=true\n"
|
||||
"# envfile=environ.txt\n"
|
||||
"timeout=3\n"
|
||||
"# timeoutsig=SIGTERM # or 15\n"
|
||||
"# connect=localhost:8080\n"
|
||||
"# listen=8080\n"
|
||||
"# pty=false\n"
|
||||
|
@ -259,14 +259,14 @@ core/cmd_debug.c: dot_trace_traverse (core, core->dbg->tree, input[2]);
|
||||
core/cmd_debug.c: r_tree_reset (core->dbg->tree);
|
||||
core/cmd_debug.c: r_debug_trace_free (core->dbg->trace);
|
||||
core/cmd_debug.c: core->dbg->trace = r_debug_trace_new ();
|
||||
core/cmd_debug.c: const char *s = r_debug_signal_resolve_i (core->dbg, core->dbg->reason.signum);
|
||||
core/cmd_debug.c: const char *s = r_signal_to_string (core->dbg->reason.signum);
|
||||
core/cmd_debug.c: P ("type=%s\n", r_debug_reason_to_string (core->dbg->reason.type));
|
||||
core/cmd_debug.c: P ("signum=%d\n", core->dbg->reason.signum);
|
||||
core/cmd_debug.c: P ("sigpid=%d\n", core->dbg->reason.tid);
|
||||
core/cmd_debug.c: P ("addr=0x%"PFMT64x"\n", core->dbg->reason.addr);
|
||||
core/cmd_debug.c: P ("bp_addr=0x%"PFMT64x"\n", core->dbg->reason.bp_addr);
|
||||
core/cmd_debug.c: P ("inbp=%s\n", r_str_bool (core->dbg->reason.bp_addr));
|
||||
core/cmd_debug.c: const char *s = r_debug_signal_resolve_i (core->dbg, core->dbg->reason.signum);
|
||||
core/cmd_debug.c: const char *s = r_signal_to_string (core->dbg->reason.signum);
|
||||
core/cmd_debug.c: P ("\"type\":\"%s\",", r_debug_reason_to_string (core->dbg->reason.type));
|
||||
core/cmd_debug.c: P ("\"signum\":%d,", core->dbg->reason.signum);
|
||||
core/cmd_debug.c: P ("\"sigpid\":%d,", core->dbg->reason.tid);
|
||||
@ -529,7 +529,7 @@ debug/debug.c: if (dbg->corebind.core && b && b->cond) {
|
||||
debug/debug.c: dbg->reason.type = reason;
|
||||
debug/debug.c: if (reason == R_DEBUG_REASON_SIGNAL && dbg->reason.signum != -1) {
|
||||
debug/debug.c: int what = r_debug_signal_what (dbg, dbg->reason.signum);
|
||||
debug/debug.c: const char *name = r_debug_signal_resolve_i (dbg, dbg->reason.signum);
|
||||
debug/debug.c: const char *name = r_signal_to_string (dbg->reason.signum);
|
||||
debug/debug.c: dbg->reason.signum, name, what);
|
||||
debug/debug.c: if (dbg->recoil_mode == R_DBG_RECOIL_NONE) {
|
||||
debug/debug.c: dbg->recoil_mode = R_DBG_RECOIL_STEP;
|
||||
@ -580,7 +580,7 @@ debug/debug.c: int what = r_debug_signal_what (dbg, dbg->reason.signum);
|
||||
debug/debug.c: sig = dbg->reason.signum;
|
||||
debug/debug.c: dbg->iob.read_at (dbg->iob.io, pc, buf, sizeof (buf));
|
||||
debug/debug.c: r_anal_op (dbg->anal, &op, pc, buf, sizeof (buf));
|
||||
debug/debug.c: const char *signame = r_debug_signal_resolve_i (dbg, dbg->reason.signum);
|
||||
debug/debug.c: const char *signame = r_signal_to_string (dbg->reason.signum);
|
||||
debug/debug.c: dbg->reason.signum, signame);
|
||||
debug/debug.c: return r_debug_continue_kill (dbg, 0); //dbg->reason.signum);
|
||||
debug/debug.c: if (!dbg->anal || !dbg->reg) {
|
||||
|
@ -10,7 +10,7 @@ OBJS+=regex/regcomp.o regex/regerror.o regex/regexec.o uleb128.o
|
||||
OBJS+=sandbox.o calc.o thread.o thread_lock.o thread_msg.o
|
||||
OBJS+=strpool.o bitmap.o strht.o p_date.o p_format.o print.o
|
||||
OBJS+=p_seven.o slist.o randomart.o log.o zip.o debruijn.o
|
||||
OBJS+=utf8.o strbuf.o lib.o name.o spaces.o syscmd.o
|
||||
OBJS+=utf8.o strbuf.o lib.o name.o spaces.o signal.o syscmd.o
|
||||
OBJS+=diff.o bdiff.o stack.o queue.o tree.o des.o
|
||||
OBJS+=punycode.o
|
||||
|
||||
|
67
libr/util/signal.c
Normal file
67
libr/util/signal.c
Normal file
@ -0,0 +1,67 @@
|
||||
#include <r_util.h>
|
||||
|
||||
#include <signal.h>
|
||||
#include <stddef.h>
|
||||
|
||||
static struct {
|
||||
const char *name;
|
||||
int code;
|
||||
} signals[] = {
|
||||
{ "SIGHUP", SIGHUP },
|
||||
{ "SIGINT", SIGINT },
|
||||
{ "SIGQUIT", SIGQUIT },
|
||||
{ "SIGILL", SIGILL },
|
||||
{ "SIGTRAP", SIGTRAP },
|
||||
{ "SIGABRT", SIGABRT },
|
||||
{ "SIGBUS", SIGBUS },
|
||||
{ "SIGFPE", SIGFPE },
|
||||
{ "SIGKILL", SIGKILL },
|
||||
{ "SIGUSR1", SIGUSR1 },
|
||||
{ "SIGSEGV", SIGSEGV },
|
||||
{ "SIGUSR2", SIGUSR2 },
|
||||
{ "SIGPIPE", SIGPIPE },
|
||||
{ "SIGALRM", SIGALRM },
|
||||
{ "SIGTERM", SIGTERM },
|
||||
{ "SIGSTKFLT", SIGSTKFLT },
|
||||
{ "SIGCHLD", SIGCHLD },
|
||||
{ "SIGCONT", SIGCONT },
|
||||
{ "SIGSTOP", SIGSTOP },
|
||||
{ "SIGTSTP", SIGTSTP },
|
||||
{ "SIGTTIN", SIGTTIN },
|
||||
{ "SIGTTOU", SIGTTOU },
|
||||
{ "SIGURG", SIGURG },
|
||||
{ "SIGXCPU", SIGXCPU },
|
||||
{ "SIGXFSZ", SIGXFSZ },
|
||||
{ "SIGVTALRM", SIGVTALRM },
|
||||
{ "SIGPROF", SIGPROF },
|
||||
#if __LINUX__
|
||||
{ "SIGWINCH", SIGWINCH },
|
||||
{ "SIGIO", SIGIO },
|
||||
{ "SIGPWR", SIGPWR },
|
||||
{ "SIGSTKSZ", SIGSTKSZ },
|
||||
#endif
|
||||
{ "SIGPOLL", SIGPOLL },
|
||||
{ "SIGSYS", SIGSYS },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
R_API int r_signal_from_string (const char *e) {
|
||||
int i;
|
||||
for (i = 1; signals[i].name; i++) {
|
||||
const char *str = signals[i].name;
|
||||
if (!strcmp (e, str)) {
|
||||
return signals[i].code;
|
||||
}
|
||||
}
|
||||
return atoi (e);
|
||||
}
|
||||
|
||||
R_API const char* r_signal_to_string (int code) {
|
||||
int i;
|
||||
for (i = 1; signals[i].name; i++) {
|
||||
if (signals[i].code == code) {
|
||||
return signals[i].name;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
@ -39,7 +39,7 @@ M.make ({
|
||||
"lock.c", "log.c", "mem.c", "mixed.c", "name.c",
|
||||
"num.c", "p_date.c", "p_format.c", "p_seven.c",
|
||||
"pool.c", "print.c", "prof.c", "randomart.c",
|
||||
"range.c", "sandbox.c", "slist.c", "str.c", "strht.c",
|
||||
"range.c", "sandbox.c", "signal.c", "slist.c", "str.c", "strht.c",
|
||||
"strpool.c", "sys.c", "thread.c", "uleb128.c", "w32-sys.c" ]
|
||||
},
|
||||
sdb: {
|
||||
|
Loading…
x
Reference in New Issue
Block a user