MSYS2-packages/gdb/0004-7.8-symtab-cygwin.patch
Christoph Reiter 0a70e5f8f2 gdb: sync patches from cygwin
to make the next update easier

* sync all patches
* change numbering for non-cygwin patches
* remove useless diff from 1006-autoreconf.patch
2024-07-09 07:19:01 +02:00

69 lines
2.5 KiB
Diff

From a9f50b60641820dd44819b9ffe54bea49a461bf5 Mon Sep 17 00:00:00 2001
From: Jon Turney <jon.turney@dronecode.org.uk>
Date: Sun, 24 Jul 2016 18:18:10 +0100
Subject: [PATCH 4/6] 7.8-symtab-cygwin.patch
See https://sourceware.org/ml/gdb-patches/2002-03/msg00557.html
---
gdb/symtab.c | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/gdb/symtab.c b/gdb/symtab.c
index e9bc7b2c933..dc92e8ee3c6 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -896,6 +896,10 @@ create_demangled_names_hash (struct objfile_per_bfd_storage *per_bfd)
free_demangled_name_entry, xcalloc, xfree));
}
+#ifdef __CYGWIN__
+#define LINKER_SYMBOLS_HAVE_WIN32_STDCALL_ARG_SIZES (1)
+#endif
+
/* See symtab.h */
gdb::unique_xmalloc_ptr<char>
@@ -905,6 +909,39 @@ symbol_find_demangled_name (struct general_symbol_info *gsymbol,
gdb::unique_xmalloc_ptr<char> demangled;
int i;
+ /* On Windows, some functions use the `stdcall' calling convention,
+ in which the callee is expected to pop the arguments off the
+ stack. Normally, the caller takes care of this, because only the
+ caller knows how many arguments it really passed. To avoid
+ confusion, the linker symbols for `stdcall' functions have names
+ with a suffix "@N" attached to them, where "N" is the number of
+ bytes they'll pop. That way, if a caller thinks some `stdcall'
+ function `foo' expects M argument bytes, but the definition of
+ `foo' expects N argument bytes, N != M, then the call will be a
+ reference to `foo@M', but the definition will have a linker
+ symbol `foo@N', and you'll get a link-time `symbol not found'
+ error, instead of a crash at run-time.
+
+ (Note how this fails to address calls through function pointers,
+ since the byte count isn't part of the function pointer's type.
+ Go, Microsoft!)
+
+ Whatever. But our demangler doesn't like that '@N' suffix, so we
+ need to strip it off. */
+ if (LINKER_SYMBOLS_HAVE_WIN32_STDCALL_ARG_SIZES)
+ {
+ char *arg_byte_suffix = strchr (mangled, '@');
+ if (arg_byte_suffix)
+ {
+ int prefix_len = arg_byte_suffix - mangled;
+ char *mangled_sans_suffix = (char *)(alloca (prefix_len + 1));
+ memcpy (mangled_sans_suffix, mangled, prefix_len);
+ mangled_sans_suffix[prefix_len] = '\0';
+
+ mangled = mangled_sans_suffix;
+ }
+ }
+
if (gsymbol->language () != language_unknown)
{
const struct language_defn *lang = language_def (gsymbol->language ());
--
2.42.1