Handle unwinding from SEGV on Windows

Message ID 20230321194240.1766622-1-tromey@adacore.com
State New
Headers
Series Handle unwinding from SEGV on Windows |

Commit Message

Tom Tromey March 21, 2023, 7:42 p.m. UTC
  PR win32/30255 points out that a call to a NULL function pointer will
leave gdb unable to "bt" on Windows.

I tracked this down to the amd64 windows unwinder.  If we treat this
scenario as if it were a leaf function, unwinding works fine.

I'm not completely sure this patch is the best way.  I considered
having it check for 'pc==0' -- but then I figured this could affect
any inaccessible PC, not just the special 0 value.

No test case because I can't run dejagnu tests on Windows.  I tested
this by hand using the test case in the bug.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30255
---
 gdb/amd64-windows-tdep.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
  

Comments

Tom Tromey April 10, 2023, 2:38 p.m. UTC | #1
>>>>> "Tom" == Tom Tromey via Gdb-patches <gdb-patches@sourceware.org> writes:

Tom> PR win32/30255 points out that a call to a NULL function pointer will
Tom> leave gdb unable to "bt" on Windows.

Tom> I tracked this down to the amd64 windows unwinder.  If we treat this
Tom> scenario as if it were a leaf function, unwinding works fine.

Tom> I'm not completely sure this patch is the best way.  I considered
Tom> having it check for 'pc==0' -- but then I figured this could affect
Tom> any inaccessible PC, not just the special 0 value.

Tom> No test case because I can't run dejagnu tests on Windows.  I tested
Tom> this by hand using the test case in the bug.

Tom> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30255

I'm checking this in.

Tom
  

Patch

diff --git a/gdb/amd64-windows-tdep.c b/gdb/amd64-windows-tdep.c
index 07df64bed60..9d69ec282d2 100644
--- a/gdb/amd64-windows-tdep.c
+++ b/gdb/amd64-windows-tdep.c
@@ -1098,13 +1098,14 @@  amd64_windows_frame_cache (frame_info_ptr this_frame, void **this_cache)
   cache->sp = extract_unsigned_integer (buf, 8, byte_order);
   cache->pc = pc;
 
+  /* If we can't find the unwind info, keep trying as though this is a
+     leaf function.  This situation can happen when PC==0, see
+     https://sourceware.org/bugzilla/show_bug.cgi?id=30255.  */
   if (amd64_windows_find_unwind_info (gdbarch, pc, &unwind_info,
 				      &cache->image_base,
 				      &cache->start_rva,
-				      &cache->end_rva))
-    return cache;
-
-  if (unwind_info == 0)
+				      &cache->end_rva)
+      || unwind_info == 0)
     {
       /* Assume a leaf function.  */
       cache->prev_sp = cache->sp + 8;