tools/perf/util/unwind-libdw.c

Source file repositories/reference/linux-study-clean/tools/perf/util/unwind-libdw.c

File Facts

System
Linux kernel
Corpus path
tools/perf/util/unwind-libdw.c
Extension
.c
Size
10824 bytes
Lines
436
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 dwfl_ui_thread_info {
	/* Back link to the dwfl. */
	Dwfl *dwfl;
	/* The current unwind info, only 1 is supported. */
	struct unwind_info *ui;
};

static char *debuginfo_path;

static int __find_debuginfo(Dwfl_Module *mod __maybe_unused, void **userdata,
			    const char *modname __maybe_unused, Dwarf_Addr base __maybe_unused,
			    const char *file_name, const char *debuglink_file __maybe_unused,
			    GElf_Word debuglink_crc __maybe_unused, char **debuginfo_file_name)
{
	const struct dso *dso = *userdata;

	assert(dso);
	if (dso__symsrc_filename(dso) && strcmp(file_name, dso__symsrc_filename(dso)))
		*debuginfo_file_name = strdup(dso__symsrc_filename(dso));
	return -1;
}

void libdw__invalidate_dwfl(struct maps *maps, void *arg)
{
	struct dwfl_ui_thread_info *dwfl_ui_ti = arg;

	if (!dwfl_ui_ti)
		return;

	assert(dwfl_ui_ti->ui == NULL);
	maps__set_libdw_addr_space_dwfl(maps, NULL);
	dwfl_end(dwfl_ui_ti->dwfl);
	free(dwfl_ui_ti);
}

static const Dwfl_Callbacks offline_callbacks = {
	.find_debuginfo		= __find_debuginfo,
	.debuginfo_path		= &debuginfo_path,
	.section_address	= dwfl_offline_section_address,
	// .find_elf is not set as we use dwfl_report_elf() instead.
};

static int __report_module(struct addr_location *al, u64 ip,
			    struct unwind_info *ui)
{
	Dwfl_Module *mod;
	struct dso *dso = NULL;
	Dwarf_Addr base;
	/*
	 * Some callers will use al->sym, so we can't just use the
	 * cheaper thread__find_map() here.
	 */
	thread__find_symbol(ui->thread, PERF_RECORD_MISC_USER, ip, al);

	if (al->map)
		dso = map__dso(al->map);

	if (!dso)
		return 0;

	/*
	 * The generated JIT DSO files only map the code segment without
	 * ELF headers.  Since JIT codes used to be packed in a memory
	 * segment, calculating the base address using pgoff falls into
	 * a different code in another DSO.  So just use the map->start
	 * directly to pick the correct one.
	 */
	if (!strncmp(dso__long_name(dso), "/tmp/jitted-", 12))
		base = map__start(al->map);
	else
		base = map__start(al->map) - map__pgoff(al->map);

	mod = dwfl_addrmodule(ui->dwfl, ip);
	if (mod) {
		Dwarf_Addr s;

		dwfl_module_info(mod, NULL, &s, NULL, NULL, NULL, NULL, NULL);
		if (s != base)
			mod = NULL;
	}

	if (!mod) {
		char filename[PATH_MAX];

		__symbol__join_symfs(filename, sizeof(filename), dso__long_name(dso));
		/* Don't hang up on device files like /dev/dri/renderD128. */
		if (is_regular_file(filename)) {
			mod = dwfl_report_elf(ui->dwfl, dso__short_name(dso), filename, -1,
					      base, false);
		}

Annotation

Implementation Notes