Share i386-linux target description between GDB and GDBserver
authorYao Qi <yao.qi@linaro.org>
Tue, 5 Sep 2017 08:54:53 +0000 (09:54 +0100)
committerYao Qi <yao.qi@linaro.org>
Tue, 5 Sep 2017 08:54:53 +0000 (09:54 +0100)
The code on creating i386-linux target descriptions are quite similar
between GDB and GDBserver, so this patch moves them into a shared file
arch/i386.c.  I didn't name it as i386-linux.c, because I want to reuse it
to create other i386 non-linux target descriptions later.

gdb:

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

* Makefile.in (ALL_TARGET_OBS): Add i386.o.
(SFILES): Add arch/i386.c.
(HFILES_NO_SRCDIR): Add arch/i386.h.
* arch/i386.c: New file.
* arch/i386.h: New file.
* arch/tdesc.h (allocate_target_description): Declare.
(set_tdesc_architecture): Declare.
(set_tdesc_osabi): Declare.
* configure.tgt (i[34567]86-*-linux*): Add i386.o.
* i386-linux-tdep.c: Don't include ../features/i386/32bit-XXX.c.
include arch/i386.h.
(i386_linux_read_description): Remove code and call
i386_create_target_description.
(set_tdesc_architecture): New function.
(set_tdesc_osabi): New function.
* target-descriptions.h (allocate_target_description): Remove.

gdb/gdbserver:

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

* Makefile.in (arch-i386.o): New rule.
* configure.srv (i[34567]86-*-linux*): Add arch-i386.o.
(x86_64-*-linux*): Likewise.
* linux-x86-tdesc.c: Don't include ../features/i386/32bit-XXX.c,
include arch/i386.h.
(i386_linux_read_description): Remove code and call
i386_create_target_description.
* tdesc.c (allocate_target_description): New function.
* tdesc.h (set_tdesc_architecture): Remove declaration.
(set_tdesc_osabi): Likewise.

15 files changed:
gdb/ChangeLog
gdb/Makefile.in
gdb/arch/i386.c [new file with mode: 0644]
gdb/arch/i386.h [new file with mode: 0644]
gdb/arch/tdesc.h
gdb/configure.tgt
gdb/gdbserver/ChangeLog
gdb/gdbserver/Makefile.in
gdb/gdbserver/configure.srv
gdb/gdbserver/linux-x86-tdesc.c
gdb/gdbserver/tdesc.c
gdb/gdbserver/tdesc.h
gdb/i386-linux-tdep.c
gdb/target-descriptions.c
gdb/target-descriptions.h

index 0ac42e480d7a22ac4e8c4747d7a26c09009e17cc..66fbca8dae10843868eba1458c784bdec3020e60 100644 (file)
@@ -1,3 +1,22 @@
+2017-09-05  Yao Qi  <yao.qi@linaro.org>
+
+       * Makefile.in (ALL_TARGET_OBS): Add i386.o.
+       (SFILES): Add arch/i386.c.
+       (HFILES_NO_SRCDIR): Add arch/i386.h.
+       * arch/i386.c: New file.
+       * arch/i386.h: New file.
+       * arch/tdesc.h (allocate_target_description): Declare.
+       (set_tdesc_architecture): Declare.
+       (set_tdesc_osabi): Declare.
+       * configure.tgt (i[34567]86-*-linux*): Add i386.o.
+       * i386-linux-tdep.c: Don't include ../features/i386/32bit-XXX.c.
+       include arch/i386.h.
+       (i386_linux_read_description): Remove code and call
+       i386_create_target_description.
+       (set_tdesc_architecture): New function.
+       (set_tdesc_osabi): New function.
+       * target-descriptions.h (allocate_target_description): Remove.
+
 2017-09-05  Yao Qi  <yao.qi@linaro.org>
 
        * arch/tdesc.h (tdesc_create_feature): Add an argument xml.
index d9094fd956f0aafc30308a331b7521b1d78ae395..2caa67437d553f43ecbd7d87308af52e02fbc1d8 100644 (file)
@@ -814,6 +814,7 @@ ALL_TARGET_OBS = \
        hppa-nbsd-tdep.o \
        hppa-obsd-tdep.o \
        hppa-tdep.o \
+       i386.o \
        i386-bsd-tdep.o \
        i386-cygwin-tdep.o \
        i386-darwin-tdep.o \
