Refactor disassembler selection
authorYao Qi <yao.qi@linaro.org>
Wed, 24 May 2017 16:23:52 +0000 (17:23 +0100)
committerYao Qi <yao.qi@linaro.org>
Wed, 24 May 2017 16:23:52 +0000 (17:23 +0100)
Nowadays, opcodes/disassemble.c:disassembler selects the proper
disassembler according to ABFD only.  However, it actually
selects disassemblers according to arch, mach, endianess, and
abfd.  This patch adds them to the parameters of disassembler,
so that its caller can still select disassemblers in case that
abfd is NULL (a typical case in GDB).

There isn't any functionality change.

binutils:

2017-05-24  Yao Qi  <yao.qi@linaro.org>

* objdump.c (disassemble_data): Caller update.

include:

2017-05-24  Yao Qi  <yao.qi@linaro.org>

* dis-asm.h (disassembler): Update declaration.

opcodes:

2017-05-24  Yao Qi  <yao.qi@linaro.org>

* disassemble.c (disassembler): Add arguments a, big and mach.
Use them.

sim/common:

2017-05-24  Yao Qi  <yao.qi@linaro.org>

* sim-trace.c (trace_disasm): Caller update.

binutils/ChangeLog
binutils/objdump.c
include/ChangeLog
include/dis-asm.h
opcodes/ChangeLog
opcodes/disassemble.c
sim/common/ChangeLog
sim/common/sim-trace.c

index 60a199a5dbe882f043f510eb5db6721367d5ec05..b2f0f11f4508fb5df86eb707571dad0a8665baac 100644 (file)
@@ -1,3 +1,7 @@
+2017-05-24  Yao Qi  <yao.qi@linaro.org>
+
+       * objdump.c (disassemble_data): Caller update.
+
 2017-05-19  Jose E. Marchesi  <jose.marchesi@oracle.com>
 
        * objcopy.c (merge_gnu_build_notes): Remove workaround that
index 5972da1d4e027c0942125ccc54567d4af117ca68..81d47a0a250b11151b625ff011daef9417e45e7e 100644 (file)
@@ -2386,7 +2386,9 @@ disassemble_data (bfd *abfd)
     }
 
   /* Use libopcodes to locate a suitable disassembler.  */
