summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElvira Khabirova <lineprinter0@gmail.com>2020-08-20 10:31:02 +0300
committerElvira Khabirova <lineprinter0@gmail.com>2020-08-21 19:39:24 +0300
commitec595a2381bf444fb59715f2b37fd0e0df0003eb (patch)
treee250f049a3d8d4f5e0238c64ee379342faed5eaa
parentc88ad3c2189af4d8dfa545a1fd78265a19447fc6 (diff)
downloadstrace-ec595a2381bf444fb59715f2b37fd0e0df0003eb.tar.gz
strace: add an option for printing syscall numbers
* print_syscall_number.c: New file. * Makefile.am (libstrace_a_SOURCES): Add it. * defs.h (struct tcb): Add true_scno field. (print_syscall_number): New function declaration. * strace.c: Add -n/--syscall-number option. (printleader): Call print_syscall_number. * syscall.c (get_scno): Assign tcp->true_scno. * tests/options-syntax.test: Check with -c/--summary-only. * strace.1.in: Document new option. * NEWS: Mention the new option.
-rw-r--r--Makefile.am1
-rw-r--r--NEWS1
-rw-r--r--defs.h3
-rw-r--r--print_syscall_number.c18
-rw-r--r--strace.1.in5
-rw-r--r--strace.c15
-rw-r--r--syscall.c1
-rwxr-xr-xtests/options-syntax.test8
8 files changed, 49 insertions, 3 deletions
diff --git a/Makefile.am b/Makefile.am
index f5447811b..4f7aceec5 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -250,6 +250,7 @@ libstrace_a_SOURCES = \
print_sigevent.c \
print_statfs.c \
print_struct_stat.c \
+ print_syscall_number.c \
print_time.c \
print_timespec.h \
print_timespec32.c \
diff --git a/NEWS b/NEWS
index 10039ceb7..81a2c943c 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,7 @@ Noteworthy changes in release ?.? (????-??-??)
==============================================
* Improvements
+ * Added -n/--syscall-number option for printing syscall numbers.
* Bug fixes
diff --git a/defs.h b/defs.h
index f7ac54f31..3333453fe 100644
--- a/defs.h
+++ b/defs.h
@@ -259,6 +259,7 @@ struct tcb {
# endif
unsigned long u_error; /* Error code */
kernel_ulong_t scno; /* System call number */
+ kernel_ulong_t true_scno; /* Same, but without subcall decoding and shuffling */
kernel_ulong_t u_arg[MAX_ARGS]; /* System call arguments */
kernel_long_t u_rval; /* Return value */
int sys_func_rval; /* Syscall entry parser's return value */
@@ -508,6 +509,8 @@ extern bool get_instruction_pointer(struct tcb *, kernel_ulong_t *);
extern bool get_stack_pointer(struct tcb *, kernel_ulong_t *);
extern void print_instruction_pointer(struct tcb *);
+extern void print_syscall_number(struct tcb *);
+
extern void print_syscall_resume(struct tcb *tcp);
extern int syscall_entering_decode(struct tcb *);
diff --git a/print_syscall_number.c b/print_syscall_number.c
new file mode 100644
index 000000000..5427afb2e
--- /dev/null
+++ b/print_syscall_number.c
@@ -0,0 +1,18 @@
+/*
+ * Copyright (c) 2020 The strace developers.
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+
+#include "defs.h"
+
+void
+print_syscall_number(struct tcb *tcp)
+{
+ if (tcp->true_scno != (kernel_ulong_t) -1) {
+ tprintf("[%4" PRI_klu "] ", tcp->true_scno);
+ } else {
+ tprintf("[????] ");
+ }
+}
diff --git a/strace.1.in b/strace.1.in
index 3b21caeca..411e159b8 100644
--- a/strace.1.in
+++ b/strace.1.in
@@ -871,6 +871,11 @@ or higher.
.TQ
.B \-\-instruction\-pointer
Print the instruction pointer at the time of the system call.
+.TP
+.B \-n
+.TQ
+.B \-\-syscall\-number
+Print the syscall number.
.if '@ENABLE_STACKTRACE_FALSE@'#' .TP
.if '@ENABLE_STACKTRACE_FALSE@'#' .B \-k
.if '@ENABLE_STACKTRACE_FALSE@'#' .TQ
diff --git a/strace.c b/strace.c
index 4c96a98b0..ce5a46ab5 100644
--- a/strace.c
+++ b/strace.c
@@ -79,6 +79,7 @@ bool Tflag;
int Tflag_scale = 1000;
int Tflag_width = 6;
bool iflag;
+bool nflag;
bool count_wallclock;
static int tflag_scale = 1000000000;
static unsigned tflag_width = 0;
@@ -355,6 +356,8 @@ Output format:\n\
"
#endif
"\
+ -n, --syscall-number\n\
+ print syscall number\n\
-o FILE, --output=FILE\n\
send trace output to FILE instead of stderr\n\
-A, --output-append-mode\n\
@@ -811,6 +814,9 @@ printleader(struct tcb *tcp)
tprints(tflag_format ? ") " : " ");
}
+ if (nflag)
+ print_syscall_number(tcp);
+
if (iflag)
print_instruction_pointer(tcp);
}
@@ -2013,7 +2019,7 @@ init(int argc, char *argv[])
qualify_signals("all");
static const char optstring[] =
- "+a:Ab:cCdDe:E:fFhiI:ko:O:p:P:qrs:S:tTu:U:vVwxX:yzZ";
+ "+a:Ab:cCdDe:E:fFhiI:kno:O:p:P:qrs:S:tTu:U:vVwxX:yzZ";
enum {
GETOPT_SECCOMP = 0x100,
@@ -2055,6 +2061,7 @@ init(int argc, char *argv[])
{ "instruction-pointer", no_argument, 0, 'i' },
{ "interruptible", required_argument, 0, 'I' },
{ "stack-traces", no_argument, 0, 'k' },
+ { "syscall-number", no_argument, 0, 'n' },
{ "output", required_argument, 0, 'o' },
{ "summary-syscall-overhead", required_argument, 0, 'O' },
{ "attach", required_argument, 0, 'p' },
@@ -2191,6 +2198,9 @@ init(int argc, char *argv[])
"build of strace");
#endif
break;
+ case 'n':
+ nflag = 1;
+ break;
case 'o':
outfname = optarg;
break;
@@ -2465,6 +2475,9 @@ init(int argc, char *argv[])
if (stack_trace_enabled)
error_msg("-k/--stack-traces has no effect "
"with -c/--summary-only");
+ if (nflag)
+ error_msg("-n/--syscall-number has no effect "
+ "with -c/--summary-only");
if (rflag)
error_msg("-r/--relative-timestamps has no effect "
"with -c/--summary-only");
diff --git a/syscall.c b/syscall.c
index bcc87025e..094885de0 100644
--- a/syscall.c
+++ b/syscall.c
@@ -1354,6 +1354,7 @@ get_scno(struct tcb *tcp)
return rc;
}
+ tcp->true_scno = tcp->scno;
tcp->scno = shuffle_scno(tcp->scno);
if (scno_is_valid(tcp->scno)) {
diff --git a/tests/options-syntax.test b/tests/options-syntax.test
index 6788e63a6..e9aaf30ec 100755
--- a/tests/options-syntax.test
+++ b/tests/options-syntax.test
@@ -268,18 +268,19 @@ if [ "$uid" -ge 0 ]; then
check_e "$umsg" -u :nosuchuser: true
- for c in i/--instruction-pointer r/--relative-timestamps t/--absolute-timestamps T/--syscall-times y/--decode-fds; do
+ for c in i/--instruction-pointer n/--syscall-number r/--relative-timestamps t/--absolute-timestamps T/--syscall-times y/--decode-fds; do
check_e "-$c has no effect with -c/--summary-only
$STRACE_EXE: $umsg" -u :nosuchuser: -c -${c%%/*} true
done
check_e "-i/--instruction-pointer has no effect with -c/--summary-only
+$STRACE_EXE: -n/--syscall-number has no effect with -c/--summary-only
$STRACE_EXE: -r/--relative-timestamps has no effect with -c/--summary-only
$STRACE_EXE: -t/--absolute-timestamps has no effect with -c/--summary-only
$STRACE_EXE: -T/--syscall-times has no effect with -c/--summary-only
$STRACE_EXE: -y/--decode-fds has no effect with -c/--summary-only
$STRACE_EXE: Only the last of -z/--successful-only/-Z/--failed-only options will take effect. See status qualifier for more complex filters.
-$STRACE_EXE: $umsg" -u :nosuchuser: -cirtTyzZ true
+$STRACE_EXE: $umsg" -u :nosuchuser: -cinrtTyzZ true
for c in --output-separately -A/--output-append-mode; do
check_e "$c has no effect without -o/--output
@@ -303,6 +304,9 @@ $STRACE_EXE: $umsg" -u :nosuchuser: --successful-only -Z true
check_e "Only the last of -z/--successful-only/-Z/--failed-only options will take effect. See status qualifier for more complex filters.
$STRACE_EXE: $umsg" -u :nosuchuser: --successful-only --failed-only true
+ check_e "-n/--syscall-number has no effect with -c/--summary-only
+$STRACE_EXE: $umsg" --user=:nosuchuser: --syscall-number --summary-only true
+
check_e "-i/--instruction-pointer has no effect with -c/--summary-only
$STRACE_EXE: $umsg" --user=:nosuchuser: --instruction-pointer --summary-only true
fi