public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug gdb/30255] New: GDB on Windows cannot retrieve a stacktrace when a NULL function pointer is called
@ 2023-03-20 17:30 luca.bacci at outlook dot com
  2023-03-21 15:46 ` [Bug gdb/30255] " tromey at sourceware dot org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: luca.bacci at outlook dot com @ 2023-03-20 17:30 UTC (permalink / raw)
  To: gdb-prs

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

            Bug ID: 30255
           Summary: GDB on Windows cannot retrieve a stacktrace when a
                    NULL function pointer is called
           Product: gdb
           Version: 13.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: gdb
          Assignee: unassigned at sourceware dot org
          Reporter: luca.bacci at outlook dot com
  Target Milestone: ---

Hello, I use gdb on MSYS2 to fix issues with GIMP, Inkscape etc on Windows. One
thing I noticed is that gdb is unable to give a stacktrace anytime the debugged
program invokes a NULL function pointer. For example, consider:

void (*func_ptr)(void);

static void a (void)
{
  func_ptr ();
}

static void b (void)
{
  a ();
}

static void c (void)
{
  b ();
}

int main() {
  c ();
}

When running under GDB 13.1 the stacktrace is not retrieved:

$ gcc -g -o sample sample.c
$ gdb ./sample.exe 
GNU gdb (GDB) 13.1
Copyright (C) 2023 Free Software Foundation, Inc.
Reading symbols from ./sample.exe...
(gdb) r
Starting program: D:\sample.exe 
[New Thread 27612.0x6ec0]

Thread 1 received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()
(gdb) bt
#0  0x0000000000000000 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
(gdb)

I have tried with lldb and it works:

$ lldb ./sample.exe 
(lldb) target create "./sample.exe"
(rrent executable set to 'D:\sample.exe' (x86_64).
(lldb) r
(lldb) Process 23036 launched: 'D:\sample.exe' (x86_64)
Process 23036 stopped
* thread #1, stop reason = Exception 0xc0000005 encountered at address
0x000000: User-mode data execution prevention (DEP) violation at location
0x00000000
    frame #0: 0x0000000000000000
error: Only part of a ReadProcessMemory or WriteProcessMemory request was
completed.
(lldb) bt
* thread #1, stop reason = Exception 0xc0000005 encountered at address
0x000000: User-mode data execution prevention (DEP) violation at location
0x00000000
  * frame #0: 0x0000000000000000
    frame #1: 0x00007ff73e2813ea sample.exe`a at sample.c:5:3
    frame #2: 0x00007ff73e2813d9 sample.exe`b at sample.c:10:3
    frame #3: 0x00007ff73e2813c9 sample.exe`c at sample.c:15:3
    frame #4: 0x00007ff73e2813b4 sample.exe`main at sample.c:19:3
    frame #5: 0x00007ff73e281316 sample.exe`__tmainCRTStartup at
crtexe.c:272:15
    frame #6: 0x00007ff73e281366 sample.exe`mainCRTStartup at crtexe.c:193:9
    frame #7: 0x00007ff90dff7614 kernel32.dll`BaseThreadInitThunk + 20
    frame #8: 0x00007ff90f1a26a1 ntdll.dll`RtlUserThreadStart + 33
(lldb)

See also: https://gitlab.com/inkscape/inkscape/-/issues/4031#note_1231250877,
where we encountered this issue due to libepoxy returning NULL function
pointers

Thank you!
Luca

-- 
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 gdb/30255] GDB on Windows cannot retrieve a stacktrace when a NULL function pointer is called
  2023-03-20 17:30 [Bug gdb/30255] New: GDB on Windows cannot retrieve a stacktrace when a NULL function pointer is called luca.bacci at outlook dot com
@ 2023-03-21 15:46 ` tromey at sourceware dot org
  2023-03-21 15:54 ` [Bug win32/30255] " tromey at sourceware dot org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: tromey at sourceware dot org @ 2023-03-21 15:46 UTC (permalink / raw)
  To: gdb-prs

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

