From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by sourceware.org (Postfix) with ESMTPS id 772E23858C2B for ; Fri, 7 Apr 2023 22:04:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 772E23858C2B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=oracle.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=oracle.com Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 337FxC9H026837 for ; Fri, 7 Apr 2023 22:04:44 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2022-7-12; bh=hWLe8uEfV6nHw8kwT3jZxDP9v6gj7ZYRL7EEbBpQWJQ=; b=Et6rXi7COGkIWqY021Dr8Sdshef/k2YvJF8fkARwhfuZfOUXw2h15fhhrxmBqvLD5MFo 8kp6NOoTntyUsdwVbAUrqIGNkcBjxWaUNFT8HfKCIlQaUbkLTXr96Bs+CHhiF+Ng5+os 67CnU7odiTSMDq4UMdWmunTJtW+h6a2iJwL4YgBy0Z475rP28+oEh9N5f0fzGk+HKCmh ZBatbPuM2FxAxxPrcxAQLip+vN2MFvDzFCWqHKYS0vZihGvIdq/cR2HzKTh/vuuPJlII jmPQGR3MA5HsdRbSXrIuXmuZXzrIhWGi0cNLrzaQmbQ7Bk7g+WpNu/5QKAM0ZCHaV9RZ kA== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3ppbhc63pk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 07 Apr 2023 22:04:43 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 337LPIMp027464 for ; Fri, 7 Apr 2023 22:04:42 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2104.outbound.protection.outlook.com [104.47.55.104]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3pptuv9tw9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 07 Apr 2023 22:04:42 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fLIkH+CKoUeRWa5QtWR9jv9EJMNS9M1vBYt9LxayYajRl/ZeimCd18xpp9uHZa4t30K2fM6LDy0Za4mkR4cDMObniO3Ti5GK5LLTe/b+faMdKgGTagiEG7DQ/9Td2mCNDi9SAN883OQDdZuYZPnf/QjAcjXIbMU91pT+CD3O7ZA7FvWL6ZpEDhCMz4s1404PPXa/xGdgWUUo8eFcXsRugxY09kP1qZUxG4Li3OCCv7BIb1o53LmYUGUCv1gX2wYPw6E1wHNSUio6wd3OjDxIIgJvoMhNF7+cuUNaKMRx4EPcVpBAdTIe/IxQv0EEzH3ABzdsArlWUbzxuDwGav6j5Q== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=hWLe8uEfV6nHw8kwT3jZxDP9v6gj7ZYRL7EEbBpQWJQ=; b=HIvaR6GI38SZNEcqL8xu88btyZXzNqUWe59RsArwUm9EgrU9ZFHeUUe3k/wwrAPvx+H3sXunZHA8D7yLkwJdnLRi/Y46808sCkTZWJi9sL27/rX0Dp4l4+qn3wBdmJrML81SWire39K3bhmxjZAS6GZlQjyLxOUdrsYaBsE1G4lNj4LEdWb/tIt3gqQP5PE8Fv0/G1GTn+ityTeMVu/Olfu8/OhTSlMH2p/W8y0VNgdW0jmDVYm4yiZluzp2KuRAFxeQq5Z8YoEb97wHUuENJX9+1/VqFJby/0zsCJZf1D/OamLDCfOL/jiMCEyfdkOPFBYY/ffJKBamiYsZQiUxDA== 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=hWLe8uEfV6nHw8kwT3jZxDP9v6gj7ZYRL7EEbBpQWJQ=; b=S6NjsN5Njvou6fOu7GExbM9V7+oIjYZneUUFHCsWQ7xj8tEkaPcoI+by5SNxAbYZtR9AyKJhk/KIhZ11XifUdPlvw4NCgQjGKoxdkr+8wyKs7B0xEXsQp2LmRthzhVy/uYIDoysZMxucgtcOs4xzpYUPwNSpBLHopP5F6p1a+vA= Received: from DS0PR10MB6798.namprd10.prod.outlook.com (2603:10b6:8:13c::20) by SJ2PR10MB7084.namprd10.prod.outlook.com (2603:10b6:a03:4c4::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6254.35; Fri, 7 Apr 2023 22:04:39 +0000 Received: from DS0PR10MB6798.namprd10.prod.outlook.com ([fe80::cffe:f272:20:9a87]) by DS0PR10MB6798.namprd10.prod.outlook.com ([fe80::cffe:f272:20:9a87%9]) with mapi id 15.20.6254.035; Fri, 7 Apr 2023 22:04:39 +0000 From: Nick Alcock To: binutils@sourceware.org Subject: [PATCH 2/3] libctf: propagate errors from parents correctly Date: Fri, 7 Apr 2023 23:04:25 +0100 Message-Id: <20230407220426.63786-2-nick.alcock@oracle.com> X-Mailer: git-send-email 2.39.1.268.g9de2f9a303 In-Reply-To: <20230407220426.63786-1-nick.alcock@oracle.com> References: <20230407220426.63786-1-nick.alcock@oracle.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: LNXP265CA0034.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:5c::22) To DS0PR10MB6798.namprd10.prod.outlook.com (2603:10b6:8:13c::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR10MB6798:EE_|SJ2PR10MB7084:EE_ X-MS-Office365-Filtering-Correlation-Id: 5d96e614-bc85-404d-0ba6-08db37b41569 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZKP6bhW/2GqSzMtOrTiMhfTUcqtjxt/1ylcSqSPaWM+W6npevDRYPvSMsFug4jAP2XQoTevTf/eI9NKF5oAuBfA89hOGkpaWz1nmSETBNtkUWy6FC7LQvlycR4rguahkNI5UdcTC83Uapu1iTEYY3Flwt2zvz2sYjdPR3sg6ltQ5BLV1VHIjt9Ep34voaCIVvWb0FwuLTalLVs1o+KhMV93xCoOfWlMP+WvcYuHMqoifbUeit265Fcy+w97pzLkccU/aQE9bOc5ki3v6L96KIQAe8CiizCyc3gb29D5dtnJYEEksamjhd+5TEQw3QZYpAccjIOKMMJMcfN3g0661MWgbkAELGlgQUpoC3LgYuTjThk86FAbS8owP00198dA7Jf58NLVNTv1MVIX/x0FJ9jv66qVmOzP5j8+3fzDPgGfezBVs3e0fkqC4nl3XsKSuS5nubvn7SHSV1It31PxYpnkADVSLtZopCYTPTXURJYm5TzeMZHukEuwgx3xwi+awFTZLlGSFYTq+4Ms5HSIAK59fK57UHAAvWNxZrNxsknGttS6D3fYpFUlv+NSng8tk X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS0PR10MB6798.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(366004)(346002)(39860400002)(376002)(396003)(136003)(451199021)(6666004)(2616005)(83380400001)(8676002)(6506007)(6512007)(1076003)(6486002)(66476007)(6916009)(86362001)(38100700002)(2906002)(44832011)(186003)(41300700001)(478600001)(316002)(66556008)(66946007)(36756003)(30864003)(8936002)(5660300002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?23hQuYpa+Nxw8XG0cuDQCrkxIqWoUI6Q8Jc2qvz4w3BvtqdTNWnkRfrtJrXf?= =?us-ascii?Q?+pJWXX2bQgolkUgXm+G6cSKA1Ev8JonRe8iw+KlccywzOWADAXZqoY3H6OXA?= =?us-ascii?Q?Mo99M7NTOP4j7HWegptNWEb0Po8kbhKApUKDznOR2OYFYr69uSWI9kPK9m20?= =?us-ascii?Q?JjuROyWSpkIMK+nWs5alMVMClOqOIW5lf8ROHN6aD25AJZObEOfo0KzbvI1a?= =?us-ascii?Q?xnY0Tku9Y4Ia0SgnLqXBYljm/Er7h/w0M+/FEPHGqKfQjyeHotv8/D1qoezC?= =?us-ascii?Q?atvOjDG//eeiEiGpb8DE1nJagWB8wAuxnakJe1b8lQZdm7/2PvtWgnXSIXB2?= =?us-ascii?Q?jMDAruv63oPC+5yQxV0Q/WqThjGkAx/L/vQ9pNq6MFBVrGy+kEk0fyZNerO/?= =?us-ascii?Q?omZ1pE+GcO90MwNcE1C2A/Rj5NRASSWnfsnE5VotXicNAnIYbyWI/cIaEL8P?= =?us-ascii?Q?XshofoDY9NJWVqYVpZjF2j1+FpzhyLqwvA8UaB5w6U0w//SoIH2Btn6Rpz+c?= =?us-ascii?Q?n1qZE6e7KJUKhueIxQ3r5wIJXRxxD/vm3IPwjkXv3y8Q608xojwcOqbWOW12?= =?us-ascii?Q?1GWonSA7ME9lQwjjNfTIixvqIMgighSPQKNdyV9zSCbjDjHn95shahPJYyEU?= =?us-ascii?Q?6XwASgksCUzGBjA0S1YKbDZ2nJlDr9oor1BFI4UlN6ilKRkjjQGFJC92UQa0?= =?us-ascii?Q?FRH7ZJ18fd4Y905AcBfuBGGEVFRcNeq0+UTJWZqdH9aJrX1RQEwyyUXDzLw4?= =?us-ascii?Q?knX/nOiZADtURm8PqANIXg/3ONHkcnNu471Dth5ZwTAVWJNwRAPbtWYy6Q5R?= =?us-ascii?Q?kv40CLlEDz8Cwqx9v4XAGo7sgwx25xOBdGoieSsTtWXzhu4D80Zv1rn+0E4H?= =?us-ascii?Q?0KM0PQ5InYEzInwYDCcHWPDj/6zQ3wibnzMlFiV27GuMDyPf3J83VsImqEZV?= =?us-ascii?Q?Wc9C/PCBHof7frE7SEe2KPGuASfsKh6k0RROrGpsQPNUF9A6428cG41bQBOO?= =?us-ascii?Q?Y4jYT/JvwwPjydXfv0wahXM4UDsTbmg3rR4VuAaI9elw1nFjfoQ7u0PFZ9DS?= =?us-ascii?Q?+5Gdca3yDbf4QzdDaNPFdXhLcl6asWHzwj6PLvLq9xaiEVSs6nxO2YHZXVOa?= =?us-ascii?Q?WD4uYEmZ3GbCFhK+cEbzw0kcS6i7Ok9GDeTtSU8lwND9HwZtIzFdI1PPlUvD?= =?us-ascii?Q?ONHiGSy646BTC87S6EKueEQgNGl9KEpL602fn/jvJzRIl7Dtrv+2nQDwr9tL?= =?us-ascii?Q?YFSLrJNru/OnZMi0aD8CyDH32+NDu2fUkNH2/3e8TB/MY85dNTGd+os0X7GM?= =?us-ascii?Q?SCHdfyrz/vDEO5V+fHI8mweWIGoK9fux/5VGVVRp4EJ38BahpUP+krz13qEy?= =?us-ascii?Q?SlorBUlejmR9/KfSkOnk0L4g1pOrXY+HvcvzKQJ9wrDzv1pgX8fFv3EXW31y?= =?us-ascii?Q?nMC2kk1gJafz8DUxh7pywLxFBtoft6ZPaL4Go5cefzkeyaUVXSZBkEiiw+Jh?= =?us-ascii?Q?0O39P1DbePMBJWmgnLz+qkDQauzzGMxcOyo+1gPjhYh4SkAJn+Rr49MdmZXY?= =?us-ascii?Q?2bz1GHneVGUor376+pZjtHzcRU0Wo40TfRkyfRf6A4ONDNjuM3zdoVx92eYB?= =?us-ascii?Q?DA=3D=3D?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: prUEJG8XLjyDBwhcDujSX9IBCPJIxPvkuJ+oSsPyRm/hcOZyr5pfVRy1QSW/WwjPDBqNrFdQ4oo/ADrK1nmFRLAnc1j34kffx+y3yyarSQ1rCXAH/43MsmsD3oeFXFHfMSfRbELlEvigy321uM1JmeWEjxRz74ArFXqD79P8r8ZR8VrmJVyQWDDuuu95AYtKmzZK6zWuMIhgoboWuqZJINEPTzt8PNFXcXSi0JHMKSByXtHGurJsSE3WbGvPWeiJ60fZwp3jSDCGXRA4WZta15zgprceT5GM84ursNGfz3LYyHHuMpZDeuRUc+cdjsjOHqdgAX9x7f6Ye9du2PhXkTJ+wFBzBFzrhxIDjCW08acCylAe2uIvbTrtEe/DPRvXHWcF3gKQuSdDN+RTItRPA9019diQVHa8aMV/CvPL27K/4K2Dla2V8JtmcO2Zevxl9br8/rqbeOrFiaLwCwWREp5Qtk7w34jcU+FI0SubPfgD8XhB8VvqIgFHa/nEIO/bsO4SN7aVrHkgWtOztgrz2fYeiyrYcWdqqh45lSxwZBfDM+DggIfZDJ7uCH5KLL5o3p9thWXU50U/O71LAXTsUTlwphFUjG00BvjOh6vxokAFzxD0EqthEJEWBQc70AlgYmqcnyvNhIAwEB8fS5slURyS7/v1SJNZDBoR6BUysRSTavRP8DCmDOhrrpgMj6q3AasMu7SNUwUZBOxkUZquS4UIn6Dcz2tHMCc1lKjuQNKlsybmhKRyug9jb2au1g8E X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5d96e614-bc85-404d-0ba6-08db37b41569 X-MS-Exchange-CrossTenant-AuthSource: DS0PR10MB6798.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Apr 2023 22:04:39.7944 (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: qlGj28tI+w0vgui70YNtH44emK4SZ1j6NCBJJ7n6pS17F5biV9obPrZcM/Py02JyHJ7JBTGnjKlkkU0FEy751w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR10MB7084 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-04-07_14,2023-04-06_03,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxscore=0 malwarescore=0 mlxlogscore=999 adultscore=0 phishscore=0 suspectscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2304070199 X-Proofpoint-GUID: M0x9FE7Fkp9fBbIbZVmKECs2b__pVyDT X-Proofpoint-ORIG-GUID: M0x9FE7Fkp9fBbIbZVmKECs2b__pVyDT X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: CTF dicts have per-dict errno values: as with other errno values these are set on error and left unchanged on success. This means that all errors *must* set the CTF errno: if a call leaves it unchanged, the caller is apt to find a previous, lingering error and misinterpret it as the real error. There are many places in libctf where we carry out operations on parent dicts as a result of carrying out other user-requested operations on child dicts (e.g. looking up information on a pointer to a type will look up the type as well: the pointer might well be in a child and the type it's a pointer to in the parent). Those operations on the parent might fail; if they do, the error must be correctly reflected on the child that the user-visible operation was carried out on. In many places this was not happening. So, audit and fix all those places. Add tests for as many of those cases as possible so they don't regress. libctf/ * ctf-create.c (ctf_add_slice): Use the original dict. * ctf-lookup.c (ctf_lookup_variable): Propagate errors. (ctf_lookup_symbol_idx): Likewise. * ctf-types.c (ctf_member_next): Likewise. (ctf_type_resolve_unsliced): Likewise. (ctf_type_aname): Likewise. (ctf_member_info): Likewise. (ctf_type_rvisit): Likewise. (ctf_func_type_info): Set the error on the right dict. (ctf_type_encoding): Use the original dict. * testsuite/libctf-writable/error-propagation.*: New test. --- libctf/ctf-create.c | 4 +- libctf/ctf-lookup.c | 19 +- libctf/ctf-types.c | 29 +++- .../libctf-writable/error-propagation.c | 164 ++++++++++++++++++ .../libctf-writable/error-propagation.lk | 1 + 5 files changed, 204 insertions(+), 13 deletions(-) create mode 100644 libctf/testsuite/libctf-writable/error-propagation.c create mode 100644 libctf/testsuite/libctf-writable/error-propagation.lk diff --git a/libctf/ctf-create.c b/libctf/ctf-create.c index 7a3b3078dba..6b342dc64a2 100644 --- a/libctf/ctf-create.c +++ b/libctf/ctf-create.c @@ -628,8 +628,8 @@ ctf_add_slice (ctf_dict_t *fp, uint32_t flag, ctf_id_t ref, point to the unimplemented type, for now, because the compiler can emit such slices, though they're not very much use. */ - resolved_ref = ctf_type_resolve_unsliced (tmp, ref); - kind = ctf_type_kind_unsliced (tmp, resolved_ref); + resolved_ref = ctf_type_resolve_unsliced (fp, ref); + kind = ctf_type_kind_unsliced (fp, resolved_ref); if ((kind != CTF_K_INTEGER) && (kind != CTF_K_FLOAT) && (kind != CTF_K_ENUM) diff --git a/libctf/ctf-lookup.c b/libctf/ctf-lookup.c index 950c0a809ac..c65849118cb 100644 --- a/libctf/ctf-lookup.c +++ b/libctf/ctf-lookup.c @@ -402,7 +402,13 @@ ctf_lookup_variable (ctf_dict_t *fp, const char *name) if (ent == NULL) { if (fp->ctf_parent != NULL) - return ctf_lookup_variable (fp->ctf_parent, name); + { + ctf_id_t ptype; + + if ((ptype = ctf_lookup_variable (fp->ctf_parent, name)) != CTF_ERR) + return ptype; + return (ctf_set_errno (fp, ctf_errno (fp->ctf_parent))); + } return (ctf_set_errno (fp, ECTF_NOTYPEDAT)); } @@ -626,7 +632,16 @@ ctf_lookup_symbol_idx (ctf_dict_t *fp, const char *symname) try_parent: if (fp->ctf_parent) - return ctf_lookup_symbol_idx (fp->ctf_parent, symname); + { + unsigned long psym; + + if ((psym = ctf_lookup_symbol_idx (fp->ctf_parent, symname)) + != (unsigned long) -1) + return psym; + + ctf_set_errno (fp, ctf_errno (fp->ctf_parent)); + return (unsigned long) -1; + } else { ctf_set_errno (fp, err); diff --git a/libctf/ctf-types.c b/libctf/ctf-types.c index dd82053e1d7..c20ff825d9a 100644 --- a/libctf/ctf-types.c +++ b/libctf/ctf-types.c @@ -177,7 +177,7 @@ ctf_member_next (ctf_dict_t *fp, ctf_id_t type, ctf_next_t **it, if (ctf_struct_member (fp, &memb, i->ctn_tp, i->u.ctn_vlen, i->ctn_size, i->ctn_n) < 0) - return -1; /* errno is set for us. */ + return (ctf_set_errno (ofp, ctf_errno (fp))); membname = ctf_strptr (fp, memb.ctlm_name); @@ -216,11 +216,12 @@ ctf_member_next (ctf_dict_t *fp, ctf_id_t type, ctf_next_t **it, ctf_next_destroy (i); *it = NULL; i->ctn_type = 0; - return ret; /* errno is set for us. */ + ctf_set_errno (ofp, ctf_errno (fp)); + return ret; } if (!ctf_assert (fp, (i->ctn_next == NULL))) - return -1; /* errno is set for us. */ + return (ctf_set_errno (ofp, ctf_errno (fp))); i->ctn_type = 0; /* This sub-struct has ended: on to the next real member. */ @@ -597,6 +598,7 @@ ctf_type_resolve (ctf_dict_t *fp, ctf_id_t type) ctf_id_t ctf_type_resolve_unsliced (ctf_dict_t *fp, ctf_id_t type) { + ctf_dict_t *ofp = fp; const ctf_type_t *tp; if ((type = ctf_type_resolve (fp, type)) == CTF_ERR) @@ -606,7 +608,13 @@ ctf_type_resolve_unsliced (ctf_dict_t *fp, ctf_id_t type) return CTF_ERR; /* errno is set for us. */ if ((LCTF_INFO_KIND (fp, tp->ctt_info)) == CTF_K_SLICE) - return ctf_type_reference (fp, type); + { + ctf_id_t ret; + + if ((ret = ctf_type_reference (fp, type)) == CTF_ERR) + return (ctf_set_errno (ofp, ctf_errno (fp))); + return ret; + } return type; } @@ -767,6 +775,7 @@ ctf_type_aname (ctf_dict_t *fp, ctf_id_t type) break; err: + ctf_set_errno (fp, ctf_errno (rfp)); free (argv); ctf_decl_fini (&cd); return NULL; @@ -1216,8 +1225,8 @@ ctf_type_encoding (ctf_dict_t *fp, ctf_id_t type, ctf_encoding_t *ep) ctf_id_t underlying; slice = (ctf_slice_t *) vlen; - underlying = ctf_type_resolve (fp, slice->cts_type); - if (ctf_type_encoding (fp, underlying, &underlying_en) < 0) + underlying = ctf_type_resolve (ofp, slice->cts_type); + if (ctf_type_encoding (ofp, underlying, &underlying_en) < 0) return -1; /* errno is set for us. */ ep->cte_format = underlying_en.cte_format; @@ -1409,7 +1418,7 @@ ctf_member_info (ctf_dict_t *fp, ctf_id_t type, const char *name, const char *membname; if (ctf_struct_member (fp, &memb, tp, vlen, vbytes, i) < 0) - return -1; /* errno is set for us. */ + return (ctf_set_errno (ofp, ctf_errno (fp))); membname = ctf_strptr (fp, memb.ctlm_name); @@ -1558,6 +1567,7 @@ ctf_enum_value (ctf_dict_t *fp, ctf_id_t type, const char *name, int *valp) int ctf_func_type_info (ctf_dict_t *fp, ctf_id_t type, ctf_funcinfo_t *fip) { + ctf_dict_t *ofp = fp; const ctf_type_t *tp; uint32_t kind; const uint32_t *args; @@ -1574,7 +1584,7 @@ ctf_func_type_info (ctf_dict_t *fp, ctf_id_t type, ctf_funcinfo_t *fip) kind = LCTF_INFO_KIND (fp, tp->ctt_info); if (kind != CTF_K_FUNCTION) - return (ctf_set_errno (fp, ECTF_NOTFUNC)); + return (ctf_set_errno (ofp, ECTF_NOTFUNC)); fip->ctc_return = tp->ctt_type; fip->ctc_flags = 0; @@ -1638,6 +1648,7 @@ static int ctf_type_rvisit (ctf_dict_t *fp, ctf_id_t type, ctf_visit_f *func, void *arg, const char *name, unsigned long offset, int depth) { + ctf_dict_t *ofp = fp; ctf_id_t otype = type; const ctf_type_t *tp; const ctf_dtdef_t *dtd; @@ -1686,7 +1697,7 @@ ctf_type_rvisit (ctf_dict_t *fp, ctf_id_t type, ctf_visit_f *func, ctf_lmember_t memb; if (ctf_struct_member (fp, &memb, tp, vlen, vbytes, i) < 0) - return -1; /* errno is set for us. */ + return (ctf_set_errno (ofp, ctf_errno (fp))); if ((rc = ctf_type_rvisit (fp, memb.ctlm_type, func, arg, ctf_strptr (fp, memb.ctlm_name), diff --git a/libctf/testsuite/libctf-writable/error-propagation.c b/libctf/testsuite/libctf-writable/error-propagation.c new file mode 100644 index 00000000000..9d25e635c85 --- /dev/null +++ b/libctf/testsuite/libctf-writable/error-propagation.c @@ -0,0 +1,164 @@ +/* Make sure that errors are propagated properly from parent dicts to children + when errors are encountered in child functions that can recurse to parents. + + We check specifically a subset of known-buggy functions. + Functions that require a buggy linker to expose, or that only fail on + assertion-failure-incurring corrupted dicts, are not tested. */ + +#include +#include +#include +#include + +static const char *desc; + +static void +check_prop_err (ctf_dict_t *child, ctf_dict_t *parent, int expected) +{ + if (ctf_errno (child) == expected) + return; + + if (ctf_errno (parent) == expected) + fprintf (stderr, "%s: error propagation failure: error \"%s\" not seen on child, " + "but instead on parent\n", desc, ctf_errmsg (ctf_errno (parent))); + else + fprintf (stderr, "%s: expected error is entirely lost: " + "\"%s\" seen on parent, \"%s\" on child\n", desc, + ctf_errmsg (ctf_errno (parent)), + ctf_errmsg (ctf_errno (child))); +} + +static void +no_prop_err (void) +{ + fprintf (stderr, "%s: expected error return not observed.\n", desc); +} + +int main (void) +{ + ctf_dict_t *parent; + ctf_dict_t *blank; + ctf_dict_t *child; + ctf_id_t void_id; + ctf_id_t base; + ctf_id_t slice; + ctf_id_t function; + ctf_encoding_t long_encoding = { CTF_INT_SIGNED, 0, sizeof (long) }; + ctf_encoding_t void_encoding = { CTF_INT_SIGNED, 0, 0 }; + ctf_encoding_t foo; + ctf_funcinfo_t fi; + ctf_id_t bar; + char *funcname; + int err; + + if ((parent = ctf_create (&err)) == NULL + || (child = ctf_create (&err)) == NULL + || (blank = ctf_create (&err)) == NULL) + { + fprintf (stderr, "Cannot create dicts: %s\n", ctf_errmsg (err)); + return 1; + } + + if ((ctf_import (child, parent)) < 0) + { + fprintf (stderr, "cannot import: %s\n", ctf_errmsg (ctf_errno (child))); + return 1; + } + + if ((void_id = ctf_add_integer (parent, CTF_ADD_ROOT, "void", &void_encoding)) + == CTF_ERR) + goto parent_err; + + if ((base = ctf_add_integer (parent, CTF_ADD_ROOT, "long int", &long_encoding)) + == CTF_ERR) + goto parent_err; + + foo.cte_format = 0; + foo.cte_bits = 4; + foo.cte_offset = 4; + if ((slice = ctf_add_slice (child, CTF_ADD_ROOT, base, &foo)) == CTF_ERR) + goto parent_err; + + if (ctf_add_variable (parent, "foo", base) < 0) + goto child_err; + + fi.ctc_return = void_id; + fi.ctc_argc = 0; + fi.ctc_flags = 0; + if ((function = ctf_add_function (child, CTF_ADD_ROOT, &fi, NULL)) == CTF_ERR) + goto child_err; + + desc = "func info lookup of non-function"; + if ((ctf_func_type_info (child, base, &fi)) != CTF_ERR) + no_prop_err (); + check_prop_err (child, parent, ECTF_NOTFUNC); + + desc = "func args lookup of non-function"; + if ((ctf_func_type_args (child, base, 0, &bar)) != CTF_ERR) + no_prop_err (); + check_prop_err (child, parent, ECTF_NOTFUNC); + + if ((ctf_import (child, blank)) < 0) + { + fprintf (stderr, "cannot reimport: %s\n", ctf_errmsg (ctf_errno (child))); + return 1; + } + + /* This is testing ctf_type_resolve_unsliced(), which is called by the enum + functions (which are not themselves buggy). This typea isn't an enum, but + that's OK: we're after an error, after all, and the type we're slicing is + not visible any longer, so nothing can tell it's not an enum. */ + + desc = "child slice resolution"; + if ((ctf_enum_value (child, slice, "foo", NULL)) != CTF_ERR) + no_prop_err (); + check_prop_err (child, parent, ECTF_BADID); + + desc = "child slice encoding lookup"; + if ((ctf_type_encoding (child, slice, &foo)) != CTF_ERR) + no_prop_err (); + check_prop_err (child, parent, ECTF_BADID); + + desc = "func info lookup of non-function"; + if ((ctf_func_type_info (child, base, &fi)) != CTF_ERR) + no_prop_err (); + check_prop_err (child, parent, ECTF_BADID); + + desc = "func args lookup of non-function"; + if ((ctf_func_type_args (child, base, 0, &bar)) != CTF_ERR) + no_prop_err (); + check_prop_err (child, parent, ECTF_BADID); + + desc = "child slice addition"; + if ((slice = ctf_add_slice (child, CTF_ADD_ROOT, base, &foo)) != CTF_ERR) + no_prop_err (); + check_prop_err (child, parent, ECTF_BADID); + + desc = "variable lookup"; + if (ctf_lookup_variable (child, "foo") != CTF_ERR) + no_prop_err (); + check_prop_err (child, parent, ECTF_NOTYPEDAT); + + desc = "function lookup via ctf_type_aname"; + if ((funcname = ctf_type_aname (child, function)) != NULL) + { + no_prop_err (); + free (funcname); + } + check_prop_err (child, parent, ECTF_BADID); + + ctf_dict_close (child); + ctf_dict_close (parent); + ctf_dict_close (blank); + fprintf (stderr, "All done.\n"); + return 0; + + parent_err: + fprintf (stderr, "cannot populate parent: %s\n", ctf_errmsg (ctf_errno (parent))); + return 1; + + child_err: + fprintf (stderr, "cannot populate child: %s\n", ctf_errmsg (ctf_errno (parent))); + return 1; + +} diff --git a/libctf/testsuite/libctf-writable/error-propagation.lk b/libctf/testsuite/libctf-writable/error-propagation.lk new file mode 100644 index 00000000000..b944f73d013 --- /dev/null +++ b/libctf/testsuite/libctf-writable/error-propagation.lk @@ -0,0 +1 @@ +All done. -- 2.39.1.268.g9de2f9a303