tools/perf/util/addr2line.c
Source file repositories/reference/linux-study-clean/tools/perf/util/addr2line.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/util/addr2line.c- Extension
.c- Size
- 10785 bytes
- Lines
- 437
- 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
addr2line.hdebug.hdso.hstring2.hsrcline.hsymbol.hsymbol_conf.hapi/io.hlinux/zalloc.hsubcmd/run-command.hinttypes.hsignal.hstdlib.hstring.h
Detected Declarations
enum cmd_a2l_stylefunction filename_splitfunction addr2line_subprocess_cleanupfunction cmd_addr2line_configurefunction read_addr2line_recordfunction inline_list__append_recordfunction cmd__addr2linefunction dso__free_a2l
Annotated Snippet
if (ch == ',') {
style = LLVM;
cached = true;
lines = 1;
pr_debug3("Detected LLVM addr2line style\n");
} else if (ch == '0') {
style = GNU_BINUTILS;
cached = true;
lines = 3;
pr_debug3("Detected binutils addr2line style\n");
} else {
if (!symbol_conf.addr2line_disable_warn) {
char *output = NULL;
size_t output_len;
io__getline(&io, &output, &output_len);
pr_warning("%s %s: addr2line configuration failed\n",
__func__, dso_name);
pr_warning("\t%c%s", ch, output);
}
pr_debug("Unknown/broken addr2line style\n");
return BROKEN;
}
while (lines) {
ch = io__get_char(&io);
if (ch <= 0)
break;
if (ch == '\n')
lines--;
}
/* Ignore SIGPIPE in the event addr2line exits. */
signal(SIGPIPE, SIG_IGN);
}
return style;
}
static int read_addr2line_record(struct io *io,
enum cmd_a2l_style style,
const char *dso_name,
u64 addr,
bool first,
char **function,
char **filename,
unsigned int *line_nr)
{
/*
* Returns:
* -1 ==> error
* 0 ==> sentinel (or other ill-formed) record read
* 1 ==> a genuine record read
*/
char *line = NULL;
size_t line_len = 0;
unsigned int dummy_line_nr = 0;
int ret = -1;
if (function != NULL)
zfree(function);
if (filename != NULL)
zfree(filename);
if (line_nr != NULL)
*line_nr = 0;
/*
* Read the first line. Without an error this will be:
* - for the first line an address like 0x1234,
* - the binutils sentinel 0x0000000000000000,
* - the llvm-addr2line the sentinel ',' character,
* - the function name line for an inlined function.
*/
if (io__getline(io, &line, &line_len) < 0 || !line_len)
goto error;
pr_debug3("%s %s: addr2line read address for sentinel: %s", __func__, dso_name, line);
if (style == LLVM && line_len == 2 && line[0] == ',') {
/* Found the llvm-addr2line sentinel character. */
zfree(&line);
return 0;
} else if (style == GNU_BINUTILS && (!first || addr != 0)) {
int zero_count = 0, non_zero_count = 0;
/*
* Check for binutils sentinel ignoring it for the case the
* requested address is 0.
*/
/* A given address should always start 0x. */
if (line_len >= 2 || line[0] != '0' || line[1] != 'x') {
for (size_t i = 2; i < line_len; i++) {
Annotation
- Immediate include surface: `addr2line.h`, `debug.h`, `dso.h`, `string2.h`, `srcline.h`, `symbol.h`, `symbol_conf.h`, `api/io.h`.
- Detected declarations: `enum cmd_a2l_style`, `function filename_split`, `function addr2line_subprocess_cleanup`, `function cmd_addr2line_configure`, `function read_addr2line_record`, `function inline_list__append_record`, `function cmd__addr2line`, `function dso__free_a2l`.
- 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.