aboutsummaryrefslogtreecommitdiff
path: root/lldb/tools
diff options
context:
space:
mode:
authorjeffreytan81 <jeffreytan@meta.com>2023-11-08 16:48:55 -0800
committerGitHub <noreply@github.com>2023-11-08 16:48:55 -0800
commitf175b9647ccdfd67300264b2d3bd76e6f9a3fb93 (patch)
tree3fb37b9fb6f7f13ff901b555f280ce64dcb274d2 /lldb/tools
parent4c9f6d6f029752eeaf71ed88c5ff74db3f9800b9 (diff)
downloadllvm-f175b9647ccdfd67300264b2d3bd76e6f9a3fb93.zip
llvm-f175b9647ccdfd67300264b2d3bd76e6f9a3fb93.tar.gz
llvm-f175b9647ccdfd67300264b2d3bd76e6f9a3fb93.tar.bz2
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@fb.com>
Diffstat (limited to 'lldb/tools')
-rw-r--r--lldb/tools/lldb-dap/BreakpointBase.cpp5
-rw-r--r--lldb/tools/lldb-dap/JSONUtils.cpp9
-rw-r--r--lldb/tools/lldb-dap/JSONUtils.h3
3 files changed, 12 insertions, 5 deletions
diff --git a/lldb/tools/lldb-dap/BreakpointBase.cpp b/lldb/tools/lldb-dap/BreakpointBase.cpp
index cd12f97..bc9bde9 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 46528a2..2ff1761 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 d829e65..02ee499 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.
///