[Lldb-commits] [lldb] 46c1f77 - Add [opt] suffix to optimized stack frame in lldb-vscode
Jeffrey Tan via lldb-commits
lldb-commits at lists.llvm.org
Mon May 23 10:03:40 PDT 2022
Author: Jeffrey Tan
Date: 2022-05-23T10:03:13-07:00
New Revision: 46c1f77e160a63726e312c0550157ee451bacd46
URL: https://github.com/llvm/llvm-project/commit/46c1f77e160a63726e312c0550157ee451bacd46
DIFF: https://github.com/llvm/llvm-project/commit/46c1f77e160a63726e312c0550157ee451bacd46.diff
LOG: Add [opt] suffix to optimized stack frame in lldb-vscode
To help user identify optimized code This diff adds a "[opt]" suffix to
optimized stack frames in lldb-vscode. This provides consistent experience
as command line lldb.
It also adds a new "optimized" attribute to DAP stack frame object so that
it is easy to identify from telemetry than parsing trailing "[opt]".
Differential Revision: https://reviews.llvm.org/D126013
Added:
lldb/test/API/tools/lldb-vscode/optimized/Makefile
lldb/test/API/tools/lldb-vscode/optimized/TestVSCode_optimized.py
lldb/test/API/tools/lldb-vscode/optimized/main.cpp
Modified:
lldb/tools/lldb-vscode/JSONUtils.cpp
Removed:
################################################################################
diff --git a/lldb/test/API/tools/lldb-vscode/optimized/Makefile b/lldb/test/API/tools/lldb-vscode/optimized/Makefile
new file mode 100644
index 000000000000..685b2606b55a
--- /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
index 000000000000..862fe632a51b
--- /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
index 000000000000..24ace4e4196f
--- /dev/null
+++ b/lldb/test/API/tools/lldb-vscode/optimized/main.cpp
@@ -0,0 +1,16 @@
+#include <stdio.h>
+#include <string>
+
+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
index 55d734e65fb5..cd8d8861d98a 100644
--- a/lldb/tools/lldb-vscode/JSONUtils.cpp
+++ b/lldb/tools/lldb-vscode/JSONUtils.cpp
@@ -751,7 +751,19 @@ llvm::json::Value CreateStackFrame(lldb::SBFrame &frame) {
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 = "<unknown>";
+ 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));
More information about the lldb-commits
mailing list