tools/perf/tests/vmlinux-kallsyms.c

Source file repositories/reference/linux-study-clean/tools/perf/tests/vmlinux-kallsyms.c

File Facts

System
Linux kernel
Corpus path
tools/perf/tests/vmlinux-kallsyms.c
Extension
.c
Size
10939 bytes
Lines
382
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.

Dependency Surface

Detected Declarations

Annotated Snippet

struct test__vmlinux_matches_kallsyms_cb_args {
	struct machine kallsyms;
	struct map *vmlinux_map;
	bool header_printed;
};

static int test__vmlinux_matches_kallsyms_cb1(struct map *map, void *data)
{
	struct test__vmlinux_matches_kallsyms_cb_args *args = data;
	struct dso *dso = map__dso(map);
	/*
	 * If it is the kernel, kallsyms is always "[kernel.kallsyms]", while
	 * the kernel will have the path for the vmlinux file being used, so use
	 * the short name, less descriptive but the same ("[kernel]" in both
	 * cases.
	 */
	struct map *pair = maps__find_by_name(args->kallsyms.kmaps,
					(dso__kernel(dso) ? dso__short_name(dso) : dso__name(dso)));

	if (pair) {
		map__set_priv(pair);
		map__put(pair);
	} else {
		if (!args->header_printed) {
			pr_info("WARN: Maps only in vmlinux:\n");
			args->header_printed = true;
		}
		map__fprintf(map, stderr);
	}
	return 0;
}

static int test__vmlinux_matches_kallsyms_cb2(struct map *map, void *data)
{
	struct test__vmlinux_matches_kallsyms_cb_args *args = data;
	struct map *pair;
	u64 mem_start = map__unmap_ip(args->vmlinux_map, map__start(map));
	u64 mem_end = map__unmap_ip(args->vmlinux_map, map__end(map));

	pair = maps__find(args->kallsyms.kmaps, mem_start);

	if (pair != NULL && !map__priv(pair) && map__start(pair) == mem_start) {
		struct dso *dso = map__dso(map);

		if (!args->header_printed) {
			pr_info("WARN: Maps in vmlinux with a different name in kallsyms:\n");
			args->header_printed = true;
		}

		pr_info("WARN: %" PRIx64 "-%" PRIx64 " %" PRIx64 " %s in kallsyms as",
			map__start(map), map__end(map), map__pgoff(map), dso__name(dso));
		if (mem_end != map__end(pair))
			pr_info(":\nWARN: *%" PRIx64 "-%" PRIx64 " %" PRIx64,
				map__start(pair), map__end(pair), map__pgoff(pair));
		pr_info(" %s\n", dso__name(dso));
		map__set_priv(pair);
	}
	map__put(pair);
	return 0;
}

static int test__vmlinux_matches_kallsyms_cb3(struct map *map, void *data)
{
	struct test__vmlinux_matches_kallsyms_cb_args *args = data;

	if (!map__priv(map)) {
		if (!args->header_printed) {
			pr_info("WARN: Maps only in kallsyms:\n");
			args->header_printed = true;
		}
		map__fprintf(map, stderr);
	}
	return 0;
}

static int test__vmlinux_matches_kallsyms(struct test_suite *test __maybe_unused,
					int subtest __maybe_unused)
{
	int err = TEST_FAIL;
	struct rb_node *nd;
	struct symbol *sym;
	struct map *kallsyms_map;
	struct machine vmlinux;
	struct maps *maps;
	u64 mem_start, mem_end;
	struct test__vmlinux_matches_kallsyms_cb_args args;

	/*
	 * Step 1:
	 *

Annotation

Implementation Notes