tools/perf/util/srcline.c
Source file repositories/reference/linux-study-clean/tools/perf/util/srcline.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/util/srcline.c- Extension
.c- Size
- 10885 bytes
- Lines
- 502
- 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
srcline.haddr2line.hdso.hcallchain.hlibbfd.hllvm.hsymbol.hlibdw.hdebug.hutil.hinttypes.hstring.hlinux/string.hlinux/zalloc.h
Detected Declarations
struct srcline_nodefunction inline_list__appendfunction inline_list__append_tailfunction addr2linefunction addr2line_configurefunction failuresfunction zfree_srclinefunction srcline__tree_insertfunction srcline__tree_deletefunction inline_node__deletefunction list_for_each_entry_safefunction inlines__tree_insertfunction inlines__tree_delete
Annotated Snippet
struct srcline_node {
u64 addr;
char *srcline;
struct rb_node rb_node;
};
void srcline__tree_insert(struct rb_root_cached *tree, u64 addr, char *srcline)
{
struct rb_node **p = &tree->rb_root.rb_node;
struct rb_node *parent = NULL;
struct srcline_node *i, *node;
bool leftmost = true;
node = zalloc(sizeof(struct srcline_node));
if (!node) {
perror("not enough memory for the srcline node");
return;
}
node->addr = addr;
node->srcline = srcline;
while (*p != NULL) {
parent = *p;
i = rb_entry(parent, struct srcline_node, rb_node);
if (addr < i->addr)
p = &(*p)->rb_left;
else {
p = &(*p)->rb_right;
leftmost = false;
}
}
rb_link_node(&node->rb_node, parent, p);
rb_insert_color_cached(&node->rb_node, tree, leftmost);
}
char *srcline__tree_find(struct rb_root_cached *tree, u64 addr)
{
struct rb_node *n = tree->rb_root.rb_node;
while (n) {
struct srcline_node *i = rb_entry(n, struct srcline_node,
rb_node);
if (addr < i->addr)
n = n->rb_left;
else if (addr > i->addr)
n = n->rb_right;
else
return i->srcline;
}
return NULL;
}
void srcline__tree_delete(struct rb_root_cached *tree)
{
struct srcline_node *pos;
struct rb_node *next = rb_first_cached(tree);
while (next) {
pos = rb_entry(next, struct srcline_node, rb_node);
next = rb_next(&pos->rb_node);
rb_erase_cached(&pos->rb_node, tree);
zfree_srcline(&pos->srcline);
zfree(&pos);
}
}
struct inline_node *dso__parse_addr_inlines(struct dso *dso, u64 addr,
struct symbol *sym)
{
const char *dso_name;
dso_name = srcline_dso_name(dso);
if (dso_name == NULL)
return NULL;
return addr2inlines(dso_name, addr, dso, sym);
}
void inline_node__delete(struct inline_node *node)
{
struct inline_list *ilist, *tmp;
list_for_each_entry_safe(ilist, tmp, &node->val, list) {
list_del_init(&ilist->list);
zfree_srcline(&ilist->srcline);
/* only the inlined symbols are owned by the list */
if (ilist->symbol && ilist->symbol->inlined)
Annotation
- Immediate include surface: `srcline.h`, `addr2line.h`, `dso.h`, `callchain.h`, `libbfd.h`, `llvm.h`, `symbol.h`, `libdw.h`.
- Detected declarations: `struct srcline_node`, `function inline_list__append`, `function inline_list__append_tail`, `function addr2line`, `function addr2line_configure`, `function failures`, `function zfree_srcline`, `function srcline__tree_insert`, `function srcline__tree_delete`, `function inline_node__delete`.
- 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.