From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1879) id 1C9603871029; Mon, 16 Mar 2020 20:58:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1C9603871029 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Simon Marchi To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb: recognize 64 bits Windows executables as Cygwin osabi X-Act-Checkin: binutils-gdb X-Git-Author: Simon Marchi X-Git-Refname: refs/heads/master X-Git-Oldrev: 2f89101fe8b6a2423116a1ad1891f56bf6fc9510 X-Git-Newrev: cb9b645d3e6b6164317104ed1a2a41c06da37bf4 Message-Id: <20200316205820.1C9603871029@sourceware.org> Date: Mon, 16 Mar 2020 20:58:20 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 Mar 2020 20:58:20 -0000 https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=cb9b645d3e6b6164317104ed1a2a41c06da37bf4 commit cb9b645d3e6b6164317104ed1a2a41c06da37bf4 Author: Simon Marchi Date: Mon Mar 16 16:56:33 2020 -0400 gdb: recognize 64 bits Windows executables as Cygwin osabi If I generate two Windows PE executables, one 32 bits and one 64 bits: $ x86_64-w64-mingw32-gcc test.c -g3 -O0 -o test_64 $ i686-w64-mingw32-gcc test.c -g3 -O0 -o test_32 $ file test_64 test_64: PE32+ executable (console) x86-64, for MS Windows $ file test_32 test_32: PE32 executable (console) Intel 80386, for MS Windows When I load the 32 bits binary in my GNU/Linux-hosted GDB, the osabi is correctly recognized as "Cygwin": $ ./gdb --data-directory=data-directory -nx test_32 (gdb) show osabi The current OS ABI is "auto" (currently "Cygwin"). When I load the 64 bits binary in GDB, the osabi is incorrectly recognized as "GNU/Linux": $ ./gdb --data-directory=data-directory -nx test_64 (gdb) show osabi The current OS ABI is "auto" (currently "GNU/Linux"). The 32 bits one gets recognized by the i386_cygwin_osabi_sniffer function, by its target name: if (strcmp (target_name, "pei-i386") == 0) return GDB_OSABI_CYGWIN; The target name for the 64 bits binaries is "pei-x86-64". It doesn't get recognized by any osabi sniffer, so GDB falls back on its default osabi, "GNU/Linux". This patch adds an osabi sniffer function for the Windows 64 bits executables in amd64-windows-tdep.c. With it, the osabi is recognized as "Cygwin", just like with the 32 bits binary. Note that it may seems strange to have a binary generated by MinGW (which has nothing to do with Cygwin) be recognized as a Cygwin binary. This is indeed not accurate, but at the moment GDB uses the Cygwin for everything Windows. Subsequent patches will add a separate "Windows" OS ABI for Windows binaries that are not Cygwin binaries. gdb/ChangeLog: * amd64-windows-tdep.c (amd64_windows_osabi_sniffer): New function. (_initialize_amd64_windows_tdep): Register osabi sniffer. Diff: --- gdb/ChangeLog | 6 ++++++ gdb/amd64-windows-tdep.c | 14 ++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index a0d97584189..1b83f4226d2 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2020-03-16 Simon Marchi + + * amd64-windows-tdep.c (amd64_windows_osabi_sniffer): New + function. + (_initialize_amd64_windows_tdep): Register osabi sniffer. + 2020-03-14 Tom Tromey * c-typeprint.c (cp_type_print_method_args): Print "__restrict__" diff --git a/gdb/amd64-windows-tdep.c b/gdb/amd64-windows-tdep.c index d4d79682dd1..2ca979513cd 100644 --- a/gdb/amd64-windows-tdep.c +++ b/gdb/amd64-windows-tdep.c @@ -1244,10 +1244,24 @@ amd64_windows_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) set_gdbarch_auto_wide_charset (gdbarch, amd64_windows_auto_wide_charset); } +static gdb_osabi +amd64_windows_osabi_sniffer (bfd *abfd) +{ + const char *target_name = bfd_get_target (abfd); + + if (strcmp (target_name, "pei-x86-64") == 0) + return GDB_OSABI_CYGWIN; + + return GDB_OSABI_UNKNOWN; +} + void _initialize_amd64_windows_tdep (); void _initialize_amd64_windows_tdep () { gdbarch_register_osabi (bfd_arch_i386, bfd_mach_x86_64, GDB_OSABI_CYGWIN, amd64_windows_init_abi); + + gdbarch_register_osabi_sniffer (bfd_arch_i386, bfd_target_coff_flavour, + amd64_windows_osabi_sniffer); }