@@ -1032,6 +1033,7 @@ SFILES = \
        agent.c \
        annotate.c \
        arch-utils.c \
+       arch/i386.c \
        auto-load.c \
        auxv.c \
        ax-gdb.c \
@@ -1502,6 +1504,7 @@ HFILES_NO_SRCDIR = \
        xtensa-tdep.h \
        arch/aarch64-insn.h \
        arch/arm.h \
+       arch/i386.h \
        cli/cli-cmds.h \
        cli/cli-decode.h \
        cli/cli-script.h \
diff --git a/gdb/arch/i386.c b/gdb/arch/i386.c
new file mode 100644 (file)
index 0000000..60cf63b
--- /dev/null
@@ -0,0 +1,66 @@
+/* Copyright (C) 2017 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include "i386.h"
+#include "tdesc.h"
+#include "x86-xstate.h"
+#include <stdlib.h>
+
+#include "../features/i386/32bit-core.c"
+#include "../features/i386/32bit-linux.c"
+#include "../features/i386/32bit-sse.c"
+#include "../features/i386/32bit-avx.c"
+#include "../features/i386/32bit-avx512.c"
+#include "../features/i386/32bit-mpx.c"
+#include "../features/i386/32bit-pkeys.c"
+
+/* Create i386 target descriptions according to XCR0.  */
+
+target_desc *
+i386_create_target_description (uint64_t xcr0)
+{
+  target_desc *tdesc = allocate_target_description ();
+
+#ifndef IN_PROCESS_AGENT
+  set_tdesc_architecture (tdesc, "i386");
+  set_tdesc_osabi (tdesc, "GNU/Linux");
+#endif
+
+  long regnum = 0;
+
+  if (xcr0 & X86_XSTATE_X87)
+    regnum = create_feature_i386_32bit_core (tdesc, regnum);
+
+  if (xcr0 & X86_XSTATE_SSE)
+    regnum = create_feature_i386_32bit_sse (tdesc, regnum);
+
+  regnum = create_feature_i386_32bit_linux (tdesc, regnum);
+
+  if (xcr0 & X86_XSTATE_AVX)
+    regnum = create_feature_i386_32bit_avx (tdesc, regnum);
+
+  if (xcr0 & X86_XSTATE_MPX)
+    regnum = create_feature_i386_32bit_mpx (tdesc, regnum);
+
+  if (xcr0 & X86_XSTATE_AVX512)
+    regnum = create_feature_i386_32bit_avx512 (tdesc, regnum);
+
+  if (xcr0 & X86_XSTATE_PKRU)
+    regnum = create_feature_i386_32bit_pkeys (tdesc, regnum);
+
+  return tdesc;
+}
diff --git a/gdb/arch/i386.h b/gdb/arch/i386.h
new file mode 100644 (file)
index 0000000..0163372
--- /dev/null
@@ -0,0 +1,21 @@
+/* Copyright (C) 2017 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include "tdesc.h"
+#include <stdint.h>
+
+target_desc *i386_create_target_description (uint64_t xcr0);
index bf50e24bd9f67d5b8db59baafbd1d2a36e57e841..78bb0fb1524c01515b91d6444e91e6b10b824797 100644 (file)
@@ -23,6 +23,16 @@ struct tdesc_type;
 struct tdesc_reg;
 struct target_desc;
 
+/* Allocate a new target_desc.  */
+target_desc *allocate_target_description (void);
+
+/* Set TARGET_DESC's architecture by NAME.  */
+void set_tdesc_architecture (target_desc *target_desc,
+                            const char *name);
+
+/* Set TARGET_DESC's osabi by NAME.  */
+void set_tdesc_osabi (target_desc *target_desc, const char *name);
+
 /* Return the type associated with ID in the context of FEATURE, or
    NULL if none.  */
 struct tdesc_type *tdesc_named_type (const struct tdesc_feature *feature,
index fdcb7b1d69dd3ed49f3ae3f76b48b8d9dcc9545f..1f263515fd4df77f14af986c5ea49ecb89d0ba66 100644 (file)
@@ -228,7 +228,8 @@ i[34567]86-*-solaris*)
        ;;
 i[34567]86-*-linux*)
        # Target: Intel 386 running GNU/Linux
