From patchwork Mon Jun 12 08:41:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yao Qi X-Patchwork-Id: 20933 Received: (qmail 73511 invoked by alias); 12 Jun 2017 08:42:42 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 71411 invoked by uid 89); 12 Jun 2017 08:42:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.1 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS, UNWANTED_LANGUAGE_BODY autolearn=ham version=3.3.2 spammy=8273 X-HELO: mail-io0-f174.google.com Received: from mail-io0-f174.google.com (HELO mail-io0-f174.google.com) (209.85.223.174) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 12 Jun 2017 08:42:11 +0000 Received: by mail-io0-f174.google.com with SMTP id t87so32535644ioe.0 for ; Mon, 12 Jun 2017 01:42:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=wqDmXMVP2kW/5TVJXB3BGmlMHpue2VbDoglhkEuCc5I=; b=oo4w8Chjo6EIgh/1T2tA3v3Kipy6g60B/o+nc/8tSqaYssHNVuP1iu0sfzSKqYzdvu gTPtM0AfHGz5G122U9yCOmCSd0aKmE3FPtpK0ThkBtXx2Dy1r0wGcniddZlMj8GRDzqj b97ql3R7ou1yxnxnGDqMuvXe2niiRv6u/lgm1IUPbD9g9QqwTRuVA9wt4J0Yd0UFuL8X Nfgo+McTc/BHGd/RB0bgty4fAIOxCPv84RzPuxx8fNexcFvSXwmgPBwMbo8C5nFeBvhM 4yHG8qBez6yOdDdbejwlSsGt4252Uw4dieOnORq6gjL0Dzcg24bmfy2dr9RlmhReElCu NLPA== X-Gm-Message-State: AKS2vOwtjOsO1uTkuWkvcG1Gcn38dbFb/E/kaUazqG8ktvE5bXpH8V7X o0eVT6XVkggLpbBW X-Received: by 10.107.161.146 with SMTP id k140mr6671174ioe.174.1497256933866; Mon, 12 Jun 2017 01:42:13 -0700 (PDT) Received: from E107787-LIN.cambridge.arm.com (static.42.136.251.148.clients.your-server.de. [148.251.136.42]) by smtp.gmail.com with ESMTPSA id u4sm5280289itu.1.2017.06.12.01.42.12 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 12 Jun 2017 01:42:13 -0700 (PDT) From: Yao Qi X-Google-Original-From: Yao Qi To: gdb-patches@sourceware.org Subject: [PATCH 13/25] Dynamically create tdesc in GDBserver Date: Mon, 12 Jun 2017 09:41:44 +0100 Message-Id: <1497256916-4958-14-git-send-email-yao.qi@linaro.org> In-Reply-To: <1497256916-4958-1-git-send-email-yao.qi@linaro.org> References: <1497256916-4958-1-git-send-email-yao.qi@linaro.org> X-IsSubscribed: yes In this patch, GDBserver starts to use gdb/features/*.c feature files by including them, so that GDBserver can create target descriptions from features dynamically, like GDB does. Adjust these feature .c files for GDBserver. These feature .c files calls some target description APIs only defined GDB, so this patch also adds them in GDBserver. TODO: complete ChangeLog. gdb: 2017-06-06 Yao Qi * features/i386/32bit-avx.c: Re-generated. * features/i386/32bit-avx512.c: Re-generated. * features/i386/32bit-core.c: Re-generated. * features/i386/32bit-linux.c: Re-generated. * features/i386/32bit-mpx.c: Re-generated. * features/i386/32bit-pkeys.c: Re-generated. * features/i386/32bit-sse.c: Re-generated. gdb/gdbserver: 2017-06-06 Yao Qi * linux-x86-tdesc.c: Include ../features/i386/32bit-*.c. (initialize_low_tdesc): Don't use tdesc_i386_XXX_linux. (i386_get_ipa_tdesc): Create target descriptions. * tdesc.c (init_target_desc): (current_target_desc): (tdesc_create_feature): + (tdesc_create_flags): + (tdesc_add_flag): + (tdesc_named_type): + (tdesc_create_reg): + (tdesc_create_vector): + (tdesc_add_bitfield): + (tdesc_add_field): + (tdesc_set_struct_size): + * tdesc.h (target_desc::target_desc): New. (target_desc::~target_desc): New. * regformats/regdat.sh: Generate code to call tdesc_create_reg. * target-descriptions.c (print_c_feature::visit): Print code for GDB. --- gdb/features/i386/32bit-avx.c | 4 ++ gdb/features/i386/32bit-avx512.c | 4 ++ gdb/features/i386/32bit-core.c | 4 ++ gdb/features/i386/32bit-linux.c | 4 ++ gdb/features/i386/32bit-mpx.c | 4 ++ gdb/features/i386/32bit-pkeys.c | 4 ++ gdb/features/i386/32bit-sse.c | 4 ++ gdb/gdbserver/linux-x86-tdesc.c | 86 +++++++++++++++++++++++++++++++++++----- gdb/gdbserver/tdesc.c | 78 +++++++++++++++++++++++++++++++++++- gdb/gdbserver/tdesc.h | 58 ++++++++++++++++++++++++++- gdb/regformats/regdat.sh | 10 ++--- gdb/target-descriptions.c | 4 ++ 12 files changed, 243 insertions(+), 21 deletions(-) diff --git a/gdb/features/i386/32bit-avx.c b/gdb/features/i386/32bit-avx.c index 53a939b..bae025d 100644 --- a/gdb/features/i386/32bit-avx.c +++ b/gdb/features/i386/32bit-avx.c @@ -1,9 +1,13 @@ /* THIS FILE IS GENERATED. -*- buffer-read-only: t -*- vi:set ro: Original: 32bit-avx.xml.tmp */ +#ifdef GDBSERVER +#include "tdesc.h" +#else #include "defs.h" #include "osabi.h" #include "target-descriptions.h" +#endif static int create_feature_i386_32bit_avx (struct target_desc *result, long regnum) diff --git a/gdb/features/i386/32bit-avx512.c b/gdb/features/i386/32bit-avx512.c index 9bbf392..ca15f8b 100644 --- a/gdb/features/i386/32bit-avx512.c +++ b/gdb/features/i386/32bit-avx512.c @@ -1,9 +1,13 @@ /* THIS FILE IS GENERATED. -*- buffer-read-only: t -*- vi:set ro: Original: 32bit-avx512.xml.tmp */ +#ifdef GDBSERVER +#include "tdesc.h" +#else #include "defs.h" #include "osabi.h" #include "target-descriptions.h" +#endif static int create_feature_i386_32bit_avx512 (struct target_desc *result, long regnum) diff --git a/gdb/features/i386/32bit-core.c b/gdb/features/i386/32bit-core.c index c5f0fca..8db91ab 100644 --- a/gdb/features/i386/32bit-core.c +++ b/gdb/features/i386/32bit-core.c @@ -1,9 +1,13 @@ /* THIS FILE IS GENERATED. -*- buffer-read-only: t -*- vi:set ro: Original: 32bit-core.xml.tmp */ +#ifdef GDBSERVER +#include "tdesc.h" +#else #include "defs.h" #include "osabi.h" #include "target-descriptions.h" +#endif static int create_feature_i386_32bit_core (struct target_desc *result, long regnum) diff --git a/gdb/features/i386/32bit-linux.c b/gdb/features/i386/32bit-linux.c index ff90d40..7535c55 100644 --- a/gdb/features/i386/32bit-linux.c +++ b/gdb/features/i386/32bit-linux.c @@ -1,9 +1,13 @@ /* THIS FILE IS GENERATED. -*- buffer-read-only: t -*- vi:set ro: Original: 32bit-linux.xml.tmp */ +#ifdef GDBSERVER +#include "tdesc.h" +#else #include "defs.h" #include "osabi.h" #include "target-descriptions.h" +#endif static int create_feature_i386_32bit_linux (struct target_desc *result, long regnum) diff --git a/gdb/features/i386/32bit-mpx.c b/gdb/features/i386/32bit-mpx.c index 50b627e..9f1ae67 100644 --- a/gdb/features/i386/32bit-mpx.c +++ b/gdb/features/i386/32bit-mpx.c @@ -1,9 +1,13 @@ /* THIS FILE IS GENERATED. -*- buffer-read-only: t -*- vi:set ro: Original: 32bit-mpx.xml.tmp */ +#ifdef GDBSERVER +#include "tdesc.h" +#else #include "defs.h" #include "osabi.h" #include "target-descriptions.h" +#endif static int create_feature_i386_32bit_mpx (struct target_desc *result, long regnum) diff --git a/gdb/features/i386/32bit-pkeys.c b/gdb/features/i386/32bit-pkeys.c index afb4958..86035ab 100644 --- a/gdb/features/i386/32bit-pkeys.c +++ b/gdb/features/i386/32bit-pkeys.c @@ -1,9 +1,13 @@ /* THIS FILE IS GENERATED. -*- buffer-read-only: t -*- vi:set ro: Original: 32bit-pkeys.xml.tmp */ +#ifdef GDBSERVER +#include "tdesc.h" +#else #include "defs.h" #include "osabi.h" #include "target-descriptions.h" +#endif static int create_feature_i386_32bit_pkeys (struct target_desc *result, long regnum) diff --git a/gdb/features/i386/32bit-sse.c b/gdb/features/i386/32bit-sse.c index 08c3948..876c04d 100644 --- a/gdb/features/i386/32bit-sse.c +++ b/gdb/features/i386/32bit-sse.c @@ -1,9 +1,13 @@ /* THIS FILE IS GENERATED. -*- buffer-read-only: t -*- vi:set ro: Original: 32bit-sse.xml.tmp */ +#ifdef GDBSERVER +#include "tdesc.h" +#else #include "defs.h" #include "osabi.h" #include "target-descriptions.h" +#endif static int create_feature_i386_32bit_sse (struct target_desc *result, long regnum) diff --git a/gdb/gdbserver/linux-x86-tdesc.c b/gdb/gdbserver/linux-x86-tdesc.c index e294a98..f247a3c 100644 --- a/gdb/gdbserver/linux-x86-tdesc.c +++ b/gdb/gdbserver/linux-x86-tdesc.c @@ -18,8 +18,17 @@ along with this program. If not, see . */ #include "server.h" +#include "tdesc.h" #include "linux-x86-tdesc.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" + #if defined __i386__ || !defined IN_PROCESS_AGENT /* Defined in auto-generated file i386-linux.c. */ void init_registers_i386_linux (void); @@ -63,15 +72,6 @@ initialize_low_tdesc () 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 } @@ -82,7 +82,73 @@ i386_get_ipa_tdesc (int idx) internal_error (__FILE__, __LINE__, "unknown ipa tdesc index: %d", idx); - return i386_tdescs[idx]; + struct target_desc **tdesc = (struct target_desc **) &i386_tdescs[idx]; + + if (*tdesc == NULL) + { + *tdesc = new target_desc (); + long regnum = 0; + + regnum = create_feature_i386_32bit_core (*tdesc, regnum); + + if (idx != X86_TDESC_MMX) + regnum = create_feature_i386_32bit_sse (*tdesc, regnum); + + regnum = create_feature_i386_32bit_linux (*tdesc, regnum); + + if (idx == X86_TDESC_AVX || idx == X86_TDESC_AVX_MPX + || idx == X86_TDESC_AVX_AVX512 + || idx == X86_TDESC_AVX_MPX_AVX512_PKU) + regnum = create_feature_i386_32bit_avx (*tdesc, regnum); + + if (idx == X86_TDESC_MPX || idx == X86_TDESC_AVX_MPX + || idx == X86_TDESC_AVX_MPX_AVX512_PKU) + regnum = create_feature_i386_32bit_mpx (*tdesc, regnum); + + if (idx == X86_TDESC_AVX_AVX512 + || idx == X86_TDESC_AVX_MPX_AVX512_PKU) + regnum = create_feature_i386_32bit_avx512 (*tdesc, regnum); + + if (idx == X86_TDESC_AVX_MPX_AVX512_PKU) + regnum = create_feature_i386_32bit_pkeys (*tdesc, regnum); + + init_target_desc (*tdesc); + +#ifndef IN_PROCESS_AGENT + static const char *expedite_regs_i386[] = { "ebp", "esp", "eip", NULL }; + (*tdesc)->expedite_regs = expedite_regs_i386; + + switch (idx) + { + case X86_TDESC_MMX: + (*tdesc)->xmltarget = "i386-mmx-linux.xml"; + break; + case X86_TDESC_SSE: + (*tdesc)->xmltarget = "i386-linux.xml"; + break; + case X86_TDESC_AVX: + (*tdesc)->xmltarget = "i386-avx-linux.xml"; + break; + case X86_TDESC_MPX: + (*tdesc)->xmltarget = "i386-mpx-linux.xml"; + break; + case X86_TDESC_AVX_MPX: + (*tdesc)->xmltarget = "i386-avx-mpx-linux.xml"; + break; + case X86_TDESC_AVX_AVX512: + (*tdesc)->xmltarget = "i386-avx-avx512-linux.xml"; + break; + case X86_TDESC_AVX_MPX_AVX512_PKU: + (*tdesc)->xmltarget = "i386-avx-mpx-avx512-pku-linux.xml"; + break; + default: + internal_error (__FILE__, __LINE__, + "unknown ipa tdesc index: %d", idx); + } + +#endif + } + return *tdesc;; } #ifdef IN_PROCESS_AGENT diff --git a/gdb/gdbserver/tdesc.c b/gdb/gdbserver/tdesc.c index 1b1882e..686c76a 100644 --- a/gdb/gdbserver/tdesc.c +++ b/gdb/gdbserver/tdesc.c @@ -41,7 +41,7 @@ init_target_desc (struct target_desc *tdesc) #ifndef IN_PROCESS_AGENT -static const struct target_desc default_description = { NULL, 0, NULL, NULL }; +static const struct target_desc default_description {}; void copy_target_description (struct target_desc *dest, @@ -61,5 +61,79 @@ current_target_desc (void) return current_process ()->tdesc; } - #endif + +struct tdesc_type +{}; + +struct tdesc_feature * +tdesc_create_feature (struct target_desc *tdesc, const char *name) +{ + return tdesc; +} + +struct tdesc_type * +tdesc_create_flags (struct tdesc_feature *feature, const char *name, + int size) +{ + return NULL; +} + +void +tdesc_add_flag (struct tdesc_type *type, int start, + const char *flag_name) +{} + +struct tdesc_type * +tdesc_named_type (const struct tdesc_feature *feature, const char *id) +{ + return NULL; +} + +void +tdesc_create_reg (struct tdesc_feature *feature, const char *name, + int regnum, int save_restore, const char *group, + int bitsize, const char *type) +{ + struct target_desc *tdesc = (struct target_desc *) feature; + + while (VEC_length (tdesc_reg_p, tdesc->reg_defs) < regnum) + { + struct reg *reg = XCNEW (struct reg); + + reg->name = ""; + reg->size = 0; + VEC_safe_push (tdesc_reg_p, tdesc->reg_defs, reg); + } + + gdb_assert (regnum == 0 + || regnum == VEC_length (tdesc_reg_p, tdesc->reg_defs)); + + struct reg *reg = XCNEW (struct reg); + + reg->name = name; + reg->size = bitsize; + VEC_safe_push (tdesc_reg_p, tdesc->reg_defs, reg); +} + +struct tdesc_type * +tdesc_create_vector (struct tdesc_feature *feature, const char *name, + struct tdesc_type *field_type, int count) +{ + return NULL; +} + +void +tdesc_add_bitfield (struct tdesc_type *type, const char *field_name, + int start, int end) +{} + +void +tdesc_add_field (struct tdesc_type *type, const char *field_name, + struct tdesc_type *field_type) +{} + +void +tdesc_set_struct_size (struct tdesc_type *type, int size) +{ +} diff --git a/gdb/gdbserver/tdesc.h b/gdb/gdbserver/tdesc.h index 424a2fd..2d4cbfa 100644 --- a/gdb/gdbserver/tdesc.h +++ b/gdb/gdbserver/tdesc.h @@ -38,13 +38,28 @@ struct target_desc #ifndef IN_PROCESS_AGENT /* An array of register names. These are the "expedite" registers: registers whose values are sent along with stop replies. */ - const char **expedite_regs; + const char **expedite_regs = NULL; /* Defines what to return when looking for the "target.xml" file in response to qXfer:features:read. Its contents can either be verbatim XML code (prefixed with a '@') or else the name of the actual XML file to be used in place of "target.xml". */ - const char *xmltarget; + const char *xmltarget = NULL; + +public: + target_desc () + : reg_defs (NULL), registers_size (0) + {} + + ~target_desc () + { + int i; + struct reg *reg; + + for (i = 0; VEC_iterate (tdesc_reg_p, reg_defs, i, reg); i++) + xfree (reg); + VEC_free (tdesc_reg_p, reg_defs); + } #endif }; @@ -62,4 +77,43 @@ void init_target_desc (struct target_desc *tdesc); const struct target_desc *current_target_desc (void); +#ifndef IN_PROCESS_AGENT +#endif + +#define tdesc_feature target_desc + +struct tdesc_type; + +struct tdesc_feature *tdesc_create_feature (struct target_desc *tdesc, + const char *name); + +struct tdesc_type *tdesc_create_flags (struct tdesc_feature *feature, + const char *name, int size); + +void tdesc_add_flag (struct tdesc_type *type, int start, + const char *flag_name); + +struct tdesc_type *tdesc_named_type (const struct tdesc_feature *feature, + const char *id); + +#define tdesc_create_union tdesc_named_type +#define tdesc_create_struct tdesc_named_type + +void tdesc_add_field (struct tdesc_type *type, const char *field_name, + struct tdesc_type *field_type); + +void tdesc_set_struct_size (struct tdesc_type *type, int size); + +void tdesc_add_bitfield (struct tdesc_type *type, const char *field_name, + int start, int end); + +void tdesc_create_reg (struct tdesc_feature *feature, const char *name, + int regnum, int save_restore, const char *group, + int bitsize, const char *type); + +struct tdesc_type *tdesc_create_vector (struct tdesc_feature *feature, + const char *name, + struct tdesc_type *field_type, + int count); + #endif /* TDESC_H */ diff --git a/gdb/regformats/regdat.sh b/gdb/regformats/regdat.sh index 236cd93..66449cc 100755 --- a/gdb/regformats/regdat.sh +++ b/gdb/regformats/regdat.sh @@ -131,7 +131,6 @@ do echo "{" echo " static struct target_desc tdesc_${name}_s;" echo " struct target_desc *result = &tdesc_${name}_s;" - echo " memset (result, 0, sizeof (*result));" continue elif test "${type}" = "xmltarget"; then @@ -150,12 +149,9 @@ do echo "$0: $1 does not specify \`\`name''." 1>&2 exit 1 else - echo " {struct reg *reg = XCNEW (struct reg);" - echo " reg->name = \"${entry}\";" - echo " reg->offset = ${offset};" - echo " reg->size = ${type};" - echo " VEC_safe_push (tdesc_reg_p, result->reg_defs, reg);" - echo " };" + echo " tdesc_create_reg ((struct tdesc_feature *) result, \"${entry}\"," + echo " 0, 0, NULL, ${type}, NULL);" + offset=`expr ${offset} + ${type}` i=`expr $i + 1` fi diff --git a/gdb/target-descriptions.c b/gdb/target-descriptions.c index 2b3083a..38e28d3 100644 --- a/gdb/target-descriptions.c +++ b/gdb/target-descriptions.c @@ -2166,9 +2166,13 @@ public: void visit (const target_desc *e) override { + printf_unfiltered ("#ifdef GDBSERVER\n"); + printf_unfiltered ("#include \"tdesc.h\"\n"); + printf_unfiltered ("#else\n"); printf_unfiltered ("#include \"defs.h\"\n"); printf_unfiltered ("#include \"osabi.h\"\n"); printf_unfiltered ("#include \"target-descriptions.h\"\n"); + printf_unfiltered ("#endif\n"); printf_unfiltered ("\n"); }