]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
DW_AT_*_file is allowed to be zero, meaning "no file".
authorMark Wielaard <mjw@redhat.com>
Wed, 23 Feb 2011 16:26:09 +0000 (17:26 +0100)
committerMark Wielaard <mjw@redhat.com>
Wed, 23 Feb 2011 16:26:09 +0000 (17:26 +0100)
libdw/c++/dwarf
libdw/c++/line_info.cc

index 085f0f9232b0d572049f2d00a1e46b73884b70d7..9553bd6915c3e5c18191c58ffd32a06d53d6a585 100644 (file)
@@ -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 ();
index e613c16bfdbcb15d34ba3dea41f8c5b9b7d3aac6..df7a2172311a4667df396a0d8673ed137e28b310 100644 (file)
@@ -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));