[Lldb-commits] [lldb] f175b96 - Improve VSCode DAP logpoint value summary (#71723)
via lldb-commits
lldb-commits at lists.llvm.org
Wed Nov 8 16:48:59 PST 2023
Author: jeffreytan81
Date: 2023-11-08T16:48:55-08:00
New Revision: f175b9647ccdfd67300264b2d3bd76e6f9a3fb93
URL: https://github.com/llvm/llvm-project/commit/f175b9647ccdfd67300264b2d3bd76e6f9a3fb93
DIFF: https://github.com/llvm/llvm-project/commit/f175b9647ccdfd67300264b2d3bd76e6f9a3fb93.diff
LOG: Improve VSCode DAP logpoint value summary (#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()`.
---------
Co-authored-by: jeffreytan81 <jeffreytan at fb.com>
Added:
Modified:
lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_logpoints.py
lldb/test/API/tools/lldb-dap/breakpoint/main.cpp
lldb/tools/lldb-dap/BreakpointBase.cpp
lldb/tools/lldb-dap/JSONUtils.cpp
lldb/tools/lldb-dap/JSONUtils.h
Removed:
################################################################################
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..2367313b095ea26 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,7 @@ 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}"
+ 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],
@@ -72,10 +72,13 @@ def test_logmessage_basic(self):
loop_count = 10
self.assertEqual(len(logMessage_output), loop_count)
+ message_addr_pattern = r"\b0x[0-9A-Fa-f]+\b"
+ message_content = '"Hello from main!"'
# Verify log message match
for idx, logMessage_line in enumerate(logMessage_output):
result = idx + 3
- self.assertEqual(logMessage_line, logMessage_prefix + str(result))
+ reg_str = f"{logMessage_prefix}{result}, {message_addr_pattern} {message_content}"
+ self.assertRegex(logMessage_line, reg_str)
@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..a84546a95af1533 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..bc9bde97678adbd 100644
--- a/lldb/tools/lldb-dap/BreakpointBase.cpp
+++ b/lldb/tools/lldb-dap/BreakpointBase.cpp
@@ -8,6 +8,7 @@
#include "BreakpointBase.h"
#include "DAP.h"
+#include "JSONUtils.h"
#include "llvm/ADT/StringExtras.h"
using namespace lldb_dap;
@@ -295,9 +296,7 @@ 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;
+ output += ValueToString(value);
} else {
output += messagePart.text;
}
diff --git a/lldb/tools/lldb-dap/JSONUtils.cpp b/lldb/tools/lldb-dap/JSONUtils.cpp
index 46528a2a28d4d6f..2ff17616c2e9986 100644
--- a/lldb/tools/lldb-dap/JSONUtils.cpp
+++ b/lldb/tools/lldb-dap/JSONUtils.cpp
@@ -210,8 +210,7 @@ static std::optional<std::string> TryCreateAutoSummary(lldb::SBValue value) {
return TryCreateAutoSummaryForContainer(value);
}
-void SetValueForKey(lldb::SBValue &v, llvm::json::Object &object,
- llvm::StringRef key) {
+std::string ValueToString(lldb::SBValue v) {
std::string result;
llvm::raw_string_ostream strm(result);
@@ -242,6 +241,12 @@ void SetValueForKey(lldb::SBValue &v, llvm::json::Object &object,
}
}
}
+ return result;
+}
+
+void SetValueForKey(lldb::SBValue &v, llvm::json::Object &object,
+ llvm::StringRef key) {
+ std::string result = ValueToString(v);
EmplaceSafeString(object, key, result);
}
diff --git a/lldb/tools/lldb-dap/JSONUtils.h b/lldb/tools/lldb-dap/JSONUtils.h
index d829e650b8f31c4..02ee499445fa19b 100644
--- a/lldb/tools/lldb-dap/JSONUtils.h
+++ b/lldb/tools/lldb-dap/JSONUtils.h
@@ -167,6 +167,9 @@ std::vector<std::string> GetStrings(const llvm::json::Object *obj,
void FillResponse(const llvm::json::Object &request,
llvm::json::Object &response);
+/// Utility function to convert SBValue \v into a string.
+std::string ValueToString(lldb::SBValue v);
+
/// Emplace the string value from an SBValue into the supplied object
/// using \a key as the key that will contain the value.
///
More information about the lldb-commits
mailing list