-       gdb_target_obs="i386-tdep.o i386-linux-tdep.o glibc-tdep.o i387-tdep.o \
+       gdb_target_obs="i386-tdep.o i386.o i386-linux-tdep.o \
+                       glibc-tdep.o i387-tdep.o \
                        solib-svr4.o symfile-mem.o \
                        linux-tdep.o linux-record.o"
        if test "x$enable_64_bit_bfd" = "xyes"; then
@@ -678,7 +679,7 @@ x86_64-*-elf*)
 x86_64-*-linux*)
        # Target: GNU/Linux x86-64
        gdb_target_obs="amd64-tdep.o amd64-linux-tdep.o i386-tdep.o \
-                       i387-tdep.o i386-linux-tdep.o glibc-tdep.o \
+                       i387-tdep.o i386.o i386-linux-tdep.o glibc-tdep.o \
                        solib-svr4.o symfile-mem.o linux-tdep.o linux-record.o"
        build_gdbserver=yes
        ;;
index 595faf59fe33678d710ef44007f5c38218834291..2a3d8d214fa5fb7b296a99756789165853f7af0c 100644 (file)
@@ -1,3 +1,16 @@
+2017-09-05  Yao Qi  <yao.qi@linaro.org>
+
+       * Makefile.in (arch-i386.o): New rule.
+       * configure.srv (i[34567]86-*-linux*): Add arch-i386.o.
+       (x86_64-*-linux*): Likewise.
+       * linux-x86-tdesc.c: Don't include ../features/i386/32bit-XXX.c,
+       include arch/i386.h.
+       (i386_linux_read_description): Remove code and call
+       i386_create_target_description.
+       * tdesc.c (allocate_target_description): New function.
+       * tdesc.h (set_tdesc_architecture): Remove declaration.
+       (set_tdesc_osabi): Likewise.
+
 2017-09-05  Yao Qi  <yao.qi@linaro.org>
 
        * linux-x86-tdesc.c: Don't include <inttypes.h>.
index 416115202d202aa5e6b41ad34fa367a488a4c965..b552b698147df91043d845f6a761f149f3acf4e3 100644 (file)
@@ -528,6 +528,10 @@ ax.o: ax.c
        $(COMPILE) $(WARN_CFLAGS_NO_FORMAT) $<
        $(POSTCOMPILE)
 
+arch-i386.o: ../arch/i386.c
+       $(COMPILE) $<
+       $(POSTCOMPILE)
+
 # Rules for objects that go in the in-process agent.
 
 %-ipa.o: %-generated.c
@@ -553,6 +557,10 @@ ax.o: ax.c
        $(IPAGENT_COMPILE) $<
        $(POSTCOMPILE)
 
+%-ipa.o: ../arch/%.c
+       $(IPAGENT_COMPILE) $<
+       $(POSTCOMPILE)
+
 # Rules for objects that go in the gdbserver binary.
 
 %.o: %-generated.c
index 1a270120be044cf78280cd2fffa8ab7b104072ab..876098b670f9b12460db184d69b9aad1d254ada3 100644 (file)
@@ -122,6 +122,7 @@ case "${target}" in
                            srv_xmlfiles="${srv_xmlfiles} $srv_amd64_linux_xmlfiles"
                            srv_tgtobj="amd64-linux-siginfo.o"
                        fi
+                       srv_tgtobj="${srv_tgtobj} arch-i386.o"
                        srv_tgtobj="${srv_tgtobj} $srv_linux_obj linux-x86-low.o x86-low.o x86-dregs.o i387-fp.o"
                        srv_tgtobj="${srv_tgtobj} linux-x86-tdesc.o"
                        srv_tgtobj="${srv_tgtobj} linux-btrace.o x86-linux.o"
@@ -131,6 +132,7 @@ case "${target}" in
                        srv_linux_thread_db=yes
                        srv_linux_btrace=yes
                        ipa_obj="${ipa_i386_linux_regobj} linux-i386-ipa.o linux-x86-tdesc-ipa.o"
+                       ipa_obj="${ipa_obj} i386-ipa.o"
                        ;;
   i[34567]86-*-lynxos*)        srv_regobj="i386.o"
                        srv_tgtobj="lynx-low.o lynx-i386-low.o fork-child.o fork-inferior.o"