-  aux.disassemble_fn = disassembler (abfd);
+  aux.disassemble_fn = disassembler (bfd_get_arch (abfd),
+                                    bfd_big_endian (abfd),
+                                    bfd_get_mach (abfd), abfd);
   if (!aux.disassemble_fn)
     {
       non_fatal (_("can't disassemble for architecture %s\n"),
index 35c99adf8e5d40b5347a87409f5aad31a4ce88c6..3eccaae03f87e35f662073953cc96fcbd2922cae 100644 (file)
@@ -1,3 +1,7 @@
+2017-05-24  Yao Qi  <yao.qi@linaro.org>
+
+       * dis-asm.h (disassembler): Update declaration.
+
 2017-05-23  Claudiu Zissulescu <claziss@synopsys.com>
 
        * opcode/arc.h (MAX_INSN_FLGS): Update to 4.
index 6f1801df98d01cd69c9e2daf66138424539e7dc7..dd935049e84d4fc9525b75cb113994730980326c 100644 (file)
@@ -354,8 +354,12 @@ extern const disasm_options_t *disassembler_options_powerpc (void);
 extern const disasm_options_t *disassembler_options_arm (void);
 extern const disasm_options_t *disassembler_options_s390 (void);
 
-/* Fetch the disassembler for a given BFD, if that support is available.  */
-extern disassembler_ftype disassembler (bfd *);
+/* Fetch the disassembler for a given architecture ARC, endianess (big
+   endian if BIG is true), bfd_mach value MACH, and ABFD, if that support
+   is available.  ABFD may be NULL.  */
+extern disassembler_ftype disassembler (enum bfd_architecture arc,
+                                       bfd_boolean big, unsigned long mach,
+                                       bfd *abfd);
 
 /* Amend the disassemble_info structure as necessary for the target architecture.
    Should only be called after initialising the info->arch field.  */
index 026c3f4a53f2f10fd8e1495eed6b9b805e91f72d..b461d78259110e40071cf073473d2f47edf87977 100644 (file)
@@ -1,3 +1,8 @@
+2017-05-24  Yao Qi  <yao.qi@linaro.org>
+
+       * disassemble.c (disassembler): Add arguments a, big and mach.
+       Use them.
+
 2017-05-22  H.J. Lu  <hongjiu.lu@intel.com>
 
        * i386-dis.c (NOTRACK_Fixup): New.
index dd7d3a32b78a17ab38e6c47fa560ec7208fe6654..e79b5c7d3836c994fcaaf05203bd1c43e848f573 100644 (file)
@@ -21,6 +21,7 @@
 #include "sysdep.h"
 #include "dis-asm.h"
 #include "safe-ctype.h"
+#include <assert.h>
 
 #ifdef ARCH_all
 #define ARCH_aarch64
 #endif
 
 disassembler_ftype
-disassembler (bfd *abfd)
+disassembler (enum bfd_architecture a, bfd_boolean big, unsigned long mach,
+             bfd *abfd)
 {
-  enum bfd_architecture a = bfd_get_arch (abfd);
   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
@@ -135,7 +147,7 @@ disassembler (bfd *abfd)
 #endif
 #ifdef ARCH_arm
     case bfd_arch_arm:
-      if (bfd_big_endian (abfd))
+      if (big)
        disassemble = print_insn_big_arm;
       else
        disassemble = print_insn_little_arm;
@@ -184,13 +196,12 @@ disassembler (bfd *abfd)
 #endif
 #ifdef ARCH_h8300
     case bfd_arch_h8300:
-      if (bfd_get_mach (abfd) == bfd_mach_h8300h
-         || bfd_get_mach (abfd) == bfd_mach_h8300hn)
+      if (mach == bfd_mach_h8300h || mach == bfd_mach_h8300hn)
        disassemble = print_insn_h8300h;
-      else if (bfd_get_mach (abfd) == bfd_mach_h8300s
-              || bfd_get_mach (abfd) == bfd_mach_h8300sn
-              || bfd_get_mach (abfd) == bfd_mach_h8300sx
-              || bfd_get_mach (abfd) == bfd_mach_h8300sxn)
+      else if (mach == bfd_mach_h8300s
+              || mach == bfd_mach_h8300sn
+              || mach == bfd_mach_h8300sx
+              || mach == bfd_mach_h8300sxn)
        disassemble = print_insn_h8300s;
       else
        disassemble = print_insn_h8300;
@@ -326,7 +337,7 @@ disassembler (bfd *abfd)
 #endif
 #ifdef ARCH_mips
     case bfd_arch_mips:
-      if (bfd_big_endian (abfd))
+      if (big)
        disassemble = print_insn_big_mips;
       else
        disassemble = print_insn_little_mips;
@@ -349,7 +360,7 @@ disassembler (bfd *abfd)
 #endif
 #ifdef ARCH_nios2
     case bfd_arch_nios2:
-      if (bfd_big_endian (abfd))
+      if (big)
        disassemble = print_insn_big_nios2;
       else
        disassemble = print_insn_little_nios2;
@@ -372,7 +383,7 @@ disassembler (bfd *abfd)
 #endif
 #ifdef ARCH_powerpc
     case bfd_arch_powerpc:
-      if (bfd_big_endian (abfd))
+      if (big)
        disassemble = print_insn_big_powerpc;
       else
        disassemble = print_insn_little_powerpc;
@@ -390,7 +401,7 @@ disassembler (bfd *abfd)
 #endif
 #ifdef ARCH_rs6000
     case bfd_arch_rs6000:
-      if (bfd_get_mach (abfd) == bfd_mach_ppc_620)
+      if (mach == bfd_mach_ppc_620)
        disassemble = print_insn_big_powerpc;
       else
        disassemble = print_insn_rs6000;
@@ -413,7 +424,7 @@ disassembler (bfd *abfd)
 #endif
 #ifdef ARCH_score
     case bfd_arch_score:
-      if (bfd_big_endian (abfd))
+      if (big)
        disassemble = print_insn_big_score;
       else
        disassemble = print_insn_little_score;
@@ -507,7 +518,7 @@ disassembler (bfd *abfd)
 #endif
 #ifdef ARCH_z8k
     case bfd_arch_z8k:
-      if (bfd_get_mach(abfd) == bfd_mach_z8001)
+      if (mach == bfd_mach_z8001)
        disassemble = print_insn_z8001;
       else
        disassemble = print_insn_z8002;
index 0d4ec46a3e3a6e8bb0799511d06e518a42c92b70..65c2f8bdce68dd033824b7ec3f812a8fb8ebe4d6 100644 (file)
@@ -1,3 +1,7 @@
+2017-05-24  Yao Qi  <yao.qi@linaro.org>
+
+       * sim-trace.c (trace_disasm): Caller update.
+
 2016-08-15  Mike Frysinger  <vapier@gentoo.org>
 
        * sim-base.h (sim_state_base): Add prog_syms_count.
index da19b829d5be80394698c95bb739e69c254e046d..ff11d20f0e9d393ca4fe8393af75c1baabd09170 100644 (file)
@@ -919,7 +919,11 @@ trace_disasm (SIM_DESC sd, sim_cpu *cpu, address_word addr)
   if (trace_data->dis_bfd != bfd)
     {
       trace_data->dis_bfd = bfd;
-      trace_data->disassembler = disassembler (trace_data->dis_bfd);
+      trace_data->disassembler
+       = disassembler (bfd_get_arch (trace_data->dis_bfd),
+                       bfd_big_endian (trace_data->dis_bfd),
+                       bfd_get_mach (trace_data->dis_bfd),
+                       trace_data->dis_bfd);
       INIT_DISASSEMBLE_INFO (*info, cpu, dis_printf);
       info->read_memory_func = dis_read;
       info->arch = bfd_get_arch (bfd);