[lldb/DWARF] Fix a split-dwarf crash while parsing compile units
authorPavel Labath <pavel@labath.sk>
Wed, 29 Apr 2020 14:14:41 +0000 (16:14 +0200)
committerPavel Labath <pavel@labath.sk>
Wed, 29 Apr 2020 14:21:11 +0000 (16:21 +0200)
commit2cf69684fb3089a2cde46fc9eac22dd6b8475b5f
tree50db30ae096f6dc4dfffe9d50a752a9d63f51615
parent19123a3e0873f238f88c25cb0d8e63f263311f9b
[lldb/DWARF] Fix a split-dwarf crash while parsing compile units

The cause of this crash is relatively simple -- we are using a
SymbolFileDWARFDwo to parse a (skeleton) dwarf unit. This cause the
CompileUnit to be created with the wrong ID, which later triggers an
assertion in SymbolFile::SetCompileUnitAtIndex. The fix is also simple
-- ensure we use the right symbol file for parsing.

However, a fairly elaborate setup is needed trigger this bug, because
ParseCompileUnit is normally called very early on (and with the right
symbol file object) during the process of accessing a compile unit.
The only way this can be triggered is if the DWARF unit is
"accidentally" pulled into scope during expression evaluation
This can happen if the "this" object used for the context of an
expression is in a namespace, and that namespace is also present in
other compile units

The included test recreates this setup.
lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
lldb/test/Shell/SymbolFile/DWARF/split-dwarf-expression-eval-bug.cpp [new file with mode: 0644]