1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2020 Facebook */
4 #include <bpf/bpf_helpers.h>
5 #include <bpf/bpf_tracing.h>
7 char _license
[] SEC("license") = "GPL";
9 #define MAX_STACK_TRACE_DEPTH 64
10 unsigned long entries
[MAX_STACK_TRACE_DEPTH
] = {};
11 #define SIZE_OF_ULONG (sizeof(unsigned long))
14 int dump_task_stack(struct bpf_iter__task
*ctx
)
16 struct seq_file
*seq
= ctx
->meta
->seq
;
17 struct task_struct
*task
= ctx
->task
;
20 if (task
== (void *)0)
23 retlen
= bpf_get_task_stack(task
, entries
,
24 MAX_STACK_TRACE_DEPTH
* SIZE_OF_ULONG
, 0);
28 BPF_SEQ_PRINTF(seq
, "pid: %8u num_entries: %8u\n", task
->pid
,
29 retlen
/ SIZE_OF_ULONG
);
30 for (i
= 0; i
< MAX_STACK_TRACE_DEPTH
; i
++) {
31 if (retlen
> i
* SIZE_OF_ULONG
)
32 BPF_SEQ_PRINTF(seq
, "[<0>] %pB\n", (void *)entries
[i
]);
34 BPF_SEQ_PRINTF(seq
, "\n");