Lines Matching +full:line +full:- +full:name

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * dwarf-aux.c : libdw auxiliary interfaces
11 #include "dwarf-aux.h"
12 #include "dwarf-regs.h"
17 * cu_find_realpath - Find the realpath of the target file
48 * cu_get_comp_dir - Get the path of compilation directory
63 /* Unlike dwarf_getsrc_die(), cu_getsrc_die() only returns statement line */
68 Dwarf_Line *line; in cu_getsrc_die() local
77 l = 0; u = nlines - 1; in cu_getsrc_die()
79 n = u - (u - l) / 2; in cu_getsrc_die()
80 line = dwarf_onesrcline(lines, n); in cu_getsrc_die()
81 if (!line || dwarf_lineaddr(line, &laddr) != 0) in cu_getsrc_die()
84 u = n - 1; in cu_getsrc_die()
88 /* Going backward to find the lowest line */ in cu_getsrc_die()
90 line = dwarf_onesrcline(lines, --l); in cu_getsrc_die()
91 if (!line || dwarf_lineaddr(line, &laddr) != 0) in cu_getsrc_die()
95 /* Going forward to find the statement line */ in cu_getsrc_die()
97 line = dwarf_onesrcline(lines, l++); in cu_getsrc_die()
98 if (!line || dwarf_lineaddr(line, &laddr) != 0 || in cu_getsrc_die()
99 dwarf_linebeginstatement(line, &flag) != 0) in cu_getsrc_die()
105 return line; in cu_getsrc_die()
109 * cu_find_lineinfo - Get a line number and file name for given address
112 * @fname: a pointer which returns the file name string
113 * @lineno: a pointer which returns the line number
115 * Find a line number and file name for @addr in @cu_die.
120 Dwarf_Line *line; in cu_find_lineinfo() local
132 line = cu_getsrc_die(cu_die, addr); in cu_find_lineinfo()
133 if (line && dwarf_lineno(line, lineno) == 0) { in cu_find_lineinfo()
134 *fname = dwarf_linesrc(line, NULL, NULL); in cu_find_lineinfo()
136 /* line number is useless without filename */ in cu_find_lineinfo()
141 return (*lineno && *fname) ? *lineno : -ENOENT; in cu_find_lineinfo()
147 * cu_walk_functions_at - Walk on function DIEs at given address
154 * should be subprogram or inlined-subroutines.
161 int ret = -ENOENT; in cu_walk_functions_at()
178 * die_get_linkage_name - Get the linkage name of the object
181 * Get the linkage name attribute of given @dw_die.
182 * For C++ binary, the linkage name will be the mangled symbol.
194 * die_compare_name - Compare diename and tname
196 * @tname: a string of target name
198 * Compare the name of @dw_die and @tname. Return false if @dw_die has no name.
202 const char *name; in die_compare_name() local
204 name = dwarf_diename(dw_die); in die_compare_name()
205 return name ? (strcmp(tname, name) == 0) : false; in die_compare_name()
209 * die_match_name - Match diename/linkage name and glob
213 * Glob matching the name of @dw_die and @glob. Return false if matching fail.
214 * This also match linkage name.
218 const char *name; in die_match_name() local
220 name = dwarf_diename(dw_die); in die_match_name()
221 if (name && strglobmatch(name, glob)) in die_match_name()
223 /* fall back to check linkage name */ in die_match_name()
224 name = die_get_linkage_name(dw_die); in die_match_name()
225 if (name && strglobmatch(name, glob)) in die_match_name()
232 * die_get_call_lineno - Get callsite line number of inline-function instance
235 * Get call-site line number of @in_die. This means from where the inline
244 return -ENOENT; in die_get_call_lineno()
251 * die_get_type - Get type DIE
288 * die_get_real_type - Get a type die, but skip qualifiers and typedef
314 return -ENOENT; in die_get_attr_udata()
320 * die_is_signed_type - Check whether a type DIE is signed or not
338 * die_is_func_def - Ensure that this DIE is a subprogram and definition
369 * die_entrypc - Returns entry PC (the lowest address) of a DIE
383 return -EINVAL; in die_entrypc()
393 return -ENOENT; in die_entrypc()
395 return dwarf_ranges(dw_die, 0, &base, addr, &end) < 0 ? -ENOENT : 0; in die_entrypc()
399 * die_is_func_instance - Ensure that this DIE is an instance of a subprogram
422 * die_get_data_member_location - Get the data-member offset
437 return -ENOENT; in die_get_data_member_location()
443 return -ENOENT; in die_get_data_member_location()
448 return -ENOTSUP; in die_get_data_member_location()
463 return -ENOENT; in die_get_call_fileno()
474 return -ENOENT; in die_get_decl_fileno()
477 /* Return the file name by index */
493 * die_get_call_file - Get callsite file name of inlined function instance
496 * Get call-site file name of @in_die. This means from which file the inline
505 * die_get_decl_file - Find the declared file name of this DIE
508 * Get declared file name of @dw_die.
519 * die_find_child - Generic DIE search function in DIE tree
572 addr == ad->addr) { in __die_search_func_tail_cb()
573 memcpy(ad->die_mem, fn_die, sizeof(Dwarf_Die)); in __die_search_func_tail_cb()
580 * die_find_tailfunc - Search for a non-inlined function with tail call at
586 * Search for a non-inlined function DIE with tail call at @addr. Stores the
602 /* die_find callback for non-inlined function search */
612 dwarf_haspc(fn_die, ad->addr)) { in __die_search_func_cb()
613 memcpy(ad->die_mem, fn_die, sizeof(Dwarf_Die)); in __die_search_func_cb()
620 * die_find_realfunc - Search a non-inlined function at given address
625 * Search a non-inlined function DIE which includes @addr. Stores the
654 * die_find_top_inlinefunc - Search the top inlined function at given address
671 * die_find_inlinefunc - Search an inlined function at given address
715 * die_find_func_rettype - Search a return type of function
717 * @name: target function name
720 * Search a non-inlined function which matches to @name and stores the
727 Dwarf_Die *die_find_func_rettype(Dwarf_Die *cu_die, const char *name, in die_find_func_rettype() argument
733 (void *)name, &tmp_die); in die_find_func_rettype()
767 if (origin == NULL || origin->addr != iwp->addr) in __die_walk_instances_cb()
780 iwp->retval = iwp->callback(inst, iwp->data); in __die_walk_instances_cb()
782 return (iwp->retval) ? DIE_FIND_CB_END : DIE_FIND_CB_CONTINUE; in __die_walk_instances_cb()
786 * die_walk_instances - Walk on instances of given DIE
793 * non-zero value, or -ENOENT if there is no instance.
801 .addr = or_die->addr, in die_walk_instances()
804 .retval = -ENOENT, in die_walk_instances()
808 return -ENOENT; in die_walk_instances()
815 /* Line walker internal parameters */
834 lw->retval = lw->callback(fname, lineno, addr, lw->data); in __die_walk_funclines_cb()
835 if (lw->retval != 0) in __die_walk_funclines_cb()
838 if (!lw->recursive) in __die_walk_funclines_cb()
845 lw->retval = lw->callback(fname, lineno, addr, lw->data); in __die_walk_funclines_cb()
846 if (lw->retval != 0) in __die_walk_funclines_cb()
851 /* Continue to search nested inlined function call-sites */ in __die_walk_funclines_cb()
870 /* Handle function declaration line */ in __die_walk_funclines()
891 lw->retval = __die_walk_funclines(sp_die, true, lw->callback, lw->data); in __die_walk_culines_cb()
892 if (lw->retval != 0) in __die_walk_culines_cb()
899 * die_walk_lines - Walk on lines inside given DIE
904 * Walk on all lines inside given @rt_die and call @callback on each line.
907 * Note that this walks not only dwarf line list, but also function entries
908 * and inline call-site.
913 Dwarf_Line *line; in die_walk_lines() local
928 pr_debug2("Failed to get the declared file name of %s\n", in die_walk_lines()
930 return -EINVAL; in die_walk_lines()
936 return -EINVAL; in die_walk_lines()
942 return -ENOENT; in die_walk_lines()
948 line = dwarf_onesrcline(lines, i); in die_walk_lines()
949 if (line == NULL || in die_walk_lines()
950 dwarf_lineno(line, &lineno) != 0 || in die_walk_lines()
951 dwarf_lineaddr(line, &addr) != 0) { in die_walk_lines()
952 pr_debug2("Failed to get line info. " in die_walk_lines()
956 /* Skip end-of-sequence */ in die_walk_lines()
957 if (dwarf_lineendsequence(line, &flag) != 0 || flag) in die_walk_lines()
959 /* Skip Non statement line-info */ in die_walk_lines()
960 if (dwarf_linebeginstatement(line, &flag) != 0 || !flag) in die_walk_lines()
966 * The line is included in given function, and in die_walk_lines()
973 /* Call-site check */ in die_walk_lines()
986 /* Get source line */ in die_walk_lines()
987 fname = dwarf_linesrc(line, NULL, NULL); in die_walk_lines()
1019 const char *name; member
1032 die_compare_name(die_mem, fvp->name) && in __die_find_variable_cb()
1041 if (dwarf_haspc(die_mem, fvp->addr)) in __die_find_variable_cb()
1048 * die_find_variable_at - Find a given name variable at given address
1050 * @name: variable name
1054 * Find a variable DIE called @name at @addr in @sp_die.
1056 Dwarf_Die *die_find_variable_at(Dwarf_Die *sp_die, const char *name, in die_find_variable_at() argument
1059 struct __find_variable_param fvp = { .name = name, .addr = addr}; in die_find_variable_at()
1067 const char *name = data; in __die_find_member_cb() local
1070 if (die_compare_name(die_mem, name)) in __die_find_member_cb()
1075 die_find_member(&type_die, name, &tmp_die)) in __die_find_member_cb()
1083 * die_find_member - Find a given name member in a data structure
1085 * @name: member name
1088 * Find a member DIE called @name in @st_die.
1090 Dwarf_Die *die_find_member(Dwarf_Die *st_die, const char *name, in die_find_member() argument
1093 return die_find_child(st_die, __die_find_member_cb, (void *)name, in die_find_member()
1098 * die_get_typename_from_type - Get the name of given type DIE
1100 * @buf: a strbuf for result type name
1102 * Get the name of @type_die and stores it to @buf. Return 0 if succeeded.
1103 * and Return -ENOENT if failed to find type name.
1104 * Note that the result will stores typedef name if possible, and stores
1121 const char *name = dwarf_diename(type_die); in die_get_typename_from_type() local
1129 else if (name == NULL) in die_get_typename_from_type()
1130 return -ENOENT; in die_get_typename_from_type()
1131 /* Write a base name */ in die_get_typename_from_type()
1132 return strbuf_addf(buf, "%s%s", tmp, name ?: ""); in die_get_typename_from_type()
1137 if (tag == DW_TAG_pointer_type && ret == -ENOENT) in die_get_typename_from_type()
1146 * die_get_typename - Get the name of given variable DIE
1148 * @buf: a strbuf for result type name
1150 * Get the name of @vr_die and stores it to @buf. Return 0 if succeeded.
1151 * and Return -ENOENT if failed to find type name.
1152 * Note that the result will stores typedef name if possible, and stores
1160 return -ENOENT; in die_get_typename()
1166 * die_get_varname - Get the name and type of given variable DIE
1168 * @buf: a strbuf for type and variable name
1170 * Get the name and type of @vr_die and stores it in @buf as "type\tname".
1188 switch (op->atom) { in reg_from_dwarf_op()
1190 return op->atom - DW_OP_reg0; in reg_from_dwarf_op()
1192 return op->atom - DW_OP_breg0; in reg_from_dwarf_op()
1195 return op->number; in reg_from_dwarf_op()
1201 return -1; in reg_from_dwarf_op()
1206 switch (op->atom) { in offset_from_dwarf_op()
1212 return op->number; in offset_from_dwarf_op()
1214 return op->number2; in offset_from_dwarf_op()
1218 return -1; in offset_from_dwarf_op()
1225 nops--; in check_allowed_ops()
1234 switch (ops->atom) { in check_allowed_ops()
1244 nops--; in check_allowed_ops()
1252 * die_get_var_innermost_scope - Get innermost scope range of given variable DIE
1258 * "@<function_name+[NN-NN,NN-NN]>".
1271 const char *name; in die_get_var_innermost_scope() local
1277 name = dwarf_diename(sp_die); in die_get_var_innermost_scope()
1278 if (!name) in die_get_var_innermost_scope()
1279 return -ENOENT; in die_get_var_innermost_scope()
1285 ret = -EINVAL; in die_get_var_innermost_scope()
1291 start -= entry; in die_get_var_innermost_scope()
1292 end -= entry; in die_get_var_innermost_scope()
1295 ret = strbuf_addf(buf, "@<%s+[%" PRIu64 "-%" PRIu64, in die_get_var_innermost_scope()
1296 name, start, end); in die_get_var_innermost_scope()
1299 ret = strbuf_addf(buf, ",%" PRIu64 "-%" PRIu64, in die_get_var_innermost_scope()
1315 * die_get_var_range - Get byte offset range of given variable DIE
1318 * @buf: a strbuf for type and variable name and byte offset range
1321 * "@<function_name+[NN-NN,NN-NN]>".
1334 const char *name; in die_get_var_range() local
1340 name = dwarf_diename(sp_die); in die_get_var_range()
1341 if (!name) in die_get_var_range()
1342 return -ENOENT; in die_get_var_range()
1345 return -EINVAL; in die_get_var_range()
1356 start -= entry; in die_get_var_range()
1357 end -= entry; in die_get_var_range()
1359 ret = strbuf_addf(buf, "@<%s+[%" PRIu64 "-%" PRIu64, in die_get_var_range()
1360 name, start, end); in die_get_var_range()
1363 ret = strbuf_addf(buf, ",%" PRIu64 "-%" PRIu64, in die_get_var_range()
1401 data->offset = 0; in match_var_offset()
1424 data->offset = addr_offset - addr_type; in match_var_offset()
1447 if (end <= data->pc) in __die_find_var_reg_cb()
1449 if (start > data->pc) in __die_find_var_reg_cb()
1453 if (data->is_fbreg && ops->atom == DW_OP_fbreg && in __die_find_var_reg_cb()
1455 match_var_offset(die_mem, data, data->offset, ops->number, in __die_find_var_reg_cb()
1460 if (data->reg < DWARF_OP_DIRECT_REGS) { in __die_find_var_reg_cb()
1462 if (ops->atom == (DW_OP_reg0 + data->reg) && in __die_find_var_reg_cb()
1464 match_var_offset(die_mem, data, data->offset, 0, in __die_find_var_reg_cb()
1469 if (ops->atom == (DW_OP_breg0 + data->reg) && in __die_find_var_reg_cb()
1471 match_var_offset(die_mem, data, data->offset, ops->number, in __die_find_var_reg_cb()
1476 if (ops->atom == DW_OP_regx && ops->number == data->reg && in __die_find_var_reg_cb()
1478 match_var_offset(die_mem, data, data->offset, 0, in __die_find_var_reg_cb()
1483 if (ops->atom == DW_OP_bregx && data->reg == ops->number && in __die_find_var_reg_cb()
1485 match_var_offset(die_mem, data, data->offset, ops->number2, in __die_find_var_reg_cb()
1494 * die_find_variable_by_reg - Find a variable saved in a register
1541 if (ops->atom != DW_OP_addr) in __die_find_var_addr_cb()
1545 match_var_offset(die_mem, data, data->addr, ops->number, in __die_find_var_addr_cb()
1553 * die_find_variable_by_addr - Find variable located at given address
1559 * Find the variable DIE located at the given address (in PC-relative mode).
1611 vt->die_off = dwarf_dieoffset(&type_die); in __die_collect_vars_cb()
1612 vt->addr = start; in __die_collect_vars_cb()
1613 vt->reg = reg_from_dwarf_op(ops); in __die_collect_vars_cb()
1614 vt->offset = offset_from_dwarf_op(ops); in __die_collect_vars_cb()
1615 vt->next = *var_types; in __die_collect_vars_cb()
1622 * die_collect_vars - Save all variables and parameters
1627 * The @var_types is a singly-linked list containing type and location info.
1660 if (ops->atom != DW_OP_addr) in __die_collect_global_vars_cb()
1673 vt->die_off = dwarf_dieoffset(&type_die); in __die_collect_global_vars_cb()
1674 vt->addr = ops->number; in __die_collect_global_vars_cb()
1675 vt->reg = -1; in __die_collect_global_vars_cb()
1676 vt->offset = 0; in __die_collect_global_vars_cb()
1677 vt->next = *var_types; in __die_collect_global_vars_cb()
1684 * die_collect_global_vars - Save all global variables
1689 * The @var_types is a singly-linked list containing type and location info.
1704 * die_get_cfa - Get frame base information
1724 return -1; in die_get_cfa()
1733 return -1; in die_get_cfa()
1738 * die_has_loclist - Check if DW_AT_location of @vr_die is a location list
1755 * die_is_optimized_target - Check if target program is compiled with
1782 * die_search_idx - Search index of given line address
1783 * @lines: Line records of single CU
1789 * matches, set index of that line in @idx. Note that single source
1790 * line can have multiple line records. i.e. single source line can
1812 * die_get_postprologue_addr - Search next address after function prologue
1814 * @lines: Line records of single CU
1819 * Look for prologue-end marker. If there is no explicit marker, return
1820 * address of next line record or next source line.
1830 Dwarf_Line *line; in die_get_postprologue_addr() local
1834 /* entrypc_lno is actual source line number */ in die_get_postprologue_addr()
1835 line = dwarf_onesrcline(lines, entrypc_idx); in die_get_postprologue_addr()
1836 if (dwarf_lineno(line, &entrypc_lno)) in die_get_postprologue_addr()
1840 line = dwarf_onesrcline(lines, i); in die_get_postprologue_addr()
1842 if (dwarf_lineaddr(line, &addr) || in die_get_postprologue_addr()
1843 dwarf_lineno(line, &lno) || in die_get_postprologue_addr()
1844 dwarf_lineprologueend(line, &p_end)) in die_get_postprologue_addr()
1851 /* clang supports prologue-end marker */ in die_get_postprologue_addr()
1855 /* Actual next line in source */ in die_get_postprologue_addr()
1860 * Single source line can have multiple line records. in die_get_postprologue_addr()
1863 * contains two line records. One points to declaration and in die_get_postprologue_addr()
1864 * other points to printf() line. Variable 'lno' won't get in die_get_postprologue_addr()
1871 dwarf_lineaddr(line, postprologue_addr); in die_get_postprologue_addr()
1873 dwarf_lineaddr(dwarf_onesrcline(lines, i - 1), in die_get_postprologue_addr()
1880 * die_skip_prologue - Use next address after prologue as probe location
1930 if (dwarf_haspc(die_mem, data->pc)) { in __die_find_scope_cb()
1933 tmp = realloc(data->scopes, (data->nr + 1) * sizeof(*tmp)); in __die_find_scope_cb()
1937 memcpy(tmp + data->nr, die_mem, sizeof(*die_mem)); in __die_find_scope_cb()
1938 data->scopes = tmp; in __die_find_scope_cb()
1939 data->nr++; in __die_find_scope_cb()
1946 * die_get_scopes - Return a list of scopes including the address
2008 * die_get_member_type - Return type info of struct member
2058 offset -= loc; in die_get_member_type()
2066 * die_deref_ptr_type - Return type info for pointer access