Fix reporting the lack of global variables in "target var".
authorJim Ingham <jingham@apple.com>
Tue, 22 Sep 2020 00:26:39 +0000 (17:26 -0700)
committerJim Ingham <jingham@apple.com>
Tue, 22 Sep 2020 00:29:40 +0000 (17:29 -0700)
There was a little thinko which meant when stopped in a frame with
debug information but whose CU didn't have any global variables we
report:

no debug info for frame <N>

This patch fixes that error message to say the intended:

no global variables in current compile unit

<rdar://problem/69086361>

lldb/source/Commands/CommandObjectTarget.cpp
lldb/test/API/functionalities/target_var/no_vars/Makefile [new file with mode: 0644]
lldb/test/API/functionalities/target_var/no_vars/TestTargetVarNoVars.py [new file with mode: 0644]
lldb/test/API/functionalities/target_var/no_vars/main.c [new file with mode: 0644]

index 30fdaf9..431c2f3 100644 (file)
@@ -907,6 +907,7 @@ protected:
         CompileUnit *comp_unit = nullptr;
         if (frame) {
           SymbolContext sc = frame->GetSymbolContext(eSymbolContextCompUnit);
+          comp_unit = sc.comp_unit;
           if (sc.comp_unit) {
             const bool can_create = true;
             VariableListSP comp_unit_varlist_sp(
diff --git a/lldb/test/API/functionalities/target_var/no_vars/Makefile b/lldb/test/API/functionalities/target_var/no_vars/Makefile
new file mode 100644 (file)
index 0000000..1049594
--- /dev/null
@@ -0,0 +1,3 @@
+C_SOURCES := main.c
+
+include Makefile.rules
diff --git a/lldb/test/API/functionalities/target_var/no_vars/TestTargetVarNoVars.py b/lldb/test/API/functionalities/target_var/no_vars/TestTargetVarNoVars.py
new file mode 100644 (file)
index 0000000..60ca8b1
--- /dev/null
@@ -0,0 +1,21 @@
+"""
+Test that target var with no variables returns a correct error
+"""
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class TestTargetVarNoVars(TestBase):
+
+    mydir = TestBase.compute_mydir(__file__)
+
+    NO_DEBUG_INFO_TESTCASE = True
+
+    def test_target_var_no_vars(self):
+        self.build()
+        lldbutil.run_to_name_breakpoint(self, 'main')
+        self.expect("target variable", substrs=['no global variables in current compile unit', 'main.c'], error=True)
+
diff --git a/lldb/test/API/functionalities/target_var/no_vars/main.c b/lldb/test/API/functionalities/target_var/no_vars/main.c
new file mode 100644 (file)
index 0000000..d7877b0
--- /dev/null
@@ -0,0 +1,5 @@
+int
+main(int argc, char **argv)
+{
+  return argc;
+}