[Lldb-commits] [lldb] 0fe220a - Show error message for optimized variables

Jeffrey Tan via lldb-commits lldb-commits at lists.llvm.org
Mon May 23 10:05:30 PDT 2022


Author: Jeffrey Tan
Date: 2022-05-23T10:04:58-07:00
New Revision: 0fe220a33179723b7b366c2b398bac3c3b4216ec

URL: https://github.com/llvm/llvm-project/commit/0fe220a33179723b7b366c2b398bac3c3b4216ec
DIFF: https://github.com/llvm/llvm-project/commit/0fe220a33179723b7b366c2b398bac3c3b4216ec.diff

LOG: Show error message for optimized variables

This fixes an issue that optimized variable error message is not shown to end
users in lldb-vscode.

Differential Revision: https://reviews.llvm.org/D126014

Added: 
    

Modified: 
    lldb/test/API/tools/lldb-vscode/optimized/TestVSCode_optimized.py
    lldb/tools/lldb-vscode/JSONUtils.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/test/API/tools/lldb-vscode/optimized/TestVSCode_optimized.py b/lldb/test/API/tools/lldb-vscode/optimized/TestVSCode_optimized.py
index 862fe632a51b..a5e40d03abe4 100644
--- a/lldb/test/API/tools/lldb-vscode/optimized/TestVSCode_optimized.py
+++ b/lldb/test/API/tools/lldb-vscode/optimized/TestVSCode_optimized.py
@@ -33,3 +33,22 @@ def test_stack_frame_name(self):
         self.assertTrue(leaf_frame['name'].endswith(' [opt]'))
         parent_frame = self.vscode.get_stackFrame(frameIndex=1)
         self.assertTrue(parent_frame['name'].endswith(' [opt]'))
+
+    @skipIfWindows
+    @skipIfRemote
+    def test_optimized_variable(self):
+        ''' Test optimized variable value contains error.
+        '''
+        program = self.getBuildArtifact("a.out")
+        self.build_and_launch(program)
+        source = 'main.cpp'
+        breakpoint_line = line_number(source, '// breakpoint 2')
+        lines = [breakpoint_line]
+        # Set breakpoint in the thread function so we can step the threads
+        breakpoint_ids = self.set_source_breakpoints(source, lines)
+        self.assertEqual(len(breakpoint_ids), len(lines),
+                        "expect correct number of breakpoints")
+        self.continue_to_breakpoints(breakpoint_ids)
+        optimized_variable = self.vscode.get_local_variable('optimized')
+
+        self.assertTrue(optimized_variable['value'].startswith('<error:'))

diff  --git a/lldb/tools/lldb-vscode/JSONUtils.cpp b/lldb/tools/lldb-vscode/JSONUtils.cpp
index cd8d8861d98a..1fb4c00a8255 100644
--- a/lldb/tools/lldb-vscode/JSONUtils.cpp
+++ b/lldb/tools/lldb-vscode/JSONUtils.cpp
@@ -136,10 +136,13 @@ void SetValueForKey(lldb::SBValue &v, llvm::json::Object &object,
   llvm::StringRef value = v.GetValue();
   llvm::StringRef summary = v.GetSummary();
   llvm::StringRef type_name = v.GetType().GetDisplayTypeName();
+  lldb::SBError error = v.GetError();
 
   std::string result;
   llvm::raw_string_ostream strm(result);
-  if (!value.empty()) {
+  if (!error.Success()) {
+    strm << "<error: " << error.GetCString() << ">";
+  } else if (!value.empty()) {
     strm << value;
     if (!summary.empty())
       strm << ' ' << summary;


        


More information about the lldb-commits mailing list