Skip to content

Commit 09fb20e

Browse files
authored
[LLDB] Check comp_unit before accessing it in DIL (#147955)
Check `symbol_context.comp_unit` before accessing it to avoid `nullptr` dereferencing.
1 parent 8a63133 commit 09fb20e

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

lldb/source/ValueObject/DILEval.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ lldb::ValueObjectSP LookupGlobalIdentifier(
5050
// Get a global variables list without the locals from the current frame
5151
SymbolContext symbol_context =
5252
stack_frame->GetSymbolContext(lldb::eSymbolContextCompUnit);
53-
lldb::VariableListSP variable_list =
54-
symbol_context.comp_unit->GetVariableList(true);
53+
lldb::VariableListSP variable_list;
54+
if (symbol_context.comp_unit)
55+
variable_list = symbol_context.comp_unit->GetVariableList(true);
5556

5657
name_ref.consume_front("::");
5758
lldb::ValueObjectSP value_sp;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
CXX_SOURCES := main.cpp
2+
CFLAGS_EXTRAS := -g0
3+
4+
include Makefile.rules
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"""
2+
Test DIL without debug info.
3+
"""
4+
5+
import lldb
6+
from lldbsuite.test.lldbtest import *
7+
from lldbsuite.test.decorators import *
8+
from lldbsuite.test import lldbutil
9+
10+
11+
class TestFrameVarDILNoDebugInfo(TestBase):
12+
NO_DEBUG_INFO_TESTCASE = True
13+
14+
def test_no_debug_info(self):
15+
self.build()
16+
lldbutil.run_to_name_breakpoint(self, "main")
17+
18+
self.runCmd("settings set target.experimental.use-DIL true")
19+
20+
self.expect(
21+
"frame var 'argc'",
22+
error=True,
23+
substrs=["use of undeclared identifier"],
24+
)
25+
self.expect(
26+
"frame var 'foo'",
27+
error=True,
28+
substrs=["use of undeclared identifier"],
29+
)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
int foo = 1;
2+
3+
int main(int argc, char **argv) { return foo; }

0 commit comments

Comments
 (0)