[lldb] Fix image lookup crash
authorAlex Langford <alangford@apple.com>
Fri, 10 Feb 2023 23:51:49 +0000 (15:51 -0800)
committerAlex Langford <alangford@apple.com>
Mon, 13 Feb 2023 18:55:10 +0000 (10:55 -0800)
commitf841c4af5f5ec887777c33130ad744ee57ad672f
tree1ff7880258427189a58d278c546ecdfcc1dc8545
parent51a07fc24cb909011e0b16793800aab4b93031ed
[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
lldb/source/Expression/DWARFExpression.cpp
lldb/test/Shell/SymbolFile/DWARF/x86/DW_OP_deref_size_static_var.s