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"
16 * cu_find_realpath - Find the realpath of the target file
47 * cu_get_comp_dir - Get the path of compilation directory
62 /* Unlike dwarf_getsrc_die(), cu_getsrc_die() only returns statement line */
67 Dwarf_Line *line; in cu_getsrc_die() local
76 l = 0; u = nlines - 1; in cu_getsrc_die()
78 n = u - (u - l) / 2; in cu_getsrc_die()
79 line = dwarf_onesrcline(lines, n); in cu_getsrc_die()
80 if (!line || dwarf_lineaddr(line, &laddr) != 0) in cu_getsrc_die()
83 u = n - 1; in cu_getsrc_die()
87 /* Going backward to find the lowest line */ in cu_getsrc_die()
89 line = dwarf_onesrcline(lines, --l); in cu_getsrc_die()
90 if (!line || dwarf_lineaddr(line, &laddr) != 0) in cu_getsrc_die()
94 /* Going forward to find the statement line */ in cu_getsrc_die()
96 line = dwarf_onesrcline(lines, l++); in cu_getsrc_die()
97 if (!line || dwarf_lineaddr(line, &laddr) != 0 || in cu_getsrc_die()
98 dwarf_linebeginstatement(line, &flag) != 0) in cu_getsrc_die()
104 return line; in cu_getsrc_die()
108 * cu_find_lineinfo - Get a line number and file name for given address
111 * @fname: a pointer which returns the file name string
112 * @lineno: a pointer which returns the line number
114 * Find a line number and file name for @addr in @cu_die.
119 Dwarf_Line *line; in cu_find_lineinfo() local
131 line = cu_getsrc_die(cu_die, addr); in cu_find_lineinfo()
132 if (line && dwarf_lineno(line, lineno) == 0) { in cu_find_lineinfo()
133 *fname = dwarf_linesrc(line, NULL, NULL); in cu_find_lineinfo()
135 /* line number is useless without filename */ in cu_find_lineinfo()
140 return *lineno ?: -ENOENT; in cu_find_lineinfo()
146 * cu_walk_functions_at - Walk on function DIEs at given address
153 * should be subprogram or inlined-subroutines.
160 int ret = -ENOENT; in cu_walk_functions_at()
177 * die_get_linkage_name - Get the linkage name of the object
180 * Get the linkage name attribute of given @dw_die.
181 * For C++ binary, the linkage name will be the mangled symbol.
193 * die_compare_name - Compare diename and tname
195 * @tname: a string of target name
197 * Compare the name of @dw_die and @tname. Return false if @dw_die has no name.
201 const char *name; in die_compare_name() local
203 name = dwarf_diename(dw_die); in die_compare_name()
204 return name ? (strcmp(tname, name) == 0) : false; in die_compare_name()
208 * die_match_name - Match diename/linkage name and glob
212 * Glob matching the name of @dw_die and @glob. Return false if matching fail.
213 * This also match linkage name.
217 const char *name; in die_match_name() local
219 name = dwarf_diename(dw_die); in die_match_name()
220 if (name && strglobmatch(name, glob)) in die_match_name()
222 /* fall back to check linkage name */ in die_match_name()
223 name = die_get_linkage_name(dw_die); in die_match_name()
224 if (name && strglobmatch(name, glob)) in die_match_name()
231 * die_get_call_lineno - Get callsite line number of inline-function instance
234 * Get call-site line number of @in_die. This means from where the inline
243 return -ENOENT; in die_get_call_lineno()
250 * die_get_type - Get type DIE
287 * die_get_real_type - Get a type die, but skip qualifiers and typedef
313 return -ENOENT; in die_get_attr_udata()
326 return -ENOENT; in die_get_attr_sdata()
332 * die_is_signed_type - Check whether a type DIE is signed or not
350 * die_is_func_def - Ensure that this DIE is a subprogram and definition
381 * die_entrypc - Returns entry PC (the lowest address) of a DIE
395 return -EINVAL; in die_entrypc()
405 return -ENOENT; in die_entrypc()
407 return dwarf_ranges(dw_die, 0, &base, addr, &end) < 0 ? -ENOENT : 0; in die_entrypc()
411 * die_is_func_instance - Ensure that this DIE is an instance of a subprogram
434 * die_get_data_member_location - Get the data-member offset
449 return -ENOENT; in die_get_data_member_location()
455 return -ENOENT; in die_get_data_member_location()
460 return -ENOTSUP; in die_get_data_member_location()
475 return -ENOENT; in die_get_call_fileno()
486 return -ENOENT; in die_get_decl_fileno()
490 * die_get_call_file - Get callsite file name of inlined function instance
493 * Get call-site file name of @in_die. This means from which file the inline
512 * die_find_child - Generic DIE search function in DIE tree
565 addr == ad->addr) { in __die_search_func_tail_cb()
566 memcpy(ad->die_mem, fn_die, sizeof(Dwarf_Die)); in __die_search_func_tail_cb()
573 * die_find_tailfunc - Search for a non-inlined function with tail call at
579 * Search for a non-inlined function DIE with tail call at @addr. Stores the
595 /* die_find callback for non-inlined function search */
605 dwarf_haspc(fn_die, ad->addr)) { in __die_search_func_cb()
606 memcpy(ad->die_mem, fn_die, sizeof(Dwarf_Die)); in __die_search_func_cb()
613 * die_find_realfunc - Search a non-inlined function at given address
618 * Search a non-inlined function DIE which includes @addr. Stores the
647 * die_find_top_inlinefunc - Search the top inlined function at given address
664 * die_find_inlinefunc - Search an inlined function at given address
717 if (origin == NULL || origin->addr != iwp->addr) in __die_walk_instances_cb()
730 iwp->retval = iwp->callback(inst, iwp->data); in __die_walk_instances_cb()
732 return (iwp->retval) ? DIE_FIND_CB_END : DIE_FIND_CB_CONTINUE; in __die_walk_instances_cb()
736 * die_walk_instances - Walk on instances of given DIE
743 * non-zero value, or -ENOENT if there is no instance.
751 .addr = or_die->addr, in die_walk_instances()
754 .retval = -ENOENT, in die_walk_instances()
758 return -ENOENT; in die_walk_instances()
765 /* Line walker internal parameters */
784 lw->retval = lw->callback(fname, lineno, addr, lw->data); in __die_walk_funclines_cb()
785 if (lw->retval != 0) in __die_walk_funclines_cb()
788 if (!lw->recursive) in __die_walk_funclines_cb()
795 lw->retval = lw->callback(fname, lineno, addr, lw->data); in __die_walk_funclines_cb()
796 if (lw->retval != 0) in __die_walk_funclines_cb()
801 /* Continue to search nested inlined function call-sites */ in __die_walk_funclines_cb()
820 /* Handle function declaration line */ in __die_walk_funclines()
841 lw->retval = __die_walk_funclines(sp_die, true, lw->callback, lw->data); in __die_walk_culines_cb()
842 if (lw->retval != 0) in __die_walk_culines_cb()
849 * die_walk_lines - Walk on lines inside given DIE
854 * Walk on all lines inside given @rt_die and call @callback on each line.
857 * Note that this walks not only dwarf line list, but also function entries
858 * and inline call-site.
863 Dwarf_Line *line; in die_walk_lines() local
881 return -EINVAL; in die_walk_lines()
887 return -ENOENT; in die_walk_lines()
893 line = dwarf_onesrcline(lines, i); in die_walk_lines()
894 if (line == NULL || in die_walk_lines()
895 dwarf_lineno(line, &lineno) != 0 || in die_walk_lines()
896 dwarf_lineaddr(line, &addr) != 0) { in die_walk_lines()
897 pr_debug2("Failed to get line info. " in die_walk_lines()
901 /* Skip end-of-sequence */ in die_walk_lines()
902 if (dwarf_lineendsequence(line, &flag) != 0 || flag) in die_walk_lines()
904 /* Skip Non statement line-info */ in die_walk_lines()
905 if (dwarf_linebeginstatement(line, &flag) != 0 || !flag) in die_walk_lines()
911 * The line is included in given function, and in die_walk_lines()
918 /* Call-site check */ in die_walk_lines()
931 /* Get source line */ in die_walk_lines()
932 fname = dwarf_linesrc(line, NULL, NULL); in die_walk_lines()
964 const char *name; member
977 die_compare_name(die_mem, fvp->name) && in __die_find_variable_cb()
986 if (dwarf_haspc(die_mem, fvp->addr)) in __die_find_variable_cb()
993 * die_find_variable_at - Find a given name variable at given address
995 * @name: variable name
999 * Find a variable DIE called @name at @addr in @sp_die.
1001 Dwarf_Die *die_find_variable_at(Dwarf_Die *sp_die, const char *name, in die_find_variable_at() argument
1004 struct __find_variable_param fvp = { .name = name, .addr = addr}; in die_find_variable_at()
1012 const char *name = data; in __die_find_member_cb() local
1015 if (die_compare_name(die_mem, name)) in __die_find_member_cb()
1020 die_find_member(&type_die, name, &tmp_die)) in __die_find_member_cb()
1028 * die_find_member - Find a given name member in a data structure
1030 * @name: member name
1033 * Find a member DIE called @name in @st_die.
1035 Dwarf_Die *die_find_member(Dwarf_Die *st_die, const char *name, in die_find_member() argument
1038 return die_find_child(st_die, __die_find_member_cb, (void *)name, in die_find_member()
1043 * die_get_typename - Get the name of given variable DIE
1045 * @buf: a strbuf for result type name
1047 * Get the name of @vr_die and stores it to @buf. Return 0 if succeeded.
1048 * and Return -ENOENT if failed to find type name.
1049 * Note that the result will stores typedef name if possible, and stores
1059 return -ENOENT; in die_get_typename()
1069 return -ENOENT; in die_get_typename()
1076 /* Write a base name */ in die_get_typename()
1084 * die_get_varname - Get the name and type of given variable DIE
1086 * @buf: a strbuf for type and variable name
1088 * Get the name and type of @vr_die and stores it in @buf as "type\tname".
1105 * die_get_var_innermost_scope - Get innermost scope range of given variable DIE
1111 * "@<function_name+[NN-NN,NN-NN]>".
1124 const char *name; in die_get_var_innermost_scope() local
1130 name = dwarf_diename(sp_die); in die_get_var_innermost_scope()
1131 if (!name) in die_get_var_innermost_scope()
1132 return -ENOENT; in die_get_var_innermost_scope()
1138 ret = -EINVAL; in die_get_var_innermost_scope()
1144 start -= entry; in die_get_var_innermost_scope()
1145 end -= entry; in die_get_var_innermost_scope()
1148 ret = strbuf_addf(buf, "@<%s+[%" PRIu64 "-%" PRIu64, in die_get_var_innermost_scope()
1149 name, start, end); in die_get_var_innermost_scope()
1152 ret = strbuf_addf(buf, ",%" PRIu64 "-%" PRIu64, in die_get_var_innermost_scope()
1168 * die_get_var_range - Get byte offset range of given variable DIE
1171 * @buf: a strbuf for type and variable name and byte offset range
1174 * "@<function_name+[NN-NN,NN-NN]>".
1187 const char *name; in die_get_var_range() local
1193 name = dwarf_diename(sp_die); in die_get_var_range()
1194 if (!name) in die_get_var_range()
1195 return -ENOENT; in die_get_var_range()
1198 return -EINVAL; in die_get_var_range()
1209 start -= entry; in die_get_var_range()
1210 end -= entry; in die_get_var_range()
1212 ret = strbuf_addf(buf, "@<%s+[%" PRIu64 "-%" PRIu64, in die_get_var_range()
1213 name, start, end); in die_get_var_range()
1216 ret = strbuf_addf(buf, ",%" PRIu64 "-%" PRIu64, in die_get_var_range()
1233 return -ENOTSUP; in die_get_var_range()
1238 * die_has_loclist - Check if DW_AT_location of @vr_die is a location list
1255 * die_is_optimized_target - Check if target program is compiled with
1282 * die_search_idx - Search index of given line address
1283 * @lines: Line records of single CU
1289 * matches, set index of that line in @idx. Note that single source
1290 * line can have multiple line records. i.e. single source line can
1312 * die_get_postprologue_addr - Search next address after function prologue
1314 * @lines: Line records of single CU
1319 * Look for prologue-end marker. If there is no explicit marker, return
1320 * address of next line record or next source line.
1330 Dwarf_Line *line; in die_get_postprologue_addr() local
1334 /* entrypc_lno is actual source line number */ in die_get_postprologue_addr()
1335 line = dwarf_onesrcline(lines, entrypc_idx); in die_get_postprologue_addr()
1336 if (dwarf_lineno(line, &entrypc_lno)) in die_get_postprologue_addr()
1340 line = dwarf_onesrcline(lines, i); in die_get_postprologue_addr()
1342 if (dwarf_lineaddr(line, &addr) || in die_get_postprologue_addr()
1343 dwarf_lineno(line, &lno) || in die_get_postprologue_addr()
1344 dwarf_lineprologueend(line, &p_end)) in die_get_postprologue_addr()
1351 /* clang supports prologue-end marker */ in die_get_postprologue_addr()
1355 /* Actual next line in source */ in die_get_postprologue_addr()
1360 * Single source line can have multiple line records. in die_get_postprologue_addr()
1363 * contains two line records. One points to declaration and in die_get_postprologue_addr()
1364 * other points to printf() line. Variable 'lno' won't get in die_get_postprologue_addr()
1371 dwarf_lineaddr(line, postprologue_addr); in die_get_postprologue_addr()
1373 dwarf_lineaddr(dwarf_onesrcline(lines, i - 1), in die_get_postprologue_addr()
1380 * die_skip_prologue - Use next address after prologue as probe location