@@ -358,6 +360,7 @@ case "${target}" in
                        ;;
   x86_64-*-linux*)     srv_regobj="$srv_amd64_linux_regobj $srv_i386_linux_regobj"
                        srv_tgtobj="$srv_linux_obj linux-x86-low.o x86-low.o x86-dregs.o i387-fp.o"
+                       srv_tgtobj="${srv_tgtobj} arch-i386.o"
                        srv_tgtobj="${srv_tgtobj} linux-x86-tdesc.o"
                        srv_tgtobj="${srv_tgtobj} linux-btrace.o x86-linux.o"
                        srv_tgtobj="${srv_tgtobj} x86-linux-dregs.o"
index 3f63d8ee78f68bfb2fb0d561a5ee3767a5dd7ffc..548e7805f260088ed8bb5e69d401280492b699a2 100644 (file)
 #include "server.h"
 #include "tdesc.h"
 #include "linux-x86-tdesc.h"
-#include "x86-xstate.h"
+#include "arch/i386.h"
+#include "common/x86-xstate.h"
 
 #if defined __i386__ || !defined IN_PROCESS_AGENT
-#include "../features/i386/32bit-core.c"
-#include "../features/i386/32bit-linux.c"
-#include "../features/i386/32bit-sse.c"
-#include "../features/i386/32bit-avx.c"
-#include "../features/i386/32bit-avx512.c"
-#include "../features/i386/32bit-mpx.c"
-#include "../features/i386/32bit-pkeys.c"
 
 /* Defined in auto-generated file i386-linux.c.  */
 void init_registers_i386_linux (void);
@@ -142,34 +136,7 @@ i386_linux_read_description (uint64_t xcr0)
 
   if (*tdesc == NULL)
     {
-      *tdesc = new target_desc ();
-
-#ifndef IN_PROCESS_AGENT
-      set_tdesc_architecture (*tdesc, "i386");
-      set_tdesc_osabi (*tdesc, "GNU/Linux");
-#endif
-
-      long regnum = 0;
-
-      if (xcr0 & X86_XSTATE_X87)
-       regnum = create_feature_i386_32bit_core (*tdesc, regnum);
-
-      if (xcr0 & X86_XSTATE_SSE)
-       regnum = create_feature_i386_32bit_sse (*tdesc, regnum);
-
-      regnum = create_feature_i386_32bit_linux (*tdesc, regnum);
-
-      if (xcr0 & X86_XSTATE_AVX)
-       regnum = create_feature_i386_32bit_avx (*tdesc, regnum);
-
-      if (xcr0 & X86_XSTATE_MPX)
-       regnum = create_feature_i386_32bit_mpx (*tdesc, regnum);
-
-      if (xcr0 & X86_XSTATE_AVX512)
-       regnum = create_feature_i386_32bit_avx512 (*tdesc, regnum);
-
-      if (xcr0 & X86_XSTATE_PKRU)
-       regnum = create_feature_i386_32bit_pkeys (*tdesc, regnum);
+      *tdesc = i386_create_target_description (xcr0);
 
       init_target_desc (*tdesc);
 
index 0b5096bbf761900e4b662d0cd034b8c6da3a9a62..53f36d556472602ceee6066bf9a76ffeacd559f2 100644 (file)
@@ -39,6 +39,12 @@ init_target_desc (struct target_desc *tdesc)
   gdb_assert (2 * tdesc->registers_size + 32 <= PBUFSIZ);
 }
 
+struct target_desc *
+allocate_target_description (void)
+{
+  return new target_desc ();
+}
+
 #ifndef IN_PROCESS_AGENT
 
 static const struct target_desc default_description {};
@@ -62,6 +68,8 @@ current_target_desc (void)
   return current_process ()->tdesc;
 }
 
+/* See arch/tdesc.h.  */
+
 void
 set_tdesc_architecture (struct target_desc *target_desc,
                        const char *name)
@@ -69,6 +77,8 @@ set_tdesc_architecture (struct target_desc *target_desc,
   target_desc->arch = xstrdup (name);
 }
 
