162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 262306a36Sopenharmony_ci#ifndef _DWARF_AUX_H 362306a36Sopenharmony_ci#define _DWARF_AUX_H 462306a36Sopenharmony_ci/* 562306a36Sopenharmony_ci * dwarf-aux.h : libdw auxiliary interfaces 662306a36Sopenharmony_ci */ 762306a36Sopenharmony_ci 862306a36Sopenharmony_ci#include <dwarf.h> 962306a36Sopenharmony_ci#include <elfutils/libdw.h> 1062306a36Sopenharmony_ci#include <elfutils/libdwfl.h> 1162306a36Sopenharmony_ci#include <elfutils/version.h> 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_cistruct strbuf; 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ci/* Find the realpath of the target file */ 1662306a36Sopenharmony_ciconst char *cu_find_realpath(Dwarf_Die *cu_die, const char *fname); 1762306a36Sopenharmony_ci 1862306a36Sopenharmony_ci/* Get DW_AT_comp_dir (should be NULL with older gcc) */ 1962306a36Sopenharmony_ciconst char *cu_get_comp_dir(Dwarf_Die *cu_die); 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_ci/* Get a line number and file name for given address */ 2262306a36Sopenharmony_ciint cu_find_lineinfo(Dwarf_Die *cudie, Dwarf_Addr addr, 2362306a36Sopenharmony_ci const char **fname, int *lineno); 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_ci/* Walk on functions at given address */ 2662306a36Sopenharmony_ciint cu_walk_functions_at(Dwarf_Die *cu_die, Dwarf_Addr addr, 2762306a36Sopenharmony_ci int (*callback)(Dwarf_Die *, void *), void *data); 2862306a36Sopenharmony_ci 2962306a36Sopenharmony_ci/* Get DW_AT_linkage_name (should be NULL for C binary) */ 3062306a36Sopenharmony_ciconst char *die_get_linkage_name(Dwarf_Die *dw_die); 3162306a36Sopenharmony_ci 3262306a36Sopenharmony_ci/* Get the lowest PC in DIE (including range list) */ 3362306a36Sopenharmony_ciint die_entrypc(Dwarf_Die *dw_die, Dwarf_Addr *addr); 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_ci/* Ensure that this DIE is a subprogram and definition (not declaration) */ 3662306a36Sopenharmony_cibool die_is_func_def(Dwarf_Die *dw_die); 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ci/* Ensure that this DIE is an instance of a subprogram */ 3962306a36Sopenharmony_cibool die_is_func_instance(Dwarf_Die *dw_die); 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_ci/* Compare diename and tname */ 4262306a36Sopenharmony_cibool die_compare_name(Dwarf_Die *dw_die, const char *tname); 4362306a36Sopenharmony_ci 4462306a36Sopenharmony_ci/* Matching diename with glob pattern */ 4562306a36Sopenharmony_cibool die_match_name(Dwarf_Die *dw_die, const char *glob); 4662306a36Sopenharmony_ci 4762306a36Sopenharmony_ci/* Get callsite line number of inline-function instance */ 4862306a36Sopenharmony_ciint die_get_call_lineno(Dwarf_Die *in_die); 4962306a36Sopenharmony_ci 5062306a36Sopenharmony_ci/* Get callsite file name of inlined function instance */ 5162306a36Sopenharmony_ciconst char *die_get_call_file(Dwarf_Die *in_die); 5262306a36Sopenharmony_ci 5362306a36Sopenharmony_ci/* Get declared file name of a DIE */ 5462306a36Sopenharmony_ciconst char *die_get_decl_file(Dwarf_Die *dw_die); 5562306a36Sopenharmony_ci 5662306a36Sopenharmony_ci/* Get type die */ 5762306a36Sopenharmony_ciDwarf_Die *die_get_type(Dwarf_Die *vr_die, Dwarf_Die *die_mem); 5862306a36Sopenharmony_ci 5962306a36Sopenharmony_ci/* Get a type die, but skip qualifiers and typedef */ 6062306a36Sopenharmony_ciDwarf_Die *die_get_real_type(Dwarf_Die *vr_die, Dwarf_Die *die_mem); 6162306a36Sopenharmony_ci 6262306a36Sopenharmony_ci/* Check whether the DIE is signed or not */ 6362306a36Sopenharmony_cibool die_is_signed_type(Dwarf_Die *tp_die); 6462306a36Sopenharmony_ci 6562306a36Sopenharmony_ci/* Get data_member_location offset */ 6662306a36Sopenharmony_ciint die_get_data_member_location(Dwarf_Die *mb_die, Dwarf_Word *offs); 6762306a36Sopenharmony_ci 6862306a36Sopenharmony_ci/* Return values for die_find_child() callbacks */ 6962306a36Sopenharmony_cienum { 7062306a36Sopenharmony_ci DIE_FIND_CB_END = 0, /* End of Search */ 7162306a36Sopenharmony_ci DIE_FIND_CB_CHILD = 1, /* Search only children */ 7262306a36Sopenharmony_ci DIE_FIND_CB_SIBLING = 2, /* Search only siblings */ 7362306a36Sopenharmony_ci DIE_FIND_CB_CONTINUE = 3, /* Search children and siblings */ 7462306a36Sopenharmony_ci}; 7562306a36Sopenharmony_ci 7662306a36Sopenharmony_ci/* Search child DIEs */ 7762306a36Sopenharmony_ciDwarf_Die *die_find_child(Dwarf_Die *rt_die, 7862306a36Sopenharmony_ci int (*callback)(Dwarf_Die *, void *), 7962306a36Sopenharmony_ci void *data, Dwarf_Die *die_mem); 8062306a36Sopenharmony_ci 8162306a36Sopenharmony_ci/* Search a non-inlined function including given address */ 8262306a36Sopenharmony_ciDwarf_Die *die_find_realfunc(Dwarf_Die *cu_die, Dwarf_Addr addr, 8362306a36Sopenharmony_ci Dwarf_Die *die_mem); 8462306a36Sopenharmony_ci 8562306a36Sopenharmony_ci/* Search a non-inlined function with tail call at given address */ 8662306a36Sopenharmony_ciDwarf_Die *die_find_tailfunc(Dwarf_Die *cu_die, Dwarf_Addr addr, 8762306a36Sopenharmony_ci Dwarf_Die *die_mem); 8862306a36Sopenharmony_ci 8962306a36Sopenharmony_ci/* Search the top inlined function including given address */ 9062306a36Sopenharmony_ciDwarf_Die *die_find_top_inlinefunc(Dwarf_Die *sp_die, Dwarf_Addr addr, 9162306a36Sopenharmony_ci Dwarf_Die *die_mem); 9262306a36Sopenharmony_ci 9362306a36Sopenharmony_ci/* Search the deepest inlined function including given address */ 9462306a36Sopenharmony_ciDwarf_Die *die_find_inlinefunc(Dwarf_Die *sp_die, Dwarf_Addr addr, 9562306a36Sopenharmony_ci Dwarf_Die *die_mem); 9662306a36Sopenharmony_ci 9762306a36Sopenharmony_ci/* Walk on the instances of given DIE */ 9862306a36Sopenharmony_ciint die_walk_instances(Dwarf_Die *in_die, 9962306a36Sopenharmony_ci int (*callback)(Dwarf_Die *, void *), void *data); 10062306a36Sopenharmony_ci 10162306a36Sopenharmony_ci/* Walker on lines (Note: line number will not be sorted) */ 10262306a36Sopenharmony_citypedef int (* line_walk_callback_t) (const char *fname, int lineno, 10362306a36Sopenharmony_ci Dwarf_Addr addr, void *data); 10462306a36Sopenharmony_ci 10562306a36Sopenharmony_ci/* 10662306a36Sopenharmony_ci * Walk on lines inside given DIE. If the DIE is a subprogram, walk only on 10762306a36Sopenharmony_ci * the lines inside the subprogram, otherwise the DIE must be a CU DIE. 10862306a36Sopenharmony_ci */ 10962306a36Sopenharmony_ciint die_walk_lines(Dwarf_Die *rt_die, line_walk_callback_t callback, void *data); 11062306a36Sopenharmony_ci 11162306a36Sopenharmony_ci/* Find a variable called 'name' at given address */ 11262306a36Sopenharmony_ciDwarf_Die *die_find_variable_at(Dwarf_Die *sp_die, const char *name, 11362306a36Sopenharmony_ci Dwarf_Addr addr, Dwarf_Die *die_mem); 11462306a36Sopenharmony_ci 11562306a36Sopenharmony_ci/* Find a member called 'name' */ 11662306a36Sopenharmony_ciDwarf_Die *die_find_member(Dwarf_Die *st_die, const char *name, 11762306a36Sopenharmony_ci Dwarf_Die *die_mem); 11862306a36Sopenharmony_ci 11962306a36Sopenharmony_ci/* Get the name of given variable DIE */ 12062306a36Sopenharmony_ciint die_get_typename(Dwarf_Die *vr_die, struct strbuf *buf); 12162306a36Sopenharmony_ci 12262306a36Sopenharmony_ci/* Get the name and type of given variable DIE, stored as "type\tname" */ 12362306a36Sopenharmony_ciint die_get_varname(Dwarf_Die *vr_die, struct strbuf *buf); 12462306a36Sopenharmony_ciint die_get_var_range(Dwarf_Die *sp_die, Dwarf_Die *vr_die, struct strbuf *buf); 12562306a36Sopenharmony_ci 12662306a36Sopenharmony_ci/* Check if target program is compiled with optimization */ 12762306a36Sopenharmony_cibool die_is_optimized_target(Dwarf_Die *cu_die); 12862306a36Sopenharmony_ci 12962306a36Sopenharmony_ci/* Use next address after prologue as probe location */ 13062306a36Sopenharmony_civoid die_skip_prologue(Dwarf_Die *sp_die, Dwarf_Die *cu_die, 13162306a36Sopenharmony_ci Dwarf_Addr *entrypc); 13262306a36Sopenharmony_ci 13362306a36Sopenharmony_ci#endif 134