tools/perf/util/probe-finder.c
Source file repositories/reference/linux-study-clean/tools/perf/util/probe-finder.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/util/probe-finder.c- Extension
.c- Size
- 49605 bytes
- Lines
- 1964
- 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
inttypes.hsys/utsname.hsys/types.hsys/stat.hfcntl.herrno.hstdio.hunistd.hstdlib.hstring.hstdarg.hdwarf-regs.hlinux/bitops.hlinux/zalloc.hevent.hdso.hdebug.hdebuginfo.hintlist.hstrbuf.hstrlist.hsymbol.hprobe-finder.hprobe-file.hstring2.h
Detected Declarations
struct find_scope_paramstruct dwarf_callback_paramstruct pubname_callback_paramstruct local_vars_finderfunction is_known_C_langfunction convert_variable_locationfunction immediate_value_is_supportedfunction dwarf_tagfunction convert_variable_typefunction strcmpfunction convert_variable_fieldsfunction print_var_not_foundfunction convert_variablefunction find_variablefunction convert_to_trace_pointfunction call_probe_finderfunction find_best_scope_cbfunction find_inner_scope_cbfunction verify_representive_linefunction probe_point_line_walkerfunction find_probe_point_by_linefunction find_lazy_match_linesfunction probe_point_lazy_walkerfunction find_probe_point_lazyfunction skip_prologuefunction probe_point_inline_cbfunction probe_point_search_cbfunction find_probe_point_by_funcfunction pubname_search_cbfunction debuginfo__find_probe_locationfunction debuginfo__find_probesfunction copy_variables_cbfunction expand_probe_argsfunction trace_event_finder_overlapfunction add_probe_trace_eventfunction fill_empty_trace_argfunction debuginfo__find_trace_eventsfunction collect_variables_cbfunction available_var_finder_overlapfunction add_available_varsfunction debuginfo__find_available_vars_atfunction debuginfo__find_probe_pointfunction line_range_add_linefunction line_range_walk_cbfunction find_line_range_by_linefunction line_range_inline_cbfunction line_range_search_cbfunction find_line_range_by_func
Annotated Snippet
struct find_scope_param {
const char *function;
const char *file;
int line;
int diff;
Dwarf_Die *die_mem;
bool found;
};
static int find_best_scope_cb(Dwarf_Die *fn_die, void *data)
{
struct find_scope_param *fsp = data;
const char *file;
int lno;
/* Skip if declared file name does not match */
if (fsp->file) {
file = die_get_decl_file(fn_die);
if (!file || strcmp(fsp->file, file) != 0)
return 0;
}
/* If the function name is given, that's what user expects */
if (fsp->function) {
if (die_match_name(fn_die, fsp->function)) {
memcpy(fsp->die_mem, fn_die, sizeof(Dwarf_Die));
fsp->found = true;
return 1;
}
} else {
/* With the line number, find the nearest declared DIE */
dwarf_decl_line(fn_die, &lno);
if (lno < fsp->line && fsp->diff > fsp->line - lno) {
/* Keep a candidate and continue */
fsp->diff = fsp->line - lno;
memcpy(fsp->die_mem, fn_die, sizeof(Dwarf_Die));
fsp->found = true;
}
}
return 0;
}
/* Return innermost DIE */
static int find_inner_scope_cb(Dwarf_Die *fn_die, void *data)
{
struct find_scope_param *fsp = data;
memcpy(fsp->die_mem, fn_die, sizeof(Dwarf_Die));
fsp->found = true;
return 1;
}
/* Find an appropriate scope fits to given conditions */
static Dwarf_Die *find_best_scope(struct probe_finder *pf, Dwarf_Die *die_mem)
{
struct find_scope_param fsp = {
.function = pf->pev->point.function,
.file = pf->fname,
.line = pf->lno,
.diff = INT_MAX,
.die_mem = die_mem,
.found = false,
};
int ret;
ret = cu_walk_functions_at(&pf->cu_die, pf->addr, find_best_scope_cb,
&fsp);
if (!ret && !fsp.found)
cu_walk_functions_at(&pf->cu_die, pf->addr,
find_inner_scope_cb, &fsp);
return fsp.found ? die_mem : NULL;
}
static int verify_representive_line(struct probe_finder *pf, const char *fname,
int lineno, Dwarf_Addr addr)
{
const char *__fname, *__func = NULL;
Dwarf_Die die_mem;
int __lineno;
/* Verify line number and address by reverse search */
if (cu_find_lineinfo(&pf->cu_die, addr, &__fname, &__lineno) < 0)
return 0;
pr_debug2("Reversed line: %s:%d\n", __fname, __lineno);
if (strcmp(fname, __fname) || lineno == __lineno)
return 0;
pr_warning("This line is sharing the address with other lines.\n");
Annotation
- Immediate include surface: `inttypes.h`, `sys/utsname.h`, `sys/types.h`, `sys/stat.h`, `fcntl.h`, `errno.h`, `stdio.h`, `unistd.h`.
- Detected declarations: `struct find_scope_param`, `struct dwarf_callback_param`, `struct pubname_callback_param`, `struct local_vars_finder`, `function is_known_C_lang`, `function convert_variable_location`, `function immediate_value_is_supported`, `function dwarf_tag`, `function convert_variable_type`, `function strcmp`.
- 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.