[Lldb-commits] [PATCH] D46362: DWARFExpression: Convert file addresses to load addresses early on

Adrian Prantl via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Wed May 2 11:52:19 PDT 2018


aprantl created this revision.
aprantl added a reviewer: clayborg.
Herald added a subscriber: JDevlieghere.

This is a change that only affects Swift and is NFC for the language plugins on llvm.org. In Swift, we can have global variables with a location such as DW_OP_addr <addr> DW_OP_deref. The DWARF expression evaluator doesn't know how to apply a DW_OP_deref to a file address, but at the very end we convert the file address into a load address.

This patch moves the file->load address conversion to right after the result of the DW_OP_addr is pushed onto the stack so that a subsequent DW_OP_deref (and potentially other operations) can be interpreted.

rdar://problem/39767528 LLDB can't deal with dwarf expressions on global variables


https://reviews.llvm.org/D46362

Files:
  include/lldb/Core/Value.h
  source/Core/Value.cpp
  source/Core/ValueObjectVariable.cpp
  source/Expression/DWARFExpression.cpp


Index: source/Expression/DWARFExpression.cpp
===================================================================
--- source/Expression/DWARFExpression.cpp
+++ source/Expression/DWARFExpression.cpp
@@ -1382,6 +1382,9 @@
     case DW_OP_addr:
       stack.push_back(Scalar(opcodes.GetAddress(&offset)));
       stack.back().SetValueType(Value::eValueTypeFileAddress);
+      stack.back().ConvertToLoadAddress(
+          frame->GetSymbolContext(eSymbolContextFunction),
+          frame->CalculateTarget().get());
       break;
 
     //----------------------------------------------------------------------
Index: source/Core/ValueObjectVariable.cpp
===================================================================
--- source/Core/ValueObjectVariable.cpp
+++ source/Core/ValueObjectVariable.cpp
@@ -234,26 +234,10 @@
         // If this variable is a simple type, we read all data for it into
         // m_data. Make sure this type has a value before we try and read it
 
+        SymbolContext var_sc;
+        variable->CalculateSymbolContext(&var_sc);
         // If we have a file address, convert it to a load address if we can.
-        if (value_type == Value::eValueTypeFileAddress && process_is_alive) {
-          lldb::addr_t file_addr =
-              m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
-          if (file_addr != LLDB_INVALID_ADDRESS) {
-            SymbolContext var_sc;
-            variable->CalculateSymbolContext(&var_sc);
-            if (var_sc.module_sp) {
-              ObjectFile *objfile = var_sc.module_sp->GetObjectFile();
-              if (objfile) {
-                Address so_addr(file_addr, objfile->GetSectionList());
-                lldb::addr_t load_addr = so_addr.GetLoadAddress(target);
-                if (load_addr != LLDB_INVALID_ADDRESS) {
-                  m_value.SetValueType(Value::eValueTypeLoadAddress);
-                  m_value.GetScalar() = load_addr;
-                }
-              }
-            }
-          }
-        }
+        m_value.ConvertToLoadAddress(var_sc, target);
 
         if (!CanProvideValue()) {
           // this value object represents an aggregate type whose children have
Index: source/Core/Value.cpp
===================================================================
--- source/Core/Value.cpp
+++ source/Core/Value.cpp
@@ -669,6 +669,30 @@
   return "???";
 }
 
+void Value::ConvertToLoadAddress(SymbolContext sc, Target *target) {
+  if (GetValueType() != eValueTypeFileAddress)
+    return;
+
+  if (!sc.module_sp)
+    return;
+
+  lldb::addr_t file_addr = GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
+  if (file_addr == LLDB_INVALID_ADDRESS)
+    return;
+
+  ObjectFile *objfile = sc.module_sp->GetObjectFile();
+  if (!objfile)
+    return;
+
+  Address so_addr(file_addr, objfile->GetSectionList());
+  lldb::addr_t load_addr = so_addr.GetLoadAddress(target);
+  if (load_addr == LLDB_INVALID_ADDRESS)
+    return;
+
+  SetValueType(Value::eValueTypeLoadAddress);
+  GetScalar() = load_addr;
+}
+
 ValueList::ValueList(const ValueList &rhs) { m_values = rhs.m_values; }
 
 const ValueList &ValueList::operator=(const ValueList &rhs) {
Index: include/lldb/Core/Value.h
===================================================================
--- include/lldb/Core/Value.h
+++ include/lldb/Core/Value.h
@@ -228,6 +228,9 @@
 
   static const char *GetContextTypeAsCString(ContextType context_type);
 
+  /// Convert this value's file address to a load address, if possible.
+  void ConvertToLoadAddress(SymbolContext sc, Target *target);
+
   bool GetData(DataExtractor &data);
 
   void Clear();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46362.144910.patch
Type: text/x-patch
Size: 3604 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20180502/9d1d9469/attachment.bin>


More information about the lldb-commits mailing list