https://github.com/ashgti created 
https://github.com/llvm/llvm-project/pull/77026

When generating a `display_value` for a variable the current approach calls 
`SBValue::GetValue()` and `SBValue::GetSummary()` to generate a `display_value` 
for the `SBValue`. However, there are cases where both of these return an empty 
string and the fallback is to print a pointer and type name instead (e.g. 
`FooBarType @ 0x00321`).

For swift types, lldb includes a langauge runtime plugin that can generate a 
description of the object but this is only used with 
`SBValue::GetDescription()`.

For example:
```
$ lldb swift-binary
... stop at breakpoint ...
lldb> script
>>> event = lldb.frame.GetValueForVariablePath("event")
>>> print("Value", event.GetValue())
Value None
>>> print("Summary", event.GetSummary())
Summary None
>>> print("Description", event) # __str__ calls SBValue::GetDescription()
Description (main.Event) event = (name = "Greetings", time = 2024-01-04 
23:38:06 UTC)
```

With this change, if GetValue and GetSummary return empty then we try 
`SBValue::GetDescription()` as a fallback before using the previous logic of 
printing `<type> @ <addr>`.

>From 7656af47e058aa7101504cb31aaa067178110351 Mon Sep 17 00:00:00 2001
From: John Harrison <harj...@google.com>
Date: Thu, 4 Jan 2024 15:42:35 -0800
Subject: [PATCH] [lldb-dap] Updating VariableDescription to use
 GetDescription() as a fallback.

When generating a `display_value` for a variable the current approach calls
`SBValue::GetValue()` and `SBValue::GetSummary()` to generate a `display_value`
for the `SBValue`. However, there are cases where both of these return an empty
string and the fallback is to print a pointer and type name instead (e.g.
"FooBarType @ 0x00321").

For swift types, lldb includes a langauge runtime plugin that can generate a
user description of the object but this is only used with
`SBValue::GetDescription()`.

For example:
```
$ lldb swift-binary
... stop at breakpoint ...
lldb> script
>>> event = lldb.frame.GetValueForVariablePath("event")
>>> print("Value", event.GetValue())
Value None
>>> print("Summary", event.GetSummary())
Summary None
>>> print("Description", event)
Description (main.Event) event = (name = "Greetings", time = 2024-01-04 
23:38:06 UTC)
```

With this change, if GetValue and GetSummary return empty then we try
`SBValue::GetDescription()` as a fallback before using the previous logic of
printing "<type> @ <addr>".
---
 lldb/tools/lldb-dap/JSONUtils.cpp | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/lldb/tools/lldb-dap/JSONUtils.cpp 
b/lldb/tools/lldb-dap/JSONUtils.cpp
index df17ac9d849176..f8ac53ef809e6e 100644
--- a/lldb/tools/lldb-dap/JSONUtils.cpp
+++ b/lldb/tools/lldb-dap/JSONUtils.cpp
@@ -1042,10 +1042,14 @@ VariableDescription::VariableDescription(lldb::SBValue 
v, bool format_hex,
         os_display_value << " " << *effective_summary;
     } else if (effective_summary) {
       os_display_value << *effective_summary;
-
-      // As last resort, we print its type and address if available.
     } else {
-      if (!raw_display_type_name.empty()) {
+      lldb::SBStream description;
+      // Try letting lldb generate a description.
+      if (v.GetDescription(description) && description.GetSize()) {
+        os_display_value << description.GetData();
+
+        // As last resort, we print its type and address if available.
+      } else if (!raw_display_type_name.empty()) {
         os_display_value << raw_display_type_name;
         lldb::addr_t address = v.GetLoadAddress();
         if (address != LLDB_INVALID_ADDRESS)

_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to