From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2048.outbound.protection.outlook.com [40.107.92.48]) by sourceware.org (Postfix) with ESMTPS id 462053857C58 for ; Fri, 5 Nov 2021 11:39:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 462053857C58 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hwU3/y4AQUbMbtRtawec2+y6OfhNKuPJt142opabvk5Igr0hbj2nc3JYlfflEbNM0/OgNNeyL8kLv1gyGu94ls/nln5pBOFRMdtefSNQ+KwhiMQOiZyaN2Cd/VJz2uRrCZo+AEN3/WsW539F8fNVW5H/HIVn962sHL1DQMi7Y5KO9F1Ghn8Z0LDprLKf3o0YA7Clv08JGQQ4ngiz2eRCPaMp16aYM5EqPjV4deqKniXNwU3Has6kixCZaM8ROwFqlAguPvC9NLKq3gpXAtjrGIeU3JIsT8wAYf2tESouY1pBnYJ8Ir1cZC/OkTZ+AFnoz/4APXQavoUW93hFVxNGfg== 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=cjGbuNLJJE2O2rgnuxFnsYAo3K2FBgORSBOwmVxhjHA=; b=NFztc8eDjSwHHrUl2jNztHX2OWWIh+vJEwiYY3DqnXQQLQ/iMXQeSFgQvT5F6WQ8dXeLXiosF0SLBvgGWKlVhH+ujnzrdjDP70596d/HzqYlxjpGN7Jcryb8D8bzcEpKHp/oN9NTyQ7gNq3UJi+mq/ihRk9ZRt5ToSIRiNmMmFTrsEKBHDqGxQqXEGGPtww+iCESRsMmStvHhynsUWx+Qy7RhF+wqTejzALF1Of7j368Okba40BmWIQF7LQxfECvc3bbptj+gXGze/dgAjrtEoV6w1gQ0S/2PU2h0RQX7ELkW+6CIkKYcIe/HKEXfJZluMFdCR11ebnqnNZ/NnRcbw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=sourceware.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none Received: from MWHPR11CA0024.namprd11.prod.outlook.com (2603:10b6:301:1::34) by MWHPR1201MB2495.namprd12.prod.outlook.com (2603:10b6:300:df::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.10; Fri, 5 Nov 2021 11:39:29 +0000 Received: from CO1NAM11FT043.eop-nam11.prod.protection.outlook.com (2603:10b6:301:1:cafe::d7) by MWHPR11CA0024.outlook.office365.com (2603:10b6:301:1::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.10 via Frontend Transport; Fri, 5 Nov 2021 11:39:29 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; sourceware.org; dkim=none (message not signed) header.d=none;sourceware.org; dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT043.mail.protection.outlook.com (10.13.174.193) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4669.10 via Frontend Transport; Fri, 5 Nov 2021 11:39:28 +0000 Received: from localhost.localdomain (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.15; Fri, 5 Nov 2021 06:39:26 -0500 From: Zoran Zaric To: Subject: [PATCH v4 23/28] Add support for any location description in CFI Date: Fri, 5 Nov 2021 11:38:44 +0000 Message-ID: <20211105113849.118800-24-zoran.zaric@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211105113849.118800-1-zoran.zaric@amd.com> References: <20211105113849.118800-1-zoran.zaric@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e3a287bb-4090-4466-48c0-08d9a050ed69 X-MS-TrafficTypeDiagnostic: MWHPR1201MB2495: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6108; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: PpcJWhmkDXYlMn0THbzAYanhQkYy2zMB4N8B1ZALx7CFXM1mibah+iSiw8DPKrw2zEpxAG22CgwKUD50VSxGjMG+LXJj5lF/HcsyYxIgciy1KBuU9QA0fXpxKkn9d4hLEYPVwS77wkc4zXqbEiqmJ5tQSBTQ/q18ZXX4hcywT0EI/F9Vtbud625VcK0swI63no9BPmX2KInO9pm1gnBth+dDmCCF9YUiV4ds987OVkY8wgza8SUYlz0Tm73tpHrDpukUDjIhhaTxcaHw4oOoVcfXGpGZQOokSFpl3bS8EUd2ZZoL/bM8J1LwLr3yEGNXZFbnHRcHaxoj8hxiEcieX40Ht79SFEGZnyAX5nJPouMd7tgz7o6PtqdJ75gd64nXz/lQ2jqL2O1Ytjtd9nryLVS0i7hVWKYAEw2L/MAfs2SF09qFTjEXufJbIFirjpoO7Ieg7lrhc/lsVrFghRVLHwBHO2t/Co6Y4eUIbTfBt/ApVl2PeX/BNHyXrKOwYmrn7XuLe4LhAU0mNhZ+abNdIxqxs9k8vg0LSEP8k326nufk+9uZNPRoqRomMpWwl3Kk2rvwMvd6IoW4FHuGUs2UEdqrf10L32QPwp9p4zv7w64nQbBgUeRaq5nMoM6Kn30k2oSnfnHhvxTvpiILE0JigmtuA1rWlDXWYf2XvDBjAJj4u3JM8DJPwF7R7OHWd61z1qZRfYA+0GgC5osQFP8woVN1tkQys84odhc5dDAtzxs= X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(4636009)(36840700001)(46966006)(336012)(508600001)(316002)(2906002)(2616005)(4326008)(426003)(86362001)(16526019)(47076005)(26005)(186003)(36860700001)(70206006)(1076003)(5660300002)(83380400001)(6666004)(356005)(82310400003)(6916009)(44832011)(8936002)(8676002)(70586007)(81166007)(36756003)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Nov 2021 11:39:28.8904 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e3a287bb-4090-4466-48c0-08d9a050ed69 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT043.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR1201MB2495 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, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP 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-List-Received-Date: Fri, 05 Nov 2021 11:39:33 -0000 From: Zoran Zaric One of the main benefits of allowing location description to be on the DWARF stack is that now CFI expression based register rules can be defined using a location description operations. This allows a register of one frame to be saved in any location, including any composite location. To fully support this feature, the execute_stack_op function in dwarf2/frame.c needs to return a single struct value object instead of just an address. Function put_frame_register_bytes also needs to change to support any location description. This support is a one of the key features to truly support optimized code. gdb/ChangeLog: * dwarf2/frame.c (execute_stack_op): Change to return a struct value object. (dwarf2_frame_cache): Change to call new execute_stack_op definition. (dwarf2_frame_prev_register): Change to call new execute_stack_op definition. * frame.c (put_frame_register_bytes): Add support for writing to composite location description. --- gdb/dwarf2/frame.c | 54 ++++++++++++++++++++++++++-------------------- gdb/frame.c | 31 ++++++++++++++++++++++---- 2 files changed, 58 insertions(+), 27 deletions(-) diff --git a/gdb/dwarf2/frame.c b/gdb/dwarf2/frame.c index e17b36e243b..e70dcd5a86e 100644 --- a/gdb/dwarf2/frame.c +++ b/gdb/dwarf2/frame.c @@ -236,16 +236,17 @@ register %s (#%d) at %s"), } } -static CORE_ADDR +static value * execute_stack_op (const gdb_byte *exp, ULONGEST len, int addr_size, struct frame_info *this_frame, CORE_ADDR initial, - int initial_in_stack_memory, dwarf2_per_objfile *per_objfile) + int initial_in_stack_memory, dwarf2_per_objfile *per_objfile, + struct type* type = nullptr, bool as_lval = true) { scoped_value_mark free_values; - struct type *type = address_type (per_objfile->objfile->arch (), - addr_size); + struct type *init_type = address_type (per_objfile->objfile->arch (), + addr_size); - value *init_value = value_at_lazy (type, initial); + value *init_value = value_at_lazy (init_type, initial); std::vector init_values; set_value_stack (init_value, initial_in_stack_memory); @@ -255,10 +256,15 @@ execute_stack_op (const gdb_byte *exp, ULONGEST len, int addr_size, = dwarf2_evaluate (exp, len, true, per_objfile, nullptr, this_frame, addr_size, &init_values, nullptr); - if (VALUE_LVAL (result_val) == lval_memory) - return value_address (result_val); - else - return value_as_address (result_val); + /* We need to clean up all the values that are not needed any more. + The problem with a value_ref_ptr class is that it disconnects the + RETVAL from the value garbage collection, so we need to make + a copy of that value on the stack to keep everything consistent. + The value_ref_ptr will clean up after itself at the end of this block. */ + value_ref_ptr value_holder = value_ref_ptr::new_reference (result_val); + free_values.free_to_mark (); + + return value_copy (result_val); } @@ -989,10 +995,14 @@ dwarf2_frame_cache (struct frame_info *this_frame, void **this_cache) break; case CFA_EXP: - cache->cfa = - execute_stack_op (fs.regs.cfa_exp, fs.regs.cfa_exp_len, - cache->addr_size, this_frame, 0, 0, - cache->per_objfile); + { + struct value *value + = execute_stack_op (fs.regs.cfa_exp, fs.regs.cfa_exp_len, + cache->addr_size, this_frame, 0, 0, + cache->per_objfile); + cache->cfa = value_address (value); + } + break; default: @@ -1190,24 +1200,22 @@ dwarf2_frame_prev_register (struct frame_info *this_frame, void **this_cache, return frame_unwind_got_register (this_frame, regnum, realnum); case DWARF2_FRAME_REG_SAVED_EXP: - addr = execute_stack_op (cache->reg[regnum].loc.exp.start, + return execute_stack_op (cache->reg[regnum].loc.exp.start, cache->reg[regnum].loc.exp.len, - cache->addr_size, - this_frame, cache->cfa, 1, - cache->per_objfile); - return frame_unwind_got_memory (this_frame, regnum, addr); + cache->addr_size, this_frame, + cache->cfa, 1, cache->per_objfile, + register_type (gdbarch, regnum)); case DWARF2_FRAME_REG_SAVED_VAL_OFFSET: addr = cache->cfa + cache->reg[regnum].loc.offset; return frame_unwind_got_constant (this_frame, regnum, addr); case DWARF2_FRAME_REG_SAVED_VAL_EXP: - addr = execute_stack_op (cache->reg[regnum].loc.exp.start, + return execute_stack_op (cache->reg[regnum].loc.exp.start, cache->reg[regnum].loc.exp.len, - cache->addr_size, - this_frame, cache->cfa, 1, - cache->per_objfile); - return frame_unwind_got_constant (this_frame, regnum, addr); + cache->addr_size, this_frame, + cache->cfa, 1, cache->per_objfile, + register_type (gdbarch, regnum), false); case DWARF2_FRAME_REG_UNSPECIFIED: /* GCC, in its infinite wisdom decided to not provide unwind diff --git a/gdb/frame.c b/gdb/frame.c index 2a899fc494f..3dd6c799847 100644 --- a/gdb/frame.c +++ b/gdb/frame.c @@ -1534,19 +1534,42 @@ put_frame_register_bytes (struct frame_info *frame, int regnum, { int curr_len = register_size (gdbarch, regnum) - offset; + struct value *value = frame_unwind_register_value (frame->next, + regnum); + if (curr_len > len) curr_len = len; const gdb_byte *myaddr = buffer.data (); - if (curr_len == register_size (gdbarch, regnum)) + + /* Computed value is a special case. The computed callback + mechanism requires a strut value argument, so we need to + make one. */ + if (value != nullptr && VALUE_LVAL (value) == lval_computed) + { + const lval_funcs *funcs = value_computed_funcs (value); + + if (funcs->write == nullptr) + error (_("Attempt to assign to an unmodifiable value.")); + + type * reg_type = register_type (gdbarch, regnum); + + struct value *from_value = allocate_value (reg_type); + memcpy (value_contents_raw (from_value), myaddr, + TYPE_LENGTH (reg_type)); + + set_value_offset (value, offset); + + funcs->write (value, from_value); + release_value (from_value); + } + else if (curr_len == register_size (gdbarch, regnum)) { put_frame_register (frame, regnum, myaddr); } else { - struct value *value = frame_unwind_register_value (frame->next, - regnum); - gdb_assert (value != NULL); + gdb_assert (value != nullptr); memcpy ((char *) value_contents_writeable (value).data () + offset, myaddr, curr_len); -- 2.17.1