From patchwork Wed Jan 10 13:08:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Rudo X-Patchwork-Id: 25326 Received: (qmail 103109 invoked by alias); 10 Jan 2018 13:10:45 -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 101649 invoked by uid 89); 10 Jan 2018 13:10:44 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy= X-HELO: mx0a-001b2d01.pphosted.com Received: from mx0b-001b2d01.pphosted.com (HELO mx0a-001b2d01.pphosted.com) (148.163.158.5) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 10 Jan 2018 13:10:42 +0000 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w0AD99Si082143 for ; Wed, 10 Jan 2018 08:10:41 -0500 Received: from e06smtp12.uk.ibm.com (e06smtp12.uk.ibm.com [195.75.94.108]) by mx0b-001b2d01.pphosted.com with ESMTP id 2fdg66skva-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 10 Jan 2018 08:10:40 -0500 Received: from localhost by e06smtp12.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 10 Jan 2018 13:10:38 -0000 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp12.uk.ibm.com (192.168.101.142) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 10 Jan 2018 13:10:36 -0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w0ADAZUK721346 for ; Wed, 10 Jan 2018 13:10:35 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 37F9CA40C4 for ; Wed, 10 Jan 2018 13:04:28 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0A118A40B9 for ; Wed, 10 Jan 2018 13:04:28 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTPS for ; Wed, 10 Jan 2018 13:03:48 +0000 (GMT) From: Philipp Rudo To: gdb-patches@sourceware.org Subject: [PATCH v4 02/11] s390: Allocate gdbarch & tdep at start of gdbarch_init Date: Wed, 10 Jan 2018 14:08:45 +0100 In-Reply-To: <20180109120144.93854-1-prudo@linux.vnet.ibm.com> References: <20180109120144.93854-1-prudo@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18011013-0008-0000-0000-000004C02CC8 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18011013-0009-0000-0000-00001E53845E Message-Id: <20180110130845.33343-1-prudo@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2018-01-10_07:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1801100184 X-IsSubscribed: yes Hi, the patch got lost on his way to the mailing list. So here is the next try. There where no changes since v3. Philipp --- Moving the allocation of gdbarch_tdep to the start of s390_gdbarch_init allows us to use its fields for tracking the different features instead of using separate variables. To make the code a little nicer move the actual allocation and initialization to a separate function. Also move the allocation of gdbarch to keep the two together. gdb/ChangeLog: * s390-linux-tdep (s390_abi_kind) : New default field. (gdbarch_tdep) : New fields. (s390_gdbarch_tdep_alloc): New function. (s390_gdbarch_init): Allocate tdep at start and use its fields instead of separate variables. --- gdb/s390-linux-tdep.c | 107 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 65 insertions(+), 42 deletions(-) diff --git a/gdb/s390-linux-tdep.c b/gdb/s390-linux-tdep.c index 5f4ed3a9af..9a444a60c5 100644 --- a/gdb/s390-linux-tdep.c +++ b/gdb/s390-linux-tdep.c @@ -85,6 +85,7 @@ static char *s390_disassembler_options; enum s390_abi_kind { + ABI_NONE, ABI_LINUX_S390, ABI_LINUX_ZSERIES }; @@ -111,9 +112,11 @@ struct gdbarch_tdep int cc_regnum; int v0_full_regnum; + bool have_upper; int have_linux_v1; int have_linux_v2; int have_tdb; + bool have_vx; bool have_gs; }; @@ -7805,6 +7808,32 @@ s390_init_linux_record_tdep (struct linux_record_tdep *record_tdep, record_tdep->ioctl_FIOQSIZE = 0x545e; } +/* Allocate and initialize new gdbarch_tdep. Caller is responsible to free + memory after use. */ + +static struct gdbarch_tdep * +s390_gdbarch_tdep_alloc () +{ + struct gdbarch_tdep *tdep = XCNEW (struct gdbarch_tdep); + + tdep->abi = ABI_NONE; + tdep->vector_abi = S390_VECTOR_ABI_NONE; + + tdep->gpr_full_regnum = -1; + tdep->v0_full_regnum = -1; + tdep->pc_regnum = -1; + tdep->cc_regnum = -1; + + tdep->have_upper = false; + tdep->have_linux_v1 = 0; + tdep->have_linux_v2 = 0; + tdep->have_tdb = 0; + tdep->have_vx = false; + tdep->have_gs = false; + + return tdep; +} + /* Set up gdbarch struct. */ static struct gdbarch * @@ -7812,16 +7841,6 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) { const struct target_desc *tdesc = info.target_desc; struct tdesc_arch_data *tdesc_data = NULL; - struct gdbarch *gdbarch; - struct gdbarch_tdep *tdep; - enum s390_abi_kind tdep_abi; - enum s390_vector_abi_kind vector_abi; - int have_upper = 0; - int have_linux_v1 = 0; - int have_linux_v2 = 0; - int have_tdb = 0; - int have_vx = 0; - int have_gs = 0; int first_pseudo_reg, last_pseudo_reg; static const char *const stap_register_prefixes[] = { "%", NULL }; static const char *const stap_register_indirection_prefixes[] = { "(", @@ -7829,25 +7848,30 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) static const char *const stap_register_indirection_suffixes[] = { ")", NULL }; + struct gdbarch_tdep *tdep = s390_gdbarch_tdep_alloc (); + struct gdbarch *gdbarch = gdbarch_alloc (&info, tdep); + /* Default ABI and register size. */ switch (info.bfd_arch_info->mach) { case bfd_mach_s390_31: - tdep_abi = ABI_LINUX_S390; + tdep->abi = ABI_LINUX_S390; break; case bfd_mach_s390_64: - tdep_abi = ABI_LINUX_ZSERIES; + tdep->abi = ABI_LINUX_ZSERIES; break; default: + xfree (tdep); + gdbarch_free (gdbarch); return NULL; } /* Use default target description if none provided by the target. */ if (!tdesc_has_registers (tdesc)) { - if (tdep_abi == ABI_LINUX_S390) + if (tdep->abi == ABI_LINUX_S390) tdesc = tdesc_s390_linux32; else tdesc = tdesc_s390x_linux64; @@ -7900,7 +7924,11 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) feature = tdesc_find_feature (tdesc, "org.gnu.gdb.s390.core"); if (feature == NULL) - return NULL; + { + xfree (tdep); + gdbarch_free (gdbarch); + return NULL; + } tdesc_data = tdesc_data_alloc (); @@ -7917,7 +7945,7 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) } else { - have_upper = 1; + tdep->have_upper = true; for (i = 0; i < 16; i++) valid_p &= tdesc_numbered_register (feature, tdesc_data, @@ -7933,6 +7961,8 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) if (feature == NULL) { tdesc_data_cleanup (tdesc_data); + xfree (tdep); + gdbarch_free (gdbarch); return NULL; } @@ -7946,6 +7976,8 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) if (feature == NULL) { tdesc_data_cleanup (tdesc_data); + xfree (tdep); + gdbarch_free (gdbarch); return NULL; } @@ -7962,13 +7994,13 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) if (tdesc_numbered_register (feature, tdesc_data, S390_LAST_BREAK_REGNUM, "last_break")) - have_linux_v1 = 1; + tdep->have_linux_v1 = 1; if (tdesc_numbered_register (feature, tdesc_data, S390_SYSTEM_CALL_REGNUM, "system_call")) - have_linux_v2 = 1; + tdep->have_linux_v2 = 1; - if (have_linux_v2 > have_linux_v1) + if (tdep->have_linux_v2 > tdep->have_linux_v1) valid_p = 0; } @@ -7980,7 +8012,7 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) valid_p &= tdesc_numbered_register (feature, tdesc_data, S390_TDB_DWORD0_REGNUM + i, tdb_regs[i]); - have_tdb = 1; + tdep->have_tdb = 1; } /* Vector registers. */ @@ -7995,7 +8027,7 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) valid_p &= tdesc_numbered_register (feature, tdesc_data, S390_V16_REGNUM + i, vxrs_high[i]); - have_vx = 1; + tdep->have_vx = true; } /* Guarded-storage registers. */ @@ -8006,14 +8038,14 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) valid_p &= tdesc_numbered_register (feature, tdesc_data, S390_GSD_REGNUM + i, gs_cb[i]); - have_gs = 1; + tdep->have_gs = true; } /* Guarded-storage broadcast control. */ feature = tdesc_find_feature (tdesc, "org.gnu.gdb.s390.gsbc"); if (feature) { - valid_p &= have_gs; + valid_p &= tdep->have_gs; for (i = 0; i < 3; i++) valid_p &= tdesc_numbered_register (feature, tdesc_data, @@ -8024,20 +8056,21 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) if (!valid_p) { tdesc_data_cleanup (tdesc_data); + xfree (tdep); + gdbarch_free (gdbarch); return NULL; } } /* Determine vector ABI. */ - vector_abi = S390_VECTOR_ABI_NONE; #ifdef HAVE_ELF - if (have_vx + if (tdep->have_vx && info.abfd != NULL && info.abfd->format == bfd_object && bfd_get_flavour (info.abfd) == bfd_target_elf_flavour && bfd_elf_get_obj_attr_int (info.abfd, OBJ_ATTR_GNU, Tag_GNU_S390_ABI_Vector) == 2) - vector_abi = S390_VECTOR_ABI_128; + tdep->vector_abi = S390_VECTOR_ABI_128; #endif /* Find a candidate among extant architectures. */ @@ -8045,29 +8078,21 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) arches != NULL; arches = gdbarch_list_lookup_by_info (arches->next, &info)) { - tdep = gdbarch_tdep (arches->gdbarch); - if (!tdep) + struct gdbarch_tdep *tmp = gdbarch_tdep (arches->gdbarch); + if (!tmp) continue; /* A program can 'choose' not to use the vector registers when they are present. Leading to the same tdesc but different tdep and thereby a different gdbarch. */ - if (tdep->vector_abi != vector_abi) + if (tmp->vector_abi != tdep->vector_abi) continue; if (tdesc_data != NULL) tdesc_data_cleanup (tdesc_data); + xfree (tdep); + gdbarch_free (gdbarch); return arches->gdbarch; } - /* Otherwise create a new gdbarch for the specified machine type. */ - tdep = XCNEW (struct gdbarch_tdep); - tdep->abi = tdep_abi; - tdep->vector_abi = vector_abi; - tdep->have_linux_v1 = have_linux_v1; - tdep->have_linux_v2 = have_linux_v2; - tdep->have_tdb = have_tdb; - tdep->have_gs = have_gs; - gdbarch = gdbarch_alloc (&info, tdep); - set_gdbarch_believe_pcc_promotion (gdbarch, 0); set_gdbarch_char_signed (gdbarch, 0); @@ -8119,14 +8144,12 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) /* Assign pseudo register numbers. */ first_pseudo_reg = gdbarch_num_regs (gdbarch); last_pseudo_reg = first_pseudo_reg; - tdep->gpr_full_regnum = -1; - if (have_upper) + if (tdep->have_upper) { tdep->gpr_full_regnum = last_pseudo_reg; last_pseudo_reg += 16; } - tdep->v0_full_regnum = -1; - if (have_vx) + if (tdep->have_vx) { tdep->v0_full_regnum = last_pseudo_reg; last_pseudo_reg += 16;