[gdb/tdep] Only catch NO_ENTRY_VALUE_ERROR in ppc_sysv_get_return_buf_addr

Message ID 20250107112436.1258-1-tdevries@suse.de
State New
Headers
Series [gdb/tdep] Only catch NO_ENTRY_VALUE_ERROR in ppc_sysv_get_return_buf_addr |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Test passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Test passed

Commit Message

Tom de Vries Jan. 7, 2025, 11:24 a.m. UTC
  Function value_of_dwarf_reg_entry throws a NO_ENTRY_VALUE_ERROR if it cannot
resolve the parameter for any reason.

But in ppc_sysv_get_return_buf_addr we do:
...
  try
    {
      return_val = value_as_address (value_of_dwarf_reg_entry (val_type,
                                                               cur_frame,
                                                               kind, kind_u));
    }
  catch (const gdb_exception_error &e)
    {
      warning ("Cannot determine the function return value.\n"
	       "Try compiling with -fvar-tracking.");
    }
...
which catches any gdb_exception_error, not just NO_ENTRY_VALUE_ERROR.

Fix this by using dwarf_reg_on_entry.

Tested on ppc64le-linux.
---
 gdb/dwarf2/loc.c    | 22 ++++++++++++++++++++++
 gdb/dwarf2/loc.h    |  9 +++++++++
 gdb/ppc-sysv-tdep.c | 25 +++++++------------------
 gdb/s390-tdep.c     | 23 -----------------------
 4 files changed, 38 insertions(+), 41 deletions(-)


base-commit: d4efbce75f1f98db0837f3791a65d9cb433f7861
  

Patch

diff --git a/gdb/dwarf2/loc.c b/gdb/dwarf2/loc.c
index 989d33901e0..84b57e560b6 100644
--- a/gdb/dwarf2/loc.c
+++ b/gdb/dwarf2/loc.c
@@ -1382,6 +1382,28 @@  value_of_dwarf_reg_entry (struct type *type, const frame_info_ptr &frame,
   return val;
 }
 
+/* See dwarf2/loc.h.  */
+
+struct value *
+dwarf_reg_on_entry (int dwarf_reg, struct type *val_type,
+		    const frame_info_ptr &frame)
+{
+  enum call_site_parameter_kind kind = CALL_SITE_PARAMETER_DWARF_REG;
+  union call_site_parameter_u kind_u = { .dwarf_reg = dwarf_reg };
+
+  try
+    {
+      return value_of_dwarf_reg_entry (val_type, frame, kind, kind_u);
+    }
+  catch (const gdb_exception_error &e)
+    {
+      if (e.error == NO_ENTRY_VALUE_ERROR)
+	return nullptr;
+
+      throw;
+    }
+}
+
 /* Read parameter of TYPE at (callee) FRAME's function entry.  DATA and
    SIZE are DWARF block used to match DW_AT_location at the caller's
    DW_TAG_call_site_parameter.
diff --git a/gdb/dwarf2/loc.h b/gdb/dwarf2/loc.h
index 78635682d94..7b960f355df 100644
--- a/gdb/dwarf2/loc.h
+++ b/gdb/dwarf2/loc.h
@@ -308,4 +308,13 @@  extern struct value *value_of_dwarf_reg_entry (struct type *type,
 					       const frame_info_ptr &frame,
 					       enum call_site_parameter_kind kind,
 					       union call_site_parameter_u kind_u);
+
+/* Try to get the value of DWARF_REG in FRAME at function entry.  If successful,
+   return it as value of type VAL_TYPE.  Thin wrapper around
+   value_of_dwarf_reg_entry that catches NO_ENTRY_VALUE_ERROR.  */
+
+extern struct value *dwarf_reg_on_entry (int dwarf_reg, struct type *val_type,
+					 const frame_info_ptr &frame);
+
+
 #endif /* GDB_DWARF2_LOC_H */
diff --git a/gdb/ppc-sysv-tdep.c b/gdb/ppc-sysv-tdep.c
index f317c94ef59..1aa32627022 100644
--- a/gdb/ppc-sysv-tdep.c
+++ b/gdb/ppc-sysv-tdep.c
@@ -2178,28 +2178,17 @@  ppc_sysv_get_return_buf_addr (struct type *val_type,
      function using the DW_OP_entry_value DWARF entries.  This requires
      compiling the user program with -fvar-tracking to resolve the
      DW_TAG_call_sites in the binary file.  */
+  int dwarf_reg = 3;
 
-  union call_site_parameter_u kind_u;
-  enum call_site_parameter_kind kind;
-  CORE_ADDR return_val = 0;
+  struct value *val_on_entry
+    = dwarf_reg_on_entry (dwarf_reg, lookup_pointer_type (val_type), cur_frame);
 
-  kind_u.dwarf_reg = 3;  /* First passed arg/return value is in r3.  */
-  kind = CALL_SITE_PARAMETER_DWARF_REG;
-
-  /* val_type is the type of the return value.  Need the pointer type
-     to the return value.  */
-  val_type = lookup_pointer_type (val_type);
-
-  try
-    {
-      return_val = value_as_address (value_of_dwarf_reg_entry (val_type,
-							       cur_frame,
-							       kind, kind_u));
-    }
-  catch (const gdb_exception_error &e)
+  if (val_on_entry == nullptr)
     {
       warning ("Cannot determine the function return value.\n"
 	       "Try compiling with -fvar-tracking.");
+      return 0;
     }
-  return return_val;
+
+  return value_as_address (val_on_entry);
 }
diff --git a/gdb/s390-tdep.c b/gdb/s390-tdep.c
index 3a672b3869d..e0d76199700 100644
--- a/gdb/s390-tdep.c
+++ b/gdb/s390-tdep.c
@@ -2120,29 +2120,6 @@  s390_return_value (struct gdbarch *gdbarch, struct value *function,
   return rvc;
 }
 
-/* Try to get the value of DWARF_REG in FRAME at function entry.  If successful,
-   return it as value of type VAL_TYPE.  */
-
-static struct value *
-dwarf_reg_on_entry (int dwarf_reg, struct type *val_type,
-		    const frame_info_ptr &frame)
-{
-  enum call_site_parameter_kind kind = CALL_SITE_PARAMETER_DWARF_REG;
-  union call_site_parameter_u kind_u = { .dwarf_reg = dwarf_reg };
-
-  try
-    {
-      return value_of_dwarf_reg_entry (val_type, frame, kind, kind_u);
-    }
-  catch (const gdb_exception_error &e)
-    {
-      if (e.error == NO_ENTRY_VALUE_ERROR)
-	return nullptr;
-
-      throw;
-    }
-}
-
 /* Both the 32-bit and 64-bit ABIs specify that values of some types are
    returned in a storage buffer provided by the caller.  Return the address of
    that storage buffer, if possible.  Implements the