[Lldb-commits] [lldb] 786bab4 - Display PC instead of <unknown> for stack trace in vscode

Tom Yang via lldb-commits lldb-commits at lists.llvm.org
Fri Aug 4 11:07:39 PDT 2023


Author: Tom Yang
Date: 2023-08-04T11:07:27-07:00
New Revision: 786bab43346939d5662c2a90f8c0ff72fe421614

URL: https://github.com/llvm/llvm-project/commit/786bab43346939d5662c2a90f8c0ff72fe421614
DIFF: https://github.com/llvm/llvm-project/commit/786bab43346939d5662c2a90f8c0ff72fe421614.diff

LOG: Display PC instead of <unknown> for stack trace in vscode

It isn't useful for users to see "<unknown>" as a stack trace when lldb fails to symbolicate a stack frame. I've replaced "<unknown>" with the value of the program counter instead.

Test Plan:

To test this, I opened a target that lldb fails to symbolicate in
VSCode, and observed in the CALL STACK section that instead of being
shown as "<unknown>", those stack frames are represented by their
program counters.

I added a new test case, `TestVSCode_stackTraceMissingFunctionName` that
exercises this feature.

I also ran `lldb-dotest -p TestVSCode` and saw that the tests passed.

Differential Revision: https://reviews.llvm.org/D156732

Added: 
    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

Modified: 
    lldb/tools/lldb-vscode/JSONUtils.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/test/API/tools/lldb-vscode/stackTraceMissingFunctionName/Makefile b/lldb/test/API/tools/lldb-vscode/stackTraceMissingFunctionName/Makefile
new file mode 100644
index 00000000000000..3d0b98f13f3d7b
--- /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
index 00000000000000..8e7da6386d8e50
--- /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
index 00000000000000..a17a9390e75af1
--- /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
index 6acb07296da3be..03826f8936ae32 100644
--- a/lldb/tools/lldb-vscode/JSONUtils.cpp
+++ b/lldb/tools/lldb-vscode/JSONUtils.cpp
@@ -701,8 +701,12 @@ llvm::json::Value CreateStackFrame(lldb::SBFrame &frame) {
   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]";


        


More information about the lldb-commits mailing list