From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from barracuda.ebox.ca (barracuda.ebox.ca [96.127.255.19]) by sourceware.org (Postfix) with ESMTPS id D7A933871029 for ; Mon, 16 Mar 2020 17:08:49 +0000 (GMT) X-ASG-Debug-ID: 1584378527-0c856e18f3b31c90001-fS2M51 Received: from smtp.ebox.ca (smtp.ebox.ca [96.127.255.82]) by barracuda.ebox.ca with ESMTP id vGkwZC4GBnAO98EI (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 16 Mar 2020 13:08:47 -0400 (EDT) X-Barracuda-Envelope-From: simon.marchi@polymtl.ca X-Barracuda-RBL-Trusted-Forwarder: 96.127.255.82 Received: from simark.lan (unknown [192.222.164.54]) by smtp.ebox.ca (Postfix) with ESMTP id CAE38441B21; Mon, 16 Mar 2020 13:08:47 -0400 (EDT) From: Simon Marchi X-Barracuda-Effective-Source-IP: 192-222-164-54.qc.cable.ebox.net[192.222.164.54] X-Barracuda-Apparent-Source-IP: 192.222.164.54 X-Barracuda-RBL-IP: 192.222.164.54 To: gdb-patches@sourceware.org Cc: Eli Zaretskii , Jon Turney , Simon Marchi Subject: [PATCH 1/7] gdb: recognize 64 bits Windows executables as Cygwin osabi Date: Mon, 16 Mar 2020 13:08:39 -0400 X-ASG-Orig-Subj: [PATCH 1/7] gdb: recognize 64 bits Windows executables as Cygwin osabi Message-Id: <20200316170845.184386-2-simon.marchi@polymtl.ca> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200316170845.184386-1-simon.marchi@polymtl.ca> References: <20200316170845.184386-1-simon.marchi@polymtl.ca> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Barracuda-Connect: smtp.ebox.ca[96.127.255.82] X-Barracuda-Start-Time: 1584378527 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://96.127.255.19:443/cgi-mod/mark.cgi X-Barracuda-Scan-Msg-Size: 2963 X-Virus-Scanned: by bsmtpd at ebox.ca X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.00 X-Barracuda-Spam-Status: No, SCORE=0.00 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=8.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.80637 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- X-Spam-Status: No, score=-23.5 required=5.0 tests=GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_DMARC_QUARANTINE, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_SOFTFAIL autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 Mar 2020 17:08:51 -0000 From: Simon Marchi 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. --- gdb/amd64-windows-tdep.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/gdb/amd64-windows-tdep.c b/gdb/amd64-windows-tdep.c index d4d79682dd18..2ca979513cd7 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); } -- 2.25.1