aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Prantl <aprantl@apple.com>2018-10-02 17:50:42 +0000
committerAdrian Prantl <aprantl@apple.com>2018-10-02 17:50:42 +0000
commitf796e763b212ffaf8a0763093f40a96e6d8cd582 (patch)
tree4ac766a2929b7dda6e4a92d6d1ab83f84df17cc3
parent9767089d003b52ec9d32b93c8533c815c9906902 (diff)
downloadllvm-f796e763b212ffaf8a0763093f40a96e6d8cd582.zip
llvm-f796e763b212ffaf8a0763093f40a96e6d8cd582.tar.gz
llvm-f796e763b212ffaf8a0763093f40a96e6d8cd582.tar.bz2
DWARFExpression: Resolve file addresses in the linked module
This is a follow-up to https://reviews.llvm.org/D46362. When evaluating a complex expression in DWARFExpression::Evaluate, file addresses must be resolved to load addresses before we can perform operations such as DW_OP_deref on them. For this the address goes through three steps 1. Read the file address as stored in the DWARF 2. Link/relocate the file address (when reading from a .dSYM, this is a no-op) 3. Convert the file address to a load address. D46362 implemented step (3) by resolving the file address using the Module that the original DWARF came from. In the case of a dSYM that is correct, but when reading from .o files, we need to look up relocated/linked addresses, so the right place to look them up is the current frame's module. This patch fixes that by setting the expression's Module to point to the linked debugmap object. A word a bout the unorthodox testcase: The motivating testcase for this fix is in Swift, but I managed to hand-modify LLVM-IR for a trivial C program to exhibit the same problem, so we can fix this in llvm.org. rdar://problem/44689915 Differential Revision: https://reviews.llvm.org/D52678 llvm-svn: 343612
-rw-r--r--lldb/include/lldb/Expression/DWARFExpression.h2
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/target_var/Makefile10
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/target_var/TestTargetVar.py22
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/target_var/globals.c6
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/target_var/globals.ll42
-rw-r--r--lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp5
6 files changed, 87 insertions, 0 deletions
diff --git a/lldb/include/lldb/Expression/DWARFExpression.h b/lldb/include/lldb/Expression/DWARFExpression.h
index 5865e57..ef5929a 100644
--- a/lldb/include/lldb/Expression/DWARFExpression.h
+++ b/lldb/include/lldb/Expression/DWARFExpression.h
@@ -152,6 +152,8 @@ public:
lldb::addr_t GetLocation_DW_OP_addr(uint32_t op_addr_idx, bool &error) const;
bool Update_DW_OP_addr(lldb::addr_t file_addr);
+
+ void SetModule(const lldb::ModuleSP &module) { m_module_wp = module; }
bool ContainsThreadLocalStorage() const;
diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/target_var/Makefile b/lldb/packages/Python/lldbsuite/test/functionalities/target_var/Makefile
new file mode 100644
index 0000000..bb9cc4f
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/target_var/Makefile
@@ -0,0 +1,10 @@
+LEVEL = ../../make
+
+include $(LEVEL)/Makefile.rules
+
+a.out: globals.ll
+ $(CC) $(CFLAGS) -g -c $^ -o globals.o
+ $(LD) $(LDFLAGS) -g globals.o -o $@
+
+clean::
+ rm -rf globals.o a.out *.dSYM
diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/target_var/TestTargetVar.py b/lldb/packages/Python/lldbsuite/test/functionalities/target_var/TestTargetVar.py
new file mode 100644
index 0000000..7a46877
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/target_var/TestTargetVar.py
@@ -0,0 +1,22 @@
+"""
+Test that target var can resolve complex DWARF expressions.
+"""
+
+import lldb
+import sys
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class targetCommandTestCase(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ @skipUnlessDarwin
+ @skipIfDarwinEmbedded # needs x86_64
+ @skipIf(debug_info="gmodules") # not relevant
+ def testTargetVarExpr(self):
+ self.build()
+ lldbutil.run_to_name_breakpoint(self, 'main')
+ self.expect("target variable i", substrs=['i', '42'])
diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/target_var/globals.c b/lldb/packages/Python/lldbsuite/test/functionalities/target_var/globals.c
new file mode 100644
index 0000000..2661928
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/target_var/globals.c
@@ -0,0 +1,6 @@
+int i = 42;
+int *p = &i;
+
+int main() {
+ return *p;
+}
diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/target_var/globals.ll b/lldb/packages/Python/lldbsuite/test/functionalities/target_var/globals.ll
new file mode 100644
index 0000000..d58b551
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/target_var/globals.ll
@@ -0,0 +1,42 @@
+source_filename = "globals.c"
+target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-apple-macosx10.14.0"
+
+@i = global i32 42, align 4
+@p = global i32* @i, align 8, !dbg !0, !dbg !6
+
+; Function Attrs: noinline nounwind optnone ssp uwtable
+define i32 @main() #0 !dbg !15 {
+entry:
+ %retval = alloca i32, align 4
+ store i32 0, i32* %retval, align 4
+ %0 = load i32*, i32** @p, align 8, !dbg !18
+ %1 = load i32, i32* %0, align 4, !dbg !18
+ ret i32 %1, !dbg !18
+}
+
+attributes #0 = { noinline nounwind optnone ssp uwtable }
+
+!llvm.dbg.cu = !{!2}
+!llvm.module.flags = !{!10, !11, !12, !13}
+!llvm.ident = !{!14}
+
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression(DW_OP_deref))
+!1 = distinct !DIGlobalVariable(name: "i", scope: !2, file: !3, line: 1, type: !9, isLocal: false, isDefinition: true)
+!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, emissionKind: FullDebug, globals: !5, nameTableKind: None)
+!3 = !DIFile(filename: "globals.c", directory: "/")
+!4 = !{}
+!5 = !{!0, !6}
+!6 = !DIGlobalVariableExpression(var: !7, expr: !DIExpression())
+!7 = distinct !DIGlobalVariable(name: "p", scope: !2, file: !3, line: 2, type: !8, isLocal: false, isDefinition: true)
+!8 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !9, size: 64)
+!9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!10 = !{i32 2, !"Dwarf Version", i32 4}
+!11 = !{i32 2, !"Debug Info Version", i32 3}
+!12 = !{i32 1, !"wchar_size", i32 4}
+!13 = !{i32 7, !"PIC Level", i32 2}
+!14 = !{!"clang version 8.0.0 (trunk 340838) (llvm/trunk 340843)"}
+!15 = distinct !DISubprogram(name: "main", scope: !3, file: !3, line: 4, type: !16, isLocal: false, isDefinition: true, scopeLine: 4, isOptimized: false, unit: !2, retainedNodes: !4)
+!16 = !DISubroutineType(types: !17)
+!17 = !{!9}
+!18 = !DILocation(line: 5, scope: !15)
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
index 1c51500..ea13399 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -3437,6 +3437,11 @@ VariableSP SymbolFileDWARF::ParseVariableDIE(const SymbolContext &sc,
is_static_lifetime = true;
}
SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile();
+ if (debug_map_symfile)
+ // Set the module of the expression to the linked module
+ // instead of the oject file so the relocated address can be
+ // found there.
+ location.SetModule(debug_map_symfile->GetObjectFile()->GetModule());
if (is_static_lifetime) {
if (is_external)