From patchwork Thu Mar 10 09:57:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Machado X-Patchwork-Id: 550088 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6713:0:0:0:0 with SMTP id u19csp835590mag; Thu, 10 Mar 2022 01:58:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJyRvccbKAmQx4Yi056rX03QDSgVvpgVSK7cWHRzIsVIGKO8VAGc/ZspQsFNkMfHzdnhqKlR X-Received: by 2002:a17:907:6d1d:b0:6d8:9fc8:b1e1 with SMTP id sa29-20020a1709076d1d00b006d89fc8b1e1mr3365488ejc.466.1646906288790; Thu, 10 Mar 2022 01:58:08 -0800 (PST) Return-Path: Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id ga11-20020a1709070c0b00b006daaccc9629si2887222ejc.517.2022.03.10.01.58.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Mar 2022 01:58:08 -0800 (PST) Received-SPF: pass (google.com: domain of gdb-patches-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=ufbOvYWP; arc=fail (signature failed); spf=pass (google.com: domain of gdb-patches-bounces+patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gdb-patches-bounces+patch=linaro.org@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 679D53858429 for ; Thu, 10 Mar 2022 09:58:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 679D53858429 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1646906287; bh=PFTbLVgI1DiEC0PBB67jbTrpZxckf2Sl3/3BMwqyMUU=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=ufbOvYWPQbxLpexSu58NLmVFYWNBtq5MTTfJnVDr0bSDAw0hdFeA3FaOaW3eJ0R2e BuX/O/RwaP2PDCP2DW1/cZlSSZsFtGEf/+v3P8FkpOg4Tloz9sW3LZQ2o8F1UO5EhC HCQxt7WE18L0axpCbEEV+l9F1EfCliv8reejGAe4= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from EUR03-VE1-obe.outbound.protection.outlook.com (mail-eopbgr50076.outbound.protection.outlook.com [40.107.5.76]) by sourceware.org (Postfix) with ESMTPS id 8B3BF385840B for ; Thu, 10 Mar 2022 09:57:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8B3BF385840B Received: from AS9PR06CA0049.eurprd06.prod.outlook.com (2603:10a6:20b:463::24) by PAXPR08MB7382.eurprd08.prod.outlook.com (2603:10a6:102:22d::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.19; Thu, 10 Mar 2022 09:57:45 +0000 Received: from AM5EUR03FT038.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:463:cafe::b2) by AS9PR06CA0049.outlook.office365.com (2603:10a6:20b:463::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14 via Frontend Transport; Thu, 10 Mar 2022 09:57:45 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM5EUR03FT038.mail.protection.outlook.com (10.152.17.118) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.22 via Frontend Transport; Thu, 10 Mar 2022 09:57:45 +0000 Received: ("Tessian outbound 18e50a6f0513:v113"); Thu, 10 Mar 2022 09:57:45 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: d4401a94fc9d01fd X-CR-MTA-TID: 64aa7808 Received: from c597c9586c71.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 97C38A95-DE21-4DDE-B466-68191DCF5DD3.1; Thu, 10 Mar 2022 09:57:38 +0000 Received: from EUR04-DB3-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id c597c9586c71.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 10 Mar 2022 09:57:38 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BMg8lHRzmxA+ySNoTioPbnSdy/X08q4+tU1XUIHS9wCZ8Lhv49XDQVk+pzWLNYbFhzcqCg8yrrZKiTwtxlUEufFPLXAfwuF2eeuj6M0vivBvVk/2eqPgCJmcQMECWjT8HL/jVImbfORq8UX+D9ndP2pevwfzvYJZnSsv7pkK/+gQZb03jFDJOPA2HbjzLi3952OG/DedkU4K3IRVPbAJSytVHnfUb1scpWpUKUDngVp1YV6IZd7PKe3xcfXlKnd8merxmbqLyP88ZCs3C8gRiGDTE1GCL/Tm3VKLvAlX+VismAbc4rcZIe5GLb1A5ZaBC1yDiKfUaIsa98I1WUh3kg== 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=PFTbLVgI1DiEC0PBB67jbTrpZxckf2Sl3/3BMwqyMUU=; b=kaPWfwfje0sr0MImDxowyLzTOK8OzqLy7lDphxqZg2U8J7kFuamH9ddiXedkF3ZjspWAR0ZCZs0wQ7zXkrpV5M78rHQw0widXZc9lK0roz6kEYchXzLe9uYkfJ4f2jHIbdlxBShAAis4g94XMxVDCKeA13H9dDvOh0OMWeQsZxvRPTZ28Pi2vy2s1AJ77fDEp/gAHCAVOl6qCDZchycMhZgDHQsVxXYRhsxoMwLpOF2B5EjAxxTyFc+lyUBB83bB7buv6w14wt2xzvKvf2qImK/iAW8CrByL52dd5NJR3fRrPsjPKHceOCS51UhlGjIWYaNhsGieEQktsZQU2oa7QQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=sourceware.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=none (message not signed); arc=none Received: from AS9PR06CA0394.eurprd06.prod.outlook.com (2603:10a6:20b:461::27) by DBBPR08MB4741.eurprd08.prod.outlook.com (2603:10a6:10:d8::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.21; Thu, 10 Mar 2022 09:57:35 +0000 Received: from AM5EUR03FT021.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:461:cafe::78) by AS9PR06CA0394.outlook.office365.com (2603:10a6:20b:461::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.22 via Frontend Transport; Thu, 10 Mar 2022 09:57:35 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 40.67.248.234 as permitted sender) receiver=protection.outlook.com; client-ip=40.67.248.234; helo=nebula.arm.com; Received: from nebula.arm.com (40.67.248.234) by AM5EUR03FT021.mail.protection.outlook.com (10.152.16.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5061.22 via Frontend Transport; Thu, 10 Mar 2022 09:57:34 +0000 Received: from AZ-NEU-EX01.Emea.Arm.com (10.251.26.4) by AZ-NEU-EX03.Arm.com (10.251.24.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2308.20; Thu, 10 Mar 2022 09:57:34 +0000 Received: from AZ-NEU-EX04.Arm.com (10.251.24.32) by AZ-NEU-EX01.Emea.Arm.com (10.251.26.4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.20; Thu, 10 Mar 2022 09:57:27 +0000 Received: from e129171.cambridge.arm.com (10.2.80.38) by mail.arm.com (10.251.24.32) with Microsoft SMTP Server id 15.1.2308.20 via Frontend Transport; Thu, 10 Mar 2022 09:57:33 +0000 To: Subject: [PATCH] [aarch64/arm] Properly extract the return value returned in memory Date: Thu, 10 Mar 2022 09:57:21 +0000 Message-ID: <20220310095721.84432-1-luis.machado@arm.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-Office365-Filtering-Correlation-Id: 3f19b7a9-c7cd-45eb-eef2-08da027c6ce6 X-MS-TrafficTypeDiagnostic: DBBPR08MB4741:EE_|AM5EUR03FT038:EE_|PAXPR08MB7382:EE_ X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: pqU1C8cZJjeM5PjidSEJw7br1JpFdRLR6HDK5sxoseVyHQa/N83hFjMNPn0q+0QTb4ATR0KDBMnl3zKoqOlTqayVxODU7d9LlGDl9Ytp93H+CulrrDJMoeKrjqSt7KQSs9Ks5tVE6tUCyuaxcRbSbEbaKEhP8toviJwGBXBHY7P2NsOBt571Sf9eZJpJCfTSYL7F6wao1cwqZW5dk/5qnamPHBEfF2EHClzY9NGb1DF1LkMZGL8tRpXRyZQnUsdia7jB8ObSCSGUNarsO2RgKBBv7Oet8SeMUhLWhQDXWIvYuZDcmQk3Yqt58LxsnCFhBWleV/MQSes26LFAXo6YAn1x7JuI9Hl+NNmL4vk9PXoJ4VDCYDym8nApoxRWzlIqLNeVM+Z5avx7oNG6/vgxbJQiBXjQzY0OVd/zEMyhgfB51buP9denUjl18ZNp6TGsYNjmCSjN4biKZGweMGq+Ig3atwiVzMC0XxNfkMod66I1DvcgI3mw96qHAExSv1BS7qVyvFSwuDkKi1qHxXzcxEO2Qs1hZNas1ELISws0R/0pxR9rACPfQhLi+ULlhp3Cvg5isAeYTNfAG2c8ClLArnlMxOXRYDzDJ8HOEaNU8zroZaSc3TE93YRFT4pJNr/sTCUI51g8gP41DQMuEbpWy1jdcOU8KZ9Fd9wmvhAW2z+4vNBKhfac7OU5Bk0YwUwwMADCtjxjzCTQpOljIiqnCWF5Dx1ICl0bel6utH0Fnkj2aw4hUYXD651shfiQomFGc6fs0oSnTloB0pvQy0hGJur00TjD+y2MYtCruwIkbig5bo9UDHSQeBtb/JspMNTuPNPP5kpBB4+80BECsNMKTXPgAhh0yB3Gtm4mpPvKqvU= X-Forefront-Antispam-Report-Untrusted: CIP:40.67.248.234; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:nebula.arm.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230001)(4636009)(36840700001)(46966006)(40470700004)(8676002)(84970400001)(316002)(82310400004)(4326008)(83380400001)(70586007)(70206006)(47076005)(508600001)(8936002)(81166007)(5660300002)(356005)(44832011)(36860700001)(86362001)(2906002)(40460700003)(6916009)(36756003)(336012)(426003)(7696005)(1076003)(26005)(186003)(2616005)(6666004)(2004002)(36900700001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR08MB4741 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT038.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: eb2e2c34-b64c-421b-8f3a-08da027c66c8 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /+pCuHDKXvHnCjpiLXsilS3bCqbKhc3MVOLPBFbeqkCCPwkwRrdoxIV2FNT0dlj0EFaC7q3sLBYK0Hu9faFhwixmTeFVmSDD3CtYcfimdPyTzlwujWXcpoq5Ke5TnCaOAVw6RfdB+IwsjN0m4OL9RMwedUJXK1oQJ1tzsIxs7OGoh3YDyVEJK8/U2r9CTeQ37+25UZSZxm9p7FtMd/1cVRtYn71vmDB1gHnUtmIBwD58Y8MW7XZ9hGDFjIxeD8fUu5aAiO91NkFLkOLsDqnWNVBYkuoC8Xnon3uX9ZxfQKU95CJlFVf0Vg2QOcmbZGubQpi8DcWkM+U3eWa37ZXG3CxbnVR3m5Y7pp54ny4r4fD+TiBuVjUdJ6QYmnueIELo0jy5ejadk9HXQXbRqa1YnamuWLBF/3watPQzei9GpWacUKPzEj5PSlasHGXHel2rg0+njg2XAXCDiY9PljfipC4/w66lr8tZ5WXxtEonv7saB4/P1/sBecJT0v+t64UrTPzF56dIwuKzHN7H1uK/atgBMnJ9zEbIjQ8THoF7jFPBomxgWDAL1GH2W6tYu4gAAtEu9IyCq1GHp3OiF3GOnJtAsWxkHdFvKTgxQXtld3YfrB1RGOtny7+HhNCu2U6AfQtrqWid0mRlWWrzbZ3P9j3WI+we30nAn4P6V7oUwpe1zJOyUiaT5tZz9pc+lkQhJnT76wDzel9nL0+h8p8uWCiuUed3Xjspw2VTVq3ENTEjvHKXqpiB0/3GckMDSEGTOkrBFIXAZvjZc3+tgiZJ23PG94b4rWQ+d10mXm6PVrE+74dg4G5fHciIoRz+tpZq X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(13230001)(4636009)(40470700004)(46966006)(36840700001)(47076005)(6916009)(336012)(83380400001)(40460700003)(70206006)(426003)(4326008)(8676002)(44832011)(2906002)(86362001)(316002)(36756003)(7696005)(1076003)(2616005)(81166007)(8936002)(26005)(186003)(6666004)(36860700001)(508600001)(5660300002)(82310400004)(84970400001)(70586007)(2004002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Mar 2022 09:57:45.1839 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3f19b7a9-c7cd-45eb-eef2-08da027c6ce6 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: AM5EUR03FT038.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR08MB7382 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY, WEIRD_PORT autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Luis Machado via Gdb-patches From: Luis Machado Reply-To: Luis Machado Errors-To: gdb-patches-bounces+patch=linaro.org@sourceware.org Sender: "Gdb-patches" From: Luis Machado When running gdb.cp/non-trivial-retval.exp, the following shows up for both aarch64-linux and armhf-linux: Breakpoint 3, f1 (i1=23, i2=100) at src/gdb/testsuite/gdb.cp/non-trivial-retval.cc:35 35 A a; (gdb) finish Run till exit from #0 f1 (i1=23, i2=100) at src/gdb/testsuite/gdb.cp/non-trivial-retval.cc:35 main () at /src/gdb/testsuite/gdb.cp/non-trivial-retval.cc:163 163 B b = f2 (i1, i2); Value returned is $6 = {a = -11952} (gdb) The return value should be {a = 123} instead. This happens because the backends don't extract the return value from the correct location. GDB should fetch a pointer to the memory location from X8 for aarch64 and r0 for armhf. With the patch, gdb.cp/non-trivial-retval.exp has full passes on aarch64-linux and armhf-linux on Ubuntu 20.04/18.04. The problem only shows up with the "finish" command. The "call" command works correctly and displays the correct return value. This is also related to PR gdb/28681 (https://sourceware.org/bugzilla/show_bug.cgi?id=28681) and fixes FAIL's in gdb.ada/mi_var_array.exp. A new testcase is provided, and it exercises GDB's ability to "finish" a function that returns a large struct (> 16 bytes) and display the contents of this struct correctly. This has always been incorrect for these backends, but no testcase exercised this particular scenario. --- gdb/aarch64-tdep.c | 21 ++++++++- gdb/arm-tdep.c | 32 +++++++++++-- gdb/testsuite/gdb.base/retval-large-struct.c | 45 +++++++++++++++++++ .../gdb.base/retval-large-struct.exp | 37 +++++++++++++++ 4 files changed, 130 insertions(+), 5 deletions(-) create mode 100644 gdb/testsuite/gdb.base/retval-large-struct.c create mode 100644 gdb/testsuite/gdb.base/retval-large-struct.exp diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c index b3efb3ebaff..3f3a65240c0 100644 --- a/gdb/aarch64-tdep.c +++ b/gdb/aarch64-tdep.c @@ -2362,7 +2362,8 @@ aarch64_return_in_memory (struct gdbarch *gdbarch, struct type *type) return 0; } - if (TYPE_LENGTH (type) > 16) + if (TYPE_LENGTH (type) > 16 + || !language_pass_by_reference (type).trivially_copyable) { /* PCS B.6 Aggregates larger than 16 bytes are passed by invisible reference. */ @@ -2474,8 +2475,24 @@ aarch64_return_value (struct gdbarch *gdbarch, struct value *func_value, { if (aarch64_return_in_memory (gdbarch, valtype)) { + /* From the AAPCS64's Result Return section: + + "Otherwise, the caller shall reserve a block of memory of + sufficient size and alignment to hold the result. The address + of the memory block shall be passed as an additional argument to + the function in x8. */ + aarch64_debug_printf ("return value in memory"); - return RETURN_VALUE_STRUCT_CONVENTION; + + if (readbuf) + { + CORE_ADDR addr; + + regcache->cooked_read (AARCH64_STRUCT_RETURN_REGNUM, &addr); + read_memory (addr, readbuf, TYPE_LENGTH (valtype)); + } + + return RETURN_VALUE_ABI_RETURNS_ADDRESS; } } diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c index d36856e1f3b..8e245648f23 100644 --- a/gdb/arm-tdep.c +++ b/gdb/arm-tdep.c @@ -8075,7 +8075,8 @@ arm_return_in_memory (struct gdbarch *gdbarch, struct type *type) { /* The AAPCS says all aggregates not larger than a word are returned in a register. */ - if (TYPE_LENGTH (type) <= ARM_INT_REGISTER_SIZE) + if (TYPE_LENGTH (type) <= ARM_INT_REGISTER_SIZE + && language_pass_by_reference (type).trivially_copyable) return 0; return 1; @@ -8086,7 +8087,8 @@ arm_return_in_memory (struct gdbarch *gdbarch, struct type *type) /* All aggregate types that won't fit in a register must be returned in memory. */ - if (TYPE_LENGTH (type) > ARM_INT_REGISTER_SIZE) + if (TYPE_LENGTH (type) > ARM_INT_REGISTER_SIZE + || !language_pass_by_reference (type).trivially_copyable) return 1; /* In the ARM ABI, "integer" like aggregate types are returned in @@ -8307,9 +8309,33 @@ arm_return_value (struct gdbarch *gdbarch, struct value *function, || valtype->code () == TYPE_CODE_UNION || valtype->code () == TYPE_CODE_ARRAY) { + /* From the AAPCS document: + + Result return: + + A Composite Type larger than 4 bytes, or whose size cannot be + determined statically by both caller and callee, is stored in memory + at an address passed as an extra argument when the function was + called (Parameter Passing, rule A.4). The memory to be used for the + result may be modified at any point during the function call. + + Parameter Passing: + + A.4: If the subroutine is a function that returns a result in memory, + then the address for the result is placed in r0 and the NCRN is set + to r1. */ if (tdep->struct_return == pcc_struct_return || arm_return_in_memory (gdbarch, valtype)) - return RETURN_VALUE_STRUCT_CONVENTION; + { + if (readbuf) + { + CORE_ADDR addr; + + regcache->cooked_read (ARM_A1_REGNUM, &addr); + read_memory (addr, readbuf, TYPE_LENGTH (valtype)); + } + return RETURN_VALUE_ABI_RETURNS_ADDRESS; + } } else if (valtype->code () == TYPE_CODE_COMPLEX) { diff --git a/gdb/testsuite/gdb.base/retval-large-struct.c b/gdb/testsuite/gdb.base/retval-large-struct.c new file mode 100644 index 00000000000..ae459741220 --- /dev/null +++ b/gdb/testsuite/gdb.base/retval-large-struct.c @@ -0,0 +1,45 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2022 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 . */ + +struct big_struct_t +{ + int int_array[5]; + double double_array[5]; + char char_array[5]; +}; + +struct big_struct_t big_struct = +{ + {1, 2, 3, 4, 5}, + {3.25, 5.0, 6.25, 1.325, -1.95}, + "abcde" +}; + +struct big_struct_t return_large_struct (void) +{ + return big_struct; +} + +int +main (int argc, char **argv) +{ + struct big_struct_t test_struct; + + test_struct = return_large_struct (); + + return 0; +} diff --git a/gdb/testsuite/gdb.base/retval-large-struct.exp b/gdb/testsuite/gdb.base/retval-large-struct.exp new file mode 100644 index 00000000000..11bc4d5fbdf --- /dev/null +++ b/gdb/testsuite/gdb.base/retval-large-struct.exp @@ -0,0 +1,37 @@ +# Copyright 2022 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 +# +# Test if "finish" behaves correctly when a function returns a +# large (> 16 bytes) struct. + +standard_testfile + +if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} { + return -1 +} + +if {![runto_main]} { + return -1 +} + +set pattern ".* = \\{int_array = \\{1, 2, 3, 4, 5\\}, double_array = \\{3.25, 5, 6.25, 1.325, -1.95\\}, char_array = \"abcde\"\\}" + +gdb_test "p return_large_struct ()" $pattern + +gdb_breakpoint "return_large_struct" +gdb_continue_to_breakpoint "Break in print_large_struct" +gdb_test "finish" $pattern "finish from return_large_struct"