diff --git a/lldb/test/API/tools/lldb-vscode/optimized/Makefile b/lldb/test/API/tools/lldb-vscode/optimized/Makefile new file mode 100644 --- /dev/null +++ b/lldb/test/API/tools/lldb-vscode/optimized/Makefile @@ -0,0 +1,3 @@ +CXX_SOURCES := main.cpp +CXXFLAGS_EXTRAS := -O3 -glldb +include Makefile.rules diff --git a/lldb/test/API/tools/lldb-vscode/optimized/TestVSCode_optimized.py b/lldb/test/API/tools/lldb-vscode/optimized/TestVSCode_optimized.py new file mode 100644 --- /dev/null +++ b/lldb/test/API/tools/lldb-vscode/optimized/TestVSCode_optimized.py @@ -0,0 +1,35 @@ +""" +Test lldb-vscode variables/stackTrace request for optimized code +""" + +from __future__ import print_function + +import unittest2 +import vscode +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil +import lldbvscode_testcase + + +class TestVSCode_optimized(lldbvscode_testcase.VSCodeTestCaseBase): + mydir = TestBase.compute_mydir(__file__) + + @skipIfWindows + @skipIfRemote + def test_stack_frame_name(self): + ''' Test optimized frame has special name suffix. + ''' + program = self.getBuildArtifact("a.out") + self.build_and_launch(program) + source = 'main.cpp' + breakpoint_line = line_number(source, '// breakpoint 1') + lines = [breakpoint_line] + 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) + leaf_frame = self.vscode.get_stackFrame(frameIndex=0) + self.assertTrue(leaf_frame['name'].endswith(' [opt]')) + parent_frame = self.vscode.get_stackFrame(frameIndex=1) + self.assertTrue(parent_frame['name'].endswith(' [opt]')) diff --git a/lldb/test/API/tools/lldb-vscode/optimized/main.cpp b/lldb/test/API/tools/lldb-vscode/optimized/main.cpp new file mode 100644 --- /dev/null +++ b/lldb/test/API/tools/lldb-vscode/optimized/main.cpp @@ -0,0 +1,16 @@ +#include +#include + +int foo(int x, int y) { + printf("Got input %d, %d\n", x, y); + return x + y + 3; // breakpoint 1 +} + +int main(int argc, char const *argv[]) { + int optimized = argc > 1 ? std::stoi(argv[1]) : 0; + + printf("argc: %d, optimized: %d\n", argc, optimized); + int result = foo(argc, 20); + printf("result: %d\n", result); // breakpoint 2 + return 0; +} diff --git a/lldb/tools/lldb-vscode/JSONUtils.cpp b/lldb/tools/lldb-vscode/JSONUtils.cpp --- a/lldb/tools/lldb-vscode/JSONUtils.cpp +++ b/lldb/tools/lldb-vscode/JSONUtils.cpp @@ -751,7 +751,19 @@ llvm::json::Object object; int64_t frame_id = MakeVSCodeFrameID(frame); object.try_emplace("id", frame_id); - EmplaceSafeString(object, "name", frame.GetFunctionName()); + + std::string frame_name; + const char *func_name = frame.GetFunctionName(); + if (func_name) + frame_name = func_name; + else + frame_name = ""; + bool is_optimized = frame.GetFunction().GetIsOptimized(); + if (is_optimized) + frame_name += " [opt]"; + EmplaceSafeString(object, "name", frame_name); + object.try_emplace("optimized", is_optimized); + int64_t disasm_line = 0; object.try_emplace("source", CreateSource(frame, disasm_line));