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.
- 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
linux/compiler.helfutils/libdw.helfutils/libdwfl.hinttypes.herrno.hdebug.hdso.hdwarf-regs.hunwind.hunwind-libdw.hmachine.hmap.hsymbol.hthread.hlinux/types.hlinux/zalloc.hevent.hperf_regs.hcallchain.hutil/env.h
Detected Declarations
struct dwfl_ui_thread_infofunction __find_debuginfofunction libdw__invalidate_dwflfunction __report_modulefunction report_modulefunction entryfunction next_threadfunction access_dso_memfunction memory_readfunction libdw_set_initial_registersfunction frame_callbackfunction unwind__get_entries
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
- Immediate include surface: `linux/compiler.h`, `elfutils/libdw.h`, `elfutils/libdwfl.h`, `inttypes.h`, `errno.h`, `debug.h`, `dso.h`, `dwarf-regs.h`.
- Detected declarations: `struct dwfl_ui_thread_info`, `function __find_debuginfo`, `function libdw__invalidate_dwfl`, `function __report_module`, `function report_module`, `function entry`, `function next_thread`, `function access_dso_mem`, `function memory_read`, `function libdw_set_initial_registers`.
- 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.