From: Mark Wielaard Date: Wed, 23 Feb 2011 16:26:09 +0000 (+0100) Subject: DW_AT_*_file is allowed to be zero, meaning "no file". X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5135cc6617c06a79793fa0ab4a9120a0138cd1fb;p=thirdparty%2Felfutils.git DW_AT_*_file is allowed to be zero, meaning "no file". --- diff --git a/libdw/c++/dwarf b/libdw/c++/dwarf index 085f0f923..9553bd691 100644 --- a/libdw/c++/dwarf +++ b/libdw/c++/dwarf @@ -1126,7 +1126,8 @@ namespace elfutils } /* Return a value unique to us while we're in memory. - This is a stable pointer into the Dwarf_Files data. */ + This is a stable pointer into the Dwarf_Files data + or to a static empty string. */ inline uintptr_t identity () const { return (uintptr_t) name (); diff --git a/libdw/c++/line_info.cc b/libdw/c++/line_info.cc index e613c16bf..df7a21723 100644 --- a/libdw/c++/line_info.cc +++ b/libdw/c++/line_info.cc @@ -61,6 +61,15 @@ stringform (Dwarf_Attribute *attr) return false; } +/* Returns true if the attribute represents a valid zero udata. + This represents "no-file". */ +static bool +zero_formudata (Dwarf_Attribute *attr) +{ + Dwarf_Word zero; + return dwarf_formudata (attr, &zero) == 0 && zero == 0; +} + /* Mock up a dummy attribute with a special kludge that get_files groks. We use these for source_file objects consed directly from an index rather than from a real attribute. */ @@ -91,7 +100,7 @@ get_files (const Dwarf_Attribute *attr, Dwarf_Files **files, Dwarf_Word *idx) Dwarf_Word dwarf::source_file::mtime () const { - if (stringform (thisattr ())) + if (stringform (thisattr ()) || zero_formudata (thisattr ())) return 0; Dwarf_Files *files; @@ -106,7 +115,7 @@ dwarf::source_file::mtime () const Dwarf_Word dwarf::source_file::size () const { - if (stringform (thisattr ())) + if (stringform (thisattr ()) || zero_formudata (thisattr ())) return 0; Dwarf_Files *files; @@ -118,12 +127,16 @@ dwarf::source_file::size () const return result; } +static const char *no_file = ""; + const char * dwarf::source_file::name () const { const char *result; if (stringform (thisattr ())) result = dwarf_formstring (thisattr ()); + else if (zero_formudata (thisattr ())) + result = no_file; else { Dwarf_Files *files; @@ -154,6 +167,9 @@ dwarf::source_file::to_string () const return plain_string (result); } + if (zero_formudata (thisattr ())) + return plain_string (no_file); + Dwarf_Files *files; Dwarf_Word idx; xif (thisattr (), get_files (thisattr (), &files, &idx));