From patchwork Mon Jul 22 11:01:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinath Parvathaneni X-Patchwork-Id: 33765 Received: (qmail 17815 invoked by alias); 22 Jul 2019 11:01:40 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 17797 invoked by uid 89); 22 Jul 2019 11:01:36 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-19.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LOTSOFHASH, KAM_SHORT, KAM_STOCKGEN, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.1 spammy=H*MI:prod, H*M:prod, sk:develop X-HELO: EUR01-VE1-obe.outbound.protection.outlook.com Received: from mail-eopbgr140077.outbound.protection.outlook.com (HELO EUR01-VE1-obe.outbound.protection.outlook.com) (40.107.14.77) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 22 Jul 2019 11:01:28 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=XrgvL+AulNwIlAFQgGmnac0weHQ8MXRYC/8LsV342GE=; b=Lhk1qDa7xZcXnSHVOIRbqBf9YGKsNUZthncxCvKnjKsp4a73JiPx4vRsnyTZCBXIbkW+3ewS71rVUlErqaPJwnm9dt9+WcNZxXfGnkZ4O4wy7vw8GfmEwrP1+HsGG5SV6LJxFTDeskHRX1aRooCdR3EPqqtykx5z5NfZrGEoJrg= Received: from VI1PR08CA0226.eurprd08.prod.outlook.com (2603:10a6:802:15::35) by VE1PR08MB4959.eurprd08.prod.outlook.com (2603:10a6:803:110::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2094.16; Mon, 22 Jul 2019 11:01:21 +0000 Received: from DB5EUR03FT021.eop-EUR03.prod.protection.outlook.com (2a01:111:f400:7e0a::201) by VI1PR08CA0226.outlook.office365.com (2603:10a6:802:15::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2094.12 via Frontend Transport; Mon, 22 Jul 2019 11:01:21 +0000 Authentication-Results: spf=temperror (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; sourceware.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; sourceware.org; dmarc=temperror action=none header.from=arm.com; Received-SPF: TempError (protection.outlook.com: error in processing during lookup of arm.com: DNS Timeout) Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DB5EUR03FT021.mail.protection.outlook.com (10.152.20.238) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2052.18 via Frontend Transport; Mon, 22 Jul 2019 11:01:20 +0000 Received: ("Tessian outbound cb57de15885d:v24"); Mon, 22 Jul 2019 11:01:20 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 3fb1018930c61716 X-CR-MTA-TID: 64aa7808 Received: from a90581265299.1 (cr-mta-lb-1.cr-mta-net [104.47.2.52]) by 64aa7808-outbound-1.mta.getcheckrecipient.com id 7BA4FBBF-A44B-4DA7-91D5-7744D9DB09C8.1; Mon, 22 Jul 2019 11:01:14 +0000 Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-db5eur01lp2052.outbound.protection.outlook.com [104.47.2.52]) by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id a90581265299.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384); Mon, 22 Jul 2019 11:01:14 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=A7UrbDeRS2kP4RUZrxL2yBP39O7/VQZu7+F2SLLxZ20kuA74H1rNLCkoHjp2MxAeUZMDVANBVtRIQll7d7zaB5utWI1DBFEtWbQU1EQsmuf6gxioxymDKIsPVrE7Q96cs+TKLvWbmCwBpXCZrGenjpSOBMX/UgFdtkQH7waq7mP+w2RY+t36SyGtBKXTdZYrNrtAOOKMfY+BfvNFXCET+gHZWlt3UMYHxvJNXnIq3PMvARgUebJ9UUIgqwmyNERhuhZ0Hs0uYAqdbQ6nsNjydmjGsd26IPqmwwvbWRHxYrfH2z2Q2DybsKT1flpjtuyBaYiwOs0IymwujhI3dNeo7Q== 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=XrgvL+AulNwIlAFQgGmnac0weHQ8MXRYC/8LsV342GE=; b=WzdKwg7xjLSYVxGjAcGtULg1Fy4zIjUQ66jZ9hNw/hGI13mR8Os/pUkULxrxylk0YFsw871GzpRF3TxXBtZBnKmccdz2k6oFBpvHqH16q2rDo80gPcSFcuW0Aru3BqCKciCR3oQcw4kc2tzHyfZRbd5VVrmMI3wmnFhEANMHYhASNtlUGd2R9VgIuu9LDcDCV7dRsC78MlMwZVgYTHpYwS6fa/ARIXjRSm9BXfeOoBIE3Pw+s061wCx4ez4ObQQXoeTvgvuQ495gBCTWabxtnE9azgdh9H7+SW5S5GCnbVh3fkvxHtMAqv+CpWS5lGLhCkbhnjeByHtK/fyXGZHcTw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=XrgvL+AulNwIlAFQgGmnac0weHQ8MXRYC/8LsV342GE=; b=Lhk1qDa7xZcXnSHVOIRbqBf9YGKsNUZthncxCvKnjKsp4a73JiPx4vRsnyTZCBXIbkW+3ewS71rVUlErqaPJwnm9dt9+WcNZxXfGnkZ4O4wy7vw8GfmEwrP1+HsGG5SV6LJxFTDeskHRX1aRooCdR3EPqqtykx5z5NfZrGEoJrg= Received: from DBBPR08MB4775.eurprd08.prod.outlook.com (20.179.45.148) by DBBPR08MB4789.eurprd08.prod.outlook.com (20.179.45.212) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2094.16; Mon, 22 Jul 2019 11:01:12 +0000 Received: from DBBPR08MB4775.eurprd08.prod.outlook.com ([fe80::596c:3223:fc3c:69f5]) by DBBPR08MB4775.eurprd08.prod.outlook.com ([fe80::596c:3223:fc3c:69f5%3]) with mapi id 15.20.2094.017; Mon, 22 Jul 2019 11:01:12 +0000 From: Srinath Parvathaneni To: "gdb-patches@sourceware.org" CC: nd , "simark@simark.ca" , "tom@tromey.com" , Alan Hayward Subject: [PATCH v3][GDB][ARM]: gdb cannot step across CMSE secure entry function code. Date: Mon, 22 Jul 2019 11:01:12 +0000 Message-ID: Authentication-Results-Original: spf=none (sender IP is ) smtp.mailfrom=Srinath.Parvathaneni@arm.com; X-Microsoft-Antispam-Untrusted: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(711020)(4605104)(1401327)(4618075)(2017052603328)(49563074)(7193020); SRVR:DBBPR08MB4789; X-MS-Exchange-PUrlCount: 3 x-checkrecipientrouted: true x-ms-oob-tlc-oobclassifiers: OLM:7219;OLM:7219; X-Forefront-Antispam-Report-Untrusted: SFV:NSPM; SFS:(10009020)(4636009)(346002)(396003)(39860400002)(376002)(366004)(136003)(54534003)(189003)(199004)(71200400001)(71190400001)(478600001)(52116002)(7696005)(102836004)(26005)(186003)(386003)(966005)(6506007)(53936002)(3846002)(6116002)(2351001)(68736007)(8676002)(5640700003)(55016002)(6436002)(99936001)(486006)(44832011)(9686003)(6306002)(66066001)(7736002)(305945005)(74316002)(476003)(33656002)(4326008)(14444005)(5024004)(14454004)(86362001)(256004)(66946007)(25786009)(5660300002)(81156014)(64756008)(66556008)(66616009)(66476007)(81166006)(66446008)(8936002)(2906002)(316002)(6916009)(99286004)(15974865002)(54906003)(52536014)(2501003)(2004002); DIR:OUT; SFP:1101; SCL:1; SRVR:DBBPR08MB4789; H:DBBPR08MB4775.eurprd08.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info-Original: zsEEnoO85GINnhav+mj2f7/HL3MJlv7JzKeiMTUrelIB1CWWgmwRty8XDVdIbnb4r7xb4fbbUtf6+i8iuay1h80KiAPB5jaz23phFgRcQMCGqQMuO0nNb6yN/jkt0VNdASoarXNCn3QtaWP7/UfkF1gpZ/pDOa4lIarXZrao4s+zKAQrpE6fLmAdkZ11KypLELpe9umQ3FZr8X6Sw2+YStKj5Rpj/0jwunmeneLK+w/1wU40T46gwlgA0L2VaIu/7nVFLAeb60/k19J6HhVTZkqrqQH0IrRBLEkniStgCahMR9enROcOIRbMr8tXNXAqbez97BNnrU7L23p0S7XUBCfeg1urLEeVbLYpeGPOzoj3LUpWwrVDYzlBJ6RZVAZfT97u54GybF02FrdBj/gR5RzyVdGzwy4UZNln5bZRsIc= MIME-Version: 1.0 Original-Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Srinath.Parvathaneni@arm.com; Return-Path: Srinath.Parvathaneni@arm.com X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB5EUR03FT021.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 1325cc91-a87b-41fa-653c-08d70e93e8cf X-IsSubscribed: yes Thank you Simon, Tom and Alan for the detailed review. I appreciate you for reviewing the patch very patiently and providing your feedback. I have incorparated all your review comments in this new patch. Hello, GDB is not able to execute "step" command on function calls of Armv8-M cmse secure entry functions. Everytime GNU linker come across definition of any cmse secure entry function in object file(s), it creates two new instructions secure gateway (sg) and original branch destination (b.w), place those two instructions in ".gnu.sgstubs" section of executable. Any function calls to these cmse secure entry functions is re-directed through secure gateway (sg) present in ".gnu.sgstubs" section. Example: Following is a function call to cmse secure entry function "foo": ... bl xxxx --->(a) ... xxxx: push {r7, lr} GNU linker on finding out "foo" is a cmse secure entry function, created sg and b.w instructions and place them in ".gnu.sgstubs" section (marked by c). The "bl" instruction (marked by a) which is a call to cmse secure entry function is modified by GNU linker (as marked by b) and call flow is re-directly through secure gateway (sg) in ".gnu.sgstubs" section. ... bl yyyy ---> (b) ... section .gnu.sgstubs: ---> (c) yyyy yyyy: sg // secure gateway b.w xxxx <__acle_se_foo> // original_branch_dest ... 0000xxxx <__acle_se_foo> xxxx: push {r7, lr} ---> (d) On invoking GDB, when the control is at "b" and we pass "step" command, the pc returns "yyyy" (sg address) which is a trampoline and which does not exist in source code. So GDB jumps to next line without jumping to "__acle_se_foo" (marked by d). The above details are published on the Arm website [1], please refer to section 5.4 (Entry functions) and section 3.4.4 (C level development flow of secure code). [1] https://developer.arm.com/architectures/cpu-architecture/m-profile/docs/ecm0359818/latest/armv8-m-security-extensions-requirements-on-development-tools-engineering-specification This patch fixes above problem by returning target pc "xxxx" to GDB on executing "step" command at "b", so that the control jumps to "__acle_se_foo" (marked by d). This patch is tested by debugging the CMSE executable using GDB on Aarch32 box. Regression tested for armv7hl-redhat-linux-gnueabi and found no regressions. Ok for master? If ok, could someone please commit this on my behalf, I don't have the commit rights. gdb/ChangeLog: 2019-07-22 Srinath Parvathaneni * arm-tdep.c (arm_skip_cmse_entry): New function. (arm_is_sgstubs_section): New function. (arm_skip_stub): Add call to arm_skip_cmse_entry function. gdb/testsuite/ChangeLog: 2019-07-22 Srinath Parvathaneni * gdb.arch/arm-cmse-sgstubs.c: New test. * gdb.arch/arm-cmse-sgstubs.exp: New file. ############### Attachment also inlined for ease of reply ############### diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c index d244707210628ab045f677c0cbad3d8b0c6d6269..2d5dd02a369508d7ae1125354ef4f2f713dd9695 100644 --- a/gdb/arm-tdep.c +++ b/gdb/arm-tdep.c @@ -8211,6 +8211,56 @@ arm_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc) *pc = extract_unsigned_integer (buf, INT_REGISTER_SIZE, byte_order); return 1; } +/* A call to cmse secure entry function "foo" at "a" is modified by + GNU ld as "b". + a) bl xxxx + + + xxxx: + + b) bl yyyy <__acle_se_foo> + + section .gnu.sgstubs: + + yyyy: sg // secure gateway + b.w xxxx <__acle_se_foo> // original_branch_dest + + <__acle_se_foo> + xxxx: + + When the control at "b", the pc contains "yyyy" (sg address) which is a + trampoline and does not exist in source code. This function returns the + target pc "xxxx". For more details please refer to section 5.4 + (Entry functions) and section 3.4.4 (C level development flow of secure code) + of "armv8-m-security-extensions-requirements-on-development-tools-engineering-specification" + document on www.developer.arm.com. */ + +static CORE_ADDR +arm_skip_cmse_entry (CORE_ADDR pc, const char *name, struct objfile *objfile) +{ + int target_len = strlen (name) + strlen ("__acle_se_") + 1; + char *target_name = (char *) alloca (target_len); + xsnprintf (target_name, target_len, "%s%s", "__acle_se_", name); + + struct bound_minimal_symbol minsym + = lookup_minimal_symbol (target_name, NULL, objfile); + + if (minsym.minsym != nullptr) + return BMSYMBOL_VALUE_ADDRESS (minsym); + + return 0; +} + +/* Return true when SEC points to ".gnu.sgstubs" section. */ + +static bool +arm_is_sgstubs_section (struct obj_section *sec) +{ + return (sec != nullptr + && sec->the_bfd_section != nullptr + && sec->the_bfd_section->name != nullptr + && streq (sec->the_bfd_section->name, ".gnu.sgstubs")); +} /* Recognize GCC and GNU ld's trampolines. If we are in a trampoline, return the target PC. Otherwise return 0. */ @@ -8290,6 +8340,12 @@ arm_skip_stub (struct frame_info *frame, CORE_ADDR pc) return 0; } + struct obj_section *section = find_pc_section (pc); + + /* Check whether SECTION points to the ".gnu.sgstubs" section. */ + if (arm_is_sgstubs_section (section)) + return arm_skip_cmse_entry (pc, name, section->objfile); + return 0; /* not a stub */ } diff --git a/gdb/testsuite/gdb.arch/arm-cmse-sgstubs.c b/gdb/testsuite/gdb.arch/arm-cmse-sgstubs.c new file mode 100644 index 0000000000000000000000000000000000000000..3ac8e6e45767e29534db0fb0c9053f00dad19d90 --- /dev/null +++ b/gdb/testsuite/gdb.arch/arm-cmse-sgstubs.c @@ -0,0 +1,50 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2019 Free Software Foundation, Inc. + + 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 +extern void func (); +void +__acle_se_func () +{ + printf ("__acle_se_func\n"); +} + +/* The following code is written using asm so that the instructions in function + * "func" will be placed in .gnu.sgstubs section of the executable. */ +asm ("\t.section .gnu.sgstubs,\"ax\",%progbits\n" + "\t.global func\n" + "\t.type func, %function\n" + "func:\n" + "\tnop @sg\n" + "\tb __acle_se_func @b.w"); + +void +fun1 () +{ + printf ("In fun1\n"); +} + +int +main (void) +{ + func (); + fun1 (); + __acle_se_func (); + func (); + + return 0; +} diff --git a/gdb/testsuite/gdb.arch/arm-cmse-sgstubs.exp b/gdb/testsuite/gdb.arch/arm-cmse-sgstubs.exp new file mode 100644 index 0000000000000000000000000000000000000000..42a265ca67697f67fa5e530d7fd64a7f6fd69929 --- /dev/null +++ b/gdb/testsuite/gdb.arch/arm-cmse-sgstubs.exp @@ -0,0 +1,50 @@ +# Copyright 2019 Free Software Foundation, Inc. + +# 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 . + +# This file is part of the gdb testsuite. + +if { ![istarget "arm*-*-*"]} { + return 1 +} + +standard_testfile +if { [prepare_for_testing "failed to prepare" $testfile $srcfile ]} { + return -1 +} + +if ![runto_main] { + untested "could not run to main" + return -1 +} + +gdb_test "si" "0x.*" "branch to func from main" + +gdb_test "ni" "0x.*" "next instruction in func" + +gdb_test "ni" "__acle_se_func ().*" "branch to __acle_se_func from func" + +gdb_test "next" "23 .*" "next in __acle_se_func function" + +gdb_test "next" "__acle_se_func.*" "next in __acle_se_func function outputs __acle_se_func" + +gdb_test "next" "main ().*" "next in __acle_se_func function controls returns to main" + +gdb_test "next" "In fun1.*" "next in main outputs In fun1" + +gdb_test "next" "__acle_se_func.*" "next in main outputs __acle_se_func" + +gdb_test "step" "__acle_se_func ().*" "control jumps to __acle_se_func from main via func" + +gdb_test "next" "__acle_se_func.*" "next in __acle_se_func function via func" diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c index d244707210628ab045f677c0cbad3d8b0c6d6269..2d5dd02a369508d7ae1125354ef4f2f713dd9695 100644 --- a/gdb/arm-tdep.c +++ b/gdb/arm-tdep.c @@ -8211,6 +8211,56 @@ arm_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc) *pc = extract_unsigned_integer (buf, INT_REGISTER_SIZE, byte_order); return 1; } +/* A call to cmse secure entry function "foo" at "a" is modified by + GNU ld as "b". + a) bl xxxx + + + xxxx: + + b) bl yyyy <__acle_se_foo> + + section .gnu.sgstubs: + + yyyy: sg // secure gateway + b.w xxxx <__acle_se_foo> // original_branch_dest + + <__acle_se_foo> + xxxx: + + When the control at "b", the pc contains "yyyy" (sg address) which is a + trampoline and does not exist in source code. This function returns the + target pc "xxxx". For more details please refer to section 5.4 + (Entry functions) and section 3.4.4 (C level development flow of secure code) + of "armv8-m-security-extensions-requirements-on-development-tools-engineering-specification" + document on www.developer.arm.com. */ + +static CORE_ADDR +arm_skip_cmse_entry (CORE_ADDR pc, const char *name, struct objfile *objfile) +{ + int target_len = strlen (name) + strlen ("__acle_se_") + 1; + char *target_name = (char *) alloca (target_len); + xsnprintf (target_name, target_len, "%s%s", "__acle_se_", name); + + struct bound_minimal_symbol minsym + = lookup_minimal_symbol (target_name, NULL, objfile); + + if (minsym.minsym != nullptr) + return BMSYMBOL_VALUE_ADDRESS (minsym); + + return 0; +} + +/* Return true when SEC points to ".gnu.sgstubs" section. */ + +static bool +arm_is_sgstubs_section (struct obj_section *sec) +{ + return (sec != nullptr + && sec->the_bfd_section != nullptr + && sec->the_bfd_section->name != nullptr + && streq (sec->the_bfd_section->name, ".gnu.sgstubs")); +} /* Recognize GCC and GNU ld's trampolines. If we are in a trampoline, return the target PC. Otherwise return 0. */ @@ -8290,6 +8340,12 @@ arm_skip_stub (struct frame_info *frame, CORE_ADDR pc) return 0; } + struct obj_section *section = find_pc_section (pc); + + /* Check whether SECTION points to the ".gnu.sgstubs" section. */ + if (arm_is_sgstubs_section (section)) + return arm_skip_cmse_entry (pc, name, section->objfile); + return 0; /* not a stub */ } diff --git a/gdb/testsuite/gdb.arch/arm-cmse-sgstubs.c b/gdb/testsuite/gdb.arch/arm-cmse-sgstubs.c new file mode 100644 index 0000000000000000000000000000000000000000..3ac8e6e45767e29534db0fb0c9053f00dad19d90 --- /dev/null +++ b/gdb/testsuite/gdb.arch/arm-cmse-sgstubs.c @@ -0,0 +1,50 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2019 Free Software Foundation, Inc. + + 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 +extern void func (); +void +__acle_se_func () +{ + printf ("__acle_se_func\n"); +} + +/* The following code is written using asm so that the instructions in function + * "func" will be placed in .gnu.sgstubs section of the executable. */ +asm ("\t.section .gnu.sgstubs,\"ax\",%progbits\n" + "\t.global func\n" + "\t.type func, %function\n" + "func:\n" + "\tnop @sg\n" + "\tb __acle_se_func @b.w"); + +void +fun1 () +{ + printf ("In fun1\n"); +} + +int +main (void) +{ + func (); + fun1 (); + __acle_se_func (); + func (); + + return 0; +} diff --git a/gdb/testsuite/gdb.arch/arm-cmse-sgstubs.exp b/gdb/testsuite/gdb.arch/arm-cmse-sgstubs.exp new file mode 100644 index 0000000000000000000000000000000000000000..42a265ca67697f67fa5e530d7fd64a7f6fd69929 --- /dev/null +++ b/gdb/testsuite/gdb.arch/arm-cmse-sgstubs.exp @@ -0,0 +1,50 @@ +# Copyright 2019 Free Software Foundation, Inc. + +# 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 . + +# This file is part of the gdb testsuite. + +if { ![istarget "arm*-*-*"]} { + return 1 +} + +standard_testfile +if { [prepare_for_testing "failed to prepare" $testfile $srcfile ]} { + return -1 +} + +if ![runto_main] { + untested "could not run to main" + return -1 +} + +gdb_test "si" "0x.*" "branch to func from main" + +gdb_test "ni" "0x.*" "next instruction in func" + +gdb_test "ni" "__acle_se_func ().*" "branch to __acle_se_func from func" + +gdb_test "next" "23 .*" "next in __acle_se_func function" + +gdb_test "next" "__acle_se_func.*" "next in __acle_se_func function outputs __acle_se_func" + +gdb_test "next" "main ().*" "next in __acle_se_func function controls returns to main" + +gdb_test "next" "In fun1.*" "next in main outputs In fun1" + +gdb_test "next" "__acle_se_func.*" "next in main outputs __acle_se_func" + +gdb_test "step" "__acle_se_func ().*" "control jumps to __acle_se_func from main via func" + +gdb_test "next" "__acle_se_func.*" "next in __acle_se_func function via func"