39 const char *src = NULL;
45 ret = dwarf_getsrcfiles(cu_die, &files, &nfiles);
49 for (i = 0; i < nfiles; i++) {
50 src = dwarf_filesrc(files, i, NULL, NULL);
70 if (dwarf_attr(cu_die, DW_AT_comp_dir, &attr) == NULL)
72 return dwarf_formstring(&attr);
85 const char **fname,
int *lineno)
90 line = dwarf_getsrc_die(cu_die, (Dwarf_Addr)addr);
91 if (line && dwarf_lineaddr(line, &laddr) == 0 &&
92 addr == (
unsigned long)laddr && dwarf_lineno(line, lineno) == 0) {
93 *fname = dwarf_linesrc(line, NULL, NULL);
99 return *lineno ?: -ENOENT;
115 int (*callback)(Dwarf_Die *,
void *),
void *
data)
126 ret = callback(sc_die, data);
144 Dwarf_Attribute
attr;
146 if (dwarf_attr_integrate(dw_die, DW_AT_linkage_name, &attr) == NULL)
148 return dwarf_formstring(&attr);
162 name = dwarf_diename(dw_die);
163 return name ? (strcmp(tname, name) == 0) :
false;
178 name = dwarf_diename(dw_die);
198 Dwarf_Attribute
attr;
201 if (!dwarf_attr(in_die, DW_AT_call_line, &attr))
204 dwarf_formudata(&attr, &ret);
218 Dwarf_Attribute
attr;
220 if (dwarf_attr_integrate(vr_die, DW_AT_type, &attr) &&
221 dwarf_formref_die(&attr, die_mem))
236 tag = dwarf_tag(vr_die);
237 }
while (tag == DW_TAG_const_type ||
238 tag == DW_TAG_restrict_type ||
239 tag == DW_TAG_volatile_type ||
240 tag == DW_TAG_shared_type);
259 }
while (vr_die && dwarf_tag(vr_die) == DW_TAG_typedef);
268 Dwarf_Attribute
attr;
270 if (dwarf_attr(tp_die, attr_name, &attr) == NULL ||
271 dwarf_formudata(&attr, result) != 0)
281 Dwarf_Attribute
attr;
283 if (dwarf_attr(tp_die, attr_name, &attr) == NULL ||
284 dwarf_formsdata(&attr, result) != 0)
304 return (ret == DW_ATE_signed_char || ret == DW_ATE_signed ||
305 ret == DW_ATE_signed_fixed);
317 Dwarf_Attribute
attr;
319 return (dwarf_tag(dw_die) == DW_TAG_subprogram &&
320 dwarf_attr(dw_die, DW_AT_declaration, &attr) == NULL);
336 return !dwarf_func_inline(dw_die) && dwarf_entrypc(dw_die, &tmp) == 0;
348 Dwarf_Attribute
attr;
353 if (dwarf_attr(mb_die, DW_AT_data_member_location, &attr) == NULL)
356 if (dwarf_formudata(&attr, offs) != 0) {
358 ret = dwarf_getlocation(&attr, &expr, &nexpr);
359 if (ret < 0 || nexpr == 0)
362 if (expr[0].atom != DW_OP_plus_uconst || nexpr != 1) {
363 pr_debug(
"Unable to get offset:Unexpected OP %x (%zd)\n",
364 expr[0].atom, nexpr);
367 *offs = (Dwarf_Word)expr[0].number;
408 if (idx < 0 || !dwarf_diecu(in_die, &cu_die, NULL, NULL) ||
409 dwarf_getsrcfiles(&cu_die, &files, NULL) != 0)
412 return dwarf_filesrc(files, idx, NULL, NULL);
432 int (*callback)(Dwarf_Die *,
void *),
433 void *
data, Dwarf_Die *die_mem)
438 ret = dwarf_child(rt_die, die_mem);
443 ret = callback(die_mem, data);
449 memcpy(die_mem, &child_die,
sizeof(Dwarf_Die));
453 dwarf_siblingof(die_mem, die_mem) == 0);
468 if (dwarf_tag(fn_die) == DW_TAG_subprogram &&
469 !dwarf_highpc(fn_die, &addr) &&
472 return DWARF_CB_ABORT;
509 if (dwarf_tag(fn_die) == DW_TAG_subprogram &&
510 dwarf_haspc(fn_die, ad->
addr)) {
512 return DWARF_CB_ABORT;
542 Dwarf_Addr *addr =
data;
544 if (dwarf_tag(die_mem) == DW_TAG_inlined_subroutine &&
545 dwarf_haspc(die_mem, *addr))
590 memcpy(die_mem, sp_die,
sizeof(Dwarf_Die));
600 int (*callback)(Dwarf_Die *,
void *);
608 Dwarf_Attribute attr_mem;
609 Dwarf_Die origin_mem;
610 Dwarf_Attribute *
attr;
614 attr = dwarf_attr(inst, DW_AT_abstract_origin, &attr_mem);
618 origin = dwarf_formref_die(attr, &origin_mem);
619 if (origin == NULL || origin->addr != iwp->
addr)
623 if (dwarf_tag(inst) == DW_TAG_inlined_subroutine) {
624 dwarf_decl_line(origin, &tmp);
653 .
addr = or_die->addr,
659 if (dwarf_diecu(or_die, &cu_die, NULL, NULL) == NULL)
682 if (dwarf_tag(in_die) == DW_TAG_inlined_subroutine) {
685 if (fname && lineno > 0 && dwarf_entrypc(in_die, &addr) == 0) {
696 fname = dwarf_decl_file(in_die);
697 if (fname && dwarf_decl_line(in_die, &lineno) == 0) {
724 fname = dwarf_decl_file(sp_die);
725 if (fname && dwarf_decl_line(sp_die, &lineno) == 0 &&
726 dwarf_entrypc(sp_die, &addr) == 0) {
742 return DWARF_CB_ABORT;
764 const char *fname, *decf = NULL;
771 if (dwarf_tag(rt_die) != DW_TAG_compile_unit) {
772 cu_die = dwarf_diecu(rt_die, &die_mem, NULL, NULL);
773 dwarf_decl_line(rt_die, &decl);
774 decf = dwarf_decl_file(rt_die);
778 pr_debug2(
"Failed to get CU from given DIE.\n");
783 if (dwarf_getsrclines(cu_die, &lines, &nlines) != 0) {
784 pr_debug2(
"Failed to get source lines on this CU.\n");
787 pr_debug2(
"Get %zd lines from this CU\n", nlines);
790 for (i = 0; i < nlines; i++) {
791 line = dwarf_onesrcline(lines, i);
793 dwarf_lineno(line, &lineno) != 0 ||
794 dwarf_lineaddr(line, &addr) != 0) {
796 "Possible error in debuginfo.\n");
800 if (rt_die != cu_die) {
806 if (!dwarf_haspc(rt_die, addr))
809 dwarf_decl_line(&die_mem, &inl);
811 decf != dwarf_decl_file(&die_mem))
816 fname = dwarf_linesrc(line, NULL, NULL);
818 ret =
callback(fname, lineno, addr, data);
827 if (rt_die != cu_die)
854 Dwarf_Attribute
attr;
857 tag = dwarf_tag(die_mem);
858 if ((tag == DW_TAG_formal_parameter ||
859 tag == DW_TAG_variable) &&
862 (dwarf_attr(die_mem, DW_AT_external, &attr) ||
863 dwarf_attr(die_mem, DW_AT_location, &attr)))
865 if (dwarf_haspc(die_mem, fvp->
addr))
881 Dwarf_Addr addr, Dwarf_Die *
die_mem)
893 if (dwarf_tag(die_mem) == DW_TAG_member) {
896 else if (!dwarf_diename(die_mem)) {
897 Dwarf_Die type_die, tmp_die;
935 const char *tmp =
"";
940 tag = dwarf_tag(&type);
941 if (tag == DW_TAG_array_type || tag == DW_TAG_pointer_type)
943 else if (tag == DW_TAG_subroutine_type) {
945 return strbuf_add(buf,
"(function_type)", 15);
947 if (!dwarf_diename(&type))
949 if (tag == DW_TAG_union_type)
951 else if (tag == DW_TAG_structure_type)
953 else if (tag == DW_TAG_enumeration_type)
956 return strbuf_addf(buf,
"%s%s", tmp, dwarf_diename(&type));
975 pr_debug(
"Failed to get type, make it unknown.\n");
979 return ret < 0 ? ret :
strbuf_addf(buf,
"\t%s", dwarf_diename(vr_die));
982 #ifdef HAVE_DWARF_GETLOCATIONS_SUPPORT 992 static int die_get_var_innermost_scope(Dwarf_Die *sp_die, Dwarf_Die *vr_die,
999 Dwarf_Addr
start, end;
1005 ret = dwarf_entrypc(sp_die, &entry);
1009 name = dwarf_diename(sp_die);
1013 count = dwarf_getscopes_die(vr_die, &scopes);
1021 while ((offset = dwarf_ranges(&scopes[1], offset, &base,
1022 &start, &end)) > 0) {
1027 ret =
strbuf_addf(buf,
"@<%s+[%" PRIu64
"-%" PRIu64,
1059 Dwarf_Addr
start, end;
1064 Dwarf_Attribute
attr;
1068 ret = dwarf_entrypc(sp_die, &entry);
1072 name = dwarf_diename(sp_die);
1076 if (dwarf_attr(vr_die, DW_AT_location, &attr) == NULL)
1079 while ((offset = dwarf_getlocations(&attr, offset, &base,
1080 &start, &end, &op, &nops)) > 0) {
1083 ret = die_get_var_innermost_scope(sp_die, vr_die, buf);
1091 ret =
strbuf_addf(buf,
"@<%s+[%" PRIu64
"-%" PRIu64,
1109 Dwarf_Die *vr_die __maybe_unused,
1110 struct strbuf *buf __maybe_unused)
1122 Dwarf_Attribute loc;
1123 int tag = dwarf_tag(vr_die);
1125 if (tag != DW_TAG_formal_parameter &&
1126 tag != DW_TAG_variable)
1129 return (dwarf_attr_integrate(vr_die, DW_AT_location, &loc) &&
1130 dwarf_whatform(&loc) == DW_FORM_sec_offset);
1149 if (!dwarf_child(cu_die, &tmp_die) &&
1153 if (!dwarf_siblingof(cu_die, &tmp_die) &&
1173 Dwarf_Addr addr,
unsigned long *idx)
1178 for (i = 0; i < nr_lines; i++) {
1179 if (dwarf_lineaddr(dwarf_onesrcline(lines, i), &tmp))
1203 unsigned long nr_lines,
1205 Dwarf_Addr *postprologue_addr)
1208 int entrypc_lno, lno;
1214 line = dwarf_onesrcline(lines, entrypc_idx);
1215 if (dwarf_lineno(line, &entrypc_lno))
1218 for (i = entrypc_idx; i < nr_lines; i++) {
1219 line = dwarf_onesrcline(lines, i);
1221 if (dwarf_lineaddr(line, &addr) ||
1222 dwarf_lineno(line, &lno) ||
1223 dwarf_lineprologueend(line, &p_end))
1235 if (lno != entrypc_lno)
1246 if (i != entrypc_idx)
1250 dwarf_lineaddr(line, postprologue_addr);
1251 if (*postprologue_addr >= highpc)
1252 dwarf_lineaddr(dwarf_onesrcline(lines, i - 1),
1271 Dwarf_Addr *entrypc)
1273 size_t nr_lines = 0;
1274 unsigned long entrypc_idx = 0;
1275 Dwarf_Lines *
lines = NULL;
1276 Dwarf_Addr postprologue_addr;
1279 if (dwarf_highpc(sp_die, &highpc))
1282 if (dwarf_getsrclines(cu_die, &lines, &nr_lines))
1289 highpc, &postprologue_addr))
1292 *entrypc = postprologue_addr;
static int die_get_attr_sdata(Dwarf_Die *tp_die, unsigned int attr_name, Dwarf_Sword *result)
int die_get_data_member_location(Dwarf_Die *mb_die, Dwarf_Word *offs)
static bool die_get_postprologue_addr(unsigned long entrypc_idx, Dwarf_Lines *lines, unsigned long nr_lines, Dwarf_Addr highpc, Dwarf_Addr *postprologue_addr)
const char * cu_get_comp_dir(Dwarf_Die *cu_die)
static int __die_walk_funclines(Dwarf_Die *sp_die, bool recursive, line_walk_callback_t callback, void *data)
Dwarf_Die * die_find_member(Dwarf_Die *st_die, const char *name, Dwarf_Die *die_mem)
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)
#define pr_debug2(fmt,...)
void die_skip_prologue(Dwarf_Die *sp_die, Dwarf_Die *cu_die, Dwarf_Addr *entrypc)
static int die_get_decl_fileno(Dwarf_Die *pdie)
Dwarf_Die * die_find_tailfunc(Dwarf_Die *cu_die, Dwarf_Addr addr, Dwarf_Die *die_mem)
bool strglobmatch(const char *str, const char *pat)
static int __die_find_variable_cb(Dwarf_Die *die_mem, void *data)
int die_walk_lines(Dwarf_Die *rt_die, line_walk_callback_t callback, void *data)
static int __die_find_inline_cb(Dwarf_Die *die_mem, void *data)
int die_get_var_range(Dwarf_Die *sp_die __maybe_unused, Dwarf_Die *vr_die __maybe_unused, struct strbuf *buf __maybe_unused)
static int __die_walk_funclines_cb(Dwarf_Die *in_die, void *data)
bool die_compare_name(Dwarf_Die *dw_die, const char *tname)
bool die_is_func_instance(Dwarf_Die *dw_die)
Dwarf_Die * die_find_child(Dwarf_Die *rt_die, int(*callback)(Dwarf_Die *, void *), void *data, Dwarf_Die *die_mem)
static int __die_walk_culines_cb(Dwarf_Die *sp_die, void *data)
Dwarf_Die * die_find_realfunc(Dwarf_Die *cu_die, Dwarf_Addr addr, Dwarf_Die *die_mem)
static bool die_has_loclist(Dwarf_Die *vr_die)
bool die_match_name(Dwarf_Die *dw_die, const char *glob)
#define pr_debug(fmt,...)
static int entry(u64 ip, struct unwind_info *ui)
int die_walk_instances(Dwarf_Die *or_die, int(*callback)(Dwarf_Die *, void *), void *data)
int strbuf_add(struct strbuf *sb, const void *data, size_t len)
static Dwarf_Die * __die_get_real_type(Dwarf_Die *vr_die, Dwarf_Die *die_mem)
static int strbuf_addstr(struct strbuf *sb, const char *s)
int cu_walk_functions_at(Dwarf_Die *cu_die, Dwarf_Addr addr, int(*callback)(Dwarf_Die *, void *), void *data)
static bool die_search_idx(Dwarf_Lines *lines, unsigned long nr_lines, Dwarf_Addr addr, unsigned long *idx)
Dwarf_Die * die_find_top_inlinefunc(Dwarf_Die *sp_die, Dwarf_Addr addr, Dwarf_Die *die_mem)
x86 movsq based memcpy() in arch/x86/lib/memcpy_64.S") MEMCPY_FN(memcpy_erms
int(* line_walk_callback_t)(const char *fname, int lineno, Dwarf_Addr addr, void *data)
int cu_find_lineinfo(Dwarf_Die *cu_die, unsigned long addr, const char **fname, int *lineno)
static int die_get_attr_udata(Dwarf_Die *tp_die, unsigned int attr_name, Dwarf_Word *result)
Dwarf_Die * die_get_type(Dwarf_Die *vr_die, Dwarf_Die *die_mem)
static int __die_walk_instances_cb(Dwarf_Die *inst, void *data)
const char * die_get_call_file(Dwarf_Die *in_die)
Dwarf_Die * die_find_inlinefunc(Dwarf_Die *sp_die, Dwarf_Addr addr, Dwarf_Die *die_mem)
bool die_is_signed_type(Dwarf_Die *tp_die)
line_walk_callback_t callback
int strtailcmp(const char *s1, const char *s2)
int(* callback)(Dwarf_Die *, void *)
Dwarf_Die * die_get_real_type(Dwarf_Die *vr_die, Dwarf_Die *die_mem)
int die_get_varname(Dwarf_Die *vr_die, struct strbuf *buf)
int strbuf_addf(struct strbuf *sb, const char *fmt,...)
static int __die_search_func_tail_cb(Dwarf_Die *fn_die, void *data)
bool die_is_func_def(Dwarf_Die *dw_die)
int die_get_typename(Dwarf_Die *vr_die, struct strbuf *buf)
static int __die_search_func_cb(Dwarf_Die *fn_die, void *data)
bool die_is_optimized_target(Dwarf_Die *cu_die)
const char * cu_find_realpath(Dwarf_Die *cu_die, const char *fname)
static int die_get_call_fileno(Dwarf_Die *in_die)
const char * die_get_linkage_name(Dwarf_Die *dw_die)
int die_get_call_lineno(Dwarf_Die *in_die)