GDB/opcodes: Remove arch/mach/endian disassembler assertions
authorMaciej W. Rozycki <macro@imgtec.com>
Mon, 7 Aug 2017 14:53:54 +0000 (15:53 +0100)
committerMaciej W. Rozycki <macro@imgtec.com>
Mon, 7 Aug 2017 14:53:54 +0000 (15:53 +0100)
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.

gdb/ChangeLog
gdb/arch-utils.c
opcodes/ChangeLog
opcodes/disassemble.c

index 818f43878f4ee92ea3557ed9c42b648212edc190..d550938ae9c180b86b89be68acffa043016d58c1 100644 (file)
@@ -1,3 +1,8 @@
+2017-08-07  Maciej W. Rozycki  <macro@imgtec.com>
+
+       * arch-utils.c (default_print_insn): Remove arch/mach/endian
+       assertions.
+
 2017-08-07  Maciej W. Rozycki  <macro@imgtec.com>
 
        * gdbarch.sh (gdbarch_info): Replace the `tdep_info' member with
index 0402eba04a80c88709a65138a656d9ee281223e2..4e0fdf4a6835fe7a1e8916fe438d4ef9efeab5bc 100644 (file)
@@ -971,13 +971,6 @@ default_print_insn (bfd_vma memaddr, disassemble_info *info)
 {
   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 59ff038f482bb1b1b53b45d423d25aa2b95bf094..61572ddd297b76954b28ea698fcfa6663fb51852 100644 (file)
@@ -1,3 +1,8 @@
+2017-08-07  Maciej W. Rozycki  <macro@imgtec.com>
+
+       * disassemble.c (disassembler): Remove arch/mach/endian
+       assertions.
+
 2017-07-25  Nick Clifton  <nickc@redhat.com>
 
        PR 21739
index cd134e87189a323ae0ef87e1452dbb0cd572c21e..00583542655de5aa28745c2434c0ee8cf92c9b6b 100644 (file)
 
 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
This page took 0.083467 seconds and 4 git commands to generate.