Skip to content

Commit

Permalink
Show error message for optimized variables
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Jeffrey Tan committed May 23, 2022
1 parent 46c1f77 commit 0fe220a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
19 changes: 19 additions & 0 deletions lldb/test/API/tools/lldb-vscode/optimized/TestVSCode_optimized.py
Expand Up @@ -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:'))
5 changes: 4 additions & 1 deletion lldb/tools/lldb-vscode/JSONUtils.cpp
Expand Up @@ -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;
Expand Down

0 comments on commit 0fe220a

Please sign in to comment.