llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-lldb Author: None (jeffreytan81) <details> <summary>Changes</summary> 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()`. --- Full diff: https://github.com/llvm/llvm-project/pull/71723.diff 5 Files Affected: - (modified) lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_logpoints.py (+5-2) - (modified) lldb/test/API/tools/lldb-dap/breakpoint/main.cpp (+2) - (modified) lldb/tools/lldb-dap/BreakpointBase.cpp (+2-3) - (modified) lldb/tools/lldb-dap/JSONUtils.cpp (+7-2) - (modified) lldb/tools/lldb-dap/JSONUtils.h (+3) ``````````diff 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..8614b3e19be6962 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,9 @@ 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_addr_pattern = r'\b0x[0-9A-Fa-f]+\b' + 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 +77,8 @@ 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)) + reg_str = f"{logMessage_prefix}{result}, {message_addr_pattern} {message}" + 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..b0946f0103c2a34 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 += ValeuToString(value); } else { output += messagePart.text; } diff --git a/lldb/tools/lldb-dap/JSONUtils.cpp b/lldb/tools/lldb-dap/JSONUtils.cpp index 46528a2a28d4d6f..84c8037108cdcd4 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 ValeuToString(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 = ValeuToString(v); EmplaceSafeString(object, key, result); } diff --git a/lldb/tools/lldb-dap/JSONUtils.h b/lldb/tools/lldb-dap/JSONUtils.h index d829e650b8f31c4..39f2be6a2dde301 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 ValeuToString(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. /// `````````` </details> https://github.com/llvm/llvm-project/pull/71723 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits