aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYao Qi <yao.qi@linaro.org>2017-05-23 16:21:12 +0100
committerYao Qi <yao.qi@linaro.org>2017-06-20 11:34:13 +0100
commit30bf6941157218d5b0093794f935de5f418cbfa0 (patch)
tree59fff884d8b5c7e11c51fed54672ecca63d78989
parent260e831b2914a676b7cc1949e2df94a0732a4078 (diff)
downloadgdb-30bf6941157218d5b0093794f935de5f418cbfa0.zip
gdb-30bf6941157218d5b0093794f935de5f418cbfa0.tar.gz
gdb-30bf6941157218d5b0093794f935de5f418cbfa0.tar.bz2
[GDBserver] Centralize tdesc for i386-linux
tdesc_i386_XXX_linux is spread in linux-x86-low.c and this patch adds a new function i386_get_ipa_tdesc to return the right tdesc according to tdesc index. Note that GDB has a similar function returning tdesc, but with different argument. Ultimately, GDB and GDBserver should share this function. gdb/gdbserver: 2017-06-07 Yao Qi <yao.qi@linaro.org> * configure.srv (srv_tgtobj): Append linux-x86-tdesc.o. (ipa_obj): Likewise. * linux-i386-ipa.c (get_ipa_tdesc): Move it to linux-x86-tdesc.c. (initialize_low_tracepoint): Don't call init_registers_XXX functions, call initialize_low_tdesc instead. * linux-x86-low.c (x86_linux_read_description): Call i386_get_ipa_tdesc. (initialize_low_arch): Don't call init_registers_i386_XXX functions, call initialize_low_tdesc. * linux-x86-tdesc.c: New file. * linux-x86-tdesc.h (x86_linux_tdesc): New X86_TDESC_LAST. (i386_get_ipa_tdesc_idx): Declare. (i386_get_ipa_tdesc): Declare. (initialize_low_tdesc): Declare.
-rw-r--r--gdb/gdbserver/configure.srv6
-rw-r--r--gdb/gdbserver/linux-i386-ipa.c36
-rw-r--r--gdb/gdbserver/linux-x86-low.c44
-rw-r--r--gdb/gdbserver/linux-x86-tdesc.c111
-rw-r--r--gdb/gdbserver/linux-x86-tdesc.h31
5 files changed, 135 insertions, 93 deletions
diff --git a/gdb/gdbserver/configure.srv b/gdb/gdbserver/configure.srv
index 43f90c9..1a5801a 100644
--- a/gdb/gdbserver/configure.srv
+++ b/gdb/gdbserver/configure.srv
@@ -122,13 +122,14 @@ case "${target}" in
srv_tgtobj="amd64-linux-siginfo.o"
fi
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"
srv_tgtobj="${srv_tgtobj} x86-linux-dregs.o"
srv_linux_usrregs=yes
srv_linux_regsets=yes
srv_linux_thread_db=yes
srv_linux_btrace=yes
- ipa_obj="${ipa_i386_linux_regobj} linux-i386-ipa.o"
+ ipa_obj="${ipa_i386_linux_regobj} linux-i386-ipa.o linux-x86-tdesc-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"
@@ -356,6 +357,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} linux-x86-tdesc.o"
srv_tgtobj="${srv_tgtobj} linux-btrace.o x86-linux.o"
srv_tgtobj="${srv_tgtobj} x86-linux-dregs.o"
srv_tgtobj="${srv_tgtobj} amd64-linux-siginfo.o"
@@ -369,7 +371,7 @@ case "${target}" in
else
ipa_obj="${ipa_amd64_linux_regobj}"
fi
- ipa_obj="${ipa_obj} linux-amd64-ipa.o"
+ ipa_obj="${ipa_obj} linux-amd64-ipa.o linux-x86-tdesc-ipa.o"
;;
x86_64-*-mingw*) srv_regobj="$srv_amd64_regobj"
srv_tgtobj="x86-low.o x86-dregs.o i387-fp.o win32-low.o win32-i386-low.o"
diff --git a/gdb/gdbserver/linux-i386-ipa.c b/gdb/gdbserver/linux-i386-ipa.c
index e9ac78b..bca3fdb 100644
--- a/gdb/gdbserver/linux-i386-ipa.c
+++ b/gdb/gdbserver/linux-i386-ipa.c
@@ -244,35 +244,6 @@ initialize_fast_tracepoint_trampoline_buffer (void)
}
}
-/* Return target_desc to use for IPA, given the tdesc index passed by
- gdbserver. */
-
-const struct target_desc *
-get_ipa_tdesc (int idx)
-{
- switch (idx)
- {
- case X86_TDESC_MMX:
- return tdesc_i386_mmx_linux;
- case X86_TDESC_SSE:
- return tdesc_i386_linux;
- case X86_TDESC_AVX:
- return tdesc_i386_avx_linux;
- case X86_TDESC_MPX:
- return tdesc_i386_mpx_linux;
- case X86_TDESC_AVX_MPX:
- return tdesc_i386_avx_mpx_linux;
- case X86_TDESC_AVX_AVX512:
- return tdesc_i386_avx_avx512_linux;
- case X86_TDESC_AVX_MPX_AVX512_PKU:
- return tdesc_i386_avx_mpx_avx512_pku_linux;
- default:
- internal_error (__FILE__, __LINE__,
- "unknown ipa tdesc index: %d", idx);
- return tdesc_i386_linux;
- }
-}
-
/* Allocate buffer for the jump pads. On i386, we can reach an arbitrary
address with a jump instruction, so just allocate normally. */
@@ -291,12 +262,7 @@ alloc_jump_pad_buffer (size_t size)
void
initialize_low_tracepoint (void)
{
- init_registers_i386_mmx_linux ();
- init_registers_i386_linux ();
- init_registers_i386_avx_linux ();
- init_registers_i386_mpx_linux ();
- init_registers_i386_avx_avx512_linux ();
- init_registers_i386_avx_mpx_avx512_pku_linux ();
+ initialize_low_tdesc ();
initialize_fast_tracepoint_trampoline_buffer ();
}
diff --git a/gdb/gdbserver/linux-x86-low.c b/gdb/gdbserver/linux-x86-low.c
index b39026c..f5d4aa1 100644
--- a/gdb/gdbserver/linux-x86-low.c
+++ b/gdb/gdbserver/linux-x86-low.c
@@ -757,7 +757,7 @@ x86_linux_read_description (void)
{
have_ptrace_getfpxregs = 0;
have_ptrace_getregset = 0;
- return tdesc_i386_mmx_linux;
+ return i386_get_ipa_tdesc (X86_TDESC_MMX);
}
else
have_ptrace_getfpxregs = 1;
@@ -878,26 +878,26 @@ x86_linux_read_description (void)
switch (xcr0 & X86_XSTATE_ALL_MASK)
{
case X86_XSTATE_AVX_MPX_AVX512_PKU_MASK:
- return tdesc_i386_avx_mpx_avx512_pku_linux;
+ return i386_get_ipa_tdesc (X86_TDESC_AVX_MPX_AVX512_PKU);
case (X86_XSTATE_AVX_AVX512_MASK):
- return tdesc_i386_avx_avx512_linux;
+ return i386_get_ipa_tdesc (X86_TDESC_AVX_AVX512);
case (X86_XSTATE_MPX_MASK):
- return tdesc_i386_mpx_linux;
+ return i386_get_ipa_tdesc (X86_TDESC_MPX);
case (X86_XSTATE_AVX_MPX_MASK):
- return tdesc_i386_avx_mpx_linux;
+ return i386_get_ipa_tdesc (X86_TDESC_AVX_MPX);
case (X86_XSTATE_AVX_MASK):
- return tdesc_i386_avx_linux;
+ return i386_get_ipa_tdesc (X86_TDESC_AVX);
default:
- return tdesc_i386_linux;
+ return i386_get_ipa_tdesc (X86_TDESC_SSE);
}
}
else
- return tdesc_i386_linux;
+ return i386_get_ipa_tdesc (X86_TDESC_SSE);
}
gdb_assert_not_reached ("failed to return tdesc");
@@ -2912,22 +2912,10 @@ x86_get_ipa_tdesc_idx (void)
return X86_TDESC_AVX_AVX512;
#endif
- if (tdesc == tdesc_i386_mmx_linux)
- return X86_TDESC_MMX;
- if (tdesc == tdesc_i386_linux || tdesc == tdesc_i386_linux_no_xml)
+ if (tdesc == tdesc_i386_linux_no_xml)
return X86_TDESC_SSE;
- if (tdesc == tdesc_i386_avx_linux)
- return X86_TDESC_AVX;
- if (tdesc == tdesc_i386_mpx_linux)
- return X86_TDESC_MPX;
- if (tdesc == tdesc_i386_avx_mpx_linux)
- return X86_TDESC_AVX_MPX;
- if (tdesc == tdesc_i386_avx_mpx_avx512_pku_linux)
- return X86_TDESC_AVX_MPX_AVX512_PKU;
- if (tdesc == tdesc_i386_avx_avx512_linux)
- return X86_TDESC_AVX_AVX512;
- return 0;
+ return i386_get_ipa_tdesc_idx (tdesc);
}
/* This is initialized assuming an amd64 target.
@@ -2996,16 +2984,12 @@ initialize_low_arch (void)
copy_target_description (tdesc_amd64_linux_no_xml, tdesc_amd64_linux);
tdesc_amd64_linux_no_xml->xmltarget = xmltarget_amd64_linux_no_xml;
#endif
- init_registers_i386_linux ();
- init_registers_i386_mmx_linux ();
- init_registers_i386_avx_linux ();
- init_registers_i386_mpx_linux ();
- init_registers_i386_avx_mpx_linux ();
- init_registers_i386_avx_avx512_linux ();
- init_registers_i386_avx_mpx_avx512_pku_linux ();
+
+ initialize_low_tdesc ();
tdesc_i386_linux_no_xml = XNEW (struct target_desc);
- copy_target_description (tdesc_i386_linux_no_xml, tdesc_i386_linux);
+ copy_target_description (tdesc_i386_linux_no_xml,
+ i386_get_ipa_tdesc (X86_TDESC_SSE));
tdesc_i386_linux_no_xml->xmltarget = xmltarget_i386_linux_no_xml;
initialize_regsets_info (&x86_regsets_info);
diff --git a/gdb/gdbserver/linux-x86-tdesc.c b/gdb/gdbserver/linux-x86-tdesc.c
new file mode 100644
index 0000000..e294a98
--- /dev/null
+++ b/gdb/gdbserver/linux-x86-tdesc.c
@@ -0,0 +1,111 @@
+/* GNU/Linux/x86-64 specific target description, for the remote server
+ for GDB.
+ 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 "server.h"
+#include "linux-x86-tdesc.h"
+
+#if defined __i386__ || !defined IN_PROCESS_AGENT
+/* Defined in auto-generated file i386-linux.c. */
+void init_registers_i386_linux (void);
+extern const struct target_desc *tdesc_i386_linux;
+
+/* Defined in auto-generated file i386-mmx-linux.c. */
+void init_registers_i386_mmx_linux (void);
+extern const struct target_desc *tdesc_i386_mmx_linux;
+
+/* Defined in auto-generated file i386-avx-linux.c. */
+void init_registers_i386_avx_linux (void);
+extern const struct target_desc *tdesc_i386_avx_linux;
+
+/* Defined in auto-generated file i386-avx-mpx-linux.c. */
+void init_registers_i386_avx_mpx_linux (void);
+extern const struct target_desc *tdesc_i386_avx_mpx_linux;
+
+/* Defined in auto-generated file i386-avx-avx512-linux.c. */
+void init_registers_i386_avx_avx512_linux (void);
+extern const struct target_desc *tdesc_i386_avx_avx512_linux;
+
+/* Defined in auto-generated file i386-avx-mpx-avx512-linux.c. */
+void init_registers_i386_avx_mpx_avx512_pku_linux (void);
+extern const struct target_desc *tdesc_i386_avx_mpx_avx512_pku_linux;
+
+/* Defined in auto-generated file i386-mpx-linux.c. */
+void init_registers_i386_mpx_linux (void);
+extern const struct target_desc *tdesc_i386_mpx_linux;
+#endif
+
+static const struct target_desc *i386_tdescs[X86_TDESC_LAST] = { };
+
+void
+initialize_low_tdesc ()
+{
+#if defined __i386__ || !defined IN_PROCESS_AGENT
+ init_registers_i386_linux ();
+ init_registers_i386_mmx_linux ();
+ init_registers_i386_avx_linux ();
+ init_registers_i386_mpx_linux ();
+ init_registers_i386_avx_mpx_linux ();
+ init_registers_i386_avx_avx512_linux ();
+ init_registers_i386_avx_mpx_avx512_pku_linux ();
+
+ i386_tdescs[X86_TDESC_MMX] = tdesc_i386_mmx_linux;
+ i386_tdescs[X86_TDESC_SSE] = tdesc_i386_linux;
+ i386_tdescs[X86_TDESC_AVX] = tdesc_i386_avx_linux;
+ i386_tdescs[X86_TDESC_MPX] = tdesc_i386_mpx_linux;
+ i386_tdescs[X86_TDESC_AVX_MPX] = tdesc_i386_avx_mpx_linux;
+ i386_tdescs[X86_TDESC_AVX_AVX512] = tdesc_i386_avx_avx512_linux;
+ i386_tdescs[X86_TDESC_AVX_MPX_AVX512_PKU]
+ = tdesc_i386_avx_mpx_avx512_pku_linux;
+#endif
+}
+
+const struct target_desc *
+i386_get_ipa_tdesc (int idx)
+{
+ if (idx >= X86_TDESC_LAST)
+ internal_error (__FILE__, __LINE__,
+ "unknown ipa tdesc index: %d", idx);
+
+ return i386_tdescs[idx];
+}
+
+#ifdef IN_PROCESS_AGENT
+
+#if defined __i386__
+const struct target_desc *
+get_ipa_tdesc (int idx)
+{
+return i386_get_ipa_tdesc (idx);
+}
+#endif
+
+#else
+int
+i386_get_ipa_tdesc_idx (const struct target_desc *tdesc)
+{
+ for (int i = 0; i < X86_TDESC_LAST; i++)
+ {
+ if (tdesc == i386_tdescs[i])
+ return i;
+ }
+
+ return 0;
+}
+
+#endif
diff --git a/gdb/gdbserver/linux-x86-tdesc.h b/gdb/gdbserver/linux-x86-tdesc.h
index bbe4078..894cf4e 100644
--- a/gdb/gdbserver/linux-x86-tdesc.h
+++ b/gdb/gdbserver/linux-x86-tdesc.h
@@ -30,6 +30,7 @@ enum x86_linux_tdesc {
X86_TDESC_AVX_MPX = 4,
X86_TDESC_AVX_AVX512 = 5,
X86_TDESC_AVX_MPX_AVX512_PKU = 6,
+ X86_TDESC_LAST = 7,
};
#ifdef __x86_64__
@@ -77,31 +78,9 @@ extern const struct target_desc *tdesc_x32_avx_avx512_linux;
#endif
#if defined __i386__ || !defined IN_PROCESS_AGENT
-/* Defined in auto-generated file i386-linux.c. */
-void init_registers_i386_linux (void);
-extern const struct target_desc *tdesc_i386_linux;
-
-/* Defined in auto-generated file i386-mmx-linux.c. */
-void init_registers_i386_mmx_linux (void);
-extern const struct target_desc *tdesc_i386_mmx_linux;
-
-/* Defined in auto-generated file i386-avx-linux.c. */
-void init_registers_i386_avx_linux (void);
-extern const struct target_desc *tdesc_i386_avx_linux;
-
-/* Defined in auto-generated file i386-avx-mpx-linux.c. */
-void init_registers_i386_avx_mpx_linux (void);
-extern const struct target_desc *tdesc_i386_avx_mpx_linux;
-
-/* Defined in auto-generated file i386-avx-avx512-linux.c. */
-void init_registers_i386_avx_avx512_linux (void);
-extern const struct target_desc *tdesc_i386_avx_avx512_linux;
+int i386_get_ipa_tdesc_idx (const struct target_desc *tdesc);
+#endif
-/* Defined in auto-generated file i386-avx-mpx-avx512-linux.c. */
-void init_registers_i386_avx_mpx_avx512_pku_linux (void);
-extern const struct target_desc *tdesc_i386_avx_mpx_avx512_pku_linux;
+const struct target_desc *i386_get_ipa_tdesc (int idx);
-/* Defined in auto-generated file i386-mpx-linux.c. */
-void init_registers_i386_mpx_linux (void);
-extern const struct target_desc *tdesc_i386_mpx_linux;
-#endif
+void initialize_low_tdesc ();