Lines Matching +full:on +full:- +full:die
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
18 * @cu_die: A DIE(dwarf information entry) of CU(compilation Unit)
48 * cu_get_comp_dir - Get the path of compilation directory
49 * @cu_die: a CU DIE
52 * Since this depends on DW_AT_comp_dir, older gcc will not
77 l = 0; u = nlines - 1; in cu_getsrc_die()
79 n = u - (u - l) / 2; in cu_getsrc_die()
84 u = n - 1; in cu_getsrc_die()
90 line = dwarf_onesrcline(lines, --l); in cu_getsrc_die()
109 * cu_find_lineinfo - Get a line number and file name for given address
110 * @cu_die: a CU DIE
141 return (*lineno && *fname) ? *lineno : -ENOENT; in cu_find_lineinfo()
147 * cu_walk_functions_at - Walk on function DIEs at given address
148 * @cu_die: A CU DIE
153 * Walk on function DIEs at given @addr in @cu_die. Passed DIEs
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
179 * @dw_die: A DIE of the object
194 * die_compare_name - Compare diename and tname
195 * @dw_die: a DIE
209 * die_match_name - Match diename/linkage name and glob
210 * @dw_die: a DIE
232 * die_get_call_lineno - Get callsite line number of inline-function instance
233 * @in_die: a DIE of an inlined 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
252 * @vr_die: a DIE of a variable
253 * @die_mem: where to store a type DIE
255 * Get a DIE of the type of given variable (@vr_die), and store
256 * it to die_mem. Return NULL if fails to get a type DIE.
269 /* Get a type die, but skip qualifiers */
288 * die_get_real_type - Get a type die, but skip qualifiers and typedef
289 * @vr_die: a DIE of a variable
290 * @die_mem: where to store a type DIE
292 * Get a DIE of the type of given variable (@vr_die), and store
293 * it to die_mem. Return NULL if fails to get a type DIE.
314 return -ENOENT; in die_get_attr_udata()
320 * die_is_signed_type - Check whether a type DIE is signed or not
321 * @tp_die: a DIE of a type
338 * die_is_func_def - Ensure that this DIE is a subprogram and definition
339 * @dw_die: a DIE
341 * Ensure that this DIE is a subprogram and NOT a declaration. This
358 * So we need to check this subprogram DIE has DW_AT_inline in die_is_func_def()
369 * die_entrypc - Returns entry PC (the lowest address) of a DIE
370 * @dw_die: a DIE
373 * Since dwarf_entrypc() does not return entry PC if the DIE has only address
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
400 * @dw_die: a DIE
402 * Ensure that this DIE is an instance (which has an entry address).
422 * die_get_data_member_location - Get the data-member offset
423 * @mb_die: a DIE of a member of a data structure
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()
455 /* Get the call file index number in CU DIE */
463 return -ENOENT; in die_get_call_fileno()
466 /* Get the declared file index number in CU DIE */
474 return -ENOENT; in die_get_decl_fileno()
493 * die_get_call_file - Get callsite file name of inlined function instance
494 * @in_die: a DIE of an 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
506 * @dw_die: a DIE for something declared.
519 * die_find_child - Generic DIE search function in DIE tree
520 * @rt_die: a root DIE
523 * @die_mem: a buffer for result DIE
525 * Trace DIE tree from @rt_die and call @callback for each child DIE.
526 * If @callback returns DIE_FIND_CB_END, this stores the DIE into
531 * Returns NULL if @callback can't find any appropriate DIE.
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
582 * @cu_die: a CU DIE which including @addr
584 * @die_mem: a buffer for result DIE
586 * Search for a non-inlined function DIE with tail call at @addr. Stores the
587 * DIE to @die_mem and returns it if found. Returns NULL if failed.
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
621 * @cu_die: a CU DIE which including @addr
623 * @die_mem: a buffer for result DIE
625 * Search a non-inlined function DIE which includes @addr. Stores the
626 * DIE to @die_mem and returns it if found. Returns NULL if failed.
654 * die_find_top_inlinefunc - Search the top inlined function at given address
655 * @sp_die: a subprogram DIE which including @addr
657 * @die_mem: a buffer for result DIE
659 * Search an inlined function DIE which includes @addr. Stores the
660 * DIE to @die_mem and returns it if found. Returns NULL if failed.
671 * die_find_inlinefunc - Search an inlined function at given address
672 * @sp_die: a subprogram DIE which including @addr
674 * @die_mem: a buffer for result DIE
676 * Search an inlined function DIE which includes @addr. Stores the
677 * DIE to @die_mem and returns it if found. Returns NULL if failed.
715 * die_find_func_rettype - Search a return type of function
716 * @cu_die: a CU DIE
718 * @die_mem: a buffer for result DIE
720 * Search a non-inlined function which matches to @name and stores the
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
787 * @or_die: an abstract original DIE
788 * @callback: a callback function which is called with instance DIE
791 * Walk on the instances of give @in_die. @in_die must be an inlined function
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()
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 */
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
900 * @rt_die: a root DIE (CU, subprogram or inlined_subroutine)
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,
906 * otherwise @rt_die must be a CU DIE.
908 * and inline call-site.
922 /* Get the CU die */ in die_walk_lines()
930 return -EINVAL; in die_walk_lines()
935 pr_debug2("Failed to get CU from given DIE.\n"); in die_walk_lines()
936 return -EINVAL; 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()
946 /* Walk on the lines on lines list */ 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()
1032 die_compare_name(die_mem, fvp->name) && in __die_find_variable_cb()
1034 * Does the DIE have location information or const value 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
1049 * @sp_die: a function DIE
1052 * @die_mem: a buffer for result DIE
1054 * Find a variable DIE called @name at @addr in @sp_die.
1083 * die_find_member - Find a given name member in a data structure
1084 * @st_die: a data structure type DIE
1086 * @die_mem: a buffer for result DIE
1088 * Find a member DIE called @name in @st_die.
1098 * die_get_typename_from_type - Get the name of given type DIE
1099 * @type_die: a 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
1147 * @vr_die: a 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
1167 * @vr_die: a 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
1253 * @sp_die: a subprogram DIE
1254 * @vr_die: a variable DIE
1258 * "@<function_name+[NN-NN,NN-NN]>".
1279 return -ENOENT; in die_get_var_innermost_scope()
1283 /* (*SCOPES)[1] is the DIE for the scope containing that scope */ 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
1316 * @sp_die: a subprogram DIE
1317 * @vr_die: a 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()
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
1495 * @sc_die: a scope DIE
1500 * @die_mem: a buffer to save the resulting DIE
1502 * Find the variable DIE accessed by the given register. It'll update the @offset
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
1554 * @sc_die: a scope DIE
1556 * @die_mem: a buffer to save the resulting DIE
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
1623 * @sc_die: a scope DIE
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
1685 * @cu_die: a CU DIE
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
1739 * @vr_die: a variable DIE
1755 * die_is_optimized_target - Check if target program is compiled with
1757 * @cu_die: a CU DIE
1782 * die_search_idx - Search index of given line address
1812 * die_get_postprologue_addr - Search next address after function prologue
1819 * Look for prologue-end marker. If there is no explicit marker, return
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
1881 * @sp_die: a subprogram DIE
1882 * @cu_die: a CU DIE
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
1947 * @cu_die: a compile unit DIE
2008 * die_get_member_type - Return type info of struct member
2009 * @type_die: a type DIE
2011 * @die_mem: a buffer to save the resulting DIE
2058 offset -= loc; in die_get_member_type()
2066 * die_deref_ptr_type - Return type info for pointer access
2067 * @ptr_die: a pointer type DIE
2069 * @die_mem: a buffer to save the resulting DIE