From patchwork Mon Oct 17 22:16:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Indu Bhagat X-Patchwork-Id: 3763 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1666771wrs; Mon, 17 Oct 2022 15:20:17 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4iqf1VOT0bdry93EIM0xy+8HOuCUqgXSx+cJevYgnO1D3cuo5m7IoB9sJfeTZVJMBPbqHv X-Received: by 2002:a17:906:7945:b0:73b:e605:f31 with SMTP id l5-20020a170906794500b0073be6050f31mr10502771ejo.129.1666045217231; Mon, 17 Oct 2022 15:20:17 -0700 (PDT) Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id u3-20020a50eac3000000b0045166555fddsi8499704edp.481.2022.10.17.15.20.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 15:20:17 -0700 (PDT) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=fqbLHrKf; arc=fail (signature failed); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6C257385087D for ; Mon, 17 Oct 2022 22:18:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6C257385087D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1666045112; bh=+h6lH6FAPlOYxpScwwtnzFkMi4hxCShHB6cWxi9NOqw=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=fqbLHrKfvBLluiCBinQdPIPXDziYED8ufKXlu6uqw9PPTgYh/GZUAiVhLKqFcex4k //B52Nkpnl1whBxkPadnxPw+0y89A/NzyqLxlSRo9OFilW9s0woTxws57Tf6qsN7Mx vH+FoVgL0yqCEfOK6+tV/9/eeoY6HVtQzxkUHz5Y= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by sourceware.org (Postfix) with ESMTPS id 9B334385AC22 for ; Mon, 17 Oct 2022 22:17:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9B334385AC22 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 29HLmj0E008250; Mon, 17 Oct 2022 22:17:16 GMT Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3k7mtyw46w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 17 Oct 2022 22:17:15 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 29HJCD5S029782; Mon, 17 Oct 2022 22:17:15 GMT Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2169.outbound.protection.outlook.com [104.47.55.169]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3k8hu5h4nq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 17 Oct 2022 22:17:14 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=b6MKGVJw3gCe987wybUTGhh3rV9PeHRqeyri6XZ97+IuguhFniiPROgWqgprBl/NRyqCcSTcIdsppgPFHOKCqSWRLqgRtc/Q9GYXWKFzbcAv57Cqt119kgg8kO41dZCMJNE1IRYCuyS8zp3zHp7oYmX5nN0Ci39zt0vxO2f5aElOWjZOGzH+9L+r7a4bNzjEZs70ebjmt05h2NR2uaveLmVI4fkhIVmb9qCkXqYlFTi3T8CRkDSc6WqshkAbVRfO95ft9oOvJ9dSuGEBFdhmBqNDqst/ZDFBPH/52tc8IKupuyXsx9V4/oHgspA+EjO1x8JwJEgbSX8leqeMJfz1TA== 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=+h6lH6FAPlOYxpScwwtnzFkMi4hxCShHB6cWxi9NOqw=; b=ApAXbIPqFxaL4Mi8kWwkWewabqm6Zx0xfgYAvspjQnJVv2Fre/Siot/stRnALliGBDn1Z3sZ6JnUm3e8NRstcJIsbOAsjJtx4ORLTZ4d/tR88hObS9dGJMhB8RROM7LfT1UW7CUlrbh5g72PyJ6WmlfXYregEyohHeqzQenpWaxwipSpjsZDZcvR2o7xms3eExYUuWn1E5ph/SDBenLmcda0ElaPv6dI4zaXZ0vt2g+nucfoB41Q8j4d3yj9NqAOGQm4jgfiBfM1Dh4iL+M28V3/JdoPx62dgjBiPQuo+EBrF9SY9gmQm2UULvKdMcx2ECZKmixmjUXFlGlzp8anqg== 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 BN6PR1001MB2147.namprd10.prod.outlook.com (2603:10b6:405:2e::26) by MW4PR10MB5862.namprd10.prod.outlook.com (2603:10b6:303:18f::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5723.26; Mon, 17 Oct 2022 22:17:12 +0000 Received: from BN6PR1001MB2147.namprd10.prod.outlook.com ([fe80::c713:91f4:e197:acd2]) by BN6PR1001MB2147.namprd10.prod.outlook.com ([fe80::c713:91f4:e197:acd2%5]) with mapi id 15.20.5709.028; Mon, 17 Oct 2022 22:17:12 +0000 To: binutils@sourceware.org Subject: [PATCH,V2 07/15] readelf/objdump: support for SFrame section Date: Mon, 17 Oct 2022 15:16:04 -0700 Message-Id: <20221017221612.495324-8-indu.bhagat@oracle.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221017221612.495324-1-indu.bhagat@oracle.com> References: <20221017221612.495324-1-indu.bhagat@oracle.com> X-ClientProxiedBy: MW4P223CA0001.NAMP223.PROD.OUTLOOK.COM (2603:10b6:303:80::6) To BN6PR1001MB2147.namprd10.prod.outlook.com (2603:10b6:405:2e::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN6PR1001MB2147:EE_|MW4PR10MB5862:EE_ X-MS-Office365-Filtering-Correlation-Id: c780ba34-ef33-4b87-0ca9-08dab08d56ab X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: HrVr+S429/vA4laf+/YWS5boDdNYoZjvVEpQ6VLyjvKkDXTkr+FG+c7446A+hXH4f0OjwAjFLyKoTUNKsw+C4BRjJnxk8+bQ8c02DMY6FphjiF0zv05nhv0KUTJrpQXJnLsBJxDcmXEnJHOrQaBlUlsfOj95oinyzHAApmJbkYMA/JMrkTxIVLez+anxe2wgS1/vSmwboh4laf92c+iNl8j8AuWJpU8ucTqPpTWjsAuv/EleWZnoIbTnHEHt9FoNvjibRXROiDP37fWPfNWafpC/wPtezbgneKVsqYHwR4HwK6dX1lI5ZleL6mOVGOwXdOMrZ8UDWMJoP2nIqLh7iok8LY+PQw7mXlOq03dB80kUgnJRsgqhjnoKG2lL0N2VyRF4SsTp3K2mMPdEccqohmq5RqQ+AoNCpd4AUMz2DYsBXSBhcVEtIQ+vmnZib0aIrJmEWcbJmaY20nxoXaTPYu9oQIR/dAyc38hCcbMLe9zWO9xwEB++ZECcgYWGYjAumPyydGVhRoTCX8aHIg5syBeKbTGmTvjLWwWNow9tx4J/LT3VWQDF1a/dcJqz+ubQswVUGm9HvOQo+SHgW5LFsnv+SC3HrXSbX97JUO6/Fbnl8rl0+iZmUvyJYVDUIZzxQpH2fAFSIgpQjX9KQS/5DS9ySENCJs3AxrAAVvLGU6GWq3Bs6hqe/ULGFjar1ipreB8TJCZ9piwsEeuHlyMJigjZOfT3gH/ax1MMsqosE4p1kxB5v+MTqu7FYKMLH+n0X6yNUN6q5yuhUCyhhDnqgQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BN6PR1001MB2147.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(396003)(366004)(39860400002)(136003)(376002)(346002)(451199015)(83380400001)(36756003)(86362001)(38100700002)(107886003)(6666004)(66946007)(66556008)(6916009)(316002)(5660300002)(44832011)(30864003)(8936002)(186003)(66476007)(6486002)(1076003)(2906002)(2616005)(478600001)(6506007)(6512007)(41300700001)(4326008)(8676002)(2004002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: JrRU8HojHUSP9wF22xbWU2wWqKhjnaUZouqNn7D56Bn+A4DvxZh/I6uijIN8R1FtLZX0ukIl7AoXn1cHRQVPp30K7YlzUUAFU97YHwWWvM7jxR6QsYSIKNrlCBDq2bFG+JfL4QyzswL6I/THaQ8l0xZRjr/ResrhnJJRu2oEom5CGTlpGFXEzRjEr6UR9iwel8SLCFC+xCmRUsEFo2l/GSm7xgjvWQD41POzPqSN0j5hgf8LTi1kQMbDyb49WyRMjZhhfqxlq0OBSZAAhXV9mnSbZTUpheYh78w4LXSOiVi1gBuTpZgc+RrQMrUbYb4N1USmutErZPC3NalqkucCEyS9Tc7R34VFJPje5zQebDo48VCcBENu3um9iHyGseg/CFNAy31w+DyA16DPmKAQ08Pyb3+LKi9GlCboRezDaErqrO84ZZbPZTE8Ew81K54jHb/dc1Xr1nqotkm71uryoNOFJpePUneT+dOU9rp6GKQ3fgOMBCixdiUowDLGI96raXXA5YDAHW8Mi+q5ST2DT2ZCPAmtDsn9cuWFRM9mNI9ypVBeRE6pWMA0dyJNnufFUrydKD8lnGD44r4euXuwIov1Gbmk3SuidJiz0NkezGS+NQRk4MlwLjNbMhJ8xNE8625hydxXMC2i1AOItEr9SOxlfZX60tIk4yn7bm6IVnCXUZ4b9Hr0viW/qR3HXl3Ezjg9WnuubimEs6xLanYy6XW754iWxKlYcqjvVs0AaKksMylj3LSa3x/TV0Z1//kdMWPHaQdnkm5DoXxkm2j/wd86RsrromyWlV6tM1Ezy6Ct+eV5/iZtn26L8ZDxUaL+CbdKfUJiPb/JwJ73YakB/RTypxSy4kjkBCARIWGAKyNx81Fl67JagWqU5FD6rdSF5HY8rRvQ0eg5Xu+J3oQdWFqIbyGDr5SzZtRDzM+gOjspzCoUV6L/VsplDY0QHqAk3rY7jzAxQ0gUDW6K8r1NMB5LL0J4a1I5ksgX7vR7y5/YOZKeGppe9MqmRjAaF+EQUujf+7afNVqUH9XfH4R56z9+eBCd+OP/aTp8zwLqaTNSHRIzKuBqnZhq5IZGbq7ZFVTERsBgJSBVLFzWM8DGBv1PX56RDmVX2PPynJEkyZzg+K3zesqjCNYVmVm1gUSRx9E3bp1iWi+CfkUQOkoNCDvrcQlR9kSOzWQpwr2r2JMMtdOXQbnFu0tdETU8Fn+J0XF3M09dwxbAMQzTaSlS9BfXCabavth2WT2DxlfNpkw2sYPWG3q8xsfNjGfVx9JFuwlYKm2RebnW2bApPtPUkt2tMgbGoXLp7N2sXtg6gIqYvpXOMRXXaVMxQTXxiaPu9PhjM5NUi6gEDdZmBl7JSl0lDO6YGzWL/FO0s1ivZtz6GNq1Qs1QQpphKlDr2jQOvBDd6/lTr9DyokmK2xhGiLnA++nrmVQ2+ycw3f/aZtIAqumGESsvKAj/jQtT+lBmvYQLi7KKlJ6NZWNmCAMzN75e1W2bXL9l2GLtzWrTCi7kUhdunKcrjQJkxbIeUwU/pKX2BvFBC3oBO4MvBareSEEarQHyJaEY6eHVq5cGPoqOJ8Ovrr+7skBj92aRSTzGW3Eo8B5Z65Riak9zXd6uk+5yTLnUlUiOCpu5XuKjXa0= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: c780ba34-ef33-4b87-0ca9-08dab08d56ab X-MS-Exchange-CrossTenant-AuthSource: BN6PR1001MB2147.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Oct 2022 22:17:11.8992 (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: glf89H3OGm6391+tBhOy/iExgNdS8oJvi7VQnLVfhS2YAphCgO333BTWu6r/uXZrz7oVPtkOUwQBrfE0x/l5Dg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR10MB5862 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-10-17_13,2022-10-17_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 mlxlogscore=999 malwarescore=0 spamscore=0 suspectscore=0 phishscore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2209130000 definitions=main-2210170127 X-Proofpoint-ORIG-GUID: DMZSliLVeSgTwReUve_xzxfGpc7HE7JP X-Proofpoint-GUID: DMZSliLVeSgTwReUve_xzxfGpc7HE7JP X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, KAM_STOCKGEN, 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-Patchwork-Original-From: Indu Bhagat via Binutils From: Indu Bhagat Reply-To: Indu Bhagat Cc: Indu Bhagat Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746975029257448159?= X-GMAIL-MSGID: =?utf-8?q?1746975029257448159?= [Changes in V2] - Fixed compilation errors seen on i686. - readelf: bugfix: --sframe=.eh_frame gives no error New behaviour: $ readelf --sframe=.eh_frame readelf: Error: SFrame decode failure: Buffer does not contain SFrame data. $ readelf --sframe=.foo readelf: Warning: Section '.foo' was not dumped because it does not exist - readelf: make --sframe arguments optional (similar to the command line option for objdump) [End of changes in V2] This patch adds support for SFrame in readelf and objdump. include/ChangeLog: * sframe-api.h (dump_sframe): New function declaration. ChangeLog: * binutils/Makefile.am: Add dependency on libsframe for readelf and objdump. * binutils/Makefile.in: Regenerate. * binutils/doc/binutils.texi: Document --sframe=[section]. * binutils/doc/sframe.options.texi: New file. * binutils/objdump.c: Add support for SFrame format. * binutils/readelf.c: Likewise. * include/sframe-api.h: Add new API for dumping .sframe section. * libsframe/Makefile.am: Add sframe-dump.c. * libsframe/Makefile.in: Regenerate. * libsframe/sframe-dump.c: New file. --- binutils/Makefile.am | 8 +- binutils/Makefile.in | 8 +- binutils/doc/binutils.texi | 4 + binutils/doc/sframe.options.texi | 10 ++ binutils/objdump.c | 75 +++++++++++++ binutils/readelf.c | 63 +++++++++++ include/sframe-api.h | 3 + libsframe/Makefile.am | 3 +- libsframe/Makefile.in | 12 ++- libsframe/sframe-dump.c | 180 +++++++++++++++++++++++++++++++ 10 files changed, 354 insertions(+), 12 deletions(-) create mode 100644 binutils/doc/sframe.options.texi create mode 100644 libsframe/sframe-dump.c diff --git a/binutils/Makefile.am b/binutils/Makefile.am index b93684d9a65..3343e390276 100644 --- a/binutils/Makefile.am +++ b/binutils/Makefile.am @@ -228,7 +228,7 @@ installcheck-local: # which depends on libintl, since we don't know whether LIBINTL_DEP will be # non-empty until configure time. Ugh! size_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB) -objdump_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB) $(OPCODES) $(LIBCTF) $(OBJDUMP_PRIVATE_OFILES) +objdump_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB) $(OPCODES) $(LIBCTF) $(OBJDUMP_PRIVATE_OFILES) $(LIBSFRAME) nm_new_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB) ar_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB) strings_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB) @@ -243,7 +243,7 @@ dlltool_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB) windres_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB) windmc_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB) addr2line_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB) -readelf_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(LIBCTF_NOBFD) +readelf_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(LIBCTF_NOBFD) $(LIBSFRAME) elfedit_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) dllwrap_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) bfdtest1_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB) @@ -258,7 +258,7 @@ objcopy_SOURCES = objcopy.c not-strip.c rename.c $(WRITE_DEBUG_SRCS) $(BULIBS) strings_SOURCES = strings.c $(BULIBS) readelf_SOURCES = readelf.c version.c unwind-ia64.c dwarf.c demanguse.c $(ELFLIBS) -readelf_LDADD = $(LIBCTF_NOBFD) $(LIBINTL) $(LIBIBERTY) $(ZLIB) $(DEBUGINFOD_LIBS) $(MSGPACK_LIBS) +readelf_LDADD = $(LIBCTF_NOBFD) $(LIBINTL) $(LIBIBERTY) $(ZLIB) $(DEBUGINFOD_LIBS) $(MSGPACK_LIBS) $(LIBSFRAME) elfedit_SOURCES = elfedit.c version.c $(ELFLIBS) elfedit_LDADD = $(LIBINTL) $(LIBIBERTY) @@ -269,7 +269,7 @@ nm_new_SOURCES = nm.c demanguse.c $(BULIBS) objdump_SOURCES = objdump.c dwarf.c prdbg.c demanguse.c $(DEBUG_SRCS) $(BULIBS) $(ELFLIBS) EXTRA_objdump_SOURCES = od-xcoff.c -objdump_LDADD = $(OBJDUMP_PRIVATE_OFILES) $(OPCODES) $(LIBCTF) $(BFDLIB) $(LIBIBERTY) $(LIBINTL) $(DEBUGINFOD_LIBS) +objdump_LDADD = $(OBJDUMP_PRIVATE_OFILES) $(OPCODES) $(LIBCTF) $(BFDLIB) $(LIBIBERTY) $(LIBINTL) $(DEBUGINFOD_LIBS) $(LIBSFRAME) objdump.@OBJEXT@:objdump.c if am__fastdepCC diff --git a/binutils/Makefile.in b/binutils/Makefile.in index 6cbdba1da26..f07cd871d93 100644 --- a/binutils/Makefile.in +++ b/binutils/Makefile.in @@ -766,7 +766,7 @@ CC_FOR_TARGET = ` \ # which depends on libintl, since we don't know whether LIBINTL_DEP will be # non-empty until configure time. Ugh! size_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB) -objdump_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB) $(OPCODES) $(LIBCTF) $(OBJDUMP_PRIVATE_OFILES) +objdump_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB) $(OPCODES) $(LIBCTF) $(OBJDUMP_PRIVATE_OFILES) $(LIBSFRAME) nm_new_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB) ar_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB) strings_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB) @@ -781,7 +781,7 @@ dlltool_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB) windres_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB) windmc_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB) addr2line_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB) -readelf_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(LIBCTF_NOBFD) +readelf_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(LIBCTF_NOBFD) $(LIBSFRAME) elfedit_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) dllwrap_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) bfdtest1_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB) @@ -791,14 +791,14 @@ size_SOURCES = size.c $(BULIBS) objcopy_SOURCES = objcopy.c not-strip.c rename.c $(WRITE_DEBUG_SRCS) $(BULIBS) strings_SOURCES = strings.c $(BULIBS) readelf_SOURCES = readelf.c version.c unwind-ia64.c dwarf.c demanguse.c $(ELFLIBS) -readelf_LDADD = $(LIBCTF_NOBFD) $(LIBINTL) $(LIBIBERTY) $(ZLIB) $(DEBUGINFOD_LIBS) $(MSGPACK_LIBS) +readelf_LDADD = $(LIBCTF_NOBFD) $(LIBINTL) $(LIBIBERTY) $(ZLIB) $(DEBUGINFOD_LIBS) $(MSGPACK_LIBS) $(LIBSFRAME) elfedit_SOURCES = elfedit.c version.c $(ELFLIBS) elfedit_LDADD = $(LIBINTL) $(LIBIBERTY) strip_new_SOURCES = objcopy.c is-strip.c rename.c $(WRITE_DEBUG_SRCS) $(BULIBS) nm_new_SOURCES = nm.c demanguse.c $(BULIBS) objdump_SOURCES = objdump.c dwarf.c prdbg.c demanguse.c $(DEBUG_SRCS) $(BULIBS) $(ELFLIBS) EXTRA_objdump_SOURCES = od-xcoff.c -objdump_LDADD = $(OBJDUMP_PRIVATE_OFILES) $(OPCODES) $(LIBCTF) $(BFDLIB) $(LIBIBERTY) $(LIBINTL) $(DEBUGINFOD_LIBS) +objdump_LDADD = $(OBJDUMP_PRIVATE_OFILES) $(OPCODES) $(LIBCTF) $(BFDLIB) $(LIBIBERTY) $(LIBINTL) $(DEBUGINFOD_LIBS) $(LIBSFRAME) cxxfilt_SOURCES = cxxfilt.c $(BULIBS) ar_SOURCES = arparse.y arlex.l ar.c not-ranlib.c arsup.c rename.c binemul.c \ emul_$(EMULATION).c $(BULIBS) diff --git a/binutils/doc/binutils.texi b/binutils/doc/binutils.texi index 6eea08fb91b..0f3860abaaa 100644 --- a/binutils/doc/binutils.texi +++ b/binutils/doc/binutils.texi @@ -2262,6 +2262,7 @@ objdump [@option{-a}|@option{--archive-headers}] [@option{-wE}|@option{--dwarf=do-not-use-debuginfod}] [@option{-L}|@option{--process-links}] [@option{--ctf=}@var{section}] + [@option{--sframe=}@var{section}] [@option{-G}|@option{--stabs}] [@option{-t}|@option{--syms}] [@option{-T}|@option{--dynamic-syms}] @@ -2843,6 +2844,8 @@ Enable additional checks for consistency of Dwarf information. @include ctf.options.texi +@include sframe.options.texi + @item -G @itemx --stabs @cindex stab @@ -4940,6 +4943,7 @@ readelf [@option{-a}|@option{--all}] [@option{--ctf-parent=}@var{section}] [@option{--ctf-symbols=}@var{section}] [@option{--ctf-strings=}@var{section}] + [@option{--sframe=}@var{section}] [@option{-I}|@option{--histogram}] [@option{-v}|@option{--version}] [@option{-W}|@option{--wide}] diff --git a/binutils/doc/sframe.options.texi b/binutils/doc/sframe.options.texi new file mode 100644 index 00000000000..9e23679a3da --- /dev/null +++ b/binutils/doc/sframe.options.texi @@ -0,0 +1,10 @@ +@c This file contains the entry for the --sframe option that is +@c common to both readelf and objdump. + +@item --sframe[=@var{section}] +@cindex SFrame + +Display the contents of the specified SFrame section. + +By default, display the name of the section named @var{.sframe}, which is the +name emitted by @command{ld}. diff --git a/binutils/objdump.c b/binutils/objdump.c index f7b4695c3e8..dd49c39b551 100644 --- a/binutils/objdump.c +++ b/binutils/objdump.c @@ -58,6 +58,7 @@ #include "demanguse.h" #include "dwarf.h" #include "ctf-api.h" +#include "sframe-api.h" #include "getopt.h" #include "safe-ctype.h" #include "dis-asm.h" @@ -108,6 +109,8 @@ static int dump_stab_section_info; /* --stabs */ static int dump_ctf_section_info; /* --ctf */ static char *dump_ctf_section_name; static char *dump_ctf_parent_name; /* --ctf-parent */ +static int dump_sframe_section_info; /* --sframe */ +static char *dump_sframe_section_name; static int do_demangle; /* -C, --demangle */ static bool disassemble; /* -d */ static bool disassemble_all; /* -D */ @@ -316,6 +319,8 @@ usage (FILE *stream, int status) fprintf (stream, _("\ --ctf[=SECTION] Display CTF info from SECTION, (default `.ctf')\n")); #endif + fprintf (stream, _("\ + --sframe[=SECTION] Display SFrame info from SECTION, (default '.sframe')\n")); fprintf (stream, _("\ -t, --syms Display the contents of the symbol table(s)\n")); fprintf (stream, _("\ @@ -462,6 +467,7 @@ enum option_values OPTION_CTF, OPTION_CTF_PARENT, #endif + OPTION_SFRAME, OPTION_VISUALIZE_JUMPS, OPTION_DISASSEMBLER_COLOR }; @@ -516,6 +522,7 @@ static struct option long_options[]= {"reloc", no_argument, NULL, 'r'}, {"section", required_argument, NULL, 'j'}, {"section-headers", no_argument, NULL, 'h'}, + {"sframe", optional_argument, NULL, OPTION_SFRAME}, {"show-raw-insn", no_argument, &show_raw_insn, 1}, {"source", no_argument, NULL, 'S'}, {"source-comment", optional_argument, NULL, OPTION_SOURCE_COMMENT}, @@ -4799,6 +4806,66 @@ dump_ctf (bfd *abfd ATTRIBUTE_UNUSED, const char *sect_name ATTRIBUTE_UNUSED, const char *parent_name ATTRIBUTE_UNUSED) {} #endif +static bfd_byte* +read_section_sframe (bfd *abfd, const char *sect_name, bfd_size_type *size_ptr, + bfd_vma *sframe_vma) +{ + asection *sframe_sect; + bfd_byte *contents; + + sframe_sect = bfd_get_section_by_name (abfd, sect_name); + if (sframe_sect == NULL) + { + printf (_("No %s section present\n\n"), + sanitize_string (sect_name)); + return NULL; + } + + if (!bfd_malloc_and_get_section (abfd, sframe_sect, &contents)) + { + non_fatal (_("reading %s section of %s failed: %s"), + sect_name, bfd_get_filename (abfd), + bfd_errmsg (bfd_get_error ())); + exit_status = 1; + free (contents); + return NULL; + } + + *size_ptr = bfd_section_size (sframe_sect); + *sframe_vma = bfd_section_vma (sframe_sect); + + return contents; +} + +static void +dump_section_sframe (bfd *abfd ATTRIBUTE_UNUSED, + const char * sect_name) +{ + sframe_decoder_ctx *sfd_ctx = NULL; + bfd_size_type sf_size; + bfd_byte *sframe_data = NULL; + bfd_vma sf_vma; + int err = 0; + + if (sect_name == NULL) + sect_name = ".sframe"; + + sframe_data = read_section_sframe (abfd, sect_name, &sf_size, &sf_vma); + + if (sframe_data == NULL) + bfd_fatal (bfd_get_filename (abfd)); + + /* Decode the contents of the section. */ + sfd_ctx = sframe_decode ((const char*)sframe_data, sf_size, &err); + if (!sfd_ctx) + bfd_fatal (bfd_get_filename (abfd)); + + printf (_("Contents of the SFrame section %s:"), + sanitize_string (sect_name)); + /* Dump the contents as text. */ + dump_sframe (sfd_ctx, sf_vma); +} + static void dump_bfd_private_header (bfd *abfd) @@ -5552,6 +5619,8 @@ dump_bfd (bfd *abfd, bool is_mainfile) { if (dump_ctf_section_info) dump_ctf (abfd, dump_ctf_section_name, dump_ctf_parent_name); + if (dump_sframe_section_info) + dump_section_sframe (abfd, dump_sframe_section_name); if (dump_stab_section_info) dump_stabs (abfd); if (dump_reloc_info && ! disassemble) @@ -6049,6 +6118,12 @@ main (int argc, char **argv) dump_ctf_parent_name = xstrdup (optarg); break; #endif + case OPTION_SFRAME: + dump_sframe_section_info = true; + if (optarg) + dump_sframe_section_name = xstrdup (optarg); + seenflag = true; + break; case 'G': dump_stab_section_info = true; seenflag = true; diff --git a/binutils/readelf.c b/binutils/readelf.c index b7fcb9729e0..89db66ecc55 100644 --- a/binutils/readelf.c +++ b/binutils/readelf.c @@ -60,6 +60,7 @@ #include "demanguse.h" #include "dwarf.h" #include "ctf-api.h" +#include "sframe-api.h" #include "demangle.h" #include "elf/common.h" @@ -187,6 +188,7 @@ typedef struct elf_section_list #define STRING_DUMP (1 << 3) /* The -p command line switch. */ #define RELOC_DUMP (1 << 4) /* The -R command line switch. */ #define CTF_DUMP (1 << 5) /* The --ctf command line switch. */ +#define SFRAME_DUMP (1 << 6) /* The --sframe command line switch. */ typedef unsigned char dump_type; @@ -230,6 +232,7 @@ static bool do_version = false; static bool do_histogram = false; static bool do_debugging = false; static bool do_ctf = false; +static bool do_sframe = false; static bool do_arch = false; static bool do_notes = false; static bool do_archive_index = false; @@ -5068,6 +5071,7 @@ enum long_option_values OPTION_CTF_PARENT, OPTION_CTF_SYMBOLS, OPTION_CTF_STRINGS, + OPTION_SFRAME_DUMP, OPTION_WITH_SYMBOL_VERSIONS, OPTION_RECURSE_LIMIT, OPTION_NO_RECURSE_LIMIT, @@ -5130,6 +5134,7 @@ static struct option options[] = {"ctf-strings", required_argument, 0, OPTION_CTF_STRINGS}, {"ctf-parent", required_argument, 0, OPTION_CTF_PARENT}, #endif + {"sframe", optional_argument, 0, OPTION_SFRAME_DUMP}, {"sym-base", optional_argument, 0, OPTION_SYM_BASE}, {0, no_argument, 0, 0} @@ -5270,6 +5275,8 @@ usage (FILE * stream) --ctf-strings=\n\ Use section as the CTF external strtab\n")); #endif + fprintf (stream, _("\ + --sframe[=NAME] Display SFrame info from section NAME, (default '.sframe')\n")); #ifdef SUPPORT_DISASSEMBLY fprintf (stream, _("\ @@ -5543,6 +5550,19 @@ parse_args (struct dump_data *dumpdata, int argc, char ** argv) free (dump_ctf_parent_name); dump_ctf_parent_name = strdup (optarg); break; + case OPTION_SFRAME_DUMP: + do_sframe = true; + /* Providing section name is optional. request_dump (), however, + thrives on non NULL optarg. Handle it explicitly here. */ + if (optarg != NULL) + request_dump (dumpdata, SFRAME_DUMP); + else + { + do_dump = true; + const char *sframe_sec_name = strdup (".sframe"); + request_dump_byname (sframe_sec_name, SFRAME_DUMP); + } + break; case OPTION_DYN_SYMS: do_dyn_syms = true; break; @@ -15832,6 +15852,44 @@ dump_section_as_ctf (Elf_Internal_Shdr * section, Filedata * filedata) } #endif +static bool +dump_section_as_sframe (Elf_Internal_Shdr * section, Filedata * filedata) +{ + void * data = NULL; + sframe_decoder_ctx *sfd_ctx = NULL; + const char *print_name = printable_section_name (filedata, section); + + bool ret = true; + size_t sf_size; + int err = 0; + + if (strcmp (print_name, "") == 0) + { + error (_("Section name must be provided \n")); + ret = false; + return ret; + } + + data = get_section_contents (section, filedata); + sf_size = section->sh_size; + /* Decode the contents of the section. */ + sfd_ctx = sframe_decode ((const char*)data, sf_size, &err); + if (!sfd_ctx) + { + ret = false; + error (_("SFrame decode failure: %s\n"), sframe_errmsg (err)); + goto fail; + } + + printf (_("Contents of the SFrame section %s:"), print_name); + /* Dump the contents as text. */ + dump_sframe (sfd_ctx, section->sh_addr); + + fail: + free (data); + return ret; +} + static bool load_specific_debug_section (enum dwarf_section_display_enum debug, const Elf_Internal_Shdr * sec, @@ -16331,6 +16389,11 @@ process_section_contents (Filedata * filedata) res = false; } #endif + if (dump & SFRAME_DUMP) + { + if (! dump_section_as_sframe (section, filedata)) + res = false; + } } if (! filedata->is_separate) diff --git a/include/sframe-api.h b/include/sframe-api.h index 7ce32b5f235..fe942c9bb09 100644 --- a/include/sframe-api.h +++ b/include/sframe-api.h @@ -149,6 +149,9 @@ sframe_decoder_get_funcdesc (sframe_decoder_ctx *ctx, int32_t *func_start_address, unsigned char *func_info); +/* SFrame textual dump. */ +extern void +dump_sframe (sframe_decoder_ctx *decoder, uint64_t addr); /* Get the base reg id from the FRE info. Sets errp if fails. */ extern unsigned int diff --git a/libsframe/Makefile.am b/libsframe/Makefile.am index 3a2218f1e5e..31576429816 100644 --- a/libsframe/Makefile.am +++ b/libsframe/Makefile.am @@ -37,7 +37,6 @@ include_HEADERS = noinst_LTLIBRARIES = libsframe.la endif -libsframe_la_SOURCES = sframe.c sframe-error.c +libsframe_la_SOURCES = sframe.c sframe-dump.c sframe-error.c libsframe_la_CPPFLAGS = -D_GNU_SOURCE -I$(srcdir) -I$(srcdir)/../include \ -I$(srcdir)/../libctf - diff --git a/libsframe/Makefile.in b/libsframe/Makefile.in index 9bf3aa20a65..f4c2415be1c 100644 --- a/libsframe/Makefile.in +++ b/libsframe/Makefile.in @@ -162,7 +162,7 @@ am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(includedir)" LTLIBRARIES = $(lib_LTLIBRARIES) $(noinst_LTLIBRARIES) libsframe_la_LIBADD = am_libsframe_la_OBJECTS = libsframe_la-sframe.lo \ - libsframe_la-sframe-error.lo + libsframe_la-sframe-dump.lo libsframe_la-sframe-error.lo libsframe_la_OBJECTS = $(am_libsframe_la_OBJECTS) AM_V_lt = $(am__v_lt_@AM_V@) am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) @@ -432,7 +432,7 @@ AM_CFLAGS = -std=gnu99 @ac_libsframe_warn_cflags@ @warn@ @c_warn@ @WARN_PEDANTIC @INSTALL_LIBBFD_FALSE@include_HEADERS = @INSTALL_LIBBFD_TRUE@include_HEADERS = $(INCDIR)/sframe.h $(INCDIR)/sframe-api.h @INSTALL_LIBBFD_FALSE@noinst_LTLIBRARIES = libsframe.la -libsframe_la_SOURCES = sframe.c sframe-error.c +libsframe_la_SOURCES = sframe.c sframe-dump.c sframe-error.c libsframe_la_CPPFLAGS = -D_GNU_SOURCE -I$(srcdir) -I$(srcdir)/../include \ -I$(srcdir)/../libctf @@ -545,6 +545,7 @@ mostlyclean-compile: distclean-compile: -rm -f *.tab.c +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsframe_la-sframe-dump.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsframe_la-sframe-error.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libsframe_la-sframe.Plo@am__quote@ @@ -576,6 +577,13 @@ libsframe_la-sframe.lo: sframe.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsframe_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libsframe_la-sframe.lo `test -f 'sframe.c' || echo '$(srcdir)/'`sframe.c +libsframe_la-sframe-dump.lo: sframe-dump.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsframe_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libsframe_la-sframe-dump.lo -MD -MP -MF $(DEPDIR)/libsframe_la-sframe-dump.Tpo -c -o libsframe_la-sframe-dump.lo `test -f 'sframe-dump.c' || echo '$(srcdir)/'`sframe-dump.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libsframe_la-sframe-dump.Tpo $(DEPDIR)/libsframe_la-sframe-dump.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='sframe-dump.c' object='libsframe_la-sframe-dump.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsframe_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libsframe_la-sframe-dump.lo `test -f 'sframe-dump.c' || echo '$(srcdir)/'`sframe-dump.c + libsframe_la-sframe-error.lo: sframe-error.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsframe_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libsframe_la-sframe-error.lo -MD -MP -MF $(DEPDIR)/libsframe_la-sframe-error.Tpo -c -o libsframe_la-sframe-error.lo `test -f 'sframe-error.c' || echo '$(srcdir)/'`sframe-error.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libsframe_la-sframe-error.Tpo $(DEPDIR)/libsframe_la-sframe-error.Plo diff --git a/libsframe/sframe-dump.c b/libsframe/sframe-dump.c new file mode 100644 index 00000000000..1c5621fce54 --- /dev/null +++ b/libsframe/sframe-dump.c @@ -0,0 +1,180 @@ +/* sframe-dump.c - Textual dump of .sframe. + + Copyright (C) 2022 Free Software Foundation, Inc. + + his file is part of libsframe. + + This program 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 of the License, 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. If not, see . */ + +#include +#include +#include +#include "sframe-impl.h" + +#define SFRAME_HEADER_FLAGS_STR_MAX_LEN 50 + +static void +dump_sframe_header (sframe_decoder_ctx *sfd_ctx) +{ + const char *verstr = NULL; + const sframe_header *header = &(sfd_ctx->sfd_header); + + /* Prepare SFrame section version string. */ + const char *version_names[] + = { "NULL", + "SFRAME_VERSION_1" }; + unsigned char ver = header->sfh_preamble.sfp_version; + if (ver <= SFRAME_VERSION) + verstr = version_names[ver]; + + /* Prepare SFrame section flags string. */ + unsigned char flags = header->sfh_preamble.sfp_flags; + char *flags_str + = (char*) calloc (sizeof (char), SFRAME_HEADER_FLAGS_STR_MAX_LEN); + if (flags) + { + const char *flag_names[] + = { "SFRAME_F_FDE_SORTED", + "SFRAME_F_FRAME_POINTER" }; + unsigned char flags = header->sfh_preamble.sfp_flags; + if (flags & SFRAME_F_FDE_SORTED) + strcpy (flags_str, flag_names[0]); + if (flags & SFRAME_F_FRAME_POINTER) + { + if (strlen (flags_str) > 0) + strcpy (flags_str, ","); + strcpy (flags_str, flag_names[1]); + } + } + else + strcpy (flags_str, "NONE"); + + const char* subsec_name = "Header"; + printf ("\n"); + printf (" %s :\n", subsec_name); + printf ("\n"); + printf (" Version: %s\n", verstr); + printf (" Flags: %s\n", flags_str); + printf (" Num FDEs: %d\n", header->sfh_num_fdes); + printf (" Num FREs: %d\n", header->sfh_num_fres); + + free (flags_str); +} + +static void +dump_sframe_func_with_fres (sframe_decoder_ctx *sfd_ctx, + unsigned int funcidx, + uint64_t sec_addr) +{ + uint32_t j = 0; + uint32_t num_fres = 0; + uint32_t func_size = 0; + int32_t func_start_address = 0; + unsigned char func_info = 0; + + uint64_t func_start_pc_vma = 0; + uint64_t fre_start_pc_vma = 0; + const char *base_reg_str[] = {"fp", "sp"}; + int32_t cfa_offset = 0; + int32_t fp_offset = 0; + int32_t ra_offset = 0; + unsigned int base_reg_id = 0; + int err[3] = {0, 0, 0}; + + sframe_frame_row_entry fre; + + /* Get the SFrame function descriptor. */ + sframe_decoder_get_funcdesc (sfd_ctx, funcidx, &num_fres, + &func_size, &func_start_address, &func_info); + /* Calculate the virtual memory address for function start pc. */ + func_start_pc_vma = func_start_address + sec_addr; + + /* Mark FDEs with [m] where the FRE start address is interpreted as a + mask. */ + int fde_type_addrmask_p = (SFRAME_V1_FUNC_FDE_TYPE (func_info) + == SFRAME_FDE_TYPE_PCMASK); + const char *fde_type_marker + = (fde_type_addrmask_p ? "[m]" : " "); + + printf ("\n func idx [%d]: pc = 0x%lx, size = %d bytes", + funcidx, + func_start_pc_vma, + func_size); + + char temp[100]; + memset (temp, 0, 100); + + printf ("\n %-7s%-8s %-10s%-10s%-10s", "STARTPC", fde_type_marker, "CFA", "FP", "RA"); + for (j = 0; j < num_fres; j++) + { + sframe_decoder_get_fre (sfd_ctx, funcidx, j, &fre); + + fre_start_pc_vma = (fde_type_addrmask_p + ? fre.fre_start_addr + : func_start_pc_vma + fre.fre_start_addr); + + /* FIXME - fixup the err caching in array. + assert no error for base reg id. */ + base_reg_id = sframe_fre_get_base_reg_id (&fre, &err[0]); + cfa_offset = sframe_fre_get_cfa_offset (&fre, &err[0]); + fp_offset = sframe_fre_get_fp_offset (&fre, &err[1]); + ra_offset = sframe_fre_get_ra_offset (&fre, &err[2]); + + /* Dump CFA info. */ + printf ("\n"); + printf (" %016lx", fre_start_pc_vma); + sprintf (temp, "%s+%d", base_reg_str[base_reg_id], cfa_offset); + printf (" %-10s", temp); + + /* Dump SP/FP info. */ + memset (temp, 0, 100); + if (err[1] == 0) + sprintf (temp, "c%+d", fp_offset); + else + strcpy (temp, "u"); + printf ("%-10s", temp); + + /* Dump RA info. */ + memset (temp, 0, 100); + if (err[2] == 0) + sprintf (temp, "c%+d", ra_offset); + else + strcpy (temp, "u"); + printf ("%-10s", temp); + } +} + +static void +dump_sframe_functions (sframe_decoder_ctx *sfd_ctx, uint64_t sec_addr) +{ + uint32_t i; + uint32_t num_fdes; + + const char* subsec_name = "Function Index"; + printf ("\n %s :\n", subsec_name); + + num_fdes = sframe_decoder_get_num_fidx (sfd_ctx); + for (i = 0; i < num_fdes; i++) + { + dump_sframe_func_with_fres (sfd_ctx, i, sec_addr); + printf ("\n"); + } +} + +void +dump_sframe (sframe_decoder_ctx *sfd_ctx, uint64_t sec_addr) +{ + dump_sframe_header (sfd_ctx); + dump_sframe_functions (sfd_ctx, sec_addr); +}