[Lldb-commits] [lldb] Improve VSCode DAP logpoint value summary (PR #71723)

via lldb-commits lldb-commits at lists.llvm.org
Wed Nov 8 10:41:14 PST 2023


https://github.com/jeffreytan81 created https://github.com/llvm/llvm-project/pull/71723

Currently VSCode logpoint uses `SBValue::GetValue` to get the value for printing. This is not providing an intuitive result for std::string or char * -- it shows the pointer value instead of the string content.

This patch improves by prefers `SBValue::GetSummary()` before using `SBValue::GetValue()`. 

>From e92d7125be6b6677d0553967bb3f8e821de3ea18 Mon Sep 17 00:00:00 2001
From: jeffreytan81 <jeffreytan at fb.com>
Date: Tue, 7 Nov 2023 16:57:23 -0800
Subject: [PATCH] Improve DAP logpoint value summary

---
 .../API/tools/lldb-dap/breakpoint/TestDAP_logpoints.py    | 5 +++--
 lldb/test/API/tools/lldb-dap/breakpoint/main.cpp          | 2 ++
 lldb/tools/lldb-dap/BreakpointBase.cpp                    | 8 +++++---
 3 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_logpoints.py b/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_logpoints.py
index 25e794a49d3ac12..44858c888a96940 100644
--- a/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_logpoints.py
+++ b/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_logpoints.py
@@ -48,7 +48,8 @@ def test_logmessage_basic(self):
         # 1. First at the loop line with logMessage
         # 2. Second guard breakpoint at a line after loop
         logMessage_prefix = "This is log message for { -- "
-        logMessage = logMessage_prefix + "{i + 3}"
+        message = '"Hello from main!"'
+        logMessage = logMessage_prefix + "{i + 3}, {message}"
         [loop_breakpoint_id, post_loop_breakpoint_id] = self.set_source_breakpoints(
             self.main_path,
             [loop_line, after_loop_line],
@@ -75,7 +76,7 @@ def test_logmessage_basic(self):
         # Verify log message match
         for idx, logMessage_line in enumerate(logMessage_output):
             result = idx + 3
-            self.assertEqual(logMessage_line, logMessage_prefix + str(result))
+            self.assertEqual(logMessage_line, f"{logMessage_prefix}{result}, {message}")
 
     @skipIfWindows
     @skipIfRemote
diff --git a/lldb/test/API/tools/lldb-dap/breakpoint/main.cpp b/lldb/test/API/tools/lldb-dap/breakpoint/main.cpp
index 935a63fab6d0c36..84560dad92c286e 100644
--- a/lldb/test/API/tools/lldb-dap/breakpoint/main.cpp
+++ b/lldb/test/API/tools/lldb-dap/breakpoint/main.cpp
@@ -28,6 +28,7 @@ int main(int argc, char const *argv[]) {
     exit(1);
   }
 
+  const char * message = "Hello from main!";
   int (*foo)(int) = (int (*)(int))dlsym(handle, "foo");
   if (foo == nullptr) {
     fprintf(stderr, "%s\n", dlerror());
@@ -38,6 +39,7 @@ int main(int argc, char const *argv[]) {
   for (int i = 0; i < 10; ++i) {
     int x = twelve(i) + thirteen(i) + a::fourteen(i); // break loop
   }
+  printf("%s\n", message);
   try {
     throw std::invalid_argument("throwing exception for testing");
   } catch (...) {
diff --git a/lldb/tools/lldb-dap/BreakpointBase.cpp b/lldb/tools/lldb-dap/BreakpointBase.cpp
index cd12f97fb13dfe9..d5253431053cc25 100644
--- a/lldb/tools/lldb-dap/BreakpointBase.cpp
+++ b/lldb/tools/lldb-dap/BreakpointBase.cpp
@@ -295,9 +295,11 @@ bool BreakpointBase::BreakpointHitCallback(
           frame.GetValueForVariablePath(expr, lldb::eDynamicDontRunTarget);
       if (value.GetError().Fail())
         value = frame.EvaluateExpression(expr);
-      const char *expr_val = value.GetValue();
-      if (expr_val)
-        output += expr_val;
+      llvm::StringRef summary_str = value.GetSummary();
+      if (!summary_str.empty())
+        output += summary_str.str();
+      else
+        output += value.GetValue();
     } else {
       output += messagePart.text;
     }



More information about the lldb-commits mailing list