binutils-gdb/gdb/windows-tdep.h
Jon Turney ff4e230326 Teach gdb how to unwind cygwin _sigbe and sigdelayed frames
The majority of functions in the cygwin DLL are wrapped by routines
which use an an alternate stack to return via a signal handler if a
signal occured while inside the function. (See [1],[2])

At present, these frames cannot be correctly unwound by gdb.  There
doesn't seem to currently be a way to correctly describe these frames
using DWARF CFI.

So instead, write a custom unwinder for _sigbe and sigdelayed frames,
which gets the return address from the alternate stack.

The offset of tls::stackptr from TIB.stacktop is determined by analyzing
the code in _sigbe or sigdelayed.

This can backtrace from _sigbe and from a sighandler through sigdelayed.

Implemented for amd64 and i386

Issues:

1. We should detect if we are in the wrapper after the return address
has been popped off the alternate stack, and if so, fetch the return
address from the register it's been popped into.

2. If there are multiple _sigbe or sigdelayed stack frames to be
unwound, this only unwinds the first one correctly, because we don't
unwind the value of the alternate stack pointer itself.

This is no worse than currently, when we can't even unwind one of
these frame correctly, but isn't quite correct.

I guess this could be handled by defining a pseudo-register to track
its value as we unwind the stack.

[1] https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;a=blob;f=winsup/cygwin/gendef
[2] https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;a=blob;f=winsup/cygwin/how-signals-work.txt

Co-Authored-By: Pedro Alves <pedro@palves.net>
Change-Id: I4a0d02c1b85d0aadaab2de3abd584eb4bda5b5cc
2024-02-23 16:16:18 +00:00

79 lines
2.6 KiB
C++

/* Copyright (C) 2008-2024 Free Software Foundation, Inc.
This file is part of GDB.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#ifndef WINDOWS_TDEP_H
#define WINDOWS_TDEP_H
#include "frame-unwind.h"
struct gdbarch;
extern struct cmd_list_element *info_w32_cmdlist;
extern void init_w32_command_list (void);
extern void windows_xfer_shared_library (const char* so_name,
CORE_ADDR load_addr,
CORE_ADDR *text_offset_cached,
struct gdbarch *gdbarch,
std::string &xml);
extern ULONGEST windows_core_xfer_shared_libraries (struct gdbarch *gdbarch,
gdb_byte *readbuf,
ULONGEST offset,
ULONGEST len);
extern std::string windows_core_pid_to_str (struct gdbarch *gdbarch,
ptid_t ptid);
/* To be called from the various GDB_OSABI_WINDOWS handlers for the
various Windows architectures and machine types. */
extern void windows_init_abi (struct gdbarch_info info,
struct gdbarch *gdbarch);
/* To be called from the various GDB_OSABI_CYGWIN handlers for the
various Windows architectures and machine types. */
extern void cygwin_init_abi (struct gdbarch_info info,
struct gdbarch *gdbarch);
/* Return true if the Portable Executable behind ABFD uses the Cygwin dll
(cygwin1.dll). */
extern bool is_linked_with_cygwin_dll (bfd *abfd);
/* Cygwin sigwapper unwinder. Unwinds signal frames over
sigbe/sigdelayed. */
struct cygwin_sigwrapper_frame_unwind : public frame_unwind
{
explicit cygwin_sigwrapper_frame_unwind
(gdb::array_view<const gdb::array_view<const gdb_byte>> patterns_list);
/* Architecture-specific list of instruction patterns to match.
It's a list of patterns instead of single pattern because some
architectures want to match more than one function
(sigbe/sigdelayed & friends). Each potential instruction
sequence is assumed to be followed by 4 bytes for tls::stackptr.
If any pattern in the list matches, then the frame is assumed to
be a sigwrapper frame. */
gdb::array_view<const gdb::array_view<const gdb_byte>> patterns_list;
};
#endif