tools/testing/selftests/bpf/prog_tests/stacktrace_ips.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/stacktrace_ips.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/prog_tests/stacktrace_ips.c- Extension
.c- Size
- 7235 bytes
- Lines
- 261
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
test_progs.hstacktrace_ips.skel.h
Detected Declarations
function check_stacktrace_ipsfunction test_stacktrace_ips_kprobe_multifunction test_stacktrace_ips_raw_tpfunction test_stacktrace_ips_kprobefunction test_stacktrace_ips_trampolinefunction __test_stacktrace_ipsfunction __test_stacktrace_ipsfunction test_stacktrace_ips
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
#include <test_progs.h>
#include "stacktrace_ips.skel.h"
#ifdef __x86_64__
static int check_stacktrace_ips(int fd, __u32 key, int cnt, ...)
{
__u64 ips[PERF_MAX_STACK_DEPTH];
struct ksyms *ksyms = NULL;
int i, err = 0;
va_list args;
/* sorted by addr */
ksyms = load_kallsyms_local();
if (!ASSERT_OK_PTR(ksyms, "load_kallsyms_local"))
return -1;
/* unlikely, but... */
if (!ASSERT_LT(cnt, PERF_MAX_STACK_DEPTH, "check_max"))
return -1;
err = bpf_map_lookup_elem(fd, &key, ips);
if (err)
goto out;
/*
* Compare all symbols provided via arguments with stacktrace ips,
* and their related symbol addresses.t
*/
va_start(args, cnt);
for (i = 0; i < cnt; i++) {
unsigned long val;
struct ksym *ksym;
val = va_arg(args, unsigned long);
ksym = ksym_search_local(ksyms, ips[i]);
if (!ASSERT_OK_PTR(ksym, "ksym_search_local"))
break;
ASSERT_EQ(ksym->addr, val, "stack_cmp");
}
va_end(args);
out:
free_kallsyms_local(ksyms);
return err;
}
static void test_stacktrace_ips_kprobe_multi(bool retprobe)
{
LIBBPF_OPTS(bpf_kprobe_multi_opts, opts,
.retprobe = retprobe
);
LIBBPF_OPTS(bpf_test_run_opts, topts);
struct stacktrace_ips *skel;
skel = stacktrace_ips__open_and_load();
if (!ASSERT_OK_PTR(skel, "stacktrace_ips__open_and_load"))
return;
if (!skel->kconfig->CONFIG_UNWINDER_ORC) {
test__skip();
goto cleanup;
}
skel->links.kprobe_multi_test = bpf_program__attach_kprobe_multi_opts(
skel->progs.kprobe_multi_test,
"bpf_testmod_stacktrace_test", &opts);
if (!ASSERT_OK_PTR(skel->links.kprobe_multi_test, "bpf_program__attach_kprobe_multi_opts"))
goto cleanup;
trigger_module_test_read(1);
load_kallsyms();
if (retprobe) {
check_stacktrace_ips(bpf_map__fd(skel->maps.stackmap), skel->bss->stack_key, 4,
ksym_get_addr("bpf_testmod_stacktrace_test_3"),
ksym_get_addr("bpf_testmod_stacktrace_test_2"),
ksym_get_addr("bpf_testmod_stacktrace_test_1"),
ksym_get_addr("bpf_testmod_test_read"));
} else {
check_stacktrace_ips(bpf_map__fd(skel->maps.stackmap), skel->bss->stack_key, 5,
ksym_get_addr("bpf_testmod_stacktrace_test"),
ksym_get_addr("bpf_testmod_stacktrace_test_3"),
ksym_get_addr("bpf_testmod_stacktrace_test_2"),
ksym_get_addr("bpf_testmod_stacktrace_test_1"),
ksym_get_addr("bpf_testmod_test_read"));
}
Annotation
- Immediate include surface: `test_progs.h`, `stacktrace_ips.skel.h`.
- Detected declarations: `function check_stacktrace_ips`, `function test_stacktrace_ips_kprobe_multi`, `function test_stacktrace_ips_raw_tp`, `function test_stacktrace_ips_kprobe`, `function test_stacktrace_ips_trampoline`, `function __test_stacktrace_ips`, `function __test_stacktrace_ips`, `function test_stacktrace_ips`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.