[Lldb-commits] [lldb] 09fb20e - [LLDB] Check comp_unit before accessing it in DIL (#147955)
via lldb-commits
lldb-commits at lists.llvm.org
Thu Jul 10 08:34:27 PDT 2025
Author: Ilia Kuklin
Date: 2025-07-10T20:34:23+05:00
New Revision: 09fb20ec7d81c1b370dd3d259250c20e505ebeed
URL: https://github.com/llvm/llvm-project/commit/09fb20ec7d81c1b370dd3d259250c20e505ebeed
DIFF: https://github.com/llvm/llvm-project/commit/09fb20ec7d81c1b370dd3d259250c20e505ebeed.diff
LOG: [LLDB] Check comp_unit before accessing it in DIL (#147955)
Check `symbol_context.comp_unit` before accessing it to avoid `nullptr`
dereferencing.
Added:
lldb/test/API/commands/frame/var-dil/basics/NoDebugInfo/Makefile
lldb/test/API/commands/frame/var-dil/basics/NoDebugInfo/TestFrameVarDILNoDebugInfo.py
lldb/test/API/commands/frame/var-dil/basics/NoDebugInfo/main.cpp
Modified:
lldb/source/ValueObject/DILEval.cpp
Removed:
################################################################################
diff --git a/lldb/source/ValueObject/DILEval.cpp b/lldb/source/ValueObject/DILEval.cpp
index 8ca9b4215985d..fd3f9f8724608 100644
--- a/lldb/source/ValueObject/DILEval.cpp
+++ b/lldb/source/ValueObject/DILEval.cpp
@@ -50,8 +50,9 @@ lldb::ValueObjectSP LookupGlobalIdentifier(
// Get a global variables list without the locals from the current frame
SymbolContext symbol_context =
stack_frame->GetSymbolContext(lldb::eSymbolContextCompUnit);
- lldb::VariableListSP variable_list =
- symbol_context.comp_unit->GetVariableList(true);
+ lldb::VariableListSP variable_list;
+ if (symbol_context.comp_unit)
+ variable_list = symbol_context.comp_unit->GetVariableList(true);
name_ref.consume_front("::");
lldb::ValueObjectSP value_sp;
diff --git a/lldb/test/API/commands/frame/var-dil/basics/NoDebugInfo/Makefile b/lldb/test/API/commands/frame/var-dil/basics/NoDebugInfo/Makefile
new file mode 100644
index 0000000000000..df9f4a7b518c7
--- /dev/null
+++ b/lldb/test/API/commands/frame/var-dil/basics/NoDebugInfo/Makefile
@@ -0,0 +1,4 @@
+CXX_SOURCES := main.cpp
+CFLAGS_EXTRAS := -g0
+
+include Makefile.rules
diff --git a/lldb/test/API/commands/frame/var-dil/basics/NoDebugInfo/TestFrameVarDILNoDebugInfo.py b/lldb/test/API/commands/frame/var-dil/basics/NoDebugInfo/TestFrameVarDILNoDebugInfo.py
new file mode 100644
index 0000000000000..defea39826267
--- /dev/null
+++ b/lldb/test/API/commands/frame/var-dil/basics/NoDebugInfo/TestFrameVarDILNoDebugInfo.py
@@ -0,0 +1,29 @@
+"""
+Test DIL without debug info.
+"""
+
+import lldb
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test.decorators import *
+from lldbsuite.test import lldbutil
+
+
+class TestFrameVarDILNoDebugInfo(TestBase):
+ NO_DEBUG_INFO_TESTCASE = True
+
+ def test_no_debug_info(self):
+ self.build()
+ lldbutil.run_to_name_breakpoint(self, "main")
+
+ self.runCmd("settings set target.experimental.use-DIL true")
+
+ self.expect(
+ "frame var 'argc'",
+ error=True,
+ substrs=["use of undeclared identifier"],
+ )
+ self.expect(
+ "frame var 'foo'",
+ error=True,
+ substrs=["use of undeclared identifier"],
+ )
diff --git a/lldb/test/API/commands/frame/var-dil/basics/NoDebugInfo/main.cpp b/lldb/test/API/commands/frame/var-dil/basics/NoDebugInfo/main.cpp
new file mode 100644
index 0000000000000..abf9ecf88fa30
--- /dev/null
+++ b/lldb/test/API/commands/frame/var-dil/basics/NoDebugInfo/main.cpp
@@ -0,0 +1,3 @@
+int foo = 1;
+
+int main(int argc, char **argv) { return foo; }
More information about the lldb-commits
mailing list