[Lldb-commits] [lldb] f841c4a - [lldb] Fix image lookup crash
Alex Langford via lldb-commits
lldb-commits at lists.llvm.org
Mon Feb 13 10:55:25 PST 2023
Author: Alex Langford
Date: 2023-02-13T10:55:10-08:00
New Revision: f841c4af5f5ec887777c33130ad744ee57ad672f
URL: https://github.com/llvm/llvm-project/commit/f841c4af5f5ec887777c33130ad744ee57ad672f
DIFF: https://github.com/llvm/llvm-project/commit/f841c4af5f5ec887777c33130ad744ee57ad672f.diff
LOG: [lldb] Fix image lookup crash
lldb may crash when performing `image lookup --verbose --address $ADDR`.
The ExecutionContext that gets passed into DWARFExpression::Evaluate may
be valid but unpopulated. However, in one specific case, we were
assuming that it has a valid Target and using it without checking first.
We reach this codepath when we attempt to get information about an
address that doesn't map to a CompileUnit in the module containing the
requested address. lldb then checks to see if it maps to a global
variable, so lldb has to evaluate the location of each global variable
in the module. If a location expression contains DW_OP_deref_size that
uses a FileAddress, we hit this code path. The simplest test case is to
take a module that has a global variable with DW_OP_deref_size in its
location expression, attempt to read an address that doesn't map to a
CompileUnit (e.g. 0x0) and ensure we don't crash.
Differential Revision: https://reviews.llvm.org/D143792
Added:
Modified:
lldb/source/Expression/DWARFExpression.cpp
lldb/test/Shell/SymbolFile/DWARF/x86/DW_OP_deref_size_static_var.s
Removed:
################################################################################
diff --git a/lldb/source/Expression/DWARFExpression.cpp b/lldb/source/Expression/DWARFExpression.cpp
index 47cef1b351807..f2ca6534c2fc1 100644
--- a/lldb/source/Expression/DWARFExpression.cpp
+++ b/lldb/source/Expression/DWARFExpression.cpp
@@ -1140,9 +1140,9 @@ bool DWARFExpression::Evaluate(
uint8_t addr_bytes[8];
Status error;
- if (exe_ctx->GetTargetRef().ReadMemory(
- so_addr, &addr_bytes, size, error,
- /*force_live_memory=*/false) == size) {
+ if (target &&
+ target->ReadMemory(so_addr, &addr_bytes, size, error,
+ /*force_live_memory=*/false) == size) {
ObjectFile *objfile = module_sp->GetObjectFile();
stack.back().GetScalar() = DerefSizeExtractDataHelper(
diff --git a/lldb/test/Shell/SymbolFile/DWARF/x86/DW_OP_deref_size_static_var.s b/lldb/test/Shell/SymbolFile/DWARF/x86/DW_OP_deref_size_static_var.s
index 00a3ff0bde5a6..bb04e03448345 100644
--- a/lldb/test/Shell/SymbolFile/DWARF/x86/DW_OP_deref_size_static_var.s
+++ b/lldb/test/Shell/SymbolFile/DWARF/x86/DW_OP_deref_size_static_var.s
@@ -1,11 +1,17 @@
# RUN: llvm-mc -filetype=obj -o %t -triple x86_64-apple-macosx10.15.0 %s
-# RUN: %lldb %t -o "target variable ug" -b | FileCheck %s
+# RUN: %lldb %t -o "target variable ug" -b \
+# RUN: | FileCheck --check-prefix=TARGET-VARIABLE %s
+# RUN: %lldb %t -o "image lookup --verbose --address 0x0" -b \
+# RUN: | FileCheck --check-prefix=IMAGE-LOOKUP %s
-# CHECK: (lldb) target variable ug
-# CHECK: (U) ug = {
-# CHECK: raw = 0
-# CHECK: = (a = 0, b = 0, c = 0, d = 0, e = 0, f = 0)
-# CHECK: }
+# TARGET-VARIABLE: (lldb) target variable ug
+# TARGET-VARIABLE: (U) ug = {
+# TARGET-VARIABLE: raw = 0
+# TARGET-VARIABLE: = (a = 0, b = 0, c = 0, d = 0, e = 0, f = 0)
+# TARGET-VARIABLE: }
+
+# IMAGE-LOOKUP: Summary:
+# IMAGE-LOOKUP: Module: file =
# We are testing how DWARFExpression::Evaluate(...) in the case of
# DW_OP_deref_size deals with static variable.
More information about the lldb-commits
mailing list