public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] [gdb/python] Make gdb.UnwindInfo.add_saved_register more robust
@ 2024-05-08 12:12 Tom de Vries
  0 siblings, 0 replies; only message in thread
From: Tom de Vries @ 2024-05-08 12:12 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=2236c5e384de20b0dd6b2fbc964a7269027cb2d9

commit 2236c5e384de20b0dd6b2fbc964a7269027cb2d9
Author: Tom de Vries <tdevries@suse.de>
Date:   Wed May 8 14:13:11 2024 +0200

    [gdb/python] Make gdb.UnwindInfo.add_saved_register more robust
    
    On arm-linux, until commit bbb12eb9c84 ("gdb/arm: Remove tpidruro register
    from non-FreeBSD target descriptions") I ran into:
    ...
    FAIL: gdb.base/inline-frame-cycle-unwind.exp: cycle at level 5: \
      backtrace when the unwind is broken at frame 5
    ...
    
    What happens is the following:
    - the TestUnwinder from inline-frame-cycle-unwind.py calls
      gdb.UnwindInfo.add_saved_register with reg == tpidruro and value
      "<unavailable>",
    - pyuw_sniffer calls value->contents ().data () to access the value of the
      register, which throws an UNAVAILABLE_ERROR,
    - this causes the TestUnwinder unwinder to fail, after which another unwinder
      succeeds and returns the correct frame, and
    - the test-case fails because it's counting on the TestUnwinder to succeed and
      return an incorrect frame.
    
    Fix this by checking for !value::entirely_available as well as
    valued::optimized_out in unwind_infopy_add_saved_register.
    
    Tested on x86_64-linux and arm-linux.
    
    Approved-By: Andrew Burgess <aburgess@redhat.com>
    
    PR python/31437
    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31437

Diff:
---
 gdb/python/py-unwind.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/gdb/python/py-unwind.c b/gdb/python/py-unwind.c
index a86ccd2c94e..18125e56a46 100644
--- a/gdb/python/py-unwind.c
+++ b/gdb/python/py-unwind.c
@@ -361,6 +361,18 @@ unwind_infopy_add_saved_register (PyObject *self, PyObject *args, PyObject *kw)
       return nullptr;
     }
 
+  if (value->optimized_out () || !value->entirely_available ())
+    {
+      /* If we allow this value to be registered here, pyuw_sniffer is going
+	 to run into an exception when trying to access its contents.
+	 Throwing an exception here just puts a burden on the user to
+	 implement the same checks on the user side.  We could return False
+	 here and True otherwise, but again that might require changes in user
+	 code.  So, handle this with minimal impact for the user, while
+	 improving robustness: silently ignore the register/value pair.  */
+      Py_RETURN_NONE;
+    }
+
   gdbpy_ref<> new_value = gdbpy_ref<>::new_reference (pyo_reg_value);
   bool found = false;
   for (saved_reg &reg : *unwind_info->saved_regs)

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-05-08 12:12 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-08 12:12 [binutils-gdb] [gdb/python] Make gdb.UnwindInfo.add_saved_register more robust Tom de Vries

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).