diff --git a/lldb/test/API/tools/lldb-vscode/stackTraceMissingFunctionName/Makefile b/lldb/test/API/tools/lldb-vscode/stackTraceMissingFunctionName/Makefile new file mode 100644 --- /dev/null +++ b/lldb/test/API/tools/lldb-vscode/stackTraceMissingFunctionName/Makefile @@ -0,0 +1,2 @@ +CXX_SOURCES := main.cpp +include Makefile.rules diff --git a/lldb/test/API/tools/lldb-vscode/stackTraceMissingFunctionName/TestVSCode_stackTraceMissingFunctionName.py b/lldb/test/API/tools/lldb-vscode/stackTraceMissingFunctionName/TestVSCode_stackTraceMissingFunctionName.py new file mode 100644 --- /dev/null +++ b/lldb/test/API/tools/lldb-vscode/stackTraceMissingFunctionName/TestVSCode_stackTraceMissingFunctionName.py @@ -0,0 +1,26 @@ +""" +Test lldb-vscode stack trace response +""" + + +import vscode +from lldbsuite.test.decorators import * +import os + +import lldbvscode_testcase +from lldbsuite.test import lldbtest, lldbutil + + +class TestVSCode_stackTraceMissingFunctionName(lldbvscode_testcase.VSCodeTestCaseBase): + @skipIfWindows + @skipIfRemote + def test_missingFunctionName(self): + """ + Test that the stack frame without a function name is given its pc in the response. + """ + program = self.getBuildArtifact("a.out") + self.build_and_launch(program) + + self.continue_to_next_stop() + frame_without_function_name = self.get_stackFrames()[0] + self.assertEquals(frame_without_function_name["name"], "0x0000000000000000") diff --git a/lldb/test/API/tools/lldb-vscode/stackTraceMissingFunctionName/main.cpp b/lldb/test/API/tools/lldb-vscode/stackTraceMissingFunctionName/main.cpp new file mode 100644 --- /dev/null +++ b/lldb/test/API/tools/lldb-vscode/stackTraceMissingFunctionName/main.cpp @@ -0,0 +1,6 @@ +int main() { + typedef void (*FooCallback)(); + FooCallback foo_callback = (FooCallback)0; + foo_callback(); // Crash at zero! + 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 @@ -701,8 +701,12 @@ const char *function_name = frame.GetDisplayFunctionName(); std::string frame_name = function_name == nullptr ? std::string() : function_name; - if (frame_name.empty()) - frame_name = ""; + if (frame_name.empty()) { + // If the function name is unavailable, display the pc address as a 16-digit + // hex string, e.g. "0x0000000000012345" + llvm::raw_string_ostream os(frame_name); + os << llvm::format_hex(frame.GetPC(), 18); + } bool is_optimized = frame.GetFunction().GetIsOptimized(); if (is_optimized) frame_name += " [opt]";