[Lldb-commits] [lldb] [lldb-dap] Add: show return value on step out (PR #106907)

Walter Erquinigo via lldb-commits lldb-commits at lists.llvm.org
Tue Sep 10 13:28:00 PDT 2024


================
@@ -3801,6 +3801,17 @@ void request_variables(const llvm::json::Object &request) {
       variable_name_counts[GetNonNullVariableName(variable)]++;
     }
 
+    // Show return value if there is any ( in the top frame )
+    auto process = g_dap.target.GetProcess();
+    auto selectedThread = process.GetSelectedThread();
+    lldb::SBValue stopReturnValue = selectedThread.GetStopReturnValue();
+    if (stopReturnValue.IsValid() &&
+        (selectedThread.GetSelectedFrame().GetFrameID() == 0)) {
+      auto renamedReturnValue = stopReturnValue.Clone("(Return Value)");
+      variables.emplace_back(
+          CreateVariable(renamedReturnValue, 0, UINT64_MAX, hex, false));
----------------
walter-erquinigo wrote:

you need to change this. You are passing `variablesReference = 0`, which means that if this variable is structured (i.e. it has children), then the user won't be able to look into it.

A little bit below this point, there's some code that handles that with

```
int64_t var_ref = 0;
      if (variable.MightHaveChildren() || variable.IsSynthetic()) {
        var_ref = g_dap.variables.InsertExpandableVariable(
            variable, /*is_permanent=*/false);
      }
variables.emplace_back(CreateVariable(
          variable, var_ref, var_ref != 0 ? var_ref : UINT64_MAX, hex,
          variable_name_counts[GetNonNullVariableName(variable)] > 1));
```
 
 You should be able to refactor out that code and use it for both cases.
Something else that you need to be aware of is that this function has an start index and end index, which gets used just below. This is used for paging.
You need to define an index for the return value whenever it's available and do the proper offset calculations for the regular variables. I suggest that this return value is index 0 so that it appears first.

Besides all of that, please create a test.

And finally, thanks for working on this. I've wanted this feature for so long.

https://github.com/llvm/llvm-project/pull/106907


More information about the lldb-commits mailing list