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

Phabricator via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Thu May 3 09:55:20 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL331462: DWARFExpression: Convert file addresses to load addresses early on. (authored by adrian, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D46362?vs=145032&id=145034#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D46362

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


Index: lldb/trunk/include/lldb/Core/Value.h
===================================================================
--- lldb/trunk/include/lldb/Core/Value.h
+++ lldb/trunk/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);
+
   bool GetData(DataExtractor &data);
 
   void Clear();
Index: lldb/trunk/source/Expression/DWARFExpression.cpp
===================================================================
--- lldb/trunk/source/Expression/DWARFExpression.cpp
+++ lldb/trunk/source/Expression/DWARFExpression.cpp
@@ -1379,10 +1379,13 @@
     // The DW_OP_addr operation has a single operand that encodes a machine
     // address and whose size is the size of an address on the target machine.
     //----------------------------------------------------------------------
-    case DW_OP_addr:
+    case DW_OP_addr: {
       stack.push_back(Scalar(opcodes.GetAddress(&offset)));
       stack.back().SetValueType(Value::eValueTypeFileAddress);
+      auto sc = frame->GetSymbolContext(eSymbolContextFunction);
+      stack.back().ConvertToLoadAddress(sc);
       break;
+    }
 
     //----------------------------------------------------------------------
     // The DW_OP_addr_sect_offset4 is used for any location expressions in
Index: lldb/trunk/source/Core/Value.cpp
===================================================================
--- lldb/trunk/source/Core/Value.cpp
+++ lldb/trunk/source/Core/Value.cpp
@@ -669,6 +669,28 @@
   return "???";
 }
 
+void Value::ConvertToLoadAddress(SymbolContext sc) {
+  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;
+
+  Address so_addr;
+  if (!sc.module_sp->ResolveFileAddress(file_addr, so_addr))
+    return;
+  lldb::addr_t load_addr = so_addr.GetLoadAddress(sc.target_sp.get());
+  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: lldb/trunk/source/Core/ValueObjectVariable.cpp
===================================================================
--- lldb/trunk/source/Core/ValueObjectVariable.cpp
+++ lldb/trunk/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);
 
         if (!CanProvideValue()) {
           // this value object represents an aggregate type whose children have


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46362.145034.patch
Type: text/x-patch
Size: 3967 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20180503/0e5f1d42/attachment.bin>


More information about the lldb-commits mailing list