From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by sourceware.org (Postfix) with ESMTPS id 556DD3857C49 for ; Tue, 2 Aug 2022 08:07:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 556DD3857C49 Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 2726XcW0012140; Tue, 2 Aug 2022 08:07:23 GMT Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3hmv8s61bs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 02 Aug 2022 08:07:23 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 2726ke08007406; Tue, 2 Aug 2022 08:07:22 GMT Received: from nam02-bn1-obe.outbound.protection.outlook.com (mail-bn1nam07lp2042.outbound.protection.outlook.com [104.47.51.42]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3hmu31tmw3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 02 Aug 2022 08:07:22 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HAkXsG5IzrnmHhwyHzqUua18hBwHmZNzkGyoqwc9AOqDJfnCxyAEDbZEEoQEcIWqJyBEWWBWK7JPOUKMWWD2UMetFTP6RmAaN0EkfQa3IinGPRpCLj+v2FupfzBT6VDexzrvrBoVAFWQkL7uUVVPSu0lFYU+kTybuQG42YpmuR0nbT2HSqjsnFYLP5DRVR8xX/elBZTxq5V74WiyzroQlr23bXwQeq/o84DOyhC50TmE5ZggogJAiMccvG5WgsCl3NUyuGkyZc+ikqhWbmxUFiwcA7SDsZiz2exbHD58xLrfBDhSL42+8/Fo77GtoRbnlPaauwqdIujB6VS37pil8Q== 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=gyfa/g5POvzN9MNmOsdmj2Xr2KLKyR/z7ZGf0bML1+s=; b=Y48nkO0EHFGptusVQaXhmr7vJd1dJw/yVPBT3zJ4EEOKO5h8+bKzgZFHWAvbYKVHf9FXtBjUY2zJFgtc00MM7NSp78+eS6CD1F4tT4Q40EcNx3eJmoEpLwg4Xwmupffu8MCgewW9ctDP4SZBdYZgkZ65Jg8nvto6xD3x8jN2zR6APXan7CuNqt5ELB2OvImHE5H2HqAX6f2S7/O8+PPU6EqJS0U2Rb6t4jydctc9D/NZ+kTi0h2f7bsOoHdsEbrpHxs6bG484/IPqo9+Ju1Dwudu1iQ3o9zPS1sDdelhfuEy/OWc/4bus+OsDfvuftBEekofitvzaeBVuQ+EM2uFiA== 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 MWHPR1001MB2158.namprd10.prod.outlook.com (2603:10b6:301:2d::17) by CH2PR10MB4184.namprd10.prod.outlook.com (2603:10b6:610:7f::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5482.11; Tue, 2 Aug 2022 08:07:20 +0000 Received: from MWHPR1001MB2158.namprd10.prod.outlook.com ([fe80::65fb:fa92:9a15:f89b]) by MWHPR1001MB2158.namprd10.prod.outlook.com ([fe80::65fb:fa92:9a15:f89b%6]) with mapi id 15.20.5482.016; Tue, 2 Aug 2022 08:07:20 +0000 From: Indu Bhagat To: binutils@sourceware.org Cc: amodra@gmail.com, weimin.pan@oracle.com, Indu Bhagat Subject: [PATCH,V6 01/10] ctf-frame.h: Add CTF Frame format definition Date: Tue, 2 Aug 2022 01:04:43 -0700 Message-Id: <20220802080452.1143351-2-indu.bhagat@oracle.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220802080452.1143351-1-indu.bhagat@oracle.com> References: <20220802080452.1143351-1-indu.bhagat@oracle.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: MW4PR04CA0074.namprd04.prod.outlook.com (2603:10b6:303:6b::19) To MWHPR1001MB2158.namprd10.prod.outlook.com (2603:10b6:301:2d::17) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6d969fc1-a734-4da6-af3a-08da745e059e X-MS-TrafficTypeDiagnostic: CH2PR10MB4184:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hfAiDh4eV12ZWCAay9JGqwvyQbo8RsA1KmH4fHOASQ61r7sRJ3KZZzgorYJykdnE54RUJxtVfptliTBjJ877ndMgd4Kf8SiJloJ2Q1nv24qcQTEdRVSndZ40tzNOvxI+vMgiEURhU1FSqTnQnan0LdV/TGWjnLZJEio+VTZRn07GOIPv0VNFMQe8uViHfDifUc4ITYSTVgz8ar1lhDBDPBkNDmxN/i6wSypEv6qNCDpkc16xRfathlUHsFDjgEN+53/7R5Js7MFYZuvnFmLGBU9j+UUtmx3HJJPYFK54U6CLxtCDayPHOKsmE5mDb9aaY0pPc0JpW2HwXbOwqHfndA8JI2MICaqsXZKE3e2gOfqcL68KqQqJ1ib+zlpFKyHTIGYhrluGlnc1BbExRhmwPqQzL7SftJmih8TnHvAkgiDU6Rc/73/JFFjyA8bqrnQuqEuw/D+V5QphFSrJsgd6DClx6ylSKYwfNemsgcqyWe3SMd7Iw86XSzOhhd2rLu5ApLx6wP3RLDJ0my29fMd1B9QQkqZRG+5vm0V0AUe3BnfbAZlvm7S+BKzS0t8tBP98SjZu7SPuK4YKQjM7zPyNOkQmKOXujvLYrgXowtMFP7flDx/Bk+StWKCeHdriYWi0tyFO7lheZg+zr+vSplqW8D+iEvDTaFvKWAUYVRnc9DepbyMUZuN/0tPlVg02l0xbre9MB1pCR6iKPsvLfMSiIblXiLo0P1EiL6JfUHqOdm1uIpmjRva3zeahYrv8NW5d20FdWJjswwGi+Lk2s5tytAo9Z4NuCTntPuVykBHgxHto2YRlhqEBzzpU6ZrDXCjZXshuFtInVla2ofYLZnBJMNT2s2rNAjDphu5xD4tFOeA= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MWHPR1001MB2158.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230016)(376002)(366004)(136003)(346002)(396003)(39860400002)(4326008)(2616005)(1076003)(107886003)(83380400001)(186003)(66476007)(8936002)(66556008)(44832011)(8676002)(5660300002)(30864003)(66946007)(2906002)(36756003)(316002)(86362001)(478600001)(6916009)(6506007)(52116002)(6666004)(41300700001)(6512007)(26005)(38350700002)(38100700002)(6486002)(2004002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?fELPkypOpaefSa+bg4rp+s1DsroNej089WREeBZ5m6g1YI38h2kQMZqupTvY?= =?us-ascii?Q?9JsQmkbaUBe2g8+i+XUNvN+npprM8euLJBrJZGpOHOPKUtikE1B514aCPCIR?= =?us-ascii?Q?b8tKsVhlpZjwZ1Xn1eV72Hb26Str4eRv8/1kuTLa1fZuMbg/4Z9Dd0/gJcgH?= =?us-ascii?Q?uSX1SiUdrvhDL8AnzxkMPzhr61GRZKdA1YxC82BVY9ZQVAn5S7RlBlCeqTUW?= =?us-ascii?Q?avHZT+uaX7NtBnNnhhGQhvqGMNyl64hLauEh7/NpkYJQfguwyKgRZia3pSvo?= =?us-ascii?Q?ldqiZ5EQziPcM1juVgPAWHtgsPneRGJV9vPi2TPNOuC6nE4zFkgoQlqHCY2x?= =?us-ascii?Q?4wSb7AwUb4u/g9hN7M5JSvJv1Zzaie2NDHOy4fuvgwauDewgWfKlxCCmARg7?= =?us-ascii?Q?XyvnD5yHpDi5ag1mEHLpRuSHdcvnEp5JwBD/M/2Iqt0iODWcudt8NYVfd7VO?= =?us-ascii?Q?pTZOHagsvGpPgUTdE3EnS2UdZuVJTFqwDKqNzerhTzWh912ncyDNswGw18uY?= =?us-ascii?Q?YcIMcWmbEPJOHjD6Oz3T4mH55DqvPKbHG9hy4KpkhYr/GPZ/saStXiTAn+je?= =?us-ascii?Q?oqRsfPO2rFVPyMMXvlIC8AJvEL630H7CQk5wYDUI9dx0w+YNlSE44fBO5DT5?= =?us-ascii?Q?3O3H1WtqZVNymdzLmna14kfbSctTjJ52bYwsysqw+894uBcPhJvHHXXCDIju?= =?us-ascii?Q?ZRZynPOsY70+o+eJ8uk2aOPqJdmYY7uB1hMiXuT5sJTXgAJ3R5oogB3UT0XH?= =?us-ascii?Q?JKSK11pih90q8edIqQ/ebKc9zgdU2R3zi1R16smqogM+d53Um7ij2NHoc9l1?= =?us-ascii?Q?VSe/XgeusGJdVbKTnar+/mtlVT70m6SoX5NPGBY2d3uiWoiwBMuKG6ICX1r3?= =?us-ascii?Q?zJkLwCii9CLer9NTHRBzemqMzGedRN/tzjcNJvodlrsG+Adc0kAA6mrU8/D3?= =?us-ascii?Q?g6ICVWkc2l1AbFxm+CCSKDu+HJRAM6pSFtq7Zdhckxy+z2tfgAtMEFnxwG3g?= =?us-ascii?Q?eAT6/9Va9jRpLbjOb+liapAyCDIOBwcfRNZXflSglo6KExF1ICBX6jpfsCE0?= =?us-ascii?Q?DDyJFVqK3oUj9CXRqjDXw0653GEB1XA8Kgcjwot4tFpnUEmWLa1kQz7kiwsh?= =?us-ascii?Q?kJ6SUYjUS0JFwI8E4TcstvhMIvr8kQRb1UYZKGymWmypS/Fk7pU3RmHtK6H9?= =?us-ascii?Q?RUioJ4FmpqZnEyuJe6hxSgJ6m7ksDwpJHIW2DJtD2JuBarDnxkRxSCrAXHpK?= =?us-ascii?Q?5mnn/KHZCwLygUhQYwlF/HVNIoi2+NlqnPYCoOPkIgChQobCo4eJmZozC2Ur?= =?us-ascii?Q?OGDymGFf/9gNicnzutMD1V3U2jedkS058NVjReIEBmWVNxioXAiUAt6/EVjZ?= =?us-ascii?Q?uuk5ckwkFTDjLlhGQ6csKoKJgosPzewQ4ZAjM0PsCkNhLbMfLbnDK/0YhT0P?= =?us-ascii?Q?d9BvnbTnQDvwD0JZyN/77RoQjK8s2ya98gSyhjvEyHhuParo+DvVa6hgPMu9?= =?us-ascii?Q?qmqkTH1+EemD46CtO1Z41th72iP8jOS3zNJq2QQbs6vrx6x6lmqUxZ/osWbw?= =?us-ascii?Q?F6J1nQDmpoYt/1+mEv2Lww+jMuRffFzGaK2REW1v?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6d969fc1-a734-4da6-af3a-08da745e059e X-MS-Exchange-CrossTenant-AuthSource: MWHPR1001MB2158.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Aug 2022 08:07:19.8723 (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: EZgoipLYdDLM9sVpgffDYv0qYEtzy/G0A1s11IXwSJiPRBm6D4jqCyZJ0yozfZBRCfnRcNr82ITbn3KVts9RLw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR10MB4184 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-08-02_04,2022-08-01_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxscore=0 suspectscore=0 adultscore=0 bulkscore=0 malwarescore=0 mlxlogscore=999 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2206140000 definitions=main-2208020038 X-Proofpoint-GUID: EzadBDt4t2FOo9B3EY4PcWeMZ0N8edE5 X-Proofpoint-ORIG-GUID: EzadBDt4t2FOo9B3EY4PcWeMZ0N8edE5 X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_ASCII_DIVIDERS, KAM_SHORT, 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 X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 02 Aug 2022 08:07:27 -0000 [Changes from V5] - Fix minor typos. [End of changes from V5] [Changes from V4] - Fix minor typos. [End of changes from V4] [Changes from V3] - CTF Format differentiates between the two possible FDE types using a bit in the fde_func_info byte - CTF_FRAME_DESCRIPTOR_ENTRY_TYPE_ADDRINC or CTF_FRAME_DESCRIPTOR_ENTRY_TYPE_ADDRMASK. The new CTF FDE type (CTF_FRAME_DESCRIPTOR_ENTRY_TYPE_ADDRMASK) is ideal for representing unwind information for regular, repetitive instruction patterns like plt entries. [End of changes from V3] [Changes from V2] - Consistent use of terminology. [End of changes from V2] [Changes from V1] - Make use of uint8_t, uint16_t consistently. Removed the usage of unsigned char, unsigned short. [End of changes from V1] The header ctf-frame.h defines the CTF Frame format. The CTF Frame format is a simple, compact format for representing unwind information. This information can be used for generating backtraces. The current version supports AMD64 and AARCH64. More details of the CTF Frame format are included in the documentation of the header file in this patch. include/ChangeLog: * ctf-frame.h: New file. --- include/ctf-frame.h | 281 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 281 insertions(+) create mode 100644 include/ctf-frame.h diff --git a/include/ctf-frame.h b/include/ctf-frame.h new file mode 100644 index 00000000000..fc46b8a06d1 --- /dev/null +++ b/include/ctf-frame.h @@ -0,0 +1,281 @@ +/* CTF Frame format description. + Copyright (C) 2022 Free Software Foundation, Inc. + + This file is part of libctfframe. + + libctfframe is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the Free + Software Foundation; either version 3, or (at your option) any later + version. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. If not see + . */ + +#ifndef _CTF_FRAME_H +#define _CTF_FRAME_H + +#include +#include +#include + + +#ifdef __cplusplus +extern "C" +{ +#endif + +/* CTF Frame format. + + CTF Frame format can be used to compactly represent the information needed + for virtual stack unwinding. CTF Frame format keeps track of the minimal + necessary information needed for stack unwinding: + - Canonical Frame Address (CFA) + - Frame Pointer (FP) + - Return Address (RA) + + The CTF Frame section itself has the following structure: + + +--------+------------+---------+ + | file | function | frame | + | header | descriptor | row | + | | entries | entries | + +--------+------------+---------+ + + The file header stores a magic number and version information, flags, and + the byte offset of each of the sections relative to the end of the header + itself. The file header also specifies the total number of Function + Descriptor Entries, Frame Row Entries and length of the FRE sub-section. + + Following the header is a list of Function Descriptor Entries (FDEs). + This list may be sorted if the flags in the file header indicate it to be + so. The sort order, if applicable, is the order of functions in the + .text.* sections in the resulting binary artifact. Each Function + Descriptor Entry specifies the start PC of a function, the size in bytes + of the function and an offset to its first Frame Row Entry (FRE). Each FDE + additionally also specifies the type of FRE it uses to encode the unwind + information. + + Next, the Frame Row Entry section is a list of variable size records, + each of which represent CTF Frame unwind information for a set of PCs. A + singular Frame Row Entry is a self-sufficient record with information on + how to virtually unwind the stack for the applicable set of PCs. + + */ + + +/* CTF Frame format versions. */ +#define CTF_FRAME_VERSION_1 1 +/* CTF Frame magic number. */ +#define CTF_FRAME_MAGIC 0xdee2 +/* Current version of CTF Frame format. */ +#define CTF_FRAME_VERSION CTF_FRAME_VERSION_1 + +/* Various flags for CTF Frame. */ + +/* Function Descriptor Entries are sorted on PC. */ +#define CTF_FRAME_F_FDE_SORTED 0x1 +/* Frame-pointer based unwinding. */ +#define CTF_FRAME_F_FRAME_POINTER 0x2 + +#define CTF_FRAME_CFA_FIXED_FP_INVALID 0 +#define CTF_FRAME_CFA_FIXED_RA_INVALID 0 + +/* Supported ABIs/Arch. */ +#define CTF_FRAME_ABI_AARCH64_ENDIAN_BIG 1 /* AARCH64 big endian. */ +#define CTF_FRAME_ABI_AARCH64_ENDIAN_LITTLE 2 /* AARCH64 little endian. */ +#define CTF_FRAME_ABI_AMD64_ENDIAN_LITTLE 3 /* AMD64 little endian. */ + +/* CTF Frame FRE types. */ +#define CTF_FRAME_ROW_ENTRY_TYPE_ADDR1 1 +#define CTF_FRAME_ROW_ENTRY_TYPE_ADDR2 2 +#define CTF_FRAME_ROW_ENTRY_TYPE_ADDR4 3 + +/* CTF Frame Function Descriptor Entry types. + + The CTF Frame format has two possible representations for functions. The + choice of which type to use is made according to the instruction patterns + in the relevant program stub. + + A CTF FDE of type CTF_FRAME_FUNC_DESC_ENTRY_TYPE_PCINC is an indication + that the PCs in the FREs should be treated as increments in bytes. This is + used for a bulk of the executable code of a program, which contains + instructions with no specific pattern. + + A CTF FDE of type CTF_FRAME_FUNC_DESC_ENTRY_TYPE_PCMASK is an indication + that the PCs in the FREs should be treated as masks. This type is useful + for the cases when a small pattern of instructions in a program stub is + repeatedly to cover a specific functionality. Typical usescases are pltN + entries, trampolines etc. */ + +/* Unwinders perform a (PC >= FRE_START_ADDR) to look up a matching FRE. */ +#define CTF_FRAME_FUNC_DESC_ENTRY_TYPE_PCINC 0 +/* Unwinders perform a (PC & FRE_START_ADDR_AS_MASK >= FRE_START_ADDR_AS_MASK) + to look up a matching FRE. */ +#define CTF_FRAME_FUNC_DESC_ENTRY_TYPE_PCMASK 1 + +typedef struct ctf_frame_preamble +{ + uint16_t ctfp_magic; /* Magic number (CTF_FRAME_MAGIC). */ + uint8_t ctfp_version; /* Data format version number (CTF_FRAME_VERSION). */ + uint8_t ctfp_flags; /* Flags. */ +} __attribute__ ((packed)) ctf_frame_preamble; + +typedef struct ctf_frame_header +{ + ctf_frame_preamble cth_frame_preamble; + /* Information about the arch (endianness) and ABI. */ + uint8_t cth_frame_abi_arch; + /* Offset for the Frame Pointer (FP) from CFA may be fixed for some + ABIs (e.g, in AMD64 when -fno-omit-frame-pointer is used). When fixed, + this field specifies the fixed stack frame offset and the individual + FREs do not need to track it. When not fixed, it is set to + CTF_FRAME_CFA_FIXED_FP_INVALID, and the individual FREs may provide + the applicable stack frame offset, if any. */ + int8_t cth_cfa_fixed_fp_offset; + /* Offset for the Return Address from CFA is fixed for some ABIs + (e.g., AMD64 has it as CFA-8). When fixed, the header specifies the + fixed stack frame offset and the individual FREs do not track it. When + not fixed, it is set to CTF_FRAME_CFA_FIXED_RA_INVALID, and individual + FREs provide the applicable stack frame offset, if any. */ + int8_t cth_cfa_fixed_ra_offset; + /* Number of CTF FDEs in this CTF Frame section. May be useful for + debugging. */ + uint32_t cth_num_fdes; + /* Number of CTF Frame row entries. */ + uint32_t cth_num_fres; + /* Number of bytes in the CTF Frame Row Entry section. */ + uint32_t cth_fre_len; + /* Offset of CTF function descriptor entry section. */ + uint32_t cth_fdeoff; + /* Offset of CTF Frame Row Entry section. */ + uint32_t cth_freoff; +} __attribute__ ((packed)) ctf_frame_header; + +typedef struct ctf_frame_func_desc_entry +{ + /* Function start address. Encoded as a signed offset, relative to the + beginning of the current FDE. */ + int32_t ctf_func_start_address; + /* Size of the function in bytes. */ + uint32_t ctf_func_size; + /* Offset of the first CTF Frame Row Entry of the function, relative to the + beginning of the CTF Frame Row Entry sub-section. */ + uint32_t ctf_func_start_fre_off; + /* Number of frame row entries for the function. */ + uint32_t ctf_func_num_fres; + /* Additional information for deciphering the unwind information for the + function. + - 4-bits: Identify the FRE type used for the function. + - 1-bit: Identify the FDE type of the function - mask or inc. + - 3-bits: Unused. + -------------------------------------------- + | Unused | FDE type | FRE type | + -------------------------------------------- + 8 5 4 0 */ + uint8_t ctf_func_info; +} __attribute__ ((packed)) ctf_frame_func_desc_entry; + +/* Macros to compose and decompose function info in FDE. */ + +#define CTF_FRAME_V1_FUNC_INFO(fde_type, fre_enc_type) \ + (((fde_type) & 0x1) << 4 | (fre_enc_type)) + +#define CTF_FRAME_V1_FUNC_FRE_TYPE(data) ((data) & 0xf) +#define CTF_FRAME_V1_FUNC_FDE_TYPE(data) ((data >> 4) & 0x1) + +/* Size of stack frame offsets in a CTF Frame Row Entry. A single CTF Frame + row entry has all offsets of the same size. Offset size may vary across + frame row entries. */ +#define CTF_FRAME_FRE_OFFSET_1B 0 +#define CTF_FRAME_FRE_OFFSET_2B 1 +#define CTF_FRAME_FRE_OFFSET_4B 2 + +/* A CTF Frame Row Entry can be SP or FP based. */ +#define CTF_FRAME_BASE_REG_FP 0 +#define CTF_FRAME_BASE_REG_SP 1 + +/* The index at which a specific offset is presented in the variable length + bytes of an FRE. */ +#define CTF_FRAME_FRE_CFA_OFFSET_IDX 0 +#define CTF_FRAME_FRE_FP_OFFSET_IDX 1 +#define CTF_FRAME_FRE_RA_OFFSET_IDX 2 + +typedef struct ctf_frame_fre_info +{ + /* Information about + - 1 bit: base reg for CFA + - 4 bits: Number of offsets (N). A value of upto 3 is allowed to track + all three of CFA, FP and RA (fixed implicit order). + - 2 bits: information about size of the offsets (S) in bytes. + Valid values are CTF_FRAME_FRE_OFFSET_1B, CTF_FRAME_FRE_OFFSET_2B, + CTF_FRAME_FRE_OFFSET_4B + - 1 bit: Unused. + ----------------------------------------------------------------------- + | Unused | Size of offsets | Number of offsets | base_reg | + ----------------------------------------------------------------------- + 8 7 5 1 0 + + */ + uint8_t fre_info; +} ctf_frame_fre_info; + +/* Macros to compose and decompose FRE info. */ + +#define CTF_FRAME_V1_FRE_INFO(base_reg_id, offset_num, offset_size) \ + ((offset_size << 5) | (offset_num << 1) | (base_reg_id)) + +#define CTF_FRAME_V1_FRE_CFA_BASE_REG_ID(data) ((data) & 0x1) +#define CTF_FRAME_V1_FRE_OFFSET_COUNT(data) (((data) >> 1) & 0xf) +#define CTF_FRAME_V1_FRE_OFFSET_SIZE(data) (((data) >> 5) & 0x3) + +/* CTF Frame Row Entry definitions. + + Used for both AMD64 and AARCH64. + + A CTF Frame Row Entry is a self-sufficient record containing CTF Frame + unwind info for a range of addresses, starting at the specified offset in + the function. Each CTF Frame Row Entry is followed by S*N bytes, where: + S is the size of the stack frame offset for the FRE, and + N is the number of stack frame offsets in the FRE + + The offsets are interpreted in order as follows: + offset1 (interpreted as CFA = BASE_REG + offset1) + offset2 (interpreted as FP = CFA + offset2) + offset3 (interpreted as RA = CFA + offset3) +*/ + +typedef struct ctf_frame_row_entry_addr1 +{ + /* Start address of the frame row entry. Encoded as an 1-byte unsigned + offset, relative to the start address of the function. */ + uint8_t ctf_fre_start_address; + ctf_frame_fre_info ctf_fre_info; +} __attribute__ ((packed)) ctf_frame_row_entry_addr1; + +typedef struct ctf_frame_row_entry_addr2 +{ + /* Start address of the frame row entry. Encoded as an 2-byte unsigned + offset, relative to the start address of the function. */ + uint16_t ctf_fre_start_address; + ctf_frame_fre_info ctf_fre_info; +} __attribute__ ((packed)) ctf_frame_row_entry_addr2; + +typedef struct ctf_frame_row_entry_addr4 +{ + /* Start address of the frame row entry. Encoded as a 4-byte unsigned + offset, relative to the start address of the function. */ + uint32_t ctf_fre_start_address; + ctf_frame_fre_info ctf_fre_info; +} __attribute__ ((packed)) ctf_frame_row_entry_addr4; + +#ifdef __cplusplus +} +#endif + +#endif /* _CTF_FRAME_H */ -- 2.37.1