From: Josh Stone Date: Wed, 19 Aug 2009 20:30:31 +0000 (-0700) Subject: PR10538: Improve location lookup for unions X-Git-Tag: release-1.0~142 X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=b57ba9b863f0bd99f70d9e4d64c5a11ec75f7317;p=systemtap.git PR10538: Improve location lookup for unions We had a bug that the starting call to find_struct_member used the same memory for the parentdie and the resulting member. If parentdie is a union, then the first member probably won't have a location, and we actually assert that it must be a union. Since we wrote the result in the same memory, we lost the real info about the parent, and so the assertion failed. * dwflpp.cxx (dwflpp::translate_components): Use distinct memory for the parent and resulting member in the call to find_struct_member. (dwflpp::find_struct_member): Remove the needless parentdie copy. --- diff --git a/dwflpp.cxx b/dwflpp.cxx index 738484292..b5663fff8 100644 --- a/dwflpp.cxx +++ b/dwflpp.cxx @@ -1624,9 +1624,9 @@ dwflpp::find_struct_member(const target_symbol::component& c, vector& locs) { Dwarf_Attribute attr; - Dwarf_Die die = *parentdie; + Dwarf_Die die; - switch (dwarf_child (&die, &die)) + switch (dwarf_child (parentdie, &die)) { case 0: /* First child found. */ break; @@ -1634,8 +1634,8 @@ dwflpp::find_struct_member(const target_symbol::component& c, return false; case -1: /* Error. */ default: /* Shouldn't happen */ - throw semantic_error (string (dwarf_tag(&die) == DW_TAG_union_type ? "union" : "struct") - + string (dwarf_diename (&die) ?: "") + throw semantic_error (string (dwarf_tag(parentdie) == DW_TAG_union_type ? "union" : "struct") + + string (dwarf_diename (parentdie) ?: "") + string (dwarf_errmsg (-1)), c.tok); } @@ -1774,17 +1774,18 @@ dwflpp::translate_components(struct obstack *pool, } { + Dwarf_Die parentdie = *die; vector locs; - if (!find_struct_member(c, die, die, locs)) + if (!find_struct_member(c, &parentdie, die, locs)) { string alternatives; stringstream members; - print_members(die, members); + print_members(&parentdie, members); if (members.str().size() != 0) alternatives = " (alternatives:" + members.str(); throw semantic_error("unable to find member '" + c.member + "' for struct " - + string(dwarf_diename(die) ?: "") + + string(dwarf_diename(&parentdie) ?: "") + alternatives, c.tok); }