diff options
Diffstat (limited to 'dwflpp.cxx')
-rw-r--r-- | dwflpp.cxx | 107 |
1 files changed, 46 insertions, 61 deletions
@@ -937,10 +937,8 @@ dwflpp::iterate_over_labels (Dwarf_Die *begin_die, static string function_name = dwarf_diename (begin_die); do { - Dwarf_Attribute attr_mem; - Dwarf_Attribute *attr = dwarf_attr (&die, DW_AT_name, &attr_mem); int tag = dwarf_tag(&die); - const char *name = dwarf_formstring (attr); + const char *name = dwarf_diename (&die); if (name == 0) continue; switch (tag) @@ -1555,7 +1553,7 @@ dwflpp::print_members(Dwarf_Die *vardie, ostream &o) if (typetag != DW_TAG_structure_type && typetag != DW_TAG_union_type) { o << " Error: " - << (dwarf_diename (vardie) ?: "<anonymous>") + << dwarf_type_name(vardie) << " isn't a struct/union"; return; } @@ -1566,15 +1564,13 @@ dwflpp::print_members(Dwarf_Die *vardie, ostream &o) switch (dwarf_child (vardie, die)) { case 1: // No children. - o << ((typetag == DW_TAG_union_type) ? " union " : " struct ") - << (dwarf_diename (die) ?: "<anonymous>") + o << dwarf_type_name(vardie) << " is empty"; break; case -1: // Error. default: // Shouldn't happen. - o << ((typetag == DW_TAG_union_type) ? " union " : " struct ") - << (dwarf_diename (die) ?: "<anonymous>") + o << dwarf_type_name(vardie) << ": " << dwarf_errmsg (-1); break; @@ -1591,20 +1587,14 @@ dwflpp::print_members(Dwarf_Die *vardie, ostream &o) o << " " << member; else { - Dwarf_Die temp_die = *die; - Dwarf_Attribute temp_attr ; - - if (!dwarf_attr_integrate (&temp_die, DW_AT_type, &temp_attr)) - { - clog << "\n Error in obtaining type attribute for " - << (dwarf_diename(&temp_die)?:"<anonymous>"); - return; - } - - if (!dwarf_formref_die (&temp_attr, &temp_die)) + Dwarf_Die temp_die; + if (!dwarf_attr_die (die, DW_AT_type, &temp_die)) { - clog << "\n Error in decoding type attribute for " - << (dwarf_diename(&temp_die)?:"<anonymous>"); + string source = dwarf_decl_file(die) ?: "<unknown source>"; + int line = -1; + dwarf_decl_line(die, &line); + clog << "\n Error in obtaining type attribute for anonymous member at " + << source << ":" << line; return; } @@ -1634,8 +1624,7 @@ dwflpp::find_struct_member(const target_symbol::component& c, return false; case -1: /* Error. */ default: /* Shouldn't happen */ - throw semantic_error (string (dwarf_tag(parentdie) == DW_TAG_union_type ? "union" : "struct") - + string (dwarf_diename (parentdie) ?: "<anonymous>") + throw semantic_error (dwarf_type_name(parentdie) + ": " + string (dwarf_errmsg (-1)), c.tok); } @@ -1650,12 +1639,8 @@ dwflpp::find_struct_member(const target_symbol::component& c, { // need to recurse for anonymous structs/unions Dwarf_Die subdie; - - if (!dwarf_attr_integrate (&die, DW_AT_type, &attr) || - !dwarf_formref_die (&attr, &subdie)) - continue; - - if (find_struct_member(c, &subdie, memberdie, locs)) + if (dwarf_attr_die (&die, DW_AT_type, &subdie) && + find_struct_member(c, &subdie, memberdie, locs)) goto success; } else if (name == c.member) @@ -1728,6 +1713,12 @@ dwflpp::translate_components(struct obstack *pool, break; case DW_TAG_pointer_type: + /* A pointer with no type is a void* -- can't dereference it. */ + if (!dwarf_hasattr_integrate (die, DW_AT_type)) + throw semantic_error ("invalid access '" + lex_cast<string>(c) + + "' vs. " + dwarf_type_name(die), + c.tok); + c_translate_pointer (pool, 1, 0 /* PR9768*/, die, tail); if (c.type != target_symbol::comp_literal_array_index && c.type != target_symbol::comp_expression_array_index) @@ -1760,15 +1751,14 @@ dwflpp::translate_components(struct obstack *pool, if (c.type != target_symbol::comp_struct_member) throw semantic_error ("invalid access '" + lex_cast<string>(c) - + "' for struct/union type", + + "' for " + dwarf_type_name(die), c.tok); if (dwarf_hasattr(die, DW_AT_declaration)) { Dwarf_Die *tmpdie = dwflpp::declaration_resolve(dwarf_diename(die)); if (tmpdie == NULL) - throw semantic_error ("unresolved struct " - + string (dwarf_diename (die) ?: "<anonymous>"), + throw semantic_error ("unresolved " + dwarf_type_name(die), c.tok); *die_mem = *tmpdie; } @@ -1778,15 +1768,26 @@ dwflpp::translate_components(struct obstack *pool, vector<Dwarf_Attribute> locs; if (!find_struct_member(c, &parentdie, die, locs)) { + /* Add a file:line hint for anonymous types */ + string source; + if (!dwarf_hasattr_integrate(&parentdie, DW_AT_name)) + { + int line; + const char *file = dwarf_decl_file(&parentdie); + if (file && dwarf_decl_line(&parentdie, &line) == 0) + source = " (" + string(file) + ":" + + lex_cast<string>(line) + ")"; + } + string alternatives; stringstream members; print_members(&parentdie, members); if (members.str().size() != 0) - alternatives = " (alternatives:" + members.str(); + alternatives = " (alternatives:" + members.str() + ")"; throw semantic_error("unable to find member '" + - c.member + "' for struct " - + string(dwarf_diename(&parentdie) ?: "<unknown>") - + alternatives, + c.member + "' for " + + dwarf_type_name(&parentdie) + + source + alternatives, c.tok); } @@ -1798,27 +1799,20 @@ dwflpp::translate_components(struct obstack *pool, break; case DW_TAG_enumeration_type: - throw semantic_error ("invalid access '" - + lex_cast<string>(c) - + "' vs. enum type " - + string(dwarf_diename (die) ?: "<anonymous type>"), - c.tok); - break; case DW_TAG_base_type: throw semantic_error ("invalid access '" + lex_cast<string>(c) - + "' vs. base type " - + string(dwarf_diename (die) ?: "<anonymous type>"), + + "' vs. " + dwarf_type_name(die), c.tok); break; + case -1: throw semantic_error ("cannot find type: " + string(dwarf_errmsg (-1)), c.tok); break; default: - throw semantic_error (string(dwarf_diename (die) ?: "<anonymous type>") - + ": unexpected type tag " + throw semantic_error (dwarf_type_name(die) + ": unexpected type tag " + lex_cast<string>(dwarf_tag (die)), c.tok); break; @@ -1881,8 +1875,6 @@ dwflpp::translate_final_fetch_or_store (struct obstack *pool, Dwarf_Die typedie_mem; Dwarf_Die *typedie; int typetag; - char const *dname; - string diestr; typedie = resolve_unqualified_inner_typedie (&typedie_mem, attr_mem, e); typetag = dwarf_tag (typedie); @@ -1908,19 +1900,15 @@ dwflpp::translate_final_fetch_or_store (struct obstack *pool, switch (typetag) { default: - dname = dwarf_diename(die); - diestr = (dname != NULL) ? dname : "<unknown>"; throw semantic_error ("unsupported type tag " + lex_cast<string>(typetag) - + " for " + diestr, e->tok); + + " for " + dwarf_type_name(die), e->tok); break; case DW_TAG_structure_type: case DW_TAG_union_type: - dname = dwarf_diename(die); - diestr = (dname != NULL) ? dname : "<unknown>"; - throw semantic_error ("struct/union '" + diestr - + "' is being accessed instead of a member of the struct/union", e->tok); + throw semantic_error ("'" + dwarf_type_name(die) + + "' is being accessed instead of a member", e->tok); break; case DW_TAG_enumeration_type: @@ -1928,9 +1916,6 @@ dwflpp::translate_final_fetch_or_store (struct obstack *pool, // Reject types we can't handle in systemtap { - dname = dwarf_diename(die); - diestr = (dname != NULL) ? dname : "<unknown>"; - Dwarf_Attribute encoding_attr; Dwarf_Word encoding = (Dwarf_Word) -1; dwarf_formudata (dwarf_attr_integrate (typedie, DW_AT_encoding, &encoding_attr), @@ -1939,7 +1924,7 @@ dwflpp::translate_final_fetch_or_store (struct obstack *pool, { // clog << "bad type1 " << encoding << " diestr" << endl; throw semantic_error ("unsupported type (mystery encoding " + lex_cast<string>(encoding) + ")" + - " for " + diestr, e->tok); + " for " + dwarf_type_name(die), e->tok); } if (encoding == DW_ATE_float @@ -1948,7 +1933,7 @@ dwflpp::translate_final_fetch_or_store (struct obstack *pool, { // clog << "bad type " << encoding << " diestr" << endl; throw semantic_error ("unsupported type (encoding " + lex_cast<string>(encoding) + ")" + - " for " + diestr, e->tok); + " for " + dwarf_type_name(die), e->tok); } } @@ -2201,7 +2186,7 @@ dwflpp::literal_stmt_for_pointer (Dwarf_Die *type_die, { if (sess.verbose>2) clog << "literal_stmt_for_pointer: finding value for " - << (dwarf_diename(type_die) ?: "<unknown>") + << dwarf_type_name(type_die) << "(" << (dwarf_diename(cu) ?: "<unknown>") << ")\n"; |