Override CalculateFrameVariableError in SymbolFileOnDemand
authorGeorge Hu <huyubohyb@gmail.com>
Wed, 2 Nov 2022 19:19:22 +0000 (12:19 -0700)
committerGeorge Hu <huyubohyb@gmail.com>
Thu, 3 Nov 2022 22:09:07 +0000 (15:09 -0700)
Differential Revision: https://reviews.llvm.org/D137284

lldb/include/lldb/Symbol/SymbolFileOnDemand.h
lldb/source/Symbol/SymbolFileOnDemand.cpp
lldb/test/API/tools/lldb-vscode/variables/TestVSCode_variables.py

index 0570839..a215c7e 100644 (file)
@@ -117,6 +117,9 @@ public:
                                 lldb::SymbolContextItem resolve_scope,
                                 lldb_private::SymbolContext &sc) override;
 
+  lldb_private::Status
+  CalculateFrameVariableError(lldb_private::StackFrame &frame) override;
+
   uint32_t ResolveSymbolContext(
       const lldb_private::SourceLocationSpec &src_location_spec,
       lldb::SymbolContextItem resolve_scope,
index b4c9ed0..737cb10 100644 (file)
@@ -274,6 +274,15 @@ SymbolFileOnDemand::ResolveSymbolContext(const Address &so_addr,
   return m_sym_file_impl->ResolveSymbolContext(so_addr, resolve_scope, sc);
 }
 
+Status SymbolFileOnDemand::CalculateFrameVariableError(StackFrame &frame) {
+  if (!m_debug_info_enabled) {
+    LLDB_LOG(GetLog(), "[{0}] {1} is skipped", GetSymbolFileName(),
+             __FUNCTION__);
+    return Status();
+  }
+  return m_sym_file_impl->CalculateFrameVariableError(frame);
+}
+
 uint32_t SymbolFileOnDemand::ResolveSymbolContext(
     const SourceLocationSpec &src_location_spec,
     SymbolContextItem resolve_scope, SymbolContextList &sc_list) {
index 9b91955..a6a7e15 100644 (file)
@@ -85,6 +85,40 @@ class TestVSCode_variables(lldbvscode_testcase.VSCodeTestCaseBase):
                           'variable "%s" in verify dictionary' % (name))
             self.verify_values(verify_dict[name], variable, varref_dict)
 
+    def darwin_dwarf_missing_obj(self, initCommands):
+        self.build(debug_info="dwarf")
+        program = self.getBuildArtifact("a.out")
+        main_obj = self.getBuildArtifact("main.o")
+        self.assertTrue(os.path.exists(main_obj))
+        # Delete the main.o file that contains the debug info so we force an
+        # error when we run to main and try to get variables
+        os.unlink(main_obj)
+
+        self.create_debug_adaptor()
+        self.assertTrue(os.path.exists(program), 'executable must exist')
+
+        self.launch(program=program,
+                    initCommands=initCommands)
+
+        functions = ['main']
+        breakpoint_ids = self.set_function_breakpoints(functions)
+        self.assertEquals(len(breakpoint_ids), len(functions), "expect one breakpoint")
+        self.continue_to_breakpoints(breakpoint_ids)
+
+        locals = self.vscode.get_local_variables()
+
+        verify_locals = {
+            '<error>': {
+                'equals': {'type': 'const char *'},
+                'contains': { 'value': [
+                    'debug map object file ',
+                    'main.o" containing debug info does not exist, debug info will not be loaded']
+                }
+            },
+        }
+        varref_dict = {}
+        self.verify_variables(verify_locals, locals, varref_dict)
+
     @skipIfWindows
     @skipIfRemote
     def test_scopes_variables_setVariable_evaluate(self):
@@ -529,33 +563,16 @@ class TestVSCode_variables(lldbvscode_testcase.VSCodeTestCaseBase):
             changing compiler options and are designed to give better feedback
             to the user.
         '''
-        self.build(debug_info="dwarf")
-        program = self.getBuildArtifact("a.out")
-        main_obj = self.getBuildArtifact("main.o")
-        self.assertTrue(os.path.exists(main_obj))
-        # Delete the main.o file that contains the debug info so we force an
-        # error when we run to main and try to get variables
-        os.unlink(main_obj)
-
-        self.create_debug_adaptor()
-        self.assertTrue(os.path.exists(program), 'executable must exist')
-        self.launch(program)
-
-        functions = ['main']
-        breakpoint_ids = self.set_function_breakpoints(functions)
-        self.assertEquals(len(breakpoint_ids), len(functions), "expect one breakpoint")
-        self.continue_to_breakpoints(breakpoint_ids)
+        self.darwin_dwarf_missing_obj(None)
 
-        locals = self.vscode.get_local_variables()
 
-        verify_locals = {
-            '<error>': {
-                'equals': {'type': 'const char *'},
-                'contains': { 'value': [
-                    'debug map object file ',
-                    'main.o" containing debug info does not exist, debug info will not be loaded']
-                }
-            },
-        }
-        varref_dict = {}
-        self.verify_variables(verify_locals, locals, varref_dict)
+    @no_debug_info_test
+    @skipUnlessDarwin
+    def test_darwin_dwarf_missing_obj_with_symbol_ondemand_enabled(self):
+        '''
+            Test that if we build a binary with DWARF in .o files and we remove
+            the .o file for main.cpp, that we get a variable named "<error>"
+            whose value matches the appriopriate error. Test with symbol_ondemand_enabled.
+        '''
+        initCommands = ['settings set symbols.load-on-demand true']
+        self.darwin_dwarf_missing_obj(initCommands)