From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 101430 invoked by alias); 11 May 2017 15:55:24 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 101081 invoked by uid 89); 11 May 2017 15:55:23 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=112430 X-HELO: mail-pf0-f172.google.com Received: from mail-pf0-f172.google.com (HELO mail-pf0-f172.google.com) (209.85.192.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 11 May 2017 15:55:20 +0000 Received: by mail-pf0-f172.google.com with SMTP id n23so10950236pfb.2 for ; Thu, 11 May 2017 08:55:22 -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=g8/oDvnxqNUs77pqmJRLfOIDa+hNc6QDJbOcWcrEDiU=; b=Qi91GuDO2Sv6c+sEtApbhGvWkZgto/zI+EzDq44O9Ztd7YNVzYJX5B1L3dwAjFHB1K 5QbkzgNwDaCp1lEe64EK4yVMfNnzXGO9CHUN5mq+2nJiF0wNGzRTd7uXd2DhJ8dhZKMd k9fBpfL+lP3Xz5qKo4Flu+6c+WZqiGSVsho3an8tfyze/o+9U3nAEY0/s9+VqXreku5c MHqzqyj6rs0lLHvJMtXzmLdY7vxdzCdpjS27opp554Nz5/27jXWF9dAnJvX09J+S7FXw ukHbICpmZk6iyKWDwHCAy0F13lxkIanCvDBu25Sy8PT7QMV7ZD5P25K3DrnHqdQa8ZIg r6jw== X-Gm-Message-State: AODbwcC/PGEzD9VA6cQtP+wNl8kHTW0R447Yn0KGkqFv7o4tWBB7A8al bsf3uad63PHBP3zw X-Received: by 10.99.127.80 with SMTP id p16mr1070994pgn.180.1494518120885; Thu, 11 May 2017 08:55:20 -0700 (PDT) Received: from E107787-LIN.cambridge.arm.com (gcc1-power7.osuosl.org. [140.211.15.137]) by smtp.gmail.com with ESMTPSA id f27sm1021158pga.41.2017.05.11.08.55.19 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 11 May 2017 08:55:20 -0700 (PDT) From: Yao Qi X-Google-Original-From: Yao Qi To: gdb-patches@sourceware.org Subject: [RFC 6/7] Lazily and dynamically create i386-linux target descriptions Date: Thu, 11 May 2017 15:55:00 -0000 Message-Id: <1494518105-15412-7-git-send-email-yao.qi@linaro.org> In-Reply-To: <1494518105-15412-1-git-send-email-yao.qi@linaro.org> References: <1494518105-15412-1-git-send-email-yao.qi@linaro.org> X-IsSubscribed: yes X-SW-Source: 2017-05/txt/msg00294.txt.bz2 Instead of using pre-generated target descriptions, this patch changes GDB to lazily and dynamically create target descriptions according to the target hardware capability (xcr0 in i386). This support any combination of target features. This patch also adds a unit test to make sure dynamically generated tdesc are identical to these generated from xml files. gdb: 2017-04-27 Yao Qi * i386-linux-tdep.c (i386_linux_read_description): Generate target description if it doesn't exist. [GDB_SELF_TEST] (i386_linux_read_description_test): New unit test. (_initialize_i386_linux_tdep) [GDB_SELF_TEST]: Register unit test. --- gdb/i386-linux-tdep.c | 85 ++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 67 insertions(+), 18 deletions(-) diff --git a/gdb/i386-linux-tdep.c b/gdb/i386-linux-tdep.c index 1bc1a6f..615cca5 100644 --- a/gdb/i386-linux-tdep.c +++ b/gdb/i386-linux-tdep.c @@ -681,27 +681,50 @@ i386_linux_core_read_xcr0 (bfd *abfd) const struct target_desc * i386_linux_read_description (uint64_t xcr0) { - switch ((xcr0 & X86_XSTATE_ALL_MASK)) + if (xcr0 == 0) + return NULL; + + static struct target_desc *i386_linux_tdescs \ + [2/*X87*/][2/*SSE*/][2/*AVX*/][2/*MPX*/][2/*AVX512*/][2/*PKRU*/] = {}; + struct target_desc **tdesc; + + tdesc = &i386_linux_tdescs[(xcr0 & X86_XSTATE_X87) ? 1 : 0] + [(xcr0 & X86_XSTATE_SSE) ? 1 : 0] + [(xcr0 & X86_XSTATE_AVX) ? 1 : 0] + [(xcr0 & X86_XSTATE_MPX) ? 1 : 0] + [(xcr0 & X86_XSTATE_AVX512) ? 1 : 0] + [(xcr0 & X86_XSTATE_PKRU) ? 1 : 0]; + + if (*tdesc == NULL) { - case X86_XSTATE_AVX_MPX_AVX512_PKU_MASK: - return tdesc_i386_avx_mpx_avx512_pku_linux; - case X86_XSTATE_AVX_AVX512_MASK: - return tdesc_i386_avx_avx512_linux; - case X86_XSTATE_MPX_MASK: - return tdesc_i386_mpx_linux; - case X86_XSTATE_AVX_MPX_MASK: - return tdesc_i386_avx_mpx_linux; - case X86_XSTATE_AVX_MASK: - return tdesc_i386_avx_linux; - case X86_XSTATE_SSE_MASK: - return tdesc_i386_linux; - case X86_XSTATE_X87_MASK: - return tdesc_i386_mmx_linux; - default: - break; + *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_org_gnu_gdb_i386_core_i386 (*tdesc, regnum); + + if (xcr0 & X86_XSTATE_SSE) + regnum = create_feature_org_gnu_gdb_i386_sse (*tdesc, regnum); + + regnum = create_feature_org_gnu_gdb_i386_linux (*tdesc, regnum); + + if (xcr0 & X86_XSTATE_AVX) + regnum = create_feature_org_gnu_gdb_i386_avx (*tdesc, regnum); + + if (xcr0 & X86_XSTATE_MPX) + regnum = create_feature_org_gnu_gdb_i386_mpx (*tdesc, regnum); + + if (xcr0 & X86_XSTATE_AVX512) + regnum = create_feature_org_gnu_gdb_i386_avx512 (*tdesc, regnum); + + if (xcr0 & X86_XSTATE_PKRU) + regnum = create_feature_org_gnu_gdb_i386_pkeys (*tdesc, regnum); } - return NULL; + return *tdesc; } /* Get Linux/x86 target description from core dump. */ @@ -1101,4 +1124,30 @@ _initialize_i386_linux_tdep (void) initialize_tdesc_i386_avx_mpx_linux (); initialize_tdesc_i386_avx_avx512_linux (); initialize_tdesc_i386_avx_mpx_avx512_pku_linux (); + +#if GDB_SELF_TEST + struct xml_and_mask + { + const char *xml_file_name; + uint64_t mask; + }; + + struct xml_and_mask array[] = { + { "i386/i386-linux.xml", X86_XSTATE_SSE_MASK }, + { "i386/i386-mmx-linux.xml", X86_XSTATE_X87_MASK }, + { "i386/i386-avx-linux.xml", X86_XSTATE_AVX_MASK }, + { "i386/i386-mpx-linux.xml", X86_XSTATE_MPX_MASK }, + { "i386/i386-avx-mpx-linux.xml", X86_XSTATE_AVX_MPX_MASK }, + { "i386/i386-avx-avx512-linux.xml", X86_XSTATE_AVX_AVX512_MASK }, + { "i386/i386-avx-mpx-avx512-pku-linux.xml", + X86_XSTATE_AVX_MPX_AVX512_PKU_MASK }, + }; + + for (auto &a : array) + { + auto tdesc = i386_linux_read_description (a.mask); + + selftests::record_xml_tdesc (a.xml_file_name, tdesc); + } +#endif /* GDB_SELF_TEST */ } -- 1.9.1