From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2057.outbound.protection.outlook.com [40.107.220.57]) by sourceware.org (Postfix) with ESMTPS id 5EAE13857C53 for ; Fri, 5 Nov 2021 11:39:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5EAE13857C53 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=B1KN0CUb5+jdasww2ARGoAtmiFlRf5lJLIQkl7ZAQ31aylkjz/dC4cefzW0C6xnmiboQs4C/XimaOD4NnqbppLW9TYWE2YemIDCJQhpvpMnWjJ0tFUB2R5i8xP0P+nUiyYIy/Ph5to50Uv1NoeCrKKHheiNVMbP21PUpMOnkXPPRm/e1jhHfDwREVGcVoJCbU046pV/iKUiehGCsdcMBombxCT/Lg7K6ZGoOzFoFbn9y2+7sJ6eZDM7D1TLc+DaEV58slOTWVAqkOHx4F8CO0IfqqaZdiGjlO52kkBoANvr0JfqDOjvxWWItDwNrKxxFP685Cy44EZu/7ndpwZJ4mw== 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=ZcyW1eLdf4nhy19aG9P/p4sps2i4+WdWy0eEkGFltSw=; b=HCkuURnAg+uRpJoJsKLb7yE5Yv9kQOGSabSk6jXTggQiyI1r3NfB4LO4LoYW8NDi9VLCy2ywo6zwvyBQVvZ3JfNFeeYuzEzqTAet2zZrQWz3qca1p/7haVwRzo/ZTsTT2C2ZZUyNoSVVAQVfehBfx1yYN9fe7caitrlVfA7/8nYo2wTVKCxnaUrBUdN/zbBb38bnSjv61NoGF4Ce0VY1XZne4eKH6MaBNLj1KY+7ejA/4NrNlo0Sz46s1OKJ7P93S+/XEJPjOrdQl1+gbikkB/sUi48PnofmXGL3zQjom580mT0MYnT6380YFnqp5kOhulnJfUvYrV8ohkS4Io6sQw== 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 MW4PR04CA0178.namprd04.prod.outlook.com (2603:10b6:303:85::33) by DM5PR12MB1516.namprd12.prod.outlook.com (2603:10b6:4:5::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4649.18; Fri, 5 Nov 2021 11:39:13 +0000 Received: from CO1NAM11FT047.eop-nam11.prod.protection.outlook.com (2603:10b6:303:85:cafe::e6) by MW4PR04CA0178.outlook.office365.com (2603:10b6:303:85::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.13 via Frontend Transport; Fri, 5 Nov 2021 11:39:13 +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 CO1NAM11FT047.mail.protection.outlook.com (10.13.174.132) 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:12 +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:08 -0500 From: Zoran Zaric To: Subject: [PATCH v4 04/28] Add to_location method to dwarf_value class Date: Fri, 5 Nov 2021 11:38:25 +0000 Message-ID: <20211105113849.118800-5-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: d09d434f-ba86-42ec-d61e-08d9a050e3e1 X-MS-TrafficTypeDiagnostic: DM5PR12MB1516: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0Qa6dpGPaW8OXu68FachZ2w163NiVpJvi63hY1aNAJmJPArZ0fmDGn53ZaQNZ1Odf/LJhgG1mb/4weu6YdbJ5mO7sXs+M4u5jr4ZbgoMBqZK7sEa0LOJy8srVIwFOV29Qm56jch+e7NoNmT4kP3bUZACYYVP60AFnlSXAMB4VnpFmRpaq406i1TdHfKlyC7A455XGLAYOQJB86WQ9vUJfan54ja/l0wIbYw+LVeh+iVQTFPEzSyr5H0hBO38iEhK2lGolfUYV0fiyTSTtURIXJli4zqiBzqDvaTIU/qmmVKtTkm7I893lTvdGOIVeelYMlHGpv824KiiEcyfokNVJyAiwPaMGqa34H/mSa4Fubm3qNkAkpFx7IK9IMuRljNpT8jC99RuD/8l2LL7YQalK1smvT230iiFog9nUPEwmOG2OZ4yF0TcLMcwi3J5HW9PKXWCSaX714lx3Y3LDxntVS9wyRK/7s3DaBUgMCDgaowaaucrVKM3cdHNS0cWPojHWCyIl6K8Sh4dYy32oqErDl9Hm6xxT7EMq0dY1uUStaevL52tzTNDPe5JwRlFnX4vfV2NUTnjWSj0a1H98JaeAf7pfBukK2Q4BKEhpaFqWbpNq2PuudjSX74OCBIH5QfCccInSPexBisO75qeXznIzVPisKzl3mXiRQwYYAIyEd3Hhy7e/6h3FjqEWCgHBhH6f+ShrB3C+azFPYjcDa+Xe3lBAyVWKJ6fvmKUkbGXkz0= 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)(2906002)(47076005)(70206006)(316002)(508600001)(4326008)(426003)(8936002)(86362001)(26005)(70586007)(83380400001)(1076003)(81166007)(8676002)(5660300002)(82310400003)(6666004)(336012)(36756003)(36860700001)(6916009)(186003)(2616005)(44832011)(356005)(16526019)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Nov 2021 11:39:12.8993 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d09d434f-ba86-42ec-d61e-08d9a050e3e1 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: CO1NAM11FT047.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1516 X-Spam-Status: No, score=-12.3 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:18 -0000 From: Zoran Zaric DWARF standard already contains an implicit conversion between location description and a DWARF value. In the DWARF 5 version, one place where this can happen is at the very end of the evaluation where a client decides if the result is expected to be in a form of a value or a location description (as_lval argument of the new evaluation method). By allowing any location description to be on the DWARF stack, these implicit conversions are expected on per operation basis which means that the new dwarf_value class need to have a support for it. This patch adds a conversion method from a dwarf_value object into a location description object. To support the conversion method we also need an implementation of the C++14 standard library function make_unique which was copied from the standard library implementation. gdb/ChangeLog: * dwarf2/expr.c (class dwarf_value::to_location): New method. gdbsupport/ChangeLog: * common-utils.h (make_unique): New function. --- gdb/dwarf2/expr.c | 25 +++++++++++++++++++++++++ gdbsupport/common-utils.h | 18 ++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/gdb/dwarf2/expr.c b/gdb/dwarf2/expr.c index 6363bcc4707..2cb93706ac4 100644 --- a/gdb/dwarf2/expr.c +++ b/gdb/dwarf2/expr.c @@ -271,6 +271,8 @@ write_to_memory (CORE_ADDR address, const gdb_byte *buffer, length, buffer); } +class dwarf_location; + /* Base class that describes entries found on a DWARF expression evaluation stack. */ @@ -284,6 +286,8 @@ class dwarf_entry virtual ~dwarf_entry () = default; }; +using dwarf_entry_up = std::unique_ptr; + /* Location description entry found on a DWARF expression evaluation stack. @@ -332,6 +336,8 @@ class dwarf_location : public dwarf_entry bool m_initialised = true; }; +using dwarf_location_up = std::unique_ptr; + /* Value entry found on a DWARF expression evaluation stack. */ class dwarf_value final : public dwarf_entry @@ -373,6 +379,10 @@ class dwarf_value final : public dwarf_entry return unpack_long (m_type, m_contents.data ()); } + /* Convert DWARF value into a DWARF memory location description. + ARCH defines an architecture of the location described. */ + dwarf_location_up to_location (struct gdbarch *arch) const; + private: /* Value contents as a stream of bytes in target byte order. */ gdb::byte_vector m_contents; @@ -410,6 +420,21 @@ class dwarf_memory final : public dwarf_location bool m_stack; }; +dwarf_location_up +dwarf_value::to_location (struct gdbarch *arch) const +{ + LONGEST offset; + + if (gdbarch_integer_to_address_p (arch)) + offset = gdbarch_integer_to_address (arch, m_type, m_contents.data ()); + else + offset = extract_unsigned_integer (m_contents.data (), + TYPE_LENGTH (m_type), + type_byte_order (m_type)); + + return make_unique (arch, offset); +} + /* Register location description entry. */ class dwarf_register final : public dwarf_location diff --git a/gdbsupport/common-utils.h b/gdbsupport/common-utils.h index 224e1f31222..be1b805f7c8 100644 --- a/gdbsupport/common-utils.h +++ b/gdbsupport/common-utils.h @@ -206,4 +206,22 @@ extern int hex2bin (const char *hex, gdb_byte *bin, int count); /* Like the above, but return a gdb::byte_vector. */ gdb::byte_vector hex2bin (const char *hex); +#if __cplusplus >= 201402L +#include + +using std::make_unique; +#else +namespace gdb { + +/* Stolen from libstdc++ and adjusted, so probably fine license-wise. */ +template +std::unique_ptr<_Tp> +make_unique (_Args &&... __args) +{ + return std::unique_ptr<_Tp> (new _Tp (std::forward<_Args>(__args)...)); +} + +} +#endif /* __cplusplus >= 201402L */ + #endif /* COMMON_COMMON_UTILS_H */ -- 2.17.1