From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id AQoEBkTwVGoyPAYAWB0awg (envelope-from ) for ; Mon, 13 Jul 2026 10:03:48 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=wMgGy9hn; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 132BA1E09B; Mon, 13 Jul 2026 10:03:48 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-6.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 56A861E033 for ; Mon, 13 Jul 2026 10:03:46 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EC5824BA2E32 for ; Mon, 13 Jul 2026 14:03:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EC5824BA2E32 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=wMgGy9hn Received: from CH5PR02CU005.outbound.protection.outlook.com (mail-northcentralusazon11012071.outbound.protection.outlook.com [40.107.200.71]) by sourceware.org (Postfix) with ESMTPS id B79EB4BA2E2C for ; Mon, 13 Jul 2026 14:01:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B79EB4BA2E2C Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=amd.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B79EB4BA2E2C Authentication-Results: sourceware.org; arc=pass smtp.remote-ip=40.107.200.71 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1783951265; cv=pass; b=LJT4hM7MUtLYKaxFSkPAD4u+6SXanvKk9U7YgSI+CCAjsEY3R8Hgqz6j07/zt1Mw9RokuEULrvJvhKmNqA3ub1Nj4W4O1KahrOYoixhNvpNb9Pe4F5jB47mNi/m3uHKb3gCdqNkWSnX0SWc/uqQVlKmEjJV/ccWVRP56YLizfUU= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1783951265; c=relaxed/simple; bh=8MVNQlcdfWIdFpsGysEtlP5rBeQ+7XaZNB3PBSFOlLQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=qjidOZGnMk5iizgVwJcP75VzdPZCvrGDr8DkxIg+IPdo1Ap2whuscQ3BHF5mPWRUGn4jHQn1im8ArHE6TCcoPha/EPXvzm0Ql1T+OGaXQ7aqTQHOhjWfUAKqH9fMP0LB6McQ3DGqaQmYGeFAFkU4UEjhfZMqPZfPMjK6vV6uQcs= ARC-Authentication-Results: i=2; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=wMgGy9hn DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B79EB4BA2E2C ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=WYdjkwK9V/KWwgJ0+iinq5ghsK0wI7dI6AL7jow2BiCRP4ioKZNYs8tZlUhAhy7C4erNVfcn/wfV/tl1MjAgCOUhBa0rDUaAjC6J0vsVfMaBcA8iHy1WP7jzm21xzLDEZYrmSJp3aMk9lRCVicRVtYQTpbsQy0YjsZjGcREmk9u+3Lfu+kVlkPaZK2EPL1QCvqmCfE3Hwbl5bknVH0lGmuPrpPRjb3Nb1vlxudcOI4J0enyofvo41DvMAGsQ+KDVuEatRX7dtdBjNSAeHzu2aznh6p++wMawmes6aBumCnMDGFLJQQX5+UKITZHJvw01o/tSvnhHSrEph4OpePbkMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=Q7x2CLddLcqJO4qicS1/tm24scspMPFxgblNUk+CllE=; b=DY+9NaaKg5uFTK29qCTOz9WBrUWNZeiZxGgCq7Rv1VTSQeFdjVdxKJh+OZnGo6cCF9reXKXEt6GJSO4a0QlBhtsNm19elD1JxEP6Gd7XaQS3nRUelVCAnXANKKgVFQPGghsPF3fxSdfovqR9TCgYrfE75AbtSwgkeVwZOpmEZxfXygdtBFcziLMN7683B7RhOuD56IEIiGQ+lkjVtSKFp8P0uWE4Gz+DlMiAk1B6n8koGi2jaqS4EoOR/9eVku5Yc6nR6K+j7c5VSQoGAd/8CNCbpPKQP0ISMgwkkbaAe97eRRTioqmo1qT2W26IjiOc8UB0Q6gvYRSurZ1Tqse3SQ== 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 (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Q7x2CLddLcqJO4qicS1/tm24scspMPFxgblNUk+CllE=; b=wMgGy9hnir72/Kifjhqcmi6Ey0Ckk/gMnjGxtzQ9aonCswPhBxLN551uiSIj/iHr9zlzT20SgIu2C63Slyv8d9Wr8GW6ki7y474Kmcbz654wo9yq8IUOGCJa1aJteIFi5dns3AJbtQj1SJVgNZP39WTFvhFwgcoD9iVkVwRFtwA= Received: from CH5PR04CA0022.namprd04.prod.outlook.com (2603:10b6:610:1f4::19) by PH7PR12MB5997.namprd12.prod.outlook.com (2603:10b6:510:1d9::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.202.18; Mon, 13 Jul 2026 14:00:51 +0000 Received: from CH1PEPF0000AD7E.namprd04.prod.outlook.com (2603:10b6:610:1f4:cafe::35) by CH5PR04CA0022.outlook.office365.com (2603:10b6:610:1f4::19) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.202.19 via Frontend Transport; Mon, 13 Jul 2026 14:00:49 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;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=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by CH1PEPF0000AD7E.mail.protection.outlook.com (10.167.244.87) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.223.9 via Frontend Transport; Mon, 13 Jul 2026 14:00:49 +0000 Received: from ctr-rack32-mi300x-1.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.41; Mon, 13 Jul 2026 09:00:41 -0500 From: Tankut Baris Aktemur To: Subject: [PATCH 07/16] gdb: convert type instance flags to bitfields Date: Mon, 13 Jul 2026 09:00:06 -0500 Message-ID: <20260713-users-aktemur-type-instance-flags-v1-7-779cad0c85ec@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260713-users-aktemur-type-instance-flags-v1-0-779cad0c85ec@amd.com> References: <20260713-users-aktemur-type-instance-flags-v1-0-779cad0c85ec@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" X-Mailer: b4 0.15.0 Content-Transfer-Encoding: 8bit X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH1PEPF0000AD7E:EE_|PH7PR12MB5997:EE_ X-MS-Office365-Filtering-Correlation-Id: 60a84d85-9ea5-41b8-e4f4-08dee0e724e0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|36860700016|82310400026|23010399003|376014|3023799007|6133799003|21046099003|18002099003|22082099003|56012099006|11063799006; X-Microsoft-Antispam-Message-Info: Ve1TihFR4UbFqH1ZVCBLJuPNQAbRVyx+SqcZrAEtCTDfBE83JctATsrGdeX0IDC49uGS+Hqao83RRxnIPO1XGJKPqUoDUta3pEDlpWi6aqrVE0ve5IQ/QV73I9aXclPNZ1RM1f1cxIHm7FDHZD2WOvs22HTetRfm8OKrauO7sXw2WzWTZy2SGUMy7ZxnxS51So6sAGQD0FEkhCjxYinQfKLm5skqtjn+ELka8HAxIxEy1/1REEmETXwKgogJbpmIlpb41/GhYmot/okkaVDTrzFfQ1rClug9Db2eYWYjsZEZABi+mj+aBKwv62TFkRavHMfco0HN+pXOXx/sjwK0lrIBxhVK0Qp1lwvnuosBNkOqLpbwOQx+6p5qT3gjz3/xZc24B28Iq1bCYWyqhXv7U2Q3vsNGTqFEm/k2lM5T/7KHfvsRFGPXJ1EXLRIIBWeq8ZGXWg5jNKn6+m/7ngr6dz+WEyx3Fcs5pojgYmGHXFOc4eWbw6WONJ7MSyaO4HjNpMq0EXwodprD2audDEjMS8d3UUHkzMy5i9muWVfh2EeI1MvbZYsqqeclnhY7TY6Yj48MEFGbtIX0iQT+2BTj58s8fvtm7LsqOfsUKXnMDprOESqoDGhElYG1JAQ1BO+il4gXBsv06bYGJqbhj9DMyntYak6m5h2DN+w5PT/3t+ZjOSRc5OGyawp4p34BB2adDU04iXJ2rNZFfJadNfHOKA== X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:satlexmb07.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230040)(1800799024)(36860700016)(82310400026)(23010399003)(376014)(3023799007)(6133799003)(21046099003)(18002099003)(22082099003)(56012099006)(11063799006); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 9X/XoKFf2VpiHOeAba+m1DU9Jn+u9ivhMXryt6GvWkMcPExu2qBZIpGPTh7Dj3OfpodZFFtbMCOmQe2dNfVnPrqm5xCGB1CbuoQP1mOz11XgkkWiNIdDao2haIJ+4U6AwRrTWzjvTzuXmtAGArIYXMnyTkm8+EhRxbMaxmY4VR8emxb/oivO4O2xpCmCiwkQsvyNS4oyLQmWWjEpHnSMdaB1TYl2c+y6gBKg6H2fns1tFqHQEndrTQ7rbKOE41AIcdkWgSIiIe0GUXB71RI8qnIgroCVAhOZRGQZahotV1QY5SCDXH6aBTnYPhzJEv1CAlthL35CLNzz9y3N+OZnSSVR7qIeDG7INSPCUZ6ehuK7IFMYGlW7WeN9fILdqpD7Qa+c91Nq3jZTO5tY8NP1ZJdx9Ema8T6desNrqsRvPVuc3LVe41U1ZTR4oM2MXsjF X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jul 2026 14:00:49.3415 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 60a84d85-9ea5-41b8-e4f4-08dee0e724e0 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=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CH1PEPF0000AD7E.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB5997 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org Convert the instance flags of a type to a struct with bitfields. This helps avoid bitwise operations and instead refer to the fields by name. In particular, Harvard address space information (i.e. code space and data space) and address class information become enum values instead of being handled by seemingly independent bits. --- gdb/d-lang.c | 9 +- gdb/expop.h | 6 ++ gdb/expprint.c | 4 +- gdb/ft32-tdep.c | 5 +- gdb/gdb-gdb.py.in | 99 +++++------------- gdb/gdbtypes.c | 105 +++++++------------ gdb/gdbtypes.h | 173 ++++++++++++++++++-------------- gdb/printcmd.c | 17 ++-- gdb/testsuite/gdb.base/maint.exp | 2 +- gdb/testsuite/gdb.gdb/python-helper.exp | 8 +- gdb/type-stack.c | 10 +- 11 files changed, 190 insertions(+), 248 deletions(-) diff --git a/gdb/d-lang.c b/gdb/d-lang.c index 0a779a7b7c0..c2a11375830 100644 --- a/gdb/d-lang.c +++ b/gdb/d-lang.c @@ -233,13 +233,8 @@ build_d_types (struct gdbarch *gdbarch) = init_float_type (alloc, gdbarch_long_double_bit (gdbarch), "real", gdbarch_long_double_format (gdbarch)); - builtin_d_type->builtin_byte->set_instance_flags - (builtin_d_type->builtin_byte->instance_flags () - | TYPE_INSTANCE_FLAG_NOTTEXT); - - builtin_d_type->builtin_ubyte->set_instance_flags - (builtin_d_type->builtin_ubyte->instance_flags () - | TYPE_INSTANCE_FLAG_NOTTEXT); + builtin_d_type->builtin_byte->set_nottext (true); + builtin_d_type->builtin_ubyte->set_nottext (true); /* Imaginary and complex types. */ builtin_d_type->builtin_ifloat diff --git a/gdb/expop.h b/gdb/expop.h index 6d6f4acdc24..ce175afbc3d 100644 --- a/gdb/expop.h +++ b/gdb/expop.h @@ -275,6 +275,12 @@ check_objfile (enum_flags val, struct objfile *objfile) return false; } +static inline bool +check_objfile (type_instance_flags val, struct objfile *objfile) +{ + return false; +} + template static inline bool check_objfile (const std::vector &collection, struct objfile *objfile) diff --git a/gdb/expprint.c b/gdb/expprint.c index e99430d2325..bc1929b1a1b 100644 --- a/gdb/expprint.c +++ b/gdb/expprint.c @@ -148,9 +148,9 @@ dump_for_expression (struct ui_file *stream, int depth, type_instance_flags flags) { gdb_printf (stream, _("%*sType flags: "), depth, ""); - if (flags & TYPE_INSTANCE_FLAG_CONST) + if (flags.is_const) gdb_puts ("const ", stream); - if (flags & TYPE_INSTANCE_FLAG_VOLATILE) + if (flags.is_volatile) gdb_puts ("volatile", stream); gdb_printf (stream, "\n"); } diff --git a/gdb/ft32-tdep.c b/gdb/ft32-tdep.c index 476e79355c7..f951a6f25e3 100644 --- a/gdb/ft32-tdep.c +++ b/gdb/ft32-tdep.c @@ -332,7 +332,7 @@ ft32_pointer_to_address (struct gdbarch *gdbarch, CORE_ADDR addr = extract_unsigned_integer (buf, type->length (), byte_order); - if (TYPE_ADDRESS_CLASS_1 (type)) + if (TYPE_ADDRESS_CLASS (type) == 1) return addr; else return addr | RAM_BIAS; @@ -579,8 +579,7 @@ ft32_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) func_void_type = lookup_function_type (void_type); tdep->pc_type = init_pointer_type (alloc, 4 * TARGET_CHAR_BIT, NULL, func_void_type); - tdep->pc_type->set_instance_flags (tdep->pc_type->instance_flags () - | TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1); + tdep->pc_type->set_address_class (1); set_gdbarch_num_regs (gdbarch, FT32_NUM_REGS); set_gdbarch_sp_regnum (gdbarch, FT32_SP_REGNUM); diff --git a/gdb/gdb-gdb.py.in b/gdb/gdb-gdb.py.in index 417b6492db5..7e39d27366e 100644 --- a/gdb/gdb-gdb.py.in +++ b/gdb/gdb-gdb.py.in @@ -20,86 +20,32 @@ import os.path import gdb -class TypeFlag: - """A class that allows us to store a flag name, its short name, - and its value. - - In the GDB sources, struct type has a component called instance_flags - in which the value is the addition of various flags. These flags are - defined by the enumerates type_instance_flag_value. This class helps us - recreate a list with all these flags that is easy to manipulate and sort. - Because all flag names start with TYPE_INSTANCE_FLAG_, a short_name - attribute is provided that strips this prefix. - - ATTRIBUTES - name: The enumeration name (eg: "TYPE_INSTANCE_FLAG_CONST"). - value: The associated value. - short_name: The enumeration name, with the suffix stripped. - """ - - def __init__(self, name, value): - self.name = name - self.value = value - self.short_name = name.replace("TYPE_INSTANCE_FLAG_", "") - - def __lt__(self, other): - """Sort by value order.""" - return self.value < other.value - - -# A list of all existing TYPE_INSTANCE_FLAGS_* enumerations, -# stored as TypeFlags objects. Lazy-initialized. -TYPE_FLAGS = None - - -class TypeFlagsPrinter: - """A class that prints a decoded form of an instance_flags value. - - This class uses a global named TYPE_FLAGS, which is a list of - all defined TypeFlag values. Using a global allows us to compute - this list only once. - - This class relies on a couple of enumeration types being defined. - If not, then printing of the instance_flag is going to be degraded, - but it's not a fatal error. - """ +class StructTypeInstanceFlagsPrettyPrinter: + """Pretty-print an object of type struct type_instance_flags""" def __init__(self, val): self.val = val def __str__(self): - global TYPE_FLAGS - if TYPE_FLAGS is None: - self.init_TYPE_FLAGS() - if not self.val: - return "0" - if TYPE_FLAGS: - flag_list = [ - flag.short_name for flag in TYPE_FLAGS if self.val & flag.value - ] - else: - flag_list = ["???"] - return "0x%x [%s]" % (self.val, "|".join(flag_list)) - - def init_TYPE_FLAGS(self): - """Initialize the TYPE_FLAGS global as a list of TypeFlag objects. - This operation requires the search of a couple of enumeration types. - If not found, a warning is printed on stdout, and TYPE_FLAGS is - set to the empty list. - - The resulting list is sorted by increasing value, to facilitate - printing of the list of flags used in an instance_flags value. - """ - global TYPE_FLAGS - TYPE_FLAGS = [] - try: - iflags = gdb.lookup_type("enum type_instance_flag_value") - except: - print("Warning: Cannot find enum type_instance_flag_value type.") - print(" `struct type' pretty-printer will be degraded") - return - TYPE_FLAGS = [TypeFlag(field.name, field.enumval) for field in iflags.fields()] - TYPE_FLAGS.sort() + fields = [] + if self.val["is_const"]: + fields.append("CONST") + if self.val["is_volatile"]: + fields.append("VOLATILE") + if self.val["harvard_aspace"] == 1: # HARVARD_ASPACE_CODE + fields.append("CODE_SPACE") + elif self.val["harvard_aspace"] == 2: # HARVARD_ASPACE_DATA + fields.append("DATA_SPACE") + if self.val["address_class"] != 0: + fields.append("ADDRESS_CLASS(%d)" % self.val["address_class"]) + if self.val["is_nottext"]: + fields.append("NOTTEXT") + if self.val["is_restrict"]: + fields.append("RESTRICT") + if self.val["is_atomic"]: + fields.append("ATOMIC") + + return "[" + "|".join(fields) + "]" class StructTypePrettyPrinter: @@ -114,7 +60,8 @@ class StructTypePrettyPrinter: fields.append("reference_type = %s" % self.val["reference_type"]) fields.append("chain = %s" % self.val["reference_type"]) fields.append( - "instance_flags = %s" % TypeFlagsPrinter(self.val["m_instance_flags"]) + "instance_flags = %s" + % StructTypeInstanceFlagsPrettyPrinter(self.val["m_instance_flags"]) ) fields.append("length = %d" % self.val["m_length"]) fields.append("main_type = %s" % self.val["main_type"]) diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index 205a79dfbc1..958a2ff9f29 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -603,14 +603,11 @@ struct type * make_type_with_harvard_address_space (struct type *type, enum harvard_address_space aspace) { - type_instance_flags new_flags - = (enum type_instance_flag_value) (aspace << 2); - - gdb_assert ((new_flags & ~(TYPE_INSTANCE_FLAG_CODE_SPACE - | TYPE_INSTANCE_FLAG_DATA_SPACE)) == 0); - new_flags |= (type->instance_flags () - & ~(TYPE_INSTANCE_FLAG_CODE_SPACE - | TYPE_INSTANCE_FLAG_DATA_SPACE)); + gdb_assert (aspace == HARVARD_ASPACE_NONE + || aspace == HARVARD_ASPACE_CODE + || aspace == HARVARD_ASPACE_DATA); + type_instance_flags new_flags = type->instance_flags (); + new_flags.harvard_aspace = aspace; return make_qualified_type (type, new_flags, NULL); } @@ -625,13 +622,9 @@ struct type * make_type_with_address_class (struct type *type, unsigned int address_class) { - type_instance_flags new_flags - = (enum type_instance_flag_value) (address_class << 4); - - gdb_assert ((new_flags & ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL) == 0); - - new_flags |= (type->instance_flags () - & ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL); + gdb_assert (address_class < 4); /* We use two bits for this field. */ + type_instance_flags new_flags = type->instance_flags (); + new_flags.address_class = address_class; return make_qualified_type (type, new_flags, NULL); } @@ -641,15 +634,9 @@ make_type_with_address_class (struct type *type, type * make_cv_type (int cnst, int voltl, type *type) { - type_instance_flags new_flags = (type->instance_flags () - & ~(TYPE_INSTANCE_FLAG_CONST - | TYPE_INSTANCE_FLAG_VOLATILE)); - - if (cnst) - new_flags |= TYPE_INSTANCE_FLAG_CONST; - - if (voltl) - new_flags |= TYPE_INSTANCE_FLAG_VOLATILE; + type_instance_flags new_flags = type->instance_flags (); + new_flags.is_const = cnst; + new_flags.is_volatile = voltl; return make_qualified_type (type, new_flags, nullptr); } @@ -659,10 +646,10 @@ make_cv_type (int cnst, int voltl, type *type) struct type * make_restrict_type (struct type *type) { - return make_qualified_type (type, - (type->instance_flags () - | TYPE_INSTANCE_FLAG_RESTRICT), - NULL); + type_instance_flags new_flags = type->instance_flags (); + new_flags.is_restrict = true; + + return make_qualified_type (type, new_flags, nullptr); } /* Make a type without const, volatile, or restrict. */ @@ -670,12 +657,12 @@ make_restrict_type (struct type *type) struct type * make_unqualified_type (struct type *type) { - return make_qualified_type (type, - (type->instance_flags () - & ~(TYPE_INSTANCE_FLAG_CONST - | TYPE_INSTANCE_FLAG_VOLATILE - | TYPE_INSTANCE_FLAG_RESTRICT)), - NULL); + type_instance_flags new_flags = type->instance_flags (); + new_flags.is_const = false; + new_flags.is_volatile = false; + new_flags.is_restrict = false; + + return make_qualified_type (type, new_flags, nullptr); } /* Make a '_Atomic'-qualified version of TYPE. */ @@ -683,10 +670,10 @@ make_unqualified_type (struct type *type) struct type * make_atomic_type (struct type *type) { - return make_qualified_type (type, - (type->instance_flags () - | TYPE_INSTANCE_FLAG_ATOMIC), - NULL); + type_instance_flags new_flags = type->instance_flags (); + new_flags.is_atomic = true; + + return make_qualified_type (type, new_flags, nullptr); } /* Replace the contents of ntype with the type *type. This changes the @@ -723,7 +710,7 @@ replace_type (struct type *ntype, struct type *type) variants. This assertion shouldn't ever be triggered because symbol readers which do construct address-class variants don't call replace_type(). */ - gdb_assert (TYPE_ADDRESS_CLASS_ALL (chain) == 0); + gdb_assert (TYPE_ADDRESS_CLASS (chain) == 0); chain->set_length (type->length ()); chain = chain->chain; @@ -1362,8 +1349,8 @@ make_vector_type (struct type *array_type) elt_type = inner_array->target_type (); if (elt_type->code () == TYPE_CODE_INT) { - type_instance_flags flags - = elt_type->instance_flags () | TYPE_INSTANCE_FLAG_NOTTEXT; + type_instance_flags flags = elt_type->instance_flags (); + flags.is_nottext = true; elt_type = make_qualified_type (elt_type, flags, NULL); inner_array->set_target_type (elt_type); } @@ -3074,19 +3061,13 @@ check_typedef (struct type *type) outer cast in a chain of casting win), instead of assuming "it can't happen". */ { - const type_instance_flags ALL_SPACES - = (TYPE_INSTANCE_FLAG_CODE_SPACE - | TYPE_INSTANCE_FLAG_DATA_SPACE); - const type_instance_flags ALL_CLASSES - = TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL; - type_instance_flags new_instance_flags = type->instance_flags (); /* Treat code vs data spaces and address classes separately. */ - if ((instance_flags & ALL_SPACES) != 0) - new_instance_flags &= ~ALL_SPACES; - if ((instance_flags & ALL_CLASSES) != 0) - new_instance_flags &= ~ALL_CLASSES; + if (instance_flags.harvard_aspace != HARVARD_ASPACE_NONE) + new_instance_flags.harvard_aspace = HARVARD_ASPACE_NONE; + if (instance_flags.address_class != 0) + new_instance_flags.address_class = 0; instance_flags |= new_instance_flags; } @@ -5039,8 +5020,7 @@ recursive_dump_type (struct type *type, int spaces) host_address_to_string (type->reference_type)); gdb_printf ("%*stype_chain %s\n", spaces, "", host_address_to_string (type->chain)); - gdb_printf ("%*sinstance_flags 0x%x", spaces, "", - (unsigned) type->instance_flags ()); + gdb_printf ("%*sinstance_flags [", spaces, ""); if (TYPE_CONST (type)) { gdb_puts (" TYPE_CONST"); @@ -5057,13 +5037,9 @@ recursive_dump_type (struct type *type, int spaces) { gdb_puts (" TYPE_DATA_SPACE"); } - if (TYPE_ADDRESS_CLASS_1 (type)) + if (TYPE_ADDRESS_CLASS (type) != 0) { - gdb_puts (" TYPE_ADDRESS_CLASS_1"); - } - if (TYPE_ADDRESS_CLASS_2 (type)) - { - gdb_puts (" TYPE_ADDRESS_CLASS_2"); + gdb_printf (" TYPE_ADDRESS_CLASS(%u)", TYPE_ADDRESS_CLASS (type)); } if (TYPE_RESTRICT (type)) { @@ -5073,7 +5049,7 @@ recursive_dump_type (struct type *type, int spaces) { gdb_puts (" TYPE_ATOMIC"); } - gdb_puts ("\n"); + gdb_puts ("]\n"); gdb_printf ("%*sflags", spaces, ""); if (type->is_unsigned ()) @@ -5875,13 +5851,8 @@ create_gdbtypes_data (struct gdbarch *gdbarch) builtin_type->builtin_uint128 = init_integer_type (alloc, 128, 1, "uint128_t"); - builtin_type->builtin_int8->set_instance_flags - (builtin_type->builtin_int8->instance_flags () - | TYPE_INSTANCE_FLAG_NOTTEXT); - - builtin_type->builtin_uint8->set_instance_flags - (builtin_type->builtin_uint8->instance_flags () - | TYPE_INSTANCE_FLAG_NOTTEXT); + builtin_type->builtin_int8->set_nottext (true); + builtin_type->builtin_uint8->set_nottext (true); /* Wide character types. */ builtin_type->builtin_char16 diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h index 854679141ff..19b6e6640ec 100644 --- a/gdb/gdbtypes.h +++ b/gdb/gdbtypes.h @@ -71,6 +71,9 @@ enum type_code }; +/* Enums for instruction-space delimited type. See the type instance + flags for more details. */ + enum harvard_address_space { HARVARD_ASPACE_NONE = 0, @@ -78,51 +81,95 @@ enum harvard_address_space HARVARD_ASPACE_DATA = 2, }; -/* Some bits for the type's instance_flags word. See the macros - below for documentation on each bit. */ +/* A type's instance_flags. */ -enum type_instance_flag_value : unsigned +struct type_instance_flags { - TYPE_INSTANCE_FLAG_CONST = (1 << 0), - TYPE_INSTANCE_FLAG_VOLATILE = (1 << 1), - TYPE_INSTANCE_FLAG_CODE_SPACE = (1 << 2), - TYPE_INSTANCE_FLAG_DATA_SPACE = (1 << 3), - TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1 = (1 << 4), - TYPE_INSTANCE_FLAG_ADDRESS_CLASS_2 = (1 << 5), - TYPE_INSTANCE_FLAG_NOTTEXT = (1 << 6), - TYPE_INSTANCE_FLAG_RESTRICT = (1 << 7), - TYPE_INSTANCE_FLAG_ATOMIC = (1 << 8) -}; + bool operator== (const type_instance_flags &other) const + { + return (is_const == other.is_const + && is_volatile == other.is_volatile + && harvard_aspace == other.harvard_aspace + && address_class == other.address_class + && is_nottext == other.is_nottext + && is_restrict == other.is_restrict + && is_atomic == other.is_atomic); + } + + bool operator!= (const type_instance_flags &other) const + { + return !(*this == other); + } + + type_instance_flags &operator|= (const type_instance_flags &other) + { + is_const = is_const || other.is_const; + is_volatile = is_volatile || other.is_volatile; + harvard_aspace + = static_cast (harvard_aspace + | other.harvard_aspace); + address_class = address_class | other.address_class; + is_nottext = is_nottext || other.is_nottext; + is_restrict = is_restrict || other.is_restrict; + is_atomic = is_atomic || other.is_atomic; + return *this; + } + + /* Constant type. If this is set, the corresponding type has a + const modifier. */ + bool is_const : 1; -DEF_ENUM_FLAGS_TYPE (enum type_instance_flag_value, type_instance_flags); + /* Volatile type. If this is set, the corresponding type has a + volatile modifier. */ + bool is_volatile : 1; -/* Not textual. By default, GDB treats all single byte integers as - characters (or elements of strings) unless this flag is set. */ + /* This is for Harvard architectures which have separate instruction + and data address spaces (and perhaps others). -#define TYPE_NOTTEXT(t) (((t)->instance_flags ()) & TYPE_INSTANCE_FLAG_NOTTEXT) + GDB usually defines a flat address space that is a superset of + the architecture's two (or more) address spaces, but this is an + extension of the architecture's model. -/* Constant type. If this is set, the corresponding type has a - const modifier. */ + If the field is set to HARVARD_ASPACE_CODE, an object of the + corresponding type resides in instruction memory, even if its + address (in the extended flat address space) does not reflect + this. -#define TYPE_CONST(t) ((((t)->instance_flags ()) & TYPE_INSTANCE_FLAG_CONST) != 0) + Similarly, if set to HARVARD_ASPACE_DATA, then an object of the + corresponding type resides in the data memory space, even if this + is not indicated by its (flat address space) address. -/* Volatile type. If this is set, the corresponding type has a - volatile modifier. */ + If set to HARVARD_ASPACE_NONE, the default space for functions / + methods is instruction space, and for data objects is data + memory. */ + harvard_address_space harvard_aspace : 2; -#define TYPE_VOLATILE(t) \ - ((((t)->instance_flags ()) & TYPE_INSTANCE_FLAG_VOLATILE) != 0) + /* Address class field. Some environments provide for pointers + whose size is different from that of a normal pointer or address + types where the bits are interpreted differently than normal + addresses. The ADDRESS_CLASS field may be used in target + specific ways to represent these different types of address + classes. */ + unsigned int address_class : 2; -/* Restrict type. If this is set, the corresponding type has a - restrict modifier. */ + /* Not textual. By default, GDB treats all single byte integers as + characters (or elements of strings) unless this flag is set. */ + bool is_nottext : 1; -#define TYPE_RESTRICT(t) \ - ((((t)->instance_flags ()) & TYPE_INSTANCE_FLAG_RESTRICT) != 0) + /* Restrict type. If this is set, the corresponding type has a + restrict modifier. */ + bool is_restrict : 1; -/* Atomic type. If this is set, the corresponding type has an - _Atomic modifier. */ + /* Atomic type. If this is set, the corresponding type has an + _Atomic modifier. */ + bool is_atomic : 1; +}; -#define TYPE_ATOMIC(t) \ - ((((t)->instance_flags ()) & TYPE_INSTANCE_FLAG_ATOMIC) != 0) +#define TYPE_NOTTEXT(t) (((t)->instance_flags ()).is_nottext) +#define TYPE_CONST(t) (((t)->instance_flags ()).is_const) +#define TYPE_VOLATILE(t) (((t)->instance_flags ()).is_volatile) +#define TYPE_RESTRICT(t) (((t)->instance_flags ()).is_restrict) +#define TYPE_ATOMIC(t) (((t)->instance_flags ()).is_atomic) /* True if this type represents either an lvalue or lvalue reference type. */ @@ -142,50 +189,14 @@ DEF_ENUM_FLAGS_TYPE (enum type_instance_flag_value, type_instance_flags); (((t)->dyn_prop (DYN_PROP_BYTE_SIZE) != nullptr) \ || ((t)->dyn_prop (DYN_PROP_BIT_SIZE) != nullptr)) -/* Instruction-space delimited type. This is for Harvard architectures - which have separate instruction and data address spaces (and perhaps - others). - - GDB usually defines a flat address space that is a superset of the - architecture's two (or more) address spaces, but this is an extension - of the architecture's model. - - If TYPE_INSTANCE_FLAG_CODE_SPACE is set, an object of the corresponding type - resides in instruction memory, even if its address (in the extended - flat address space) does not reflect this. - - Similarly, if TYPE_INSTANCE_FLAG_DATA_SPACE is set, then an object of the - corresponding type resides in the data memory space, even if - this is not indicated by its (flat address space) address. - - If neither flag is set, the default space for functions / methods - is instruction space, and for data objects is data memory. */ - #define TYPE_CODE_SPACE(t) \ - ((((t)->instance_flags ()) & TYPE_INSTANCE_FLAG_CODE_SPACE) != 0) + (((t)->instance_flags ()).harvard_aspace == HARVARD_ASPACE_CODE) #define TYPE_DATA_SPACE(t) \ - ((((t)->instance_flags ()) & TYPE_INSTANCE_FLAG_DATA_SPACE) != 0) - -/* Address class flags. Some environments provide for pointers - whose size is different from that of a normal pointer or address - types where the bits are interpreted differently than normal - addresses. The TYPE_INSTANCE_FLAG_ADDRESS_CLASS_n flags may be used in - target specific ways to represent these different types of address - classes. */ - -#define TYPE_ADDRESS_CLASS_1(t) (((t)->instance_flags ()) \ - & TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1) -#define TYPE_ADDRESS_CLASS_2(t) (((t)->instance_flags ()) \ - & TYPE_INSTANCE_FLAG_ADDRESS_CLASS_2) -#define TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL \ - (TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1 | TYPE_INSTANCE_FLAG_ADDRESS_CLASS_2) -#define TYPE_ADDRESS_CLASS_ALL(t) (((t)->instance_flags ()) \ - & TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL) -#define TYPE_ADDRESS_CLASS_FROM_INSTANCE_FLAGS(t) \ - ((unsigned int) ((t) & TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL) >> 4) + (((t)->instance_flags ()).harvard_aspace == HARVARD_ASPACE_DATA) + #define TYPE_ADDRESS_CLASS(t) \ - (TYPE_ADDRESS_CLASS_FROM_INSTANCE_FLAGS ((t)->instance_flags ())) + (((t)->instance_flags ()).address_class) /* Information about a single discriminant. */ @@ -1163,10 +1174,10 @@ struct type this->field (0).set_type (index_type); } - /* Return the instance flags converted to the correct type. */ + /* Return the instance flags. */ const type_instance_flags instance_flags () const { - return (enum type_instance_flag_value) this->m_instance_flags; + return this->m_instance_flags; } /* Set the instance flags. */ @@ -1175,6 +1186,18 @@ struct type this->m_instance_flags = flags; } + /* Set the address class id. */ + void set_address_class (unsigned int address_class) + { + this->m_instance_flags.address_class = address_class; + } + + /* Set the is_nottext flag. */ + void set_nottext (bool flag) + { + this->m_instance_flags.is_nottext = flag; + } + /* Get the bounds bounds of this type. The type must be a range type. */ range_bounds *bounds () const { @@ -1593,7 +1616,7 @@ struct type instance flags are completely inherited from the target type. No qualifiers can be cleared by the typedef. See also check_typedef. */ - unsigned m_instance_flags : 9; + type_instance_flags m_instance_flags; /* Length of storage for a value of this type. The value is the expression in host bytes of what sizeof(type) would return. This diff --git a/gdb/printcmd.c b/gdb/printcmd.c index 3f6cfa9dde3..2b86b89e6be 100644 --- a/gdb/printcmd.c +++ b/gdb/printcmd.c @@ -1056,17 +1056,12 @@ format_to_type (format_data fmt, gdbarch *gdbarch, type_instance_flags flags) gdb_assert (val_type != nullptr); - if ((flags & TYPE_INSTANCE_FLAG_CODE_SPACE) != 0) + if (flags.harvard_aspace != HARVARD_ASPACE_NONE) val_type = make_type_with_harvard_address_space (val_type, - HARVARD_ASPACE_CODE); - else if ((flags & TYPE_INSTANCE_FLAG_DATA_SPACE) != 0) - val_type = make_type_with_harvard_address_space (val_type, - HARVARD_ASPACE_DATA); + flags.harvard_aspace); - unsigned int aclass - = (unsigned int) (flags & TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL) >> 4; - if (aclass != 0) - val_type = make_type_with_address_class (val_type, aclass); + if (flags.address_class != 0) + val_type = make_type_with_address_class (val_type, flags.address_class); return val_type; } @@ -1899,7 +1894,7 @@ x_command (const char *exp, int from_tty) else next_address = value_as_address (val); - type_instance_flags flags = 0; + type_instance_flags flags {}; if (val->type ()->is_pointer_or_reference ()) flags = val->type ()->target_type ()->instance_flags (); @@ -2186,7 +2181,7 @@ do_one_display (struct display *d) if (d->format.format == 'i') addr = gdbarch_addr_bits_remove (d->exp->gdbarch, addr); - type_instance_flags flags = 0; + type_instance_flags flags {}; if (val->type ()->is_pointer_or_reference ()) flags = val->type ()->target_type ()->instance_flags (); diff --git a/gdb/testsuite/gdb.base/maint.exp b/gdb/testsuite/gdb.base/maint.exp index 0099eb672dc..f0c183c8c41 100644 --- a/gdb/testsuite/gdb.base/maint.exp +++ b/gdb/testsuite/gdb.base/maint.exp @@ -280,7 +280,7 @@ foreach { test_name command } $test_list { set msg "maint print type" gdb_test_multiple "maint print type argc" $msg { - -re "type node $hex\r\nname .int. \\($hex\\)\r\ncode $hex \\(TYPE_CODE_INT\\)\r\nlength \[24\]\r\nobjfile $hex\r\ntarget_type $hex\r\npointer_type $hex\r\nreference_type $hex\r\ntype_chain $hex\r\ninstance_flags $hex\r\nflags\r\nnfields 0 $hex\r\n$gdb_prompt $" { + -re "type node $hex\r\nname .int. \\($hex\\)\r\ncode $hex \\(TYPE_CODE_INT\\)\r\nlength \[24\]\r\nobjfile $hex\r\ntarget_type $hex\r\npointer_type $hex\r\nreference_type $hex\r\ntype_chain $hex\r\ninstance_flags \\\[\\\]\r\nflags\r\nnfields 0 $hex\r\n$gdb_prompt $" { pass $msg } } diff --git a/gdb/testsuite/gdb.gdb/python-helper.exp b/gdb/testsuite/gdb.gdb/python-helper.exp index e700deda16d..d1cca48cbb8 100644 --- a/gdb/testsuite/gdb.gdb/python-helper.exp +++ b/gdb/testsuite/gdb.gdb/python-helper.exp @@ -151,7 +151,7 @@ proc test_python_helper {} { "\{pointer_type = 0x0," \ " reference_type = 0x0," \ " chain = 0x0," \ - " instance_flags = 0," \ + " instance_flags = \\\[\\\]," \ " length = $decimal," \ " main_type = $hex\}"] gdb_test -prompt $outer_prompt_re "print *val->m_type" $answer "pretty print type" @@ -166,6 +166,12 @@ proc test_python_helper {} { " int_stuff = \{ bit_size = $decimal, bit_offset = $decimal \}\}"] gdb_test -prompt $outer_prompt_re "print *val->m_type->main_type" $answer "pretty print type->main_type" + # Test printing instance flags using an artificial type. + set answer [string_to_regexp {instance_flags = [VOLATILE|DATA_SPACE|ADDRESS_CLASS(3)]}] + gdb_test -prompt $outer_prompt_re \ + "print *make_type_with_harvard_address_space (make_cv_type (0, 1, make_type_with_address_class (val->m_type, 3)), 2)" \ + "${answer}.*" "pretty print type instance flags" + # Send the continue to the outer GDB, which resumes the inner GDB, # we then detect the prompt from the inner GDB, hence the use of # -i here. diff --git a/gdb/type-stack.c b/gdb/type-stack.c index f49e6d05e10..50912d110f6 100644 --- a/gdb/type-stack.c +++ b/gdb/type-stack.c @@ -101,7 +101,7 @@ type_stack::insert (struct gdbarch *gdbarch, const char *string) type_instance_flags type_stack::follow_type_instance_flags () { - type_instance_flags flags = 0; + type_instance_flags flags {}; for (;;) switch (pop ()) @@ -109,16 +109,16 @@ type_stack::follow_type_instance_flags () case tp_end: return flags; case tp_const: - flags |= TYPE_INSTANCE_FLAG_CONST; + flags.is_const = true; break; case tp_volatile: - flags |= TYPE_INSTANCE_FLAG_VOLATILE; + flags.is_volatile = true; break; case tp_atomic: - flags |= TYPE_INSTANCE_FLAG_ATOMIC; + flags.is_atomic = true; break; case tp_restrict: - flags |= TYPE_INSTANCE_FLAG_RESTRICT; + flags.is_restrict = true; break; default: gdb_assert_not_reached ("unrecognized tp_ value in follow_types"); -- 2.34.1