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

via lldb-commits lldb-commits at lists.llvm.org
Sun Oct 6 07:06:53 PDT 2024


https://github.com/Da-Viper updated https://github.com/llvm/llvm-project/pull/106907

>From 2ca64edb00d1f7b9d2938c9db32644c4a8cbc13e Mon Sep 17 00:00:00 2001
From: Ezike Ebuka <yerimyah1 at gmail.com>
Date: Sun, 1 Sep 2024 13:48:41 +0100
Subject: [PATCH 1/3] Add: show return value on step out

---
 lldb/tools/lldb-dap/lldb-dap.cpp | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp b/lldb/tools/lldb-dap/lldb-dap.cpp
index c5c4b09f15622b..c9116c62c46b5e 100644
--- a/lldb/tools/lldb-dap/lldb-dap.cpp
+++ b/lldb/tools/lldb-dap/lldb-dap.cpp
@@ -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));
+    }
+
     // Now we construct the result with unique display variable names
     for (auto i = start_idx; i < end_idx; ++i) {
       lldb::SBValue variable = top_scope->GetValueAtIndex(i);

>From 8119240ca46e0e9d25ebc1b9c41d1eb9bd4f9ee2 Mon Sep 17 00:00:00 2001
From: Ezike Ebuka <yerimyah1 at gmail.com>
Date: Sun, 1 Sep 2024 14:10:54 +0100
Subject: [PATCH 2/3] format file

---
 lldb/tools/lldb-dap/lldb-dap.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp b/lldb/tools/lldb-dap/lldb-dap.cpp
index c9116c62c46b5e..bf87dd838c8a74 100644
--- a/lldb/tools/lldb-dap/lldb-dap.cpp
+++ b/lldb/tools/lldb-dap/lldb-dap.cpp
@@ -3809,7 +3809,7 @@ void request_variables(const llvm::json::Object &request) {
         (selectedThread.GetSelectedFrame().GetFrameID() == 0)) {
       auto renamedReturnValue = stopReturnValue.Clone("(Return Value)");
       variables.emplace_back(
-          CreateVariable(renamedReturnValue,0, UINT64_MAX, hex, false));
+          CreateVariable(renamedReturnValue, 0, UINT64_MAX, hex, false));
     }
 
     // Now we construct the result with unique display variable names

>From d50238b0f7603ddf387be2f02e8a067a0158b761 Mon Sep 17 00:00:00 2001
From: Ezike Ebuka <yerimyah1 at gmail.com>
Date: Sun, 15 Sep 2024 22:22:09 +0100
Subject: [PATCH 3/3] [lldb-dap] Add: Show children for return values

---
 lldb/tools/lldb-dap/lldb-dap.cpp | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/lldb/tools/lldb-dap/lldb-dap.cpp b/lldb/tools/lldb-dap/lldb-dap.cpp
index bf87dd838c8a74..90b179e1e743c8 100644
--- a/lldb/tools/lldb-dap/lldb-dap.cpp
+++ b/lldb/tools/lldb-dap/lldb-dap.cpp
@@ -3803,13 +3803,19 @@ void request_variables(const llvm::json::Object &request) {
 
     // 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));
+    auto selected_thread = process.GetSelectedThread();
+    lldb::SBValue stop_return_value = selected_thread.GetStopReturnValue();
+    if (stop_return_value.IsValid() &&
+        (selected_thread.GetSelectedFrame().GetFrameID() == 0)) {
+      auto renamed_return_value = stop_return_value.Clone("(Return Value)");
+      int64_t return_ref = 0;
+      if (stop_return_value.MightHaveChildren() ||
+          stop_return_value.IsSynthetic()) {
+        return_ref = g_dap.variables.InsertExpandableVariable(
+            stop_return_value, /*is_permanent=*/false);
+      }
+      variables.emplace_back(CreateVariable(renamed_return_value, return_ref,
+                                            UINT64_MAX, hex, false));
     }
 
     // Now we construct the result with unique display variable names



More information about the lldb-commits mailing list