llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lldb

Author: John Harrison (ashgti)

<details>
<summary>Changes</summary>

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&gt; script
&gt;&gt;&gt; event = lldb.frame.GetValueForVariablePath("event")
&gt;&gt;&gt; print("Value", event.GetValue())
Value None
&gt;&gt;&gt; print("Summary", event.GetSummary())
Summary None
&gt;&gt;&gt; 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 `&lt;type&gt; @ &lt;addr&gt;`.

---
Full diff: https://github.com/llvm/llvm-project/pull/77026.diff


1 Files Affected:

- (modified) lldb/tools/lldb-dap/JSONUtils.cpp (+7-3) 


``````````diff
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)

``````````

</details>


https://github.com/llvm/llvm-project/pull/77026
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to