[Lldb-commits] [PATCH] D56068: Use reference only for DW_FORM_ref*

Jan Kratochvil via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Mon Dec 24 16:47:49 PST 2018


jankratochvil created this revision.
jankratochvil added reviewers: clayborg, aprantl.
jankratochvil added a project: LLDB.
Herald added a subscriber: JDevlieghere.

D53530 <https://reviews.llvm.org/D53530> could interpret `DW_AT_count` in `DW_FORM_data1` as a DIE reference as it did not verify its form. Verify that reference really uses only `DW_FORM_ref*`  forms as it could otherwise accidentally follow a constant number as DIE offset. That fixes a regression as described there. <https://reviews.llvm.org/D53530#1340708>
That `DW_FORM_ref_sig8` comment should be updated by D54670 <https://reviews.llvm.org/D54670> after it gets approved.


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D56068

Files:
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.h


Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.h
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.h
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.h
@@ -71,6 +71,7 @@
   bool ExtractValue(const lldb_private::DWARFDataExtractor &data,
                     lldb::offset_t *offset_ptr);
   const uint8_t *BlockData() const;
+  bool FormIsReference() const;
   uint64_t Reference() const;
   uint64_t Reference(dw_offset_t offset) const;
   bool Boolean() const { return m_value.value.uval != 0; }
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp
@@ -603,6 +603,25 @@
   return symbol_file->get_debug_addr_data().GetMaxU64(&offset, index_size);
 }
 
+bool DWARFFormValue::FormIsReference() const {
+  switch (m_form) {
+  case DW_FORM_ref1:
+  case DW_FORM_ref2:
+  case DW_FORM_ref4:
+  case DW_FORM_ref8:
+  case DW_FORM_ref_udata:
+  case DW_FORM_ref_addr:
+    return true;
+    break;
+
+  // It cannot be resolved by the Reference() method.
+  case DW_FORM_ref_sig8:
+  default:
+    break;
+  }
+  return false;
+}
+
 uint64_t DWARFFormValue::Reference() const {
   uint64_t die_offset = m_value.value.uval;
   switch (m_form) {
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
@@ -1001,7 +1001,8 @@
     bool check_specification_or_abstract_origin) const {
   DWARFFormValue form_value;
   if (GetAttributeValue(dwarf2Data, cu, attr, form_value, nullptr,
-                        check_specification_or_abstract_origin))
+                        check_specification_or_abstract_origin)
+      && form_value.FormIsReference())
     return form_value.Reference();
   return fail_value;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56068.179481.patch
Type: text/x-patch
Size: 2106 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20181225/f3afbf64/attachment.bin>


More information about the lldb-commits mailing list