From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from aserp2120.oracle.com (aserp2120.oracle.com [141.146.126.78]) by sourceware.org (Postfix) with ESMTPS id 346F2386F46A for ; Tue, 2 Feb 2021 01:49:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 346F2386F46A Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 1121mu1M140379 for ; Tue, 2 Feb 2021 01:49:20 GMT Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2120.oracle.com with ESMTP id 36cydkraj0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 02 Feb 2021 01:49:20 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 1121eVqa036179 for ; Tue, 2 Feb 2021 01:49:19 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2174.outbound.protection.outlook.com [104.47.59.174]) by userp3030.oracle.com with ESMTP id 36dhcvvw9n-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 02 Feb 2021 01:49:19 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iKIlBEhKfo0EeQTAIXJ0bpFDADKt2suj0Iq5Z56fewJbJsxfdjRX75E1A4hreYfYS7L4EXqygXjKlq494OkquUvc0ZICJ8epdQibqm4mx8ePgJP5IpG1iniuzwlIRlk0i298C3kHlVfP60FBMYEC92MWtjKcyMftTS3AqcwEpzAXtqW5vcozo5rjBzCtA+2ActO3sVjk1fmCRXpaCbQvcntyojDEad8bHRL4+/ltwdHqRz+kOI9aANHznKE7y+1GbjLI57s4u+9eWcdzyHdbD98eQDRd4LIylSXDTopWe2MQ2Ejnq9l3RXZPAaVTYKyE2zvSMZGjhbWsx3IuvFD7AQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=h1/gGNNIFy3edPPG15mRwtGRJosgZLyG89NeYn+VQvg=; b=WeIFEw37tNRL1V5PZ+jKNLRt4Wj3wjS6BK4G3xv1+V53C1e8sp0MXNFqaaj0Uci6Tm4hT1+Hst3L0x4GnOQ8Wxb9iDtEVnWj3tqUU/YtndsoFE9w2zzkyCNcq9YqPUs1/SJxDaktwIPYNBK9sSDJWyYenbKUHgJhBXdddh7eXsrdEm1EPBTsmITZpPCoPdju+f+1QetWJ9/psfwNrgy8qNm/S4nAxSxHNXT0rbApY/1o+VCoWbSFxxpAHl2aQcDStNuXJaNneLNTgy8jnzajKNefYYJphGMFB4vjEkjt4H9ZQ7La1vNlmbF0xzmzB1HNqwW/lOwOXQNqwRtQLkRn4A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none Received: from BN6PR10MB1748.namprd10.prod.outlook.com (2603:10b6:405:9::16) by BN6PR1001MB2098.namprd10.prod.outlook.com (2603:10b6:405:2d::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3805.24; Tue, 2 Feb 2021 01:49:16 +0000 Received: from BN6PR10MB1748.namprd10.prod.outlook.com ([fe80::1163:f828:25bb:2538]) by BN6PR10MB1748.namprd10.prod.outlook.com ([fe80::1163:f828:25bb:2538%7]) with mapi id 15.20.3805.028; Tue, 2 Feb 2021 01:49:16 +0000 From: Weimin Pan To: gdb-patches@sourceware.org Subject: [PATCH 3/5] CTF: handle forward reference type Date: Mon, 1 Feb 2021 20:48:46 -0500 Message-Id: <1612230528-25905-4-git-send-email-weimin.pan@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1612230528-25905-3-git-send-email-weimin.pan@oracle.com> References: <1612230528-25905-1-git-send-email-weimin.pan@oracle.com> <1612230528-25905-2-git-send-email-weimin.pan@oracle.com> <1612230528-25905-3-git-send-email-weimin.pan@oracle.com> Content-Type: text/plain X-Originating-IP: [148.87.23.6] X-ClientProxiedBy: CH2PR11CA0002.namprd11.prod.outlook.com (2603:10b6:610:54::12) To BN6PR10MB1748.namprd10.prod.outlook.com (2603:10b6:405:9::16) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.us.oracle.com (148.87.23.6) by CH2PR11CA0002.namprd11.prod.outlook.com (2603:10b6:610:54::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3805.16 via Frontend Transport; Tue, 2 Feb 2021 01:49:15 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 746b6fab-9738-42df-68ff-08d8c71cbf93 X-MS-TrafficTypeDiagnostic: BN6PR1001MB2098: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: E83J6bKbFMrc8iBOm/CVKacT+qzPmnnXY5sRo4u68mtVV8jUDAxXf6TI2W/LpDPn9ptIysyMEUipr+V8Ksp1S9P8+TkpxzWk6qq2+Z7m0uhzqueqx8ode5jGJQcmtbwBV3qmvswJ3i96QxJz5cptZuZI/D0wjQzB2hDLx2OqHmCNy2IIiBw04gyz6TxzyfyQfjcToCVBxct7Tgl8YdruRXHiuD+cepmRzaycIDfyqntiqPzB8mOHF4TvxlDuYL2Vdcs4N3JeD+fZ3YMfG2LxDGaqwEBTx3tuURl7dkcxvdwh29IR8gKllWId7+xKHANKpk1o13NRpTsX9cxe+5rsP1uXZux8yb0EedYauoMiDdyuMjK0Jd3kXjeB8djsEWfnRV1NIr7WXsjHadwLQNiGLnrOZmLYt9Gs+KyG6AdUuABNlt0CLJCL6uUD88Fw21CbDShNB7VC/33FphJtPFtpZo4isdnzMSAOIhvqxdHygr1A+nxSViKvCbXmDkW26Ea/49hJOj1JCXaBjm7kP/CVpw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BN6PR10MB1748.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(346002)(376002)(39860400002)(136003)(396003)(366004)(7696005)(8676002)(5660300002)(83380400001)(2906002)(478600001)(66556008)(66476007)(66946007)(44832011)(956004)(26005)(16526019)(52116002)(86362001)(316002)(6666004)(8936002)(6486002)(6916009)(36756003)(2616005)(186003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?qRuKX01GzgEi+jVBl2Sac4zYe02uQon5/XHSow3jomkKEOHmb3T1xqAScP9i?= =?us-ascii?Q?zoExtMW/VICl5Jtr5ZQiPISw7Vg7vU/aCGJmn3ROaC/9oaw9xMHh1vJskHOd?= =?us-ascii?Q?Ax9cDgYCIGhi69jZjWL86L2EjzOyxMbdFqo31LdW9pZ4EQSBtP0wACh+9m+n?= =?us-ascii?Q?eZdpZYb20MIPXqjCzl7/XviixqcJjUaxr9SZIXQmFDYQx4C4FR6E75Yjgmnn?= =?us-ascii?Q?c76VYX6gtsuTJ6tXLJuaVrUTWoYRxKj3XyW8rpVG2SqPwlq+vOj+bnk14VLY?= =?us-ascii?Q?lWshxTQKwXXI32BzbO/f9l05BWMBwB9Ptm/sOimxeR+rdsOk3CorSkHaIkQm?= =?us-ascii?Q?R3YemENc9Nc0CVi6kwEoQgsQErr3jFuU76l3CozgIwLOVM5i9q/8whSjYExW?= =?us-ascii?Q?0XjAOuQT8T1+B4djG2YOqrSLZRJyUo2oNvz9vrMil9nJ6iy8/BN28gz4aTUc?= =?us-ascii?Q?AhFQeplWJIaIeivBuW0As0tilwcczNKvmFlkuYdPPHfLmSXd6NO1z/LuHSza?= =?us-ascii?Q?vxnd2RaT8VK0Wct7SRLKrIMTVpkX5H1qnLmgKcw/pIAM8lYOnkeA/NBw1sIB?= =?us-ascii?Q?CzgcKE8aIksCJqOEPMufZoa9gYohL4dZranQja+KbEnjdlOP6dBLmXFEDdpp?= =?us-ascii?Q?D6ENLOjCNRrEWOKKgdK1kG+h/PpPjWODhqBSj39xYzwmTPMk023u3ZwIIe1m?= =?us-ascii?Q?MxxbTjHOjKFy61D+icxUN0GAXTK09Pg+U8+mRC/LsUUXxILHrwk5lQ4PEW74?= =?us-ascii?Q?7+2nbwRtBckRFC47Ki76AtskHikZ794nHr5WAHX4F1LAHsTICiYoh/oPgOyB?= =?us-ascii?Q?tJlFgYuFTUT0MMVCjYVF6bm2swmuzASyH23l5XmygTrgbbTivtH7cBkG4Why?= =?us-ascii?Q?ZZqnGMeNtVj2evADC37PI8h+wS5kZLOGJmv8NTnFTL9evEH/w3FBR65tcdLg?= =?us-ascii?Q?SYmPALi25yw2zE4OVP7nR65pf1JCSB1m8WjY3d0Wb1DHGlF4yG7g/zrA6wv4?= =?us-ascii?Q?KF7JGFvgT4W2pdyclJeFNzIGcI2k4QLaZZKf8ALFaeIWtELDczEoRaXpS28I?= =?us-ascii?Q?iY44WunO?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 746b6fab-9738-42df-68ff-08d8c71cbf93 X-MS-Exchange-CrossTenant-AuthSource: BN6PR10MB1748.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Feb 2021 01:49:16.1914 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: NZzWSM6bNUF4nx8yTANhvqKzWLKUbSzR2rFHKAXeSHF76UaeavGjg5kC1tSLWPM7nt5BvUTxvKLbHzngVonfFw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR1001MB2098 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9882 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 mlxlogscore=999 phishscore=0 spamscore=0 suspectscore=0 malwarescore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2102020009 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9882 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 adultscore=0 priorityscore=1501 impostorscore=0 malwarescore=0 clxscore=1015 spamscore=0 lowpriorityscore=0 phishscore=0 mlxlogscore=999 mlxscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2102020010 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_STOCKGEN, MSGID_FROM_MTA_HEADER, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 02 Feb 2021 01:49:23 -0000 Added function fetch_tid_type which calls get_tid_type and will set up the type, associated with a tid, if it is not read in yet. Also implement function read_forward_type which handles the CTF_K_FORWARD kind. Expanded gdb.base/ctf-ptype.exp to add cases with forward references. --- gdb/ctfread.c | 78 ++++++++++++++++++++++++++++++------ gdb/testsuite/gdb.base/ctf-ptype.c | 12 ++++++ gdb/testsuite/gdb.base/ctf-ptype.exp | 2 + 3 files changed, 79 insertions(+), 13 deletions(-) diff --git a/gdb/ctfread.c b/gdb/ctfread.c index c75fe25..931b609 100644 --- a/gdb/ctfread.c +++ b/gdb/ctfread.c @@ -186,6 +186,8 @@ static struct type *read_typedef_type (struct ctf_context *cp, ctf_id_t tid, static void process_struct_members (struct ctf_context *cp, ctf_id_t tid, struct type *type); +static struct type *read_forward_type (struct ctf_context *cp, ctf_id_t tid); + static struct symbol *new_symbol (struct ctf_context *cp, struct type *type, ctf_id_t tid); @@ -269,6 +271,25 @@ struct ctf_tid_and_type return NULL; } +/* Fetch the type for TID in CCP OF's tid_and_type hash, add the type to + context CCP if hash is empty or TID does not have a saved type. */ + +static struct type * +fetch_tid_type (struct ctf_context *ccp, ctf_id_t tid) +{ + struct objfile *of = ccp->of; + struct type *typ; + + typ = get_tid_type (of, tid); + if (typ == NULL) + { + ctf_add_type_cb (tid, ccp); + typ = get_tid_type (of, tid); + } + + return typ; +} + /* Return the size of storage in bits for INTEGER, FLOAT, or ENUM. */ static int @@ -368,7 +389,7 @@ struct ctf_tid_and_type FIELD_NAME (*fp) = name; kind = ctf_type_kind (ccp->fp, tid); - t = get_tid_type (ccp->of, tid); + t = fetch_tid_type (ccp, tid); if (t == NULL) { t = read_type_record (ccp, tid); @@ -661,7 +682,7 @@ struct ctf_tid_and_type type->set_code (TYPE_CODE_FUNC); ctf_func_type_info (fp, tid, &cfi); - rettype = get_tid_type (of, cfi.ctc_return); + rettype = fetch_tid_type (ccp, cfi.ctc_return); TYPE_TARGET_TYPE (type) = rettype; set_type_align (type, ctf_type_align (fp, tid)); @@ -792,11 +813,11 @@ struct ctf_tid_and_type return NULL; } - element_type = get_tid_type (objfile, ar.ctr_contents); + element_type = fetch_tid_type (ccp, ar.ctr_contents); if (element_type == NULL) return NULL; - idx_type = get_tid_type (objfile, ar.ctr_index); + idx_type = fetch_tid_type (ccp, ar.ctr_index); if (idx_type == NULL) idx_type = objfile_type (objfile)->builtin_int; @@ -824,7 +845,7 @@ struct ctf_tid_and_type struct objfile *objfile = ccp->of; struct type *base_type, *cv_type; - base_type = get_tid_type (objfile, btid); + base_type = fetch_tid_type (ccp, btid); if (base_type == NULL) { base_type = read_type_record (ccp, btid); @@ -848,7 +869,7 @@ struct ctf_tid_and_type ctf_dict_t *fp = ccp->fp; struct type *base_type, *cv_type; - base_type = get_tid_type (objfile, btid); + base_type = fetch_tid_type (ccp, btid); if (base_type == NULL) { base_type = read_type_record (ccp, btid); @@ -874,7 +895,7 @@ struct ctf_tid_and_type struct objfile *objfile = ccp->of; struct type *base_type, *cv_type; - base_type = get_tid_type (objfile, btid); + base_type = fetch_tid_type (ccp, btid); if (base_type == NULL) { base_type = read_type_record (ccp, btid); @@ -901,7 +922,7 @@ struct ctf_tid_and_type char *aname = obstack_strdup (&objfile->objfile_obstack, name); this_type = init_type (objfile, TYPE_CODE_TYPEDEF, 0, aname); set_tid_type (objfile, tid, this_type); - target_type = get_tid_type (objfile, btid); + target_type = fetch_tid_type (ccp, btid); if (target_type != this_type) TYPE_TARGET_TYPE (this_type) = target_type; else @@ -920,7 +941,7 @@ struct ctf_tid_and_type struct objfile *of = ccp->of; struct type *target_type, *type; - target_type = get_tid_type (of, btid); + target_type = fetch_tid_type (ccp, btid); if (target_type == NULL) { target_type = read_type_record (ccp, btid); @@ -937,6 +958,34 @@ struct ctf_tid_and_type return set_tid_type (of, tid, type); } +/* Read all information from a TID of CTF_K_FORWARD. */ + +static struct type * +read_forward_type (struct ctf_context *ccp, ctf_id_t tid) +{ + struct objfile *of = ccp->of; + ctf_dict_t *fp = ccp->fp; + struct type *type; + uint32_t kind; + + type = alloc_type (of); + + gdb::unique_xmalloc_ptr name (ctf_type_aname_raw (fp, tid)); + if (name != NULL && strlen (name.get() ) != 0) + type->set_name (obstack_strdup (&of->objfile_obstack, name.get ())); + + kind = ctf_type_kind_forwarded (fp, tid); + if (kind == CTF_K_UNION) + type->set_code (TYPE_CODE_UNION); + else + type->set_code (TYPE_CODE_STRUCT); + + TYPE_LENGTH (type) = 0; + type->set_is_stub (true); + + return set_tid_type (of, tid, type); +} + /* Read information associated with type TID. */ static struct type * @@ -990,6 +1039,9 @@ struct ctf_tid_and_type case CTF_K_ARRAY: type = read_array_type (ccp, tid); break; + case CTF_K_FORWARD: + type = read_forward_type (ccp, tid); + break; case CTF_K_UNKNOWN: break; default: @@ -1136,7 +1188,7 @@ struct ctf_tid_and_type if ((tid = ctf_lookup_by_symbol (ccp->fp, idx)) == CTF_ERR) return NULL; - type = get_tid_type (ccp->of, tid); + type = fetch_tid_type (ccp, tid); if (type == NULL) return NULL; @@ -1170,7 +1222,7 @@ struct ctf_tid_and_type return NULL; tid = ctf_lookup_by_symbol (ccp->fp, idx); - ftype = get_tid_type (ccp->of, tid); + ftype = fetch_tid_type (ccp, tid); if (finfo.ctc_flags & CTF_FUNC_VARARG) ftype->set_has_varargs (true); ftype->set_num_fields (argc); @@ -1184,7 +1236,7 @@ struct ctf_tid_and_type to find the argument type. */ for (int iparam = 0; iparam < argc; iparam++) { - atyp = get_tid_type (ccp->of, argv[iparam]); + atyp = fetch_tid_type (ccp, argv[iparam]); if (atyp) ftype->field (iparam).set_type (atyp); else @@ -1192,7 +1244,7 @@ struct ctf_tid_and_type } sym = new_symbol (ccp, ftype, tid); - rettyp = get_tid_type (ccp->of, finfo.ctc_return); + rettyp = fetch_tid_type (ccp, finfo.ctc_return); if (rettyp != NULL) SYMBOL_TYPE (sym) = rettyp; else diff --git a/gdb/testsuite/gdb.base/ctf-ptype.c b/gdb/testsuite/gdb.base/ctf-ptype.c index cbc7815..51c7c68 100644 --- a/gdb/testsuite/gdb.base/ctf-ptype.c +++ b/gdb/testsuite/gdb.base/ctf-ptype.c @@ -124,6 +124,18 @@ struct { a symbol. */ t_struct3 v_struct3; +/**** Some misc more complicated things *******/ + +struct link { + struct link *next; +#ifdef __STDC__ + struct link *(*linkfunc) (struct link *self, int flags); +#else + struct link *(*linkfunc) (); +#endif + struct t_struct stuff[3]; +} *s_link; + /**** unions *******/ union t_union { diff --git a/gdb/testsuite/gdb.base/ctf-ptype.exp b/gdb/testsuite/gdb.base/ctf-ptype.exp index 056f712..7dd6d95 100644 --- a/gdb/testsuite/gdb.base/ctf-ptype.exp +++ b/gdb/testsuite/gdb.base/ctf-ptype.exp @@ -76,6 +76,8 @@ if [gdb_test "ptype v_t_struct_p->v_float_member" "type = float"]<0 then { return -1 } +gdb_test "ptype struct link" "type = struct link \{\[\r\n\]+\[ \t\]+struct link \\*next;\[\r\n\]+\[ \t\]+struct link \\*\\(\\*linkfunc\\)\\((struct link \\*, int|void|)\\);\[\r\n\]+\[ \t\]+struct t_struct stuff.3.;\[\r\n\]+\}.*" "ptype linked list structure" + # # test ptype command with unions # -- 1.8.3.1