+/* See arch/tdesc.h.  */
+
 void
 set_tdesc_osabi (struct target_desc *target_desc, const char *name)
 {
index fe3c78ff058509a8210566d42cf207cf89be474c..71249e4eda03e4499a2d85297c55875fea05bf1a 100644 (file)
@@ -142,10 +142,6 @@ void init_target_desc (struct target_desc *tdesc);
 const struct target_desc *current_target_desc (void);
 
 #ifndef IN_PROCESS_AGENT
-void set_tdesc_architecture (struct target_desc *target_desc,
-                            const char *name);
-void set_tdesc_osabi (struct target_desc *target_desc, const char *name);
-
 const char *tdesc_get_features_xml (struct target_desc *tdesc);
 #endif
 
index 792706caec34bdee9ac29a27d558e5b9b493de93..c47aa6e8caf45b82c06d0c1a11088faf6c56f11f 100644 (file)
 #include "record-full.h"
 #include "linux-record.h"
 
-#include "features/i386/32bit-core.c"
-#include "features/i386/32bit-sse.c"
-#include "features/i386/32bit-linux.c"
-#include "features/i386/32bit-avx.c"
-#include "features/i386/32bit-mpx.c"
-#include "features/i386/32bit-avx512.c"
-#include "features/i386/32bit-pkeys.c"
+#include "arch/i386.h"
 #include "target-descriptions.h"
 
 /* Return non-zero, when the register is in the corresponding register
@@ -700,33 +694,7 @@ i386_linux_read_description (uint64_t xcr0)
     [(xcr0 & X86_XSTATE_PKRU) ? 1 : 0];
 
   if (*tdesc == NULL)
-    {
-      *tdesc = allocate_target_description ();
-      set_tdesc_architecture (*tdesc, bfd_scan_arch ("i386"));
-      set_tdesc_osabi (*tdesc, osabi_from_tdesc_string ("GNU/Linux"));
-
-      long regnum = 0;
-
-      if (xcr0 & X86_XSTATE_X87)
-       regnum = create_feature_i386_32bit_core (*tdesc, regnum);
-
-      if (xcr0 & X86_XSTATE_SSE)
-       regnum = create_feature_i386_32bit_sse (*tdesc, regnum);
-
-      regnum = create_feature_i386_32bit_linux (*tdesc, regnum);
-
-      if (xcr0 & X86_XSTATE_AVX)
-       regnum = create_feature_i386_32bit_avx (*tdesc, regnum);
-
-      if (xcr0 & X86_XSTATE_MPX)
-       regnum = create_feature_i386_32bit_mpx (*tdesc, regnum);
-
-      if (xcr0 & X86_XSTATE_AVX512)
-       regnum = create_feature_i386_32bit_avx512 (*tdesc, regnum);
-
-      if (xcr0 & X86_XSTATE_PKRU)
-       regnum = create_feature_i386_32bit_pkeys (*tdesc, regnum);
-    }
+    *tdesc = i386_create_target_description (xcr0);
 
   return *tdesc;
 }
index 6135e0d99eea359bf6ccd2e7c541e58c57baed7b..7a8dac0e93b33fbf32a2259b692af72e64a7e9e6 100644 (file)
@@ -1823,6 +1823,15 @@ set_tdesc_property (struct target_desc *target_desc,
   VEC_safe_push (property_s, target_desc->properties, &new_prop);
 }
 
+/* See arch/tdesc.h.  */
+
+void
+set_tdesc_architecture (struct target_desc *target_desc,
+                       const char *name)
+{
+  set_tdesc_architecture (target_desc, bfd_scan_arch (name));
+}
+
 void
 set_tdesc_architecture (struct target_desc *target_desc,
                        const struct bfd_arch_info *arch)
@@ -1830,6 +1839,14 @@ set_tdesc_architecture (struct target_desc *target_desc,
   target_desc->arch = arch;
 }
 
+/* See arch/tdesc.h.  */
+
+void
+set_tdesc_osabi (struct target_desc *target_desc, const char *name)
+{
+  set_tdesc_osabi (target_desc, osabi_from_tdesc_string (name));
+}
+
 void
 set_tdesc_osabi (struct target_desc *target_desc, enum gdb_osabi osabi)
 {
index c4f9b92e456d5fcd23eba0e5d3d3a1ac394d8555..e97a3738e221691e165ef559a658d68801aef455 100644 (file)
@@ -201,7 +201,6 @@ int tdesc_register_in_reggroup_p (struct gdbarch *gdbarch, int regno,
 
 /* Methods for constructing a target description.  */
 
-struct target_desc *allocate_target_description (void);
 struct cleanup *make_cleanup_free_target_description (struct target_desc *);
 void set_tdesc_architecture (struct target_desc *,
                             const struct bfd_arch_info *);