[Lldb-commits] [PATCH] D156732: Display PC instead of <unknown> for stack trace in vscode
Tom Yang via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Thu Aug 3 12:59:59 PDT 2023
zhyty updated this revision to Diff 546979.
zhyty added a comment.
remove a.out
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D156732/new/
https://reviews.llvm.org/D156732
Files:
lldb/test/API/tools/lldb-vscode/stackTraceMissingFunctionName/Makefile
lldb/test/API/tools/lldb-vscode/stackTraceMissingFunctionName/TestVSCode_stackTraceMissingFunctionName.py
lldb/test/API/tools/lldb-vscode/stackTraceMissingFunctionName/main.cpp
lldb/tools/lldb-vscode/JSONUtils.cpp
Index: lldb/tools/lldb-vscode/JSONUtils.cpp
===================================================================
--- lldb/tools/lldb-vscode/JSONUtils.cpp
+++ 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 = "<unknown>";
+ 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]";
Index: lldb/test/API/tools/lldb-vscode/stackTraceMissingFunctionName/main.cpp
===================================================================
--- /dev/null
+++ 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;
+}
Index: lldb/test/API/tools/lldb-vscode/stackTraceMissingFunctionName/TestVSCode_stackTraceMissingFunctionName.py
===================================================================
--- /dev/null
+++ 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")
Index: lldb/test/API/tools/lldb-vscode/stackTraceMissingFunctionName/Makefile
===================================================================
--- /dev/null
+++ lldb/test/API/tools/lldb-vscode/stackTraceMissingFunctionName/Makefile
@@ -0,0 +1,2 @@
+CXX_SOURCES := main.cpp
+include Makefile.rules
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156732.546979.patch
Type: text/x-patch
Size: 2585 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20230803/ecfe05ef/attachment.bin>
More information about the lldb-commits
mailing list