Commit 7bb52337 authored by Brendan Gregg's avatar Brendan Gregg Committed by GitHub

Merge pull request #1369 from pchaigno/execsnoop-max-args

execsnoop: argument to change the number of arguments parsed
parents fdf9b08c a0c9b48b
...@@ -35,6 +35,9 @@ Only print command lines matching this name (regex) ...@@ -35,6 +35,9 @@ Only print command lines matching this name (regex)
.TP .TP
\-l LINE \-l LINE
Only print commands where arg contains this line (regex) Only print commands where arg contains this line (regex)
.TP
\--max-args MAXARGS
Maximum number of arguments parsed and displayed, defaults to 20
.SH EXAMPLES .SH EXAMPLES
.TP .TP
Trace all exec() syscalls: Trace all exec() syscalls:
......
...@@ -44,6 +44,8 @@ parser.add_argument("-n", "--name", ...@@ -44,6 +44,8 @@ parser.add_argument("-n", "--name",
help="only print commands matching this name (regex), any arg") help="only print commands matching this name (regex), any arg")
parser.add_argument("-l", "--line", parser.add_argument("-l", "--line",
help="only print commands where arg contains this line (regex)") help="only print commands where arg contains this line (regex)")
parser.add_argument("--max-args", default="20",
help="maximum number of arguments parsed and displayed, defaults to 20")
args = parser.parse_args() args = parser.parse_args()
# define BPF program # define BPF program
...@@ -52,7 +54,6 @@ bpf_text = """ ...@@ -52,7 +54,6 @@ bpf_text = """
#include <linux/sched.h> #include <linux/sched.h>
#include <linux/fs.h> #include <linux/fs.h>
#define MAXARG 20
#define ARGSIZE 128 #define ARGSIZE 128
enum event_type { enum event_type {
...@@ -99,28 +100,12 @@ int kprobe__sys_execve(struct pt_regs *ctx, struct filename *filename, ...@@ -99,28 +100,12 @@ int kprobe__sys_execve(struct pt_regs *ctx, struct filename *filename,
__submit_arg(ctx, (void *)filename, &data); __submit_arg(ctx, (void *)filename, &data);
int i = 1; // skip first arg, as we submitted filename // skip first arg, as we submitted filename
#pragma unroll
// unrolled loop to walk argv[] (MAXARG) for (int i = 1; i < MAXARG; i++) {
if (submit_arg(ctx, (void *)&__argv[i], &data) == 0) goto out; i++; if (submit_arg(ctx, (void *)&__argv[i], &data) == 0)
if (submit_arg(ctx, (void *)&__argv[i], &data) == 0) goto out; i++; goto out;
if (submit_arg(ctx, (void *)&__argv[i], &data) == 0) goto out; i++; }
if (submit_arg(ctx, (void *)&__argv[i], &data) == 0) goto out; i++;
if (submit_arg(ctx, (void *)&__argv[i], &data) == 0) goto out; i++;
if (submit_arg(ctx, (void *)&__argv[i], &data) == 0) goto out; i++;
if (submit_arg(ctx, (void *)&__argv[i], &data) == 0) goto out; i++;
if (submit_arg(ctx, (void *)&__argv[i], &data) == 0) goto out; i++;
if (submit_arg(ctx, (void *)&__argv[i], &data) == 0) goto out; i++; // X
if (submit_arg(ctx, (void *)&__argv[i], &data) == 0) goto out; i++;
if (submit_arg(ctx, (void *)&__argv[i], &data) == 0) goto out; i++;
if (submit_arg(ctx, (void *)&__argv[i], &data) == 0) goto out; i++;
if (submit_arg(ctx, (void *)&__argv[i], &data) == 0) goto out; i++;
if (submit_arg(ctx, (void *)&__argv[i], &data) == 0) goto out; i++;
if (submit_arg(ctx, (void *)&__argv[i], &data) == 0) goto out; i++;
if (submit_arg(ctx, (void *)&__argv[i], &data) == 0) goto out; i++;
if (submit_arg(ctx, (void *)&__argv[i], &data) == 0) goto out; i++;
if (submit_arg(ctx, (void *)&__argv[i], &data) == 0) goto out; i++;
if (submit_arg(ctx, (void *)&__argv[i], &data) == 0) goto out; i++; // XX
// handle truncated argument list // handle truncated argument list
char ellipsis[] = "..."; char ellipsis[] = "...";
...@@ -143,7 +128,7 @@ int kretprobe__sys_execve(struct pt_regs *ctx) ...@@ -143,7 +128,7 @@ int kretprobe__sys_execve(struct pt_regs *ctx)
""" """
# initialize BPF # initialize BPF
b = BPF(text=bpf_text) b = BPF(text=bpf_text.replace("MAXARG", args.max_args))
# header # header
if args.timestamp: if args.timestamp:
......
...@@ -79,7 +79,7 @@ rpm 3345452 4146419 0 /bin/rpm -qa testpkg ...@@ -79,7 +79,7 @@ rpm 3345452 4146419 0 /bin/rpm -qa testpkg
USAGE message: USAGE message:
# ./execsnoop -h # ./execsnoop -h
usage: execsnoop [-h] [-t] [-x] [-n NAME] usage: execsnoop [-h] [-t] [-x] [-n NAME] [-l LINE] [--max-args MAX_ARGS]
Trace exec() syscalls Trace exec() syscalls
...@@ -91,10 +91,12 @@ optional arguments: ...@@ -91,10 +91,12 @@ optional arguments:
arg arg
-l LINE, --line LINE only print commands where arg contains this line -l LINE, --line LINE only print commands where arg contains this line
(regex) (regex)
--max-args MAX_ARGS maximum number of arguments parsed and displayed,
defaults to 20
examples: examples:
./execsnoop # trace all exec() syscalls ./execsnoop # trace all exec() syscalls
./execsnoop -x # include failed exec()s ./execsnoop -x # include failed exec()s
./execsnoop -t # include timestamps ./execsnoop -t # include timestamps
./execsnoop -n main # only print command lines containing "main" ./execsnoop -n main # only print command lines containing "main"
./execsnoop -l tpkg # only print command where arguments contains "tpkg" ./execsnoop -l tpkg # only print command where arguments contains "tpkg"
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment