Lines Matching +full:data +full:- +full:lines
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
67 Dwarf_Lines *lines; in cu_getsrc_die() local
72 if (dwarf_getsrclines(cu_die, &lines, &nlines) != 0 || in cu_getsrc_die()
76 /* Lines are sorted by address, use binary search */ in cu_getsrc_die()
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()
84 u = n - 1; in cu_getsrc_die()
90 line = dwarf_onesrcline(lines, --l); in cu_getsrc_die()
97 line = dwarf_onesrcline(lines, l++); in cu_getsrc_die()
109 * cu_find_lineinfo - Get a line number and file name for given address
141 return (*lineno && *fname) ? *lineno : -ENOENT; in cu_find_lineinfo()
144 static int __die_find_inline_cb(Dwarf_Die *die_mem, void *data);
147 * cu_walk_functions_at - Walk on function DIEs at given address
151 * @data: A user data
154 * should be subprogram or inlined-subroutines.
157 int (*callback)(Dwarf_Die *, void *), void *data) in cu_walk_functions_at() argument
161 int ret = -ENOENT; in cu_walk_functions_at()
168 ret = callback(sc_die, data); in cu_walk_functions_at()
178 * die_get_linkage_name - Get the linkage name of the object
194 * die_compare_name - Compare diename and tname
209 * die_match_name - Match diename/linkage name and glob
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
423 * @mb_die: a DIE of a member of a data structure
424 * @offs: The offset of the member in the data structure
426 * Get the offset of @mb_die in the data structure including @mb_die, and
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()
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
519 * die_find_child - Generic DIE search function in DIE tree
522 * @data: a user data passed to the callback function
535 void *data, Dwarf_Die *die_mem) in die_find_child() argument
545 ret = callback(die_mem, data); in die_find_child()
550 die_find_child(die_mem, callback, data, &child_die)) { in die_find_child()
565 static int __die_search_func_tail_cb(Dwarf_Die *fn_die, void *data) in __die_search_func_tail_cb() argument
567 struct __addr_die_search_param *ad = data; in __die_search_func_tail_cb()
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 */
603 static int __die_search_func_cb(Dwarf_Die *fn_die, void *data) in __die_search_func_cb() argument
605 struct __addr_die_search_param *ad = data; in __die_search_func_cb()
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
642 static int __die_find_inline_cb(Dwarf_Die *die_mem, void *data) in __die_find_inline_cb() argument
644 Dwarf_Addr *addr = data; in __die_find_inline_cb()
654 * die_find_top_inlinefunc - Search the top inlined function at given address
671 * die_find_inlinefunc - Search an inlined function at given address
700 static int __die_find_func_rettype_cb(Dwarf_Die *die_mem, void *data) in __die_find_func_rettype_cb() argument
708 if (func_name && !strcmp(func_name, data)) in __die_find_func_rettype_cb()
715 * die_find_func_rettype - Search a return type of function
720 * Search a non-inlined function which matches to @name and stores the
746 void *data; member
750 static int __die_walk_instances_cb(Dwarf_Die *inst, void *data) in __die_walk_instances_cb() argument
752 struct __instance_walk_param *iwp = data; in __die_walk_instances_cb()
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
789 * @data: user data
793 * non-zero value, or -ENOENT if there is no instance.
796 void *data) in die_walk_instances() argument
801 .addr = or_die->addr, in die_walk_instances()
803 .data = data, in die_walk_instances()
804 .retval = -ENOENT, in die_walk_instances()
808 return -ENOENT; in die_walk_instances()
819 void *data; member
823 static int __die_walk_funclines_cb(Dwarf_Die *in_die, void *data) in __die_walk_funclines_cb() argument
825 struct __line_walk_param *lw = data; in __die_walk_funclines_cb()
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()
855 /* Walk on lines of blocks included in given DIE */
857 line_walk_callback_t callback, void *data) in __die_walk_funclines() argument
862 .data = data, in __die_walk_funclines()
874 lw.retval = callback(fname, lineno, addr, data); in __die_walk_funclines()
883 static int __die_walk_culines_cb(Dwarf_Die *sp_die, void *data) in __die_walk_culines_cb() argument
885 struct __line_walk_param *lw = data; in __die_walk_culines_cb()
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
902 * @data: user data
904 * Walk on all lines inside given @rt_die and call @callback on each line.
905 * If the @rt_die is a function, walk only on the lines inside the function,
908 * and inline call-site.
910 int die_walk_lines(Dwarf_Die *rt_die, line_walk_callback_t callback, void *data) in die_walk_lines() argument
912 Dwarf_Lines *lines; in die_walk_lines() local
930 return -EINVAL; in die_walk_lines()
936 return -EINVAL; in die_walk_lines()
939 /* Get lines list in the CU */ in die_walk_lines()
940 if (dwarf_getsrclines(cu_die, &lines, &nlines) != 0) { in die_walk_lines()
941 pr_debug2("Failed to get source lines on this CU.\n"); in die_walk_lines()
942 return -ENOENT; in die_walk_lines()
944 pr_debug2("Get %zd lines from this CU\n", nlines); in die_walk_lines()
946 /* Walk on the lines on lines list */ in die_walk_lines()
948 line = dwarf_onesrcline(lines, i); in die_walk_lines()
956 /* Skip end-of-sequence */ in die_walk_lines()
959 /* Skip Non statement line-info */ in die_walk_lines()
962 /* Filter lines based on address */ in die_walk_lines()
973 /* Call-site check */ in die_walk_lines()
989 ret = callback(fname, lineno, addr, data); in die_walk_lines()
995 * Dwarf lines doesn't include function declarations and inlined in die_walk_lines()
1001 * inner inlined functions don't have the lines of the in die_walk_lines()
1004 ret = __die_walk_funclines(rt_die, false, callback, data); in die_walk_lines()
1008 .data = data, in die_walk_lines()
1023 static int __die_find_variable_cb(Dwarf_Die *die_mem, void *data) in __die_find_variable_cb() argument
1025 struct __find_variable_param *fvp = data; in __die_find_variable_cb()
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
1065 static int __die_find_member_cb(Dwarf_Die *die_mem, void *data) in __die_find_member_cb() argument
1067 const char *name = data; in __die_find_member_cb()
1083 * die_find_member - Find a given name member in a data structure
1084 * @st_die: a data structure type DIE
1098 * die_get_typename_from_type - Get the name of given type DIE
1103 * and Return -ENOENT if failed to find type name.
1130 return -ENOENT; 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
1151 * and Return -ENOENT if failed to find type name.
1160 return -ENOENT; in die_get_typename()
1166 * die_get_varname - Get the name and type of given variable DIE
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]>".
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()
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
1321 * "@<function_name+[NN-NN,NN-NN]>".
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()
1363 ret = strbuf_addf(buf, ",%" PRIu64 "-%" PRIu64, in die_get_var_range()
1380 /* Target memory address (for global data) */
1384 /* Access offset, set for global data */
1393 static bool match_var_offset(Dwarf_Die *die_mem, struct find_var_data *data, in match_var_offset() argument
1401 data->offset = 0; in match_var_offset()
1424 data->offset = addr_offset - addr_type; in match_var_offset()
1431 struct find_var_data *data = arg; in __die_find_var_reg_cb() local
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
1509 struct find_var_data data = { in die_find_variable_by_reg() local
1517 result = die_find_child(sc_die, __die_find_var_reg_cb, &data, die_mem); in die_find_variable_by_reg()
1519 *poffset = data.offset; in die_find_variable_by_reg()
1526 struct find_var_data *data = arg; in __die_find_var_addr_cb() local
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
1555 * @addr: the data address to find
1559 * Find the variable DIE located at the given address (in PC-relative mode).
1565 struct find_var_data data = { in die_find_variable_by_addr() local
1570 result = die_find_child(sc_die, __die_find_var_addr_cb, &data, die_mem); in die_find_variable_by_addr()
1572 *offset = data.offset; in die_find_variable_by_addr()
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
1784 * @nr_lines: Number of @lines
1788 * Search for @addr by looping over every lines of CU. If address
1793 static bool die_search_idx(Dwarf_Lines *lines, unsigned long nr_lines, in die_search_idx() argument
1800 if (dwarf_lineaddr(dwarf_onesrcline(lines, i), &tmp)) in die_search_idx()
1812 * die_get_postprologue_addr - Search next address after function prologue
1814 * @lines: Line records of single CU
1815 * @nr_lines: Number of @lines
1819 * Look for prologue-end marker. If there is no explicit marker, return
1823 Dwarf_Lines *lines, in die_get_postprologue_addr() argument
1835 line = dwarf_onesrcline(lines, entrypc_idx); in die_get_postprologue_addr()
1840 line = dwarf_onesrcline(lines, i); in die_get_postprologue_addr()
1851 /* clang supports prologue-end marker */ 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
1896 Dwarf_Lines *lines = NULL; in die_skip_prologue() local
1903 if (dwarf_getsrclines(cu_die, &lines, &nr_lines)) in die_skip_prologue()
1906 if (!die_search_idx(lines, nr_lines, *entrypc, &entrypc_idx)) in die_skip_prologue()
1909 if (!die_get_postprologue_addr(entrypc_idx, lines, nr_lines, in die_skip_prologue()
1928 struct find_scope_data *data = arg; in __die_find_scope_cb() local
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
1958 struct find_scope_data data = { in die_get_scopes() local
1963 die_find_child(cu_die, __die_find_scope_cb, &data, &die_mem); in die_get_scopes()
1965 *scopes = data.scopes; in die_get_scopes()
1966 return data.nr; in die_get_scopes()
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