[Lldb-commits] [lldb] r131721 - /lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp

Stephen Wilson wilsons at start.ca
Thu May 19 21:27:12 PDT 2011


Author: wilsons
Date: Thu May 19 23:27:12 2011
New Revision: 131721

URL: http://llvm.org/viewvc/llvm-project?rev=131721&view=rev
Log:
Do not parse DIE's outside a compilation units range.

In DWARFCompileUnit::ExtractDIEsIfNeeded we are relying on a compilation units
DIEs to be terminated by a null entry.  I think the standard is fairly clear
that all sibling chains are to be terminated by null, but at least gcc 4.5.2
disagrees -- the top level chain drops the final entry.  This results in us
interpreting the next compilation unit header as a DIE.

Regardless of whether gcc is right or wrong, we should not overstep a
compilation units extent.  This patch ensures that we do not attempt to extract
a DIE beyond the length specified for a given DWARFCompileUnit by ensuring our
current offset is strictly less than the start of the next CU.


Modified:
    lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp?rev=131721&r1=131720&r2=131721&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp Thu May 19 23:27:12 2011
@@ -154,8 +154,11 @@
                         m_offset,
                         cu_die_only);
 
-    // Set the offset to that of the first DIE
+    // Set the offset to that of the first DIE and calculate the start of the
+    // next compilation unit header.
     uint32_t offset = GetFirstDIEOffset();
+    uint32_t next_cu_offset = GetNextCompileUnitOffset();
+
     DWARFDebugInfoEntry die;
         // Keep a flat array of the DIE for binary lookup by DIE offset
 //    Log *log = LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO);
@@ -173,7 +176,8 @@
     const DataExtractor& debug_info_data = m_dwarf2Data->get_debug_info_data();
 
     const uint8_t *fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize (GetAddressByteSize());
-    while (die.FastExtract (debug_info_data, this, fixed_form_sizes, &offset))
+    while (offset < next_cu_offset &&
+           die.FastExtract (debug_info_data, this, fixed_form_sizes, &offset))
     {
 //        if (log)
 //            log->Printf("0x%8.8x: %*.*s%s%s",
@@ -220,18 +224,22 @@
                 break;  // We are done with this compile unit!
         }
 
-        if (offset > GetNextCompileUnitOffset())
+    }
+
+    // Give a little bit of info if we encounter corrupt DWARF (our offset
+    // should always terminate at or before the start of the next compilation
+    // unit header).
+    if (offset > next_cu_offset)
+    {
+        char path[PATH_MAX];
+        ObjectFile *objfile = m_dwarf2Data->GetObjectFile();
+        if (objfile)
         {
-            char path[PATH_MAX];
-            ObjectFile *objfile = m_dwarf2Data->GetObjectFile();
-            if (objfile)
-            {
-                objfile->GetFileSpec().GetPath(path, sizeof(path));
-            }
-            fprintf (stderr, "warning: DWARF compile unit extends beyond its bounds cu 0x%8.8x at 0x%8.8x in '%s'\n", GetOffset(), offset, path);
-            break;
+            objfile->GetFileSpec().GetPath(path, sizeof(path));
         }
+        fprintf (stderr, "warning: DWARF compile unit extends beyond its bounds cu 0x%8.8x at 0x%8.8x in '%s'\n", GetOffset(), offset, path);
     }
+
     SetDIERelations();
     return m_die_array.size();
 }





More information about the lldb-commits mailing list