Tom Tromey <tromey at sourceware dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2023-03-21
                 CC|                            |tromey at sourceware dot org
     Ever confirmed|0                           |1

--- Comment #1 from Tom Tromey <tromey at sourceware dot org> ---
I can reproduce.

-- 
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 win32/30255] GDB on Windows cannot retrieve a stacktrace when a NULL function pointer is called
  2023-03-20 17:30 [Bug gdb/30255] New: GDB on Windows cannot retrieve a stacktrace when a NULL function pointer is called luca.bacci at outlook dot com
  2023-03-21 15:46 ` [Bug gdb/30255] " tromey at sourceware dot org
@ 2023-03-21 15:54 ` tromey at sourceware dot org
  2023-03-21 16:20 ` tromey at sourceware dot org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: tromey at sourceware dot org @ 2023-03-21 15:54 UTC (permalink / raw)
  To: gdb-prs

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

Tom Tromey <tromey at sourceware dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|gdb                         |win32

--- Comment #2 from Tom Tromey <tromey at sourceware dot org> ---
Changing component.

-- 
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 win32/30255] GDB on Windows cannot retrieve a stacktrace when a NULL function pointer is called
  2023-03-20 17:30 [Bug gdb/30255] New: GDB on Windows cannot retrieve a stacktrace when a NULL function pointer is called luca.bacci at outlook dot com
  2023-03-21 15:46 ` [Bug gdb/30255] " tromey at sourceware dot org
  2023-03-21 15:54 ` [Bug win32/30255] " tromey at sourceware dot org
@ 2023-03-21 16:20 ` tromey at sourceware dot org
  2023-03-21 18:30 ` tromey at sourceware dot org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: tromey at sourceware dot org @ 2023-03-21 16:20 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #3 from Tom Tromey <tromey at sourceware dot org> ---
I wonder where the unwound PC comes from.

-- 
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 win32/30255] GDB on Windows cannot retrieve a stacktrace when a NULL function pointer is called
  2023-03-20 17:30 [Bug gdb/30255] New: GDB on Windows cannot retrieve a stacktrace when a NULL function pointer is called luca.bacci at outlook dot com
                   ` (2 preceding siblings ...)
  2023-03-21 16:20 ` tromey at sourceware dot org
@ 2023-03-21 18:30 ` tromey at sourceware dot org
  2023-03-21 19:43 ` tromey at sourceware dot org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: tromey at sourceware dot org @ 2023-03-21 18:30 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #4 from Tom Tromey <tromey at sourceware dot org> ---
(In reply to Tom Tromey from comment #3)
> I wonder where the unwound PC comes from.

Probably right there on the stack:

(gdb) x/20xb $sp
0x5ffd68:       0xf1    0x16    0x35    0x8e    0xf7    0x7f    0x00    0x00

(gdb) disassemble $
Dump of assembler code for function a:
   0x00007ff78e3516e0 <+0>:     push   %rbp
   0x00007ff78e3516e1 <+1>:     mov    %rsp,%rbp
   0x00007ff78e3516e4 <+4>:     sub    $0x20,%rsp
   0x00007ff78e3516e8 <+8>:     mov    0x5951(%rip),%rax        #
0x7ff78e357040 <func_ptr>
   0x00007ff78e3516ef <+15>:    call   *%rax
   0x00007ff78e3516f1 <+17>:    nop

-- 
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 win32/30255] GDB on Windows cannot retrieve a stacktrace when a NULL function pointer is called
  2023-03-20 17:30 [Bug gdb/30255] New: GDB on Windows cannot retrieve a stacktrace when a NULL function pointer is called luca.bacci at outlook dot com
                   ` (3 preceding siblings ...)
  2023-03-21 18:30 ` tromey at sourceware dot org
@ 2023-03-21 19:43 ` tromey at sourceware dot org
  2023-03-21 20:22 ` luca.bacci at outlook dot com
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: tromey at sourceware dot org @ 2023-03-21 19:43 UTC (permalink / raw)
  To: gdb-prs

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

Tom Tromey <tromey at sourceware dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at sourceware dot org   |tromey at sourceware dot org

--- Comment #5 from Tom Tromey <tromey at sourceware dot org> ---
https://sourceware.org/pipermail/gdb-patches/2023-March/198196.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 win32/30255] GDB on Windows cannot retrieve a stacktrace when a NULL function pointer is called
  2023-03-20 17:30 [Bug gdb/30255] New: GDB on Windows cannot retrieve a stacktrace when a NULL function pointer is called luca.bacci at outlook dot com
                   ` (4 preceding siblings ...)
  2023-03-21 19:43 ` tromey at sourceware dot org
@ 2023-03-21 20:22 ` luca.bacci at outlook dot com
  2023-04-10 14:41 ` cvs-commit at gcc dot gnu.org
  2023-04-10 14:42 ` tromey at sourceware dot org
  7 siblings, 0 replies; 9+ messages in thread
From: luca.bacci at outlook dot com @ 2023-03-21 20:22 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #6 from Luca Bacci <luca.bacci at outlook dot com> ---
Great. Thank you very much, Tom!

-- 
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 win32/30255] GDB on Windows cannot retrieve a stacktrace when a NULL function pointer is called
  2023-03-20 17:30 [Bug gdb/30255] New: GDB on Windows cannot retrieve a stacktrace when a NULL function pointer is called luca.bacci at outlook dot com
                   ` (5 preceding siblings ...)
  2023-03-21 20:22 ` luca.bacci at outlook dot com
@ 2023-04-10 14:41 ` cvs-commit at gcc dot gnu.org
  2023-04-10 14:42 ` tromey at sourceware dot org
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-04-10 14:41 UTC (permalink / raw)
  To: gdb-prs

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

--- Comment #7 from cvs-commit at gcc dot gnu.org <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Tom Tromey <tromey@sourceware.org>:

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

commit a0f6c61c9ab998cd77b0899a4bdea9576d6d775f
Author: Tom Tromey <tromey@adacore.com>
Date:   Tue Mar 21 13:40:03 2023 -0600

    Handle unwinding from SEGV on Windows

    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

-- 
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 win32/30255] GDB on Windows cannot retrieve a stacktrace when a NULL function pointer is called
  2023-03-20 17:30 [Bug gdb/30255] New: GDB on Windows cannot retrieve a stacktrace when a NULL function pointer is called luca.bacci at outlook dot com
                   ` (6 preceding siblings ...)
  2023-04-10 14:41 ` cvs-commit at gcc dot gnu.org
@ 2023-04-10 14:42 ` tromey at sourceware dot org
  7 siblings, 0 replies; 9+ messages in thread
From: tromey at sourceware dot org @ 2023-04-10 14:42 UTC (permalink / raw)
  To: gdb-prs

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

Tom Tromey <tromey at sourceware dot org> changed:

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

--- Comment #8 from Tom Tromey <tromey at sourceware dot 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

end of thread, other threads:[~2023-04-10 14:42 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-20 17:30 [Bug gdb/30255] New: GDB on Windows cannot retrieve a stacktrace when a NULL function pointer is called luca.bacci at outlook dot com
2023-03-21 15:46 ` [Bug gdb/30255] " tromey at sourceware dot org
2023-03-21 15:54 ` [Bug win32/30255] " tromey at sourceware dot org
2023-03-21 16:20 ` tromey at sourceware dot org
2023-03-21 18:30 ` tromey at sourceware dot org
2023-03-21 19:43 ` tromey at sourceware dot org
2023-03-21 20:22 ` luca.bacci at outlook dot com
2023-04-10 14:41 ` cvs-commit at gcc dot gnu.org
2023-04-10 14:42 ` tromey at sourceware dot 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).