public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug python/31437] New: [gdb/python] Unavailable register breaks python unwinding
@ 2024-03-01 12:24 vries at gcc dot gnu.org
  2024-03-01 12:27 ` [Bug python/31437] " vries at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: vries at gcc dot gnu.org @ 2024-03-01 12:24 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=31437

            Bug ID: 31437
           Summary: [gdb/python] Unavailable register breaks python
                    unwinding
           Product: gdb
           Version: HEAD
            Status: NEW
          Severity: normal
          Priority: P2
         Component: python
          Assignee: unassigned at sourceware dot org
          Reporter: vries at gcc dot gnu.org
  Target Milestone: ---

On arm-linux, until this commit:
...
commit bbb12eb9c84aa2b32480b7c022c494c2469ef717
Author: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
Date:   Mon Feb 26 19:11:45 2024 -0300

    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
...

Because this was the only reported progression, I decided to investigate a bit
further.

I found that the python unwinder fails because this piece of code in
pyuw_sniffer ignores the fact that value can be !entirely_available:
...
    /* Populate registers array.  */
    for (int i = 0; i < unwind_info->saved_regs->size (); ++i)
      {
        ...
        memcpy (cached->data.get (), value->contents ().data (), data_size);
      }
  }
...
which throws an unavailable error, which is then caught by
frame_unwind_try_unwinder:
...
      if (ex.error == NOT_AVAILABLE_ERROR)
        {
          /* This usually means that not even the PC is available,              
             thus most unwinders aren't able to determine if they're            
             the best fit.  Keep trying.  Fallback prologue unwinders           
             should always accept the frame.  */
          return 0;
        }
...

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug python/31437] [gdb/python] Unavailable register breaks python unwinding
  2024-03-01 12:24 [Bug python/31437] New: [gdb/python] Unavailable register breaks python unwinding vries at gcc dot gnu.org
@ 2024-03-01 12:27 ` vries at gcc dot gnu.org
  2024-03-02  8:52 ` vries at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: vries at gcc dot gnu.org @ 2024-03-01 12:27 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=31437

--- Comment #1 from Tom de Vries <vries at gcc dot gnu.org> ---
With commit bbb12eb9c84aa2b32480b7c022c494c2469ef717 reverted, and this patch:
...
diff --git a/gdb/python/py-unwind.c b/gdb/python/py-unwind.c
index 56f925bc57f..90f8ba4f293 100644
--- a/gdb/python/py-unwind.c
+++ b/gdb/python/py-unwind.c
@@ -916,6 +916,13 @@ pyuw_sniffer (const struct frame_unwind *self, const
frame_info_ptr &this_frame,
        gdb_assert (data_size == value->type ()->length ());

        cached_reg_t *cached = new (&cached_frame->reg[i]) cached_reg_t ();
+
+       if (!value->entirely_available ())
+          {
+            cached->num = -1;
+            continue;
+          }
+
        cached->num = reg->number;
        cached->data.reset ((gdb_byte *) xmalloc (data_size));
        memcpy (cached->data.get (), value->contents ().data (), data_size);
...
the test-case still passes for me on arm-linux.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug python/31437] [gdb/python] Unavailable register breaks python unwinding
  2024-03-01 12:24 [Bug python/31437] New: [gdb/python] Unavailable register breaks python unwinding vries at gcc dot gnu.org
  2024-03-01 12:27 ` [Bug python/31437] " vries at gcc dot gnu.org
@ 2024-03-02  8:52 ` vries at gcc dot gnu.org
  2024-03-02 12:37 ` vries at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: vries at gcc dot gnu.org @ 2024-03-02  8:52 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=31437

--- Comment #2 from Tom de Vries <vries at gcc dot gnu.org> ---
I realized it's cleaner to go with a fix in unwind_infopy_add_saved_register:
...
diff --git a/gdb/python/py-unwind.c b/gdb/python/py-unwind.c
index 56f925bc57f..1c1289f7e7d 100644
--- a/gdb/python/py-unwind.c
+++ b/gdb/python/py-unwind.c
@@ -362,6 +362,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)
...

I'll test this and submit.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug python/31437] [gdb/python] Unavailable register breaks python unwinding
  2024-03-01 12:24 [Bug python/31437] New: [gdb/python] Unavailable register breaks python unwinding vries at gcc dot gnu.org
  2024-03-01 12:27 ` [Bug python/31437] " vries at gcc dot gnu.org
  2024-03-02  8:52 ` vries at gcc dot gnu.org
@ 2024-03-02 12:37 ` vries at gcc dot gnu.org
  2024-03-19  9:29 ` cvs-commit at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: vries at gcc dot gnu.org @ 2024-03-02 12:37 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=31437

--- Comment #3 from Tom de Vries <vries at gcc dot gnu.org> ---
https://sourceware.org/pipermail/gdb-patches/2024-March/206965.html

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug python/31437] [gdb/python] Unavailable register breaks python unwinding
  2024-03-01 12:24 [Bug python/31437] New: [gdb/python] Unavailable register breaks python unwinding vries at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2024-03-02 12:37 ` vries at gcc dot gnu.org
@ 2024-03-19  9:29 ` cvs-commit at gcc dot gnu.org
  2024-05-08  8:36 ` vries at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-03-19  9:29 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=31437

--- Comment #4 from Sourceware Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Tom de Vries <vries@sourceware.org>:

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

commit 306361f0687a60b06503a2df3c0ba949afca215f
Author: Tom de Vries <tdevries@suse.de>
Date:   Tue Mar 19 10:30:36 2024 +0100

    [gdb] Further fix "value is not available" with debug frame

    In commit 2aaba744467 ("[gdb] Fix "value is not available" with debug
frame")
    I fixed a case in frame_unwind_register_value where using "set debug frame
on"
    caused an "info frame" command to abort, reporting a "value is not
available"
    error, due to the tpidruro register being unavailable.

    Subsequently, commit bbb12eb9c84 ("gdb/arm: Remove tpidruro register from
    non-FreeBSD target descriptions") removed the unavailable register, which
    caused a progression on test-case gdb.base/inline-frame-cycle-unwind.exp.

    While investigating the progression (see PR python/31437), I found that the
    "debug frame" output of the test-case (when reverting commit bbb12eb9c84)
    showed a smilar problem:
    ...
    Python Exception <class 'gdb.error'>: value is not available^M
    ...
    that was absent without "debug frame".

    Fix this likewise in fetch_lazy_register, and update the test-case to check
    for the exception.

    Furthermore, I realized that there's both value::entirely_available and
    value::entirely_unavailable, and that commit 2aaba744467 handled the case
    of !entirely_available by printing unavailable.

    Instead, print:
    - "unavailable" for entirely_unavailable, and
    - "partly unavailable" for !entirely_unavailable && !entirely_available.

    Tested on x86_64-linux and arm-linux.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug python/31437] [gdb/python] Unavailable register breaks python unwinding
  2024-03-01 12:24 [Bug python/31437] New: [gdb/python] Unavailable register breaks python unwinding vries at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2024-03-19  9:29 ` cvs-commit at gcc dot gnu.org
@ 2024-05-08  8:36 ` vries at gcc dot gnu.org
  2024-05-08 12:12 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: vries at gcc dot gnu.org @ 2024-05-08  8:36 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=31437

--- Comment #5 from Tom de Vries <vries at gcc dot gnu.org> ---
This is probably a duplicate of PR30548.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug python/31437] [gdb/python] Unavailable register breaks python unwinding
  2024-03-01 12:24 [Bug python/31437] New: [gdb/python] Unavailable register breaks python unwinding vries at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2024-05-08  8:36 ` vries at gcc dot gnu.org
@ 2024-05-08 12:12 ` cvs-commit at gcc dot gnu.org
  2024-05-08 12:14 ` vries at gcc dot gnu.org
  2024-05-08 12:15 ` vries at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-05-08 12:12 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=31437

--- Comment #6 from Sourceware Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Tom de Vries <vries@sourceware.org>:

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

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug python/31437] [gdb/python] Unavailable register breaks python unwinding
  2024-03-01 12:24 [Bug python/31437] New: [gdb/python] Unavailable register breaks python unwinding vries at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2024-05-08 12:12 ` cvs-commit at gcc dot gnu.org
@ 2024-05-08 12:14 ` vries at gcc dot gnu.org
  2024-05-08 12:15 ` vries at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: vries at gcc dot gnu.org @ 2024-05-08 12:14 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=31437

Tom de Vries <vries at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED
   Target Milestone|---                         |15.1

--- Comment #7 from Tom de Vries <vries at gcc dot gnu.org> ---
Fixed.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug python/31437] [gdb/python] Unavailable register breaks python unwinding
  2024-03-01 12:24 [Bug python/31437] New: [gdb/python] Unavailable register breaks python unwinding vries at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2024-05-08 12:14 ` vries at gcc dot gnu.org
@ 2024-05-08 12:15 ` vries at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: vries at gcc dot gnu.org @ 2024-05-08 12:15 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=31437

--- Comment #8 from Tom de Vries <vries at gcc dot gnu.org> ---
*** Bug 30548 has been marked as a duplicate of this bug. ***

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2024-05-08 12:15 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-01 12:24 [Bug python/31437] New: [gdb/python] Unavailable register breaks python unwinding vries at gcc dot gnu.org
2024-03-01 12:27 ` [Bug python/31437] " vries at gcc dot gnu.org
2024-03-02  8:52 ` vries at gcc dot gnu.org
2024-03-02 12:37 ` vries at gcc dot gnu.org
2024-03-19  9:29 ` cvs-commit at gcc dot gnu.org
2024-05-08  8:36 ` vries at gcc dot gnu.org
2024-05-08 12:12 ` cvs-commit at gcc dot gnu.org
2024-05-08 12:14 ` vries at gcc dot gnu.org
2024-05-08 12:15 ` vries at gcc dot gnu.org

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).