From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 2HubAQ18zl9ETQAAWB0awg (envelope-from ) for ; Mon, 07 Dec 2020 14:01:33 -0500 Received: by simark.ca (Postfix, from userid 112) id 74A7D1F071; Mon, 7 Dec 2020 14:01:31 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,RDNS_NONE, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from sourceware.org (unknown [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 6DE1B1EF4B for ; Mon, 7 Dec 2020 14:01:30 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 102563951C4C; Mon, 7 Dec 2020 19:01:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 102563951C4C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1607367690; bh=Pz+pIRuRKn3Q8JUPBfEDiQy7R2qQjFZZN8+BMbg54Hk=; 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=soABD6QFu/PI/Q2dIxJWIs5S/eUhakZ18dXOXcwYL2gE4GLYOpk2odVUjFLuBfLJO TjYB80/G5xxaahP/7aZ3Hu9EzNgA1ziJpPvyqfoEKfuq2MhYd7HSmOiJXwY0OPPcoq KAOfFbwBzdjRZgH4TOMKiZLCzqBMfGcGW2nvv+tY= Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2056.outbound.protection.outlook.com [40.107.244.56]) by sourceware.org (Postfix) with ESMTPS id 86972393D02B for ; Mon, 7 Dec 2020 19:01:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 86972393D02B ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KK99JkgNAgZyyqCnAykftJAoIOjnvN7Bg9DGtLYFM9pLY+ZUEm5I/puFfZoz/I/HYR2AcoTJ5Ef4/V87RsGo/wkBtxJit/nFGiaPi/i2pD/fWq+sDbbJtNSGcpTN5dEG96xEc1Hlhzr7seCD2b2aUsvW5GSlGZS626cwDjS//r+88HggJ472LVCGajvLKNfWgyh6+ivqNPlWpmaHzAaNlyw9bWAp+EYhOmXiaFkqiuNC/OTvrnyFrUdRYRGEQb307EwBkAWLp5qrkQqUmj5/xMWf2O7z9cuobz71ozym9z7nkhyRo311GtlLVF5ZmIgrW4TU4PynY3bU9rh6sVgVoQ== 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=Pz+pIRuRKn3Q8JUPBfEDiQy7R2qQjFZZN8+BMbg54Hk=; b=USmgbBCgZFIu5jkyc3cAuGg0tpKCiZingLO21NtF0+oYAXP5GuwzLgWRtEQYGVoi3dd36/BGAmNQI8YkMeDr4p3dLAy4Eq4fFW9hwP1V49A6FnY6aR07+gc93TarAKzX26Om67oKVyF8eD2tREHnJ7wnw/EuorQ8JPUjvnCSZFso26DtBZY5Bjm1CiS4Df/swCEeznFKZTGHmlY3czbzb4nmLTs8yLcUuiuOp8uv74V5hwB7ihf+xfAO9sLKzenTGA8NRikw+lieT8Fo1Vd146gqH+f8+oCpp/Jsb8FBy3Gmzf2QWCjkhIev94wEi4yyuPTWutIlm4URgyVjODMIKg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none Received: from DM6PR12MB2762.namprd12.prod.outlook.com (2603:10b6:5:45::15) by DM6PR12MB4561.namprd12.prod.outlook.com (2603:10b6:5:2ac::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3632.18; Mon, 7 Dec 2020 19:01:16 +0000 Received: from DM6PR12MB2762.namprd12.prod.outlook.com ([fe80::6841:61df:984b:b3c]) by DM6PR12MB2762.namprd12.prod.outlook.com ([fe80::6841:61df:984b:b3c%3]) with mapi id 15.20.3632.021; Mon, 7 Dec 2020 19:01:16 +0000 To: gdb-patches@sourceware.org Subject: [PATCH 16/30] Add new register access interface to expr.c Date: Mon, 7 Dec 2020 19:00:17 +0000 Message-Id: <20201207190031.13341-17-Zoran.Zaric@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201207190031.13341-1-Zoran.Zaric@amd.com> References: <20201207190031.13341-1-Zoran.Zaric@amd.com> Content-Type: text/plain X-Originating-IP: [2a00:23c7:5a85:6801:5c7:2db6:d2c2:ae4e] X-ClientProxiedBy: AM4PR0101CA0053.eurprd01.prod.exchangelabs.com (2603:10a6:200:41::21) To DM6PR12MB2762.namprd12.prod.outlook.com (2603:10b6:5:45::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (2a00:23c7:5a85:6801:5c7:2db6:d2c2:ae4e) by AM4PR0101CA0053.eurprd01.prod.exchangelabs.com (2603:10a6:200:41::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3632.17 via Frontend Transport; Mon, 7 Dec 2020 19:01:12 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: f20d77fd-d09a-4509-5334-08d89ae27995 X-MS-TrafficTypeDiagnostic: DM6PR12MB4561: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6108; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: lZLDj5Guf1ogQqD8zfc0rsKVdTCqcwd4RSchrFoOYM0KuasIhu9ieu1goK7LivwXd5rGottTsPEpYmTTaKljTXHJ86d8+cH+p2hn2EqJ6dWlAh5wAe5q6En8bprWHYY4BWFEPC0lAnf6cOjusnzDE2qrJItTGFPvYD2lRLSMVLlslEqcOArZ/qsDQZqFILciU4pWjPczjf3OR4JWEJb8JDPhtIUqiKnGZM6Me2s210b2a41Tn0BfYEHMEoiYbIsz1gEYwXQu58He17xSR7GaDWrJuA1Rh65kzDBmCNQ5UZsgMeCv0E74Izgv0aei2Kx5CIhKwGFHOtsUIUfRWmZAu1UJLKPgQwNftO9AzsoMYVALKFSD1nFD4w64A+8nAdE3 X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM6PR12MB2762.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(376002)(346002)(39860400002)(366004)(136003)(396003)(1076003)(83380400001)(86362001)(6506007)(4326008)(69590400008)(52116002)(36756003)(2906002)(6512007)(8676002)(6486002)(16526019)(2616005)(66946007)(66476007)(66556008)(6916009)(5660300002)(186003)(8936002)(478600001)(316002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?sJiwE5zIo/k6EwVR1UgEHCTkd28+HISkrq3BVWavFUyt0G7TLF4qDg91BYde?= =?us-ascii?Q?ejEZTLgxQiFfzYLj2Ng+EeD8HvfQx0PFTqgWzQdiYHjisMT+rskTYjPRoXew?= =?us-ascii?Q?VMvj8McCmjZc2XQjgbRy2NTWSCmmbrMyd2pNKR0D91V4bGkJHUhtYUFyVa2+?= =?us-ascii?Q?qgDm1AG0Fs7hj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?Q?ple7L8ER?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB2762.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2020 19:01:15.4647 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-Network-Message-Id: f20d77fd-d09a-4509-5334-08d89ae27995 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 3PXzLcTuw7PfIaW2bArdqkcl/YeJ5VIEgFoQgW/PmoQgxLl1IHK9D/bJ0MSlIOd4GFONkcCLzenUgl7ZY6ByEg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4561 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: , From: Zoran Zaric via Gdb-patches Reply-To: Zoran Zaric Cc: Zoran Zaric Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" DWARF expression evaluator is currently using get_frame_register_bytes and put_frame_register_bytes interface for register access. The problem with evaluator using this interface is that it allows a bleed out register access. This means that if the caller specifies a larger amount of data then the size of a specified register, the operation will continue accessing the neighboring registers until a full amount of data has been reached. DWARF specification does not define this behavior, so a new simplified register access interface is needed instead. * dwarf2/expr.c (read_from_register): New function. (write_to_register): New function. (rw_pieced_value): Now calls the read_from_register and write_to_register functions. --- gdb/dwarf2/expr.c | 131 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 107 insertions(+), 24 deletions(-) diff --git a/gdb/dwarf2/expr.c b/gdb/dwarf2/expr.c index b1283e70df..0493bd926e 100644 --- a/gdb/dwarf2/expr.c +++ b/gdb/dwarf2/expr.c @@ -98,6 +98,94 @@ read_addr_from_reg (struct frame_info *frame, int reg) return address_from_register (regnum, frame); } +/* Read register REGNUM's contents in a given FRAME context. + + The data read is offsetted by OFFSET, and the number of bytes read + is defined by LENGTH. The data is then copied into the + caller-managed buffer BUF. + + If the register is optimized out or unavailable for the given + FRAME, the OPTIMIZED and UNAVAILABLE outputs are set + accordingly */ + +static void +read_from_register (struct frame_info *frame, int regnum, + CORE_ADDR offset, int length, gdb_byte *buf, + int *optimized, int *unavailable) +{ + struct gdbarch *gdbarch = get_frame_arch (frame); + int regsize = register_size (gdbarch, regnum); + int numregs = gdbarch_num_cooked_regs (gdbarch); + + /* If a register is wholly inside the OFFSET, skip it. */ + if (frame == NULL || !regsize + || (offset + length) > regsize || numregs < regnum) + { + (*optimized) = 0; + (*unavailable) = 1; + return; + } + + gdb::byte_vector temp_buf (regsize); + enum lval_type lval; + CORE_ADDR address; + int realnum; + + frame_register (frame, regnum, optimized, unavailable, + &lval, &address, &realnum, temp_buf.data ()); + + if (!(*optimized) && !(*unavailable)) + memcpy (buf, (char *) temp_buf.data () + offset, length); + + return; +} + +/* Write register REGNUM's contents in a given FRAME context. + + The data written is offsetted by OFFSET, and the number of bytes + written is defined by LENGTH. The data is copied from + caller-managed buffer BUF. + + If the register is optimized out or unavailable for the given + FRAME, the OPTIMIZED and UNAVAILABLE outputs are set + accordingly. */ + +static void +write_to_register (struct frame_info *frame, int regnum, + CORE_ADDR offset, int length, gdb_byte *buf, + int *optimized, int *unavailable) +{ + struct gdbarch *gdbarch = get_frame_arch (frame); + int regsize = register_size (gdbarch, regnum); + int numregs = gdbarch_num_cooked_regs (gdbarch); + + /* If a register is wholly inside of OFFSET, skip it. */ + if (frame == NULL || !regsize + || (offset + length) > regsize || numregs < regnum) + { + (*optimized) = 0; + (*unavailable) = 1; + return; + } + + gdb::byte_vector temp_buf (regsize); + enum lval_type lval; + CORE_ADDR address; + int realnum; + + frame_register (frame, regnum, optimized, unavailable, + &lval, &address, &realnum, temp_buf.data ()); + + if (!(*optimized) && !(*unavailable)) + { + memcpy ((char *) temp_buf.data () + offset, buf, length); + + put_frame_register (frame, regnum, temp_buf.data ()); + } + + return; +} + struct piece_closure { /* Reference count. */ @@ -235,23 +323,19 @@ rw_pieced_value (struct value *v, struct value *from) if (from == NULL) { /* Read mode. */ - if (!get_frame_register_bytes (frame, gdb_regnum, - bits_to_skip / 8, - this_size, buffer.data (), - &optim, &unavail)) - { - if (optim) - mark_value_bits_optimized_out (v, offset, - this_size_bits); - if (unavail) - mark_value_bits_unavailable (v, offset, - this_size_bits); - break; - } - - copy_bitwise (v_contents, offset, - buffer.data (), bits_to_skip % 8, - this_size_bits, bits_big_endian); + read_from_register (frame, gdb_regnum, bits_to_skip / 8, + this_size, buffer.data (), + &optim, &unavail); + + if (optim) + mark_value_bits_optimized_out (v, offset, this_size_bits); + if (unavail) + mark_value_bits_unavailable (v, offset, this_size_bits); + /* Only copy data if valid. */ + if (!optim && !unavail) + copy_bitwise (v_contents, offset, + buffer.data (), bits_to_skip % 8, + this_size_bits, bits_big_endian); } else { @@ -260,10 +344,9 @@ rw_pieced_value (struct value *v, struct value *from) { /* Data is copied non-byte-aligned into the register. Need some bits from original register value. */ - get_frame_register_bytes (frame, gdb_regnum, - bits_to_skip / 8, - this_size, buffer.data (), - &optim, &unavail); + read_from_register (frame, gdb_regnum, bits_to_skip / 8, + this_size, buffer.data (), + &optim, &unavail); if (optim) throw_error (OPTIMIZED_OUT_ERROR, _("Can't do read-modify-write to " @@ -279,9 +362,9 @@ rw_pieced_value (struct value *v, struct value *from) copy_bitwise (buffer.data (), bits_to_skip % 8, from_contents, offset, this_size_bits, bits_big_endian); - put_frame_register_bytes (frame, gdb_regnum, - bits_to_skip / 8, - this_size, buffer.data ()); + write_to_register (frame, gdb_regnum, bits_to_skip / 8, + this_size, buffer.data (), + &optim, &unavail); } } break; -- 2.17.1