From patchwork Tue Aug 1 16:39:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Maciej W. Rozycki" X-Patchwork-Id: 21841 Received: (qmail 101982 invoked by alias); 1 Aug 2017 16:39:21 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 101957 invoked by uid 89); 1 Aug 2017 16:39:20 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy= X-Spam-User: qpsmtpd, 2 recipients X-HELO: mailapp01.imgtec.com Received: from mailapp01.imgtec.com (HELO mailapp01.imgtec.com) (195.59.15.196) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 01 Aug 2017 16:39:19 +0000 Received: from HHMAIL01.hh.imgtec.org (unknown [10.100.10.19]) by Forcepoint Email with ESMTPS id C2DE7F3F27989; Tue, 1 Aug 2017 17:39:11 +0100 (IST) Received: from [10.20.78.24] (10.20.78.24) by HHMAIL01.hh.imgtec.org (10.100.10.21) with Microsoft SMTP Server id 14.3.294.0; Tue, 1 Aug 2017 17:39:15 +0100 Date: Tue, 1 Aug 2017 17:39:33 +0100 From: "Maciej W. Rozycki" To: , CC: Alan Modra , Yao Qi Subject: [PATCH] GDB/opcodes: Remove arch/mach/endian disassembler assertions Message-ID: User-Agent: Alpine 2.00 (DEB 1167 2008-08-23) MIME-Version: 1.0 Fix `set architecture' and `set endian' command disassembly regressions from commit 39503f82427e ("Delegate opcodes to select disassembler in GDB"), and commit 003ca0fd2286 ("Refactor disassembler selection"), as well as a MIPS compressed ISA disassembly target regression from commit 6394c606997f ("Don't use print_insn_XXX in GDB"), which caused assertion failures to trigger. For example with the `mips-linux-gnu' target we get: $ cat main.c int main (void) { return 0; } $ gcc -mips32r2 -O2 main.c -o main $ gcc -mips16 -mips32r2 -O2 main.c -o main16 $ gdb GNU gdb (GDB) 8.0.50.20170731-git [...] (gdb) file main Reading symbols from main...done. (gdb) show architecture The target architecture is set automatically (currently mips:isa32r2) (gdb) show endian The target endianness is set automatically (currently big endian) (gdb) disassemble main Dump of assembler code for function main: 0x00400500 <+0>: jr ra 0x00400504 <+4>: move v0,zero End of assembler dump. (gdb) set architecture mips:isa64r2 The target architecture is assumed to be mips:isa64r2 (gdb) disassemble main Dump of assembler code for function main: 0x00400500 <+0>: .../gdb/arch-utils.c:979: internal-error: int default_print_insn(bfd_vma, disassemble_info*): Assertion `info->mach == bfd_get_mach (exec_bfd)' failed. A problem internal to GDB has been detected, further debugging may prove unreliable. Quit this debugging session? (y or n) n [...] Command aborted. (gdb) set architecture auto The target architecture is set automatically (currently mips:isa32r2) (gdb) set endian little The target is assumed to be little endian (gdb) disassemble main Dump of assembler code for function main: 0x00400500 <+0>: .../gdb/arch-utils.c:978: internal-error: int default_print_insn(bfd_vma, disassemble_info*): Assertion `info->endian == (bfd_big_endian (exec_bfd) ? BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE)' failed. A problem internal to GDB has been detected, further debugging may prove unreliable. Quit this debugging session? (y or n) n [...] Command aborted. (gdb) set endian auto The target endianness is set automatically (currently big endian) (gdb) set architecture i386 The target architecture is assumed to be i386 (gdb) disassemble main Dump of assembler code for function main: 0x00400500 <+0>: .../gdb/arch-utils.c:976: internal-error: int default_print_insn(bfd_vma, disassemble_info*): Assertion `info->arch == bfd_get_arch (exec_bfd)' failed. A problem internal to GDB has been detected, further debugging may prove unreliable. Quit this debugging session? (y or n) n [...] Command aborted. (gdb) set architecture auto The target architecture is set automatically (currently mips:isa32r2) (gdb) file main16 Load new symbol table from "main16"? (y or n) y Reading symbols from main16...done. (gdb) disassemble main Dump of assembler code for function main: 0x00400501 <+0>: .../gdb/arch-utils.c:979: internal-error: int default_print_insn(bfd_vma, disassemble_info*): Assertion `info->mach == bfd_get_mach (exec_bfd)' failed. A problem internal to GDB has been detected, further debugging may prove unreliable. Quit this debugging session? (y or n) n Command aborted. (gdb) Remove the assertions then, restoring previous semantics: (gdb) file main Reading symbols from main...done. (gdb) set architecture mips:isa64r2 The target architecture is assumed to be mips:isa64r2 (gdb) disassemble main Dump of assembler code for function main: 0x00400500 <+0>: jr ra 0x00400504 <+4>: move v0,zero End of assembler dump. (gdb) set endian little The target is assumed to be little endian (gdb) disassemble main Dump of assembler code for function main: 0x00400500 <+0>: j 0x3800c 0x00400504 <+4>: addiu s0,t0,0 End of assembler dump. (gdb) set architecture i386 The target architecture is assumed to be i386 (gdb) disassemble main Dump of assembler code for function main: 0x00400500 <+0>: add %eax,%esp 0x00400502 <+2>: add %cl,(%eax) 0x00400504 <+4>: add %al,(%eax) 0x00400506 <+6>: adc %ah,0x0 End of assembler dump. (gdb) set architecture auto The target architecture is set automatically (currently mips:isa32r2) (gdb) set endian auto The target endianness is set automatically (currently big endian) (gdb) file main16 Load new symbol table from "main16"? (y or n) y Reading symbols from main16...done. (gdb) disassemble main Dump of assembler code for function main: 0x00400501 <+0>: jr ra 0x00400503 <+2>: li v0,0 End of assembler dump. (gdb) gdb/ * arch-utils.c (default_print_insn): Remove arch/mach/endian assertions. opcodes/ * disassemble.c (disassembler): Remove arch/mach/endian assertions. --- Hi, Regression-tested with GDB using the `mips-linux-gnu' target, o32 ABI, bringing the number of failures down by ~300. Also no regressions between plain commit 6394c606997f^ and commit 6394c606997f with this patch applied (as long as the mem-break fix, posted separately, has been also applied). OK to apply. Maciej --- gdb/arch-utils.c | 7 ------- opcodes/disassemble.c | 13 +------------ 2 files changed, 1 insertion(+), 19 deletions(-) gdb-opcode-disassemble-assert.diff Index: binutils/gdb/arch-utils.c =================================================================== --- binutils.orig/gdb/arch-utils.c 2017-07-31 16:21:27.410997829 +0100 +++ binutils/gdb/arch-utils.c 2017-07-31 16:22:15.571550657 +0100 @@ -971,13 +971,6 @@ default_print_insn (bfd_vma memaddr, dis { disassembler_ftype disassemble_fn; - if (exec_bfd != NULL) - { - gdb_assert (info->arch == bfd_get_arch (exec_bfd)); - gdb_assert (info->endian == (bfd_big_endian (exec_bfd) - ? BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE)); - gdb_assert (info->mach == bfd_get_mach (exec_bfd)); - } disassemble_fn = disassembler (info->arch, info->endian == BFD_ENDIAN_BIG, info->mach, exec_bfd); Index: binutils/opcodes/disassemble.c =================================================================== --- binutils.orig/opcodes/disassemble.c 2017-07-31 11:12:12.000000000 +0100 +++ binutils/opcodes/disassemble.c 2017-07-31 16:23:47.294937646 +0100 @@ -111,21 +111,10 @@ disassembler_ftype disassembler (enum bfd_architecture a, bfd_boolean big, unsigned long mach, - bfd *abfd) + bfd *abfd ATTRIBUTE_UNUSED) { disassembler_ftype disassemble; - if (abfd != NULL) - { - /* Do some asserts that the first three parameters should equal - to what we can get from ABFD. On the other hand, these - asserts help removing some compiler errors on unused - parameter. */ - assert (a == bfd_get_arch (abfd)); - assert (big == bfd_big_endian (abfd)); - assert (mach == bfd_get_mach (abfd)); - } - switch (a) { /* If you add a case to this table, also add it to the