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
This commit is contained in:
Jeffrey Tan 2022-05-17 09:17:26 -07:00
parent 224a8653c9
commit 46c1f77e16
4 changed files with 67 additions and 1 deletions

View File

@ -0,0 +1,3 @@
CXX_SOURCES := main.cpp
CXXFLAGS_EXTRAS := -O3 -glldb
include Makefile.rules

View File

@ -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]'))

View File

@ -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;
}

View File

@ -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));