Arm: Fix disassembler crashing on -b binary when thumb file and thumb not forced.
authorTamar Christina <tamar.christina@arm.com>
Fri, 19 Oct 2018 09:31:42 +0000 (10:31 +0100)
committerTamar Christina <tamar.christina@arm.com>
Fri, 19 Oct 2018 09:33:11 +0000 (10:33 +0100)
The disassembler for Arm has some aborts in it in places it assumes can never
be reached.  Under normal circumstances they indeed cannot be reached because
the right options are selected from the ARM attributes in the ELF file.

However when disassembling with -b binary then if you do not get the options
right the disassembler just aborts.  This changes it so it just prints how it
was trying to interpret the instruction and prints UNKNOWN instructions next to it.

This way the user has an idea of what's going.

gas/ChangeLog:

* testsuite/gas/arm/undefined-insn-arm.d: New test.
* testsuite/gas/arm/undefined-insn-thumb.d: New test.
* testsuite/gas/arm/undefined-insn.s: New test.

opcodes/ChangeLog:

* arm-dis.c (UNKNOWN_INSTRUCTION_32BIT): Format specifier for arm mode.
(UNKNOWN_INSTRUCTION_16BIT): Format specifier for thumb mode.
(print_insn_arm, print_insn_thumb16, print_insn_thumb32): Use them.

gas/ChangeLog
gas/testsuite/gas/arm/undefined-insn-arm.d [new file with mode: 0644]
gas/testsuite/gas/arm/undefined-insn-thumb.d [new file with mode: 0644]
gas/testsuite/gas/arm/undefined-insn.s [new file with mode: 0644]
opcodes/ChangeLog
opcodes/arm-dis.c

index ff9de52ce80c53ee2c45bffd347c2ba85eb81944..7f9b0e4f9c62cce2b02f602a0d5bcbf5edf80261 100644 (file)
@@ -1,3 +1,9 @@
+2018-10-19  Tamar Christina  <tamar.christina@arm.com>
+
+       * testsuite/gas/arm/undefined-insn-arm.d: New test.
+       * testsuite/gas/arm/undefined-insn-thumb.d: New test.
+       * testsuite/gas/arm/undefined-insn.s: New test.
+
 2018-10-19  Fredrik Noring  <noring@nocrew.org>
 
        * testsuite/gas/mips/r5900.s: Extend the R5900 short loop fix
diff --git a/gas/testsuite/gas/arm/undefined-insn-arm.d b/gas/testsuite/gas/arm/undefined-insn-arm.d
new file mode 100644 (file)
index 0000000..265a507
--- /dev/null
@@ -0,0 +1,5 @@
+#name: Undefined binary printing in arm mode
+#skip: *-unknown-pe *-*-vxworks
+#source: undefined-insn.s
+#objdump: -D -b binary -m armv7e-m
+#...
diff --git a/gas/testsuite/gas/arm/undefined-insn-thumb.d b/gas/testsuite/gas/arm/undefined-insn-thumb.d
new file mode 100644 (file)
index 0000000..72385f0
--- /dev/null
@@ -0,0 +1,5 @@
+#name: Undefined binary printing in thumb mode
+#skip: *-unknown-pe *-*-vxworks
+#source: undefined-insn.s
+#objdump: -D -b binary -m armv7e-m -M force-thumb
+#...
diff --git a/gas/testsuite/gas/arm/undefined-insn.s b/gas/testsuite/gas/arm/undefined-insn.s
new file mode 100644 (file)
index 0000000..cf59a03
--- /dev/null
@@ -0,0 +1 @@
+       .inst 0xffffffff
index 4f5e200e38d94264447468fd8a97269d8dadf124..3d26869e51f6225131c1e899f1907b63d1f2ce8c 100644 (file)
@@ -1,3 +1,9 @@
+2018-10-19  Tamar Christina  <tamar.christina@arm.com>
+
+       * arm-dis.c (UNKNOWN_INSTRUCTION_32BIT): Format specifier for arm mode.
+       (UNKNOWN_INSTRUCTION_16BIT): Format specifier for thumb mode.
+       (print_insn_arm, print_insn_thumb16, print_insn_thumb32): Use them.
+
 2018-10-16  Matthew Malcomson  <matthew.malcomson@arm.com>
 
        * aarch64-opc.c (struct operand_qualifier_data): Change qualifier data
index f22a78f70d551bf8033a2d2b5b9b44243fd020c0..f0b90510c60071e4fbd835fbed3adce1aa0189d7 100644 (file)
@@ -141,6 +141,8 @@ enum opcode_sentinel_enum
 } opcode_sentinels;
 
 #define UNDEFINED_INSTRUCTION      "\t\t; <UNDEFINED> instruction: %0-31x"
+#define UNKNOWN_INSTRUCTION_32BIT  "\t\t; <UNDEFINED> instruction: %08x"
+#define UNKNOWN_INSTRUCTION_16BIT  "\t\t; <UNDEFINED> instruction: %04x"
 #define UNPREDICTABLE_INSTRUCTION  "\t; <UNPREDICTABLE>"
 
 /* Common coprocessor opcodes shared between Arm and Thumb-2.  */
@@ -5194,7 +5196,8 @@ print_insn_arm (bfd_vma pc, struct disassemble_info *info, long given)
          return;
        }
     }
-  abort ();
+  func (stream, UNKNOWN_INSTRUCTION_32BIT, (unsigned)given);
+  return;
 }
 
 /* Print one 16-bit Thumb instruction from PC on INFO->STREAM.  */
@@ -5465,7 +5468,8 @@ print_insn_thumb16 (bfd_vma pc, struct disassemble_info *info, long given)
       }
 
   /* No match.  */
-  abort ();
+  func (stream, UNKNOWN_INSTRUCTION_16BIT, (unsigned)given);
+  return;
 }
 
 /* Return the name of an V7M special register.  */
@@ -6089,7 +6093,8 @@ print_insn_thumb32 (bfd_vma pc, struct disassemble_info *info, long given)
       }
 
   /* No match.  */
-  abort ();
+  func (stream, UNKNOWN_INSTRUCTION_32BIT, (unsigned)given);
+  return;
 }
 
 /* Print data bytes on INFO->STREAM.  */
This page took 0.031504 seconds and 4 git commands to generate.