Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 38 additions & 18 deletions libbpf-tools/ksnoop.c
Original file line number Diff line number Diff line change
Expand Up @@ -633,10 +633,25 @@ static int parse_trace(char *str, struct trace *trace)
return 0;
}

static int parse_traces(int argc, char **argv, struct trace **traces)
static int parse_traces(int argc, char **argv, struct trace *traces)
{
__u8 i;

for (i = 0; i < argc; i++) {
if (parse_trace(argv[i], &(traces[i])))
return -EINVAL;

if (!stack_mode || i == 0)
continue;
/* tell stack mode trace which function to expect next */
traces[i].prev_ip = traces[i-1].func.ip;
traces[i-1].next_ip = traces[i].func.ip;
}
return i;
}

static int alloc_traces(int argc, struct trace **traces)
{
if (argc == 0)
usage();

Expand All @@ -649,28 +664,26 @@ static int parse_traces(int argc, char **argv, struct trace **traces)
p_err("Could not allocate %d traces", argc);
return -ENOMEM;
}
for (i = 0; i < argc; i++) {
if (parse_trace(argv[i], &((*traces)[i])))
return -EINVAL;
if (!stack_mode || i == 0)
continue;
/* tell stack mode trace which function to expect next */
(*traces)[i].prev_ip = (*traces)[i-1].func.ip;
(*traces)[i-1].next_ip = (*traces)[i].func.ip;
}
return i;

return 0;
}

static int cmd_info(int argc, char **argv)
{
struct trace *traces = NULL;
char str[MAX_STR];
int nr_traces;
int nr_traces, err;
__u8 i, j;

nr_traces = parse_traces(argc, argv, &traces);
if (nr_traces < 0)
err = alloc_traces(argc, &traces);
if (err < 0)
return err;

nr_traces = parse_traces(argc, argv, traces);
if (nr_traces < 0) {
free(traces);
return nr_traces;
}

for (i = 0; i < nr_traces; i++) {
struct func *func = &traces[i].func;
Expand Down Expand Up @@ -845,18 +858,25 @@ static int cmd_trace(int argc, char **argv)
struct bpf_map *perf_map, *func_map;
struct perf_buffer *pb = NULL;
struct ksnoop_bpf *skel;
int i, nr_traces, ret = -1;
int i, nr_traces, ret;
struct trace *traces = NULL;

nr_traces = parse_traces(argc, argv, &traces);
if (nr_traces < 0)
ret = alloc_traces(argc, &traces);
if (ret < 0)
return ret;
ret = -1;

nr_traces = parse_traces(argc, argv, traces);
if (nr_traces < 0) {
free(traces);
return nr_traces;
}

skel = ksnoop_bpf__open_and_load();
if (!skel) {
ret = -errno;
p_err("Could not load ksnoop BPF: %s", strerror(-ret));
return 1;
goto cleanup;
}

perf_map = skel->maps.ksnoop_perf_map;
Expand Down