Linux Perf
dwarf-aux.c File Reference
#include <errno.h>
#include <inttypes.h>
#include <stdbool.h>
#include "util.h"
#include "debug.h"
#include "dwarf-aux.h"
#include "string2.h"
Include dependency graph for dwarf-aux.c:

Go to the source code of this file.

Classes

struct  __addr_die_search_param
 
struct  __instance_walk_param
 
struct  __line_walk_param
 
struct  __find_variable_param
 

Functions

const char * cu_find_realpath (Dwarf_Die *cu_die, const char *fname)
 
const char * cu_get_comp_dir (Dwarf_Die *cu_die)
 
int cu_find_lineinfo (Dwarf_Die *cu_die, unsigned long addr, const char **fname, int *lineno)
 
static int __die_find_inline_cb (Dwarf_Die *die_mem, void *data)
 
int cu_walk_functions_at (Dwarf_Die *cu_die, Dwarf_Addr addr, int(*callback)(Dwarf_Die *, void *), void *data)
 
const char * die_get_linkage_name (Dwarf_Die *dw_die)
 
bool die_compare_name (Dwarf_Die *dw_die, const char *tname)
 
bool die_match_name (Dwarf_Die *dw_die, const char *glob)
 
int die_get_call_lineno (Dwarf_Die *in_die)
 
Dwarf_Die * die_get_type (Dwarf_Die *vr_die, Dwarf_Die *die_mem)
 
static Dwarf_Die * __die_get_real_type (Dwarf_Die *vr_die, Dwarf_Die *die_mem)
 
Dwarf_Die * die_get_real_type (Dwarf_Die *vr_die, Dwarf_Die *die_mem)
 
static int die_get_attr_udata (Dwarf_Die *tp_die, unsigned int attr_name, Dwarf_Word *result)
 
static int die_get_attr_sdata (Dwarf_Die *tp_die, unsigned int attr_name, Dwarf_Sword *result)
 
bool die_is_signed_type (Dwarf_Die *tp_die)
 
bool die_is_func_def (Dwarf_Die *dw_die)
 
bool die_is_func_instance (Dwarf_Die *dw_die)
 
int die_get_data_member_location (Dwarf_Die *mb_die, Dwarf_Word *offs)
 
static int die_get_call_fileno (Dwarf_Die *in_die)
 
static int die_get_decl_fileno (Dwarf_Die *pdie)
 
const char * die_get_call_file (Dwarf_Die *in_die)
 
Dwarf_Die * die_find_child (Dwarf_Die *rt_die, int(*callback)(Dwarf_Die *, void *), void *data, Dwarf_Die *die_mem)
 
static int __die_search_func_tail_cb (Dwarf_Die *fn_die, void *data)
 
Dwarf_Die * die_find_tailfunc (Dwarf_Die *cu_die, Dwarf_Addr addr, Dwarf_Die *die_mem)
 
static int __die_search_func_cb (Dwarf_Die *fn_die, void *data)
 
Dwarf_Die * die_find_realfunc (Dwarf_Die *cu_die, Dwarf_Addr addr, Dwarf_Die *die_mem)
 
Dwarf_Die * die_find_top_inlinefunc (Dwarf_Die *sp_die, Dwarf_Addr addr, Dwarf_Die *die_mem)
 
Dwarf_Die * die_find_inlinefunc (Dwarf_Die *sp_die, Dwarf_Addr addr, Dwarf_Die *die_mem)
 
static int __die_walk_instances_cb (Dwarf_Die *inst, void *data)
 
int die_walk_instances (Dwarf_Die *or_die, int(*callback)(Dwarf_Die *, void *), void *data)
 
static int __die_walk_funclines_cb (Dwarf_Die *in_die, void *data)
 
static int __die_walk_funclines (Dwarf_Die *sp_die, bool recursive, line_walk_callback_t callback, void *data)
 
static int __die_walk_culines_cb (Dwarf_Die *sp_die, void *data)
 
int die_walk_lines (Dwarf_Die *rt_die, line_walk_callback_t callback, void *data)
 
static int __die_find_variable_cb (Dwarf_Die *die_mem, void *data)
 
at @addr in @sp_die.
Dwarf_Die * die_find_variable_at (Dwarf_Die *sp_die, const char *name, Dwarf_Addr addr, Dwarf_Die *die_mem)
 
static int __die_find_member_cb (Dwarf_Die *die_mem, void *data)
 
in @st_die.
Dwarf_Die * die_find_member (Dwarf_Die *st_die, const char *name, Dwarf_Die *die_mem)
 
int die_get_typename (Dwarf_Die *vr_die, struct strbuf *buf)
 
int die_get_varname (Dwarf_Die *vr_die, struct strbuf *buf)
 
int die_get_var_range (Dwarf_Die *sp_die __maybe_unused, Dwarf_Die *vr_die __maybe_unused, struct strbuf *buf __maybe_unused)
 
static bool die_has_loclist (Dwarf_Die *vr_die)
 
bool die_is_optimized_target (Dwarf_Die *cu_die)
 
static bool die_search_idx (Dwarf_Lines *lines, unsigned long nr_lines, Dwarf_Addr addr, unsigned long *idx)
 
static bool die_get_postprologue_addr (unsigned long entrypc_idx, Dwarf_Lines *lines, unsigned long nr_lines, Dwarf_Addr highpc, Dwarf_Addr *postprologue_addr)
 
void die_skip_prologue (Dwarf_Die *sp_die, Dwarf_Die *cu_die, Dwarf_Addr *entrypc)
 

Function Documentation

◆ __die_find_inline_cb()

static int __die_find_inline_cb ( Dwarf_Die *  die_mem,
void *  data 
)
static

Definition at line 540 of file dwarf-aux.c.

◆ __die_find_member_cb()

static int __die_find_member_cb ( Dwarf_Die *  die_mem,
void *  data 
)
static

Definition at line 889 of file dwarf-aux.c.

Here is the call graph for this function:

◆ __die_find_variable_cb()

static int __die_find_variable_cb ( Dwarf_Die *  die_mem,
void *  data 
)
static

Definition at line 851 of file dwarf-aux.c.

Here is the call graph for this function:

◆ __die_get_real_type()

static Dwarf_Die* __die_get_real_type ( Dwarf_Die *  vr_die,
Dwarf_Die *  die_mem 
)
static

Definition at line 228 of file dwarf-aux.c.

Here is the call graph for this function:

◆ __die_search_func_cb()

static int __die_search_func_cb ( Dwarf_Die *  fn_die,
void *  data 
)
static

Definition at line 501 of file dwarf-aux.c.

Here is the call graph for this function:

◆ __die_search_func_tail_cb()

static int __die_search_func_tail_cb ( Dwarf_Die *  fn_die,
void *  data 
)
static

Definition at line 463 of file dwarf-aux.c.

Here is the call graph for this function:

◆ __die_walk_culines_cb()

static int __die_walk_culines_cb ( Dwarf_Die *  sp_die,
void *  data 
)
static

Definition at line 736 of file dwarf-aux.c.

Here is the call graph for this function:

◆ __die_walk_funclines()

static int __die_walk_funclines ( Dwarf_Die *  sp_die,
bool  recursive,
line_walk_callback_t  callback,
void *  data 
)
static

Definition at line 709 of file dwarf-aux.c.

Here is the call graph for this function:

◆ __die_walk_funclines_cb()

static int __die_walk_funclines_cb ( Dwarf_Die *  in_die,
void *  data 
)
static

Definition at line 675 of file dwarf-aux.c.

Here is the call graph for this function:

◆ __die_walk_instances_cb()

static int __die_walk_instances_cb ( Dwarf_Die *  inst,
void *  data 
)
static

Definition at line 605 of file dwarf-aux.c.

Here is the call graph for this function:

◆ cu_find_lineinfo()

int cu_find_lineinfo ( Dwarf_Die *  cu_die,
unsigned long  addr,
const char **  fname,
int *  lineno 
)

cu_find_lineinfo - Get a line number and file name for given address : a CU DIE : An address : a pointer which returns the file name string : a pointer which returns the line number

Find a line number and file name for in .

Definition at line 84 of file dwarf-aux.c.

Here is the call graph for this function:

◆ cu_find_realpath()

const char* cu_find_realpath ( Dwarf_Die *  cu_die,
const char *  fname 
)

cu_find_realpath - Find the realpath of the target file : A DIE(dwarf information entry) of CU(compilation Unit) : The tail filename of the target file

Find the real(long) path of in .

Definition at line 35 of file dwarf-aux.c.

Here is the call graph for this function:

◆ cu_get_comp_dir()

const char* cu_get_comp_dir ( Dwarf_Die *  cu_die)

cu_get_comp_dir - Get the path of compilation directory : a CU DIE

Get the path of compilation directory of given . Since this depends on DW_AT_comp_dir, older gcc will not embedded it. In that case, this returns NULL.

Definition at line 67 of file dwarf-aux.c.

◆ cu_walk_functions_at()

int cu_walk_functions_at ( Dwarf_Die *  cu_die,
Dwarf_Addr  addr,
int(*)(Dwarf_Die *, void *)  callback,
void *  data 
)

cu_walk_functions_at - Walk on function DIEs at given address : A CU DIE : An address : A callback which called with found DIEs : A user data

Walk on function DIEs at given in . Passed DIEs should be subprogram or inlined-subroutines.

Definition at line 114 of file dwarf-aux.c.

Here is the call graph for this function:

◆ die_compare_name()

bool die_compare_name ( Dwarf_Die *  dw_die,
const char *  tname 
)

die_compare_name - Compare diename and tname : a DIE : a string of target name

Compare the name of and . Return false if has no name.

Definition at line 158 of file dwarf-aux.c.

◆ die_find_child()

Dwarf_Die* die_find_child ( Dwarf_Die *  rt_die,
int(*)(Dwarf_Die *, void *)  callback,
void *  data,
Dwarf_Die *  die_mem 
)

die_find_child - Generic DIE search function in DIE tree : a root DIE : a callback function : a user data passed to the callback function : a buffer for result DIE

Trace DIE tree from and call for each child DIE. If returns DIE_FIND_CB_END, this stores the DIE into and returns it. If returns DIE_FIND_CB_CONTINUE, this continues to trace the tree. Optionally, can return DIE_FIND_CB_CHILD and DIE_FIND_CB_SIBLING, those means trace only the children and trace only the siblings respectively. Returns NULL if can't find any appropriate DIE.

Definition at line 431 of file dwarf-aux.c.

Here is the call graph for this function:

◆ die_find_inlinefunc()

Dwarf_Die* die_find_inlinefunc ( Dwarf_Die *  sp_die,
Dwarf_Addr  addr,
Dwarf_Die *  die_mem 
)

die_find_inlinefunc - Search an inlined function at given address : a subprogram DIE which including : target address : a buffer for result DIE

Search an inlined function DIE which includes . Stores the DIE to and returns it if found. Returns NULL if failed. If several inlined functions are expanded recursively, this trace it down and returns deepest one.

Definition at line 579 of file dwarf-aux.c.

Here is the call graph for this function:

◆ die_find_member()

Dwarf_Die* die_find_member ( Dwarf_Die *  st_die,
const char *  name,
Dwarf_Die *  die_mem 
)

Definition at line 914 of file dwarf-aux.c.

Here is the call graph for this function:

◆ die_find_realfunc()

Dwarf_Die* die_find_realfunc ( Dwarf_Die *  cu_die,
Dwarf_Addr  addr,
Dwarf_Die *  die_mem 
)

die_find_realfunc - Search a non-inlined function at given address : a CU DIE which including : target address : a buffer for result DIE

Search a non-inlined function DIE which includes . Stores the DIE to and returns it if found. Returns NULL if failed.

Definition at line 526 of file dwarf-aux.c.

Here is the call graph for this function:

◆ die_find_tailfunc()

Dwarf_Die* die_find_tailfunc ( Dwarf_Die *  cu_die,
Dwarf_Addr  addr,
Dwarf_Die *  die_mem 
)

die_find_tailfunc - Search for a non-inlined function with tail call at given address : a CU DIE which including : target address : a buffer for result DIE

Search for a non-inlined function DIE with tail call at . Stores the DIE to and returns it if found. Returns NULL if failed.

Definition at line 487 of file dwarf-aux.c.

Here is the call graph for this function:

◆ die_find_top_inlinefunc()

Dwarf_Die* die_find_top_inlinefunc ( Dwarf_Die *  sp_die,
Dwarf_Addr  addr,
Dwarf_Die *  die_mem 
)

die_find_top_inlinefunc - Search the top inlined function at given address : a subprogram DIE which including : target address : a buffer for result DIE

Search an inlined function DIE which includes . Stores the DIE to and returns it if found. Returns NULL if failed. Even if several inlined functions are expanded recursively, this doesn't trace it down, and returns the topmost one.

Definition at line 562 of file dwarf-aux.c.

Here is the call graph for this function:

◆ die_find_variable_at()

Dwarf_Die* die_find_variable_at ( Dwarf_Die *  sp_die,
const char *  name,
Dwarf_Addr  addr,
Dwarf_Die *  die_mem 
)

Definition at line 880 of file dwarf-aux.c.

Here is the call graph for this function:

◆ die_get_attr_sdata()

static int die_get_attr_sdata ( Dwarf_Die *  tp_die,
unsigned int  attr_name,
Dwarf_Sword *  result 
)
static

Definition at line 278 of file dwarf-aux.c.

◆ die_get_attr_udata()

static int die_get_attr_udata ( Dwarf_Die *  tp_die,
unsigned int  attr_name,
Dwarf_Word *  result 
)
static

Definition at line 265 of file dwarf-aux.c.

◆ die_get_call_file()

const char* die_get_call_file ( Dwarf_Die *  in_die)

die_get_call_file - Get callsite file name of inlined function instance : a DIE of an inlined function instance

Get call-site file name of . This means from which file the inline function is called.

Definition at line 401 of file dwarf-aux.c.

Here is the call graph for this function:

◆ die_get_call_fileno()

static int die_get_call_fileno ( Dwarf_Die *  in_die)
static

Definition at line 373 of file dwarf-aux.c.

Here is the call graph for this function:

◆ die_get_call_lineno()

int die_get_call_lineno ( Dwarf_Die *  in_die)

die_get_call_lineno - Get callsite line number of inline-function instance : a DIE of an inlined function instance

Get call-site line number of . This means from where the inline function is called.

Definition at line 196 of file dwarf-aux.c.

◆ die_get_data_member_location()

int die_get_data_member_location ( Dwarf_Die *  mb_die,
Dwarf_Word *  offs 
)

die_get_data_member_location - Get the data-member offset : a DIE of a member of a data structure : The offset of the member in the data structure

Get the offset of in the data structure including , and stores result offset to . If any error occurs this returns errno.

Definition at line 346 of file dwarf-aux.c.

◆ die_get_decl_fileno()

static int die_get_decl_fileno ( Dwarf_Die *  pdie)
static

Definition at line 384 of file dwarf-aux.c.

Here is the call graph for this function:

◆ die_get_linkage_name()

const char* die_get_linkage_name ( Dwarf_Die *  dw_die)

die_get_linkage_name - Get the linkage name of the object : A DIE of the object

Get the linkage name attiribute of given . For C++ binary, the linkage name will be the mangled symbol.

Definition at line 142 of file dwarf-aux.c.

◆ die_get_postprologue_addr()

static bool die_get_postprologue_addr ( unsigned long  entrypc_idx,
Dwarf_Lines *  lines,
unsigned long  nr_lines,
Dwarf_Addr  highpc,
Dwarf_Addr *  postprologue_addr 
)
static

Definition at line 1201 of file dwarf-aux.c.

◆ die_get_real_type()

Dwarf_Die* die_get_real_type ( Dwarf_Die *  vr_die,
Dwarf_Die *  die_mem 
)

die_get_real_type - Get a type die, but skip qualifiers and typedef : a DIE of a variable : where to store a type DIE

Get a DIE of the type of given variable (), and store it to die_mem. Return NULL if fails to get a type DIE. If the type is qualifiers (e.g. const) or typedef, this skips it and tries to find real type (structure or basic types, e.g. int).

Definition at line 255 of file dwarf-aux.c.

Here is the call graph for this function:

◆ die_get_type()

Dwarf_Die* die_get_type ( Dwarf_Die *  vr_die,
Dwarf_Die *  die_mem 
)

die_get_type - Get type DIE : a DIE of a variable : where to store a type DIE

Get a DIE of the type of given variable (), and store it to die_mem. Return NULL if fails to get a type DIE.

Definition at line 216 of file dwarf-aux.c.

◆ die_get_typename()

int die_get_typename ( Dwarf_Die *  vr_die,
struct strbuf buf 
)

die_get_typename - Get the name of given variable DIE : a variable DIE : a strbuf for result type name

Get the name of and stores it to . Return 0 if succeeded. and Return -ENOENT if failed to find type name. Note that the result will stores typedef name if possible, and stores "*(function_type)" if the type is a function pointer.

Definition at line 931 of file dwarf-aux.c.

Here is the call graph for this function:

◆ die_get_var_range()

int die_get_var_range ( Dwarf_Die *sp_die  __maybe_unused,
Dwarf_Die *vr_die  __maybe_unused,
struct strbuf *buf  __maybe_unused 
)

Definition at line 1108 of file dwarf-aux.c.

◆ die_get_varname()

int die_get_varname ( Dwarf_Die *  vr_die,
struct strbuf buf 
)

die_get_varname - Get the name and type of given variable DIE : a variable DIE : a strbuf for type and variable name

Get the name and type of and stores it in as "type\tname".

Definition at line 969 of file dwarf-aux.c.

Here is the call graph for this function:

◆ die_has_loclist()

static bool die_has_loclist ( Dwarf_Die *  vr_die)
static

Definition at line 1120 of file dwarf-aux.c.

◆ die_is_func_def()

bool die_is_func_def ( Dwarf_Die *  dw_die)

die_is_func_def - Ensure that this DIE is a subprogram and definition : a DIE

Ensure that this DIE is a subprogram and NOT a declaration. This returns true if is a function definition.

Definition at line 315 of file dwarf-aux.c.

◆ die_is_func_instance()

bool die_is_func_instance ( Dwarf_Die *  dw_die)

die_is_func_instance - Ensure that this DIE is an instance of a subprogram : a DIE

Ensure that this DIE is an instance (which has an entry address). This returns true if is a function instance. If not, you need to call die_walk_instances() to find actual instances.

Definition at line 331 of file dwarf-aux.c.

◆ die_is_optimized_target()

bool die_is_optimized_target ( Dwarf_Die *  cu_die)

Definition at line 1142 of file dwarf-aux.c.

Here is the call graph for this function:

◆ die_is_signed_type()

bool die_is_signed_type ( Dwarf_Die *  tp_die)

die_is_signed_type - Check whether a type DIE is signed or not : a DIE of a type

Get the encoding of and return true if the encoding is signed.

Definition at line 297 of file dwarf-aux.c.

Here is the call graph for this function:

◆ die_match_name()

bool die_match_name ( Dwarf_Die *  dw_die,
const char *  glob 
)

die_match_name - Match diename/linkage name and glob : a DIE : a string of target glob pattern

Glob matching the name of and . Return false if matching fail. This also match linkage name.

Definition at line 174 of file dwarf-aux.c.

Here is the call graph for this function:

◆ die_search_idx()

static bool die_search_idx ( Dwarf_Lines *  lines,
unsigned long  nr_lines,
Dwarf_Addr  addr,
unsigned long *  idx 
)
static

Definition at line 1172 of file dwarf-aux.c.

◆ die_skip_prologue()

void die_skip_prologue ( Dwarf_Die *  sp_die,
Dwarf_Die *  cu_die,
Dwarf_Addr *  entrypc 
)

Definition at line 1270 of file dwarf-aux.c.

Here is the call graph for this function:

◆ die_walk_instances()

int die_walk_instances ( Dwarf_Die *  or_die,
int(*)(Dwarf_Die *, void *)  callback,
void *  data 
)

die_walk_instances - Walk on instances of given DIE : an abstract original DIE : a callback function which is called with instance DIE : user data

Walk on the instances of give . must be an inlined function declartion. This returns the return value of if it returns non-zero value, or -ENOENT if there is no instance.

Definition at line 647 of file dwarf-aux.c.

Here is the call graph for this function:

◆ die_walk_lines()

int die_walk_lines ( Dwarf_Die *  rt_die,
line_walk_callback_t  callback,
void *  data 
)

die_walk_lines - Walk on lines inside given DIE : a root DIE (CU, subprogram or inlined_subroutine) : callback routine : user data

Walk on all lines inside given and call on each line. If the is a function, walk only on the lines inside the function, otherwise must be a CU DIE. Note that this walks not only dwarf line list, but also function entries and inline call-site.

Definition at line 759 of file dwarf-aux.c.

Here is the call graph for this function: