From patchwork Tue Oct 8 17:11:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 98548 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E6EAE386183E for ; Tue, 8 Oct 2024 17:12:49 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 49CA0385DDF6 for ; Tue, 8 Oct 2024 17:12:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 49CA0385DDF6 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 49CA0385DDF6 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728407524; cv=none; b=P56NzpP2AfXS/vL4S1gx1BFlInDxBacyKQ8W+CWB8+WG1N8gbqExo2TgkwMbrnKpTW/PiMsr8pqPZPI3hwmVVLnQYBRbLcQPjio62/X/k6hff6hVyXaOfc9Hlir5R23PhpDJIpVDuotcU7N97aEV5WcDWqKU94loXJJyKwUslXI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728407524; c=relaxed/simple; bh=QIsQV0OCC7UNvLFU/YBUvR7Cjp5TtRTMkIx90kicNAk=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=GyhhW74kxOU23YkryksuHo2wQ/1dP5EdUyIC/xRGPgGzOKtwGmet8RCfSWcKOGoTTLPrdZFtjE+jyoGM3otcvtsiK4T+m1t44CfrfuaIHx2RvOOUmXZGhbjytKdv7Ect0kTUlanxBnG6NBUeyDQBoZib5HeXzTGyZ0cJq80OwIg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728407520; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=G109xaU2rhl2tBNZM58sYOlzptorRCmkJMRLoatoHkU=; b=Zg9ssdxYvjEValcdofMZW3EHWWWI/WvW7v8e5fW/D1QBlhltV6kUwhymFku1S4UuO0b3af gTNiBVScCeFi18PigXPazdA4L6LkOZCLr9Jz8I82xMBrhgqj7MXYnZL2hfWuwPYtqF2KnS I3TKKVNaFR2GKbWVUoop8I0G1DhDNCQ= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-581-YvO-k1TdNgmKfQ10eJkOrg-1; Tue, 08 Oct 2024 13:11:59 -0400 X-MC-Unique: YvO-k1TdNgmKfQ10eJkOrg-1 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-a7d2d414949so510456166b.0 for ; Tue, 08 Oct 2024 10:11:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728407518; x=1729012318; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=v0mjRRinxyC/NqM/YtlInz4PxpLTKa3Kg11YYnLu2a4=; b=dc5LQZfd6zttWosxzSFeTBg+o6urqn2vwrhxt8PWNJ3PJTsjZOPzYYQhHI3uBb99wR iacL4v1l4vkHy3LuHsadB0CRVS7xtblwoEuWtZ/lOXcZpMCitRsZqy157GyCwi8vL7UP p8zigigdqS+WCGOu3KbVsyuTQouEI+dEvFq7dkRWyGSMXKZZBTlDDEpRnMFw3kRg4YIh vp814fKlmXnHisLnhELVE1uIexJRwkdTV1qc5EA1NRxQiul4Ai+PPWqPJWVIPoYEBvR8 dHjAQWJc7XasphPSwKuzOnk1kY3OXOKsEQy2/9PaWL8SchDvVK0PQOrpyDUU2OWHg4d4 taFQ== X-Gm-Message-State: AOJu0Yz5XwJytvNOv8ZQhpQyN7RGF0DqxCN5ppj9St1PNp5+eyS5N6Ke OhDUPtiq1Nq7uvVFlYuyIXh5MK8YqZeyDmcNu906YM4xbr1UlgGkMkJQpAliY63kU93qTGmnT9N ZeJSIY5RLprNcUxsebrxwbZGlSkn00XpNlqSQoHN6ZQ6OtQ+i9VyAdO+fexX9kRC+PqIl7ZYELy Xr+3GR7zSa0rO4ZTIonbg+Y83NWPZiNZ3wiDqdkAQLVho= X-Received: by 2002:a17:907:3f07:b0:a99:59c6:9185 with SMTP id a640c23a62f3a-a9959c6922bmr510769566b.17.1728407517972; Tue, 08 Oct 2024 10:11:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFhDLBNc1S5jeU6YV6P4T2bh9HGMo6JsT1JmyIpv2crnOQEB+8nrzPQ/pQqrbY5z4IFSubthA== X-Received: by 2002:a17:907:3f07:b0:a99:59c6:9185 with SMTP id a640c23a62f3a-a9959c6922bmr510764966b.17.1728407517307; Tue, 08 Oct 2024 10:11:57 -0700 (PDT) Received: from localhost ([195.213.152.26]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a992e664fb9sm534241366b.88.2024.10.08.10.11.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Oct 2024 10:11:57 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess , Luis Machado Subject: [PATCH 4/5] gdb/gdbserver: change shared set_tdesc_osabi to take gdb_osabi Date: Tue, 8 Oct 2024 18:11:49 +0100 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIM_INVALID, DKIM_SIGNED, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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~patchwork=sourceware.org@sourceware.org There is a single declaration of set_tdesc_osabi that is shared between gdbserver/ and gdb/, this declaration takes a 'const char *' argument which is the string representing an osabi. Then in gdb/ we have an overload of set_tdesc_osabi which takes an 'enum gdb_osabi'. In this commit I change the shared set_tdesc_osabi to be the version which takes an 'enum gdb_osabi', and I remove the version which takes a 'const char *'. All users of set_tdesc_osabi are updated to pass an 'enum gdb_osabi'. The features/ code, which is generated from the xml files, requires a new function to be added to osabi.{c,h} which can return a string representation of an 'enum gdb_osabi'. With that new function in place the features/ code is regenerated. This change is being made to support the next commit. In the next commit gdbserver will be updated to call set_tdesc_osabi in more cases. The problem is that gdbserver stores the osabi as a string. The issue here is that a typo in the gdbserver/ code might go unnoticed and result in gdbserver sending back an invalid osabi string. To fix this we want gdbserver to pass an 'enum gdb_osabi' to the set_tdesc_osabi function. With that requirement in place it seems to make sense if all calls to set_tdesc_osabi pass an 'enum gdb_osabi'. There should be no user visible changes after this commit. --- gdb/arch/amd64.c | 3 ++- gdb/arch/i386.c | 3 ++- gdb/arch/tic6x.c | 3 ++- gdb/features/mips-dsp-linux.c | 2 +- gdb/features/mips-linux.c | 2 +- gdb/features/or1k-linux.c | 2 +- gdb/features/sparc/sparc32-solaris.c | 2 +- gdb/features/sparc/sparc64-solaris.c | 2 +- gdb/osabi.c | 29 ++++++++++++++++++++++++++++ gdb/osabi.h | 4 ++++ gdb/target-descriptions.c | 11 ++--------- gdb/target-descriptions.h | 1 - gdbserver/tdesc.cc | 3 ++- gdbsupport/tdesc.h | 4 +++- 14 files changed, 51 insertions(+), 20 deletions(-) diff --git a/gdb/arch/amd64.c b/gdb/arch/amd64.c index 548b32f252f..a04fcddd215 100644 --- a/gdb/arch/amd64.c +++ b/gdb/arch/amd64.c @@ -17,6 +17,7 @@ #include "amd64.h" #include "gdbsupport/x86-xstate.h" +#include "gdbsupport/osabi-common.h" #include #include "../features/i386/64bit-avx.c" @@ -45,7 +46,7 @@ amd64_create_target_description (uint64_t xcr0, bool is_x32, bool is_linux, is_x32 ? "i386:x64-32" : "i386:x86-64"); if (is_linux) - set_tdesc_osabi (tdesc.get (), "GNU/Linux"); + set_tdesc_osabi (tdesc.get (), GDB_OSABI_LINUX); #endif long regnum = 0; diff --git a/gdb/arch/i386.c b/gdb/arch/i386.c index 49375e7c495..72159d8ed70 100644 --- a/gdb/arch/i386.c +++ b/gdb/arch/i386.c @@ -18,6 +18,7 @@ #include "i386.h" #include "gdbsupport/tdesc.h" #include "gdbsupport/x86-xstate.h" +#include "gdbsupport/osabi-common.h" #include #include "../features/i386/32bit-core.c" @@ -38,7 +39,7 @@ i386_create_target_description (uint64_t xcr0, bool is_linux, bool segments) #ifndef IN_PROCESS_AGENT set_tdesc_architecture (tdesc.get (), "i386"); if (is_linux) - set_tdesc_osabi (tdesc.get (), "GNU/Linux"); + set_tdesc_osabi (tdesc.get (), GDB_OSABI_LINUX); #endif long regnum = 0; diff --git a/gdb/arch/tic6x.c b/gdb/arch/tic6x.c index 680a7942070..c1082d48eea 100644 --- a/gdb/arch/tic6x.c +++ b/gdb/arch/tic6x.c @@ -16,6 +16,7 @@ along with this program. If not, see . */ #include "gdbsupport/tdesc.h" +#include "gdbsupport/osabi-common.h" #include "tic6x.h" #include "../features/tic6x-core.c" @@ -30,7 +31,7 @@ tic6x_create_target_description (enum c6x_feature feature) target_desc_up tdesc = allocate_target_description (); set_tdesc_architecture (tdesc.get (), "tic6x"); - set_tdesc_osabi (tdesc.get (), "GNU/Linux"); + set_tdesc_osabi (tdesc.get (), GDB_OSABI_LINUX); long regnum = 0; diff --git a/gdb/features/mips-dsp-linux.c b/gdb/features/mips-dsp-linux.c index 17d30aac68f..4873037b69d 100644 --- a/gdb/features/mips-dsp-linux.c +++ b/gdb/features/mips-dsp-linux.c @@ -11,7 +11,7 @@ initialize_tdesc_mips_dsp_linux (void) target_desc_up result = allocate_target_description (); set_tdesc_architecture (result.get (), bfd_scan_arch ("mips")); - set_tdesc_osabi (result.get (), "GNU/Linux"); + set_tdesc_osabi (result.get (), GDB_OSABI_LINUX); struct tdesc_feature *feature; diff --git a/gdb/features/mips-linux.c b/gdb/features/mips-linux.c index a43526db24e..5ff2e5fb92d 100644 --- a/gdb/features/mips-linux.c +++ b/gdb/features/mips-linux.c @@ -11,7 +11,7 @@ initialize_tdesc_mips_linux (void) target_desc_up result = allocate_target_description (); set_tdesc_architecture (result.get (), bfd_scan_arch ("mips")); - set_tdesc_osabi (result.get (), "GNU/Linux"); + set_tdesc_osabi (result.get (), GDB_OSABI_LINUX); struct tdesc_feature *feature; diff --git a/gdb/features/or1k-linux.c b/gdb/features/or1k-linux.c index 551b38f59c0..85a681f89ba 100644 --- a/gdb/features/or1k-linux.c +++ b/gdb/features/or1k-linux.c @@ -11,7 +11,7 @@ initialize_tdesc_or1k_linux (void) target_desc_up result = allocate_target_description (); set_tdesc_architecture (result.get (), bfd_scan_arch ("or1k")); - set_tdesc_osabi (result.get (), "GNU/Linux"); + set_tdesc_osabi (result.get (), GDB_OSABI_LINUX); struct tdesc_feature *feature; diff --git a/gdb/features/sparc/sparc32-solaris.c b/gdb/features/sparc/sparc32-solaris.c index ce57abaaaf2..70affdbc5b5 100644 --- a/gdb/features/sparc/sparc32-solaris.c +++ b/gdb/features/sparc/sparc32-solaris.c @@ -11,7 +11,7 @@ initialize_tdesc_sparc32_solaris (void) target_desc_up result = allocate_target_description (); set_tdesc_architecture (result.get (), bfd_scan_arch ("sparc")); - set_tdesc_osabi (result.get (), "Solaris"); + set_tdesc_osabi (result.get (), GDB_OSABI_SOLARIS); struct tdesc_feature *feature; diff --git a/gdb/features/sparc/sparc64-solaris.c b/gdb/features/sparc/sparc64-solaris.c index 92cc88cd5cf..98edabe3864 100644 --- a/gdb/features/sparc/sparc64-solaris.c +++ b/gdb/features/sparc/sparc64-solaris.c @@ -11,7 +11,7 @@ initialize_tdesc_sparc64_solaris (void) target_desc_up result = allocate_target_description (); set_tdesc_architecture (result.get (), bfd_scan_arch ("sparc:v9")); - set_tdesc_osabi (result.get (), "Solaris"); + set_tdesc_osabi (result.get (), GDB_OSABI_SOLARIS); struct tdesc_feature *feature; diff --git a/gdb/osabi.c b/gdb/osabi.c index 6c00228fb4a..47ef349c6be 100644 --- a/gdb/osabi.c +++ b/gdb/osabi.c @@ -524,6 +524,35 @@ generic_elf_osabi_sniffer (bfd *abfd) return osabi; } + +/* See osabi.h. */ +const char * +gdbarch_osabi_enum_name (enum gdb_osabi osabi) +{ + switch (osabi) + { +#define GDB_OSABI_DEF_FIRST(Enum, Name, Regex) \ + case GDB_OSABI_ ## Enum: \ + return "GDB_OSABI_" #Enum; + +#define GDB_OSABI_DEF(Enum, Name, Regex) \ + case GDB_OSABI_ ## Enum: \ + return "GDB_OSABI_" #Enum; + +#define GDB_OSABI_DEF_LAST(Enum, Name, Regex) \ + case GDB_OSABI_ ## Enum: \ + return "GDB_OSABI_" #Enum; + +#include "gdbsupport/osabi-common.def" + +#undef GDB_OSABI_DEF_LAST +#undef GDB_OSABI_DEF +#undef GDB_OSABI_DEF_FIRST + } + + gdb_assert_not_reached (); +} + static void set_osabi (const char *args, int from_tty, struct cmd_list_element *c) diff --git a/gdb/osabi.h b/gdb/osabi.h index 984bdd4e5dc..02ac5503db3 100644 --- a/gdb/osabi.h +++ b/gdb/osabi.h @@ -52,4 +52,8 @@ void gdbarch_init_osabi (struct gdbarch_info, struct gdbarch *); void generic_elf_osabi_sniff_abi_tag_sections (bfd *, asection *, enum gdb_osabi *); +/* Return a string version of OSABI. This is used when generating code + which calls set_tdesc_osabi and an 'enum gdb_osabi' value is needed. */ +const char *gdbarch_osabi_enum_name (enum gdb_osabi osabi); + #endif /* OSABI_H */ diff --git a/gdb/target-descriptions.c b/gdb/target-descriptions.c index c165750c6c5..1bd22c273a2 100644 --- a/gdb/target-descriptions.c +++ b/gdb/target-descriptions.c @@ -1199,12 +1199,6 @@ set_tdesc_architecture (struct target_desc *target_desc, /* See gdbsupport/tdesc.h. */ -void -set_tdesc_osabi (struct target_desc *target_desc, const char *name) -{ - set_tdesc_osabi (target_desc, osabi_from_tdesc_string (name)); -} - void set_tdesc_osabi (struct target_desc *target_desc, enum gdb_osabi osabi) { @@ -1317,9 +1311,8 @@ class print_c_tdesc : public tdesc_element_visitor if (tdesc_osabi (e) > GDB_OSABI_UNKNOWN && tdesc_osabi (e) < GDB_OSABI_INVALID) { - gdb_printf - (" set_tdesc_osabi (result.get (), \"%s\");\n", - gdbarch_osabi_name (tdesc_osabi (e))); + const char *enum_name = gdbarch_osabi_enum_name (tdesc_osabi (e)); + gdb_printf (" set_tdesc_osabi (result.get (), %s);\n", enum_name); gdb_printf ("\n"); } diff --git a/gdb/target-descriptions.h b/gdb/target-descriptions.h index d708dbd3589..dc83db0acf2 100644 --- a/gdb/target-descriptions.h +++ b/gdb/target-descriptions.h @@ -219,7 +219,6 @@ int tdesc_register_in_reggroup_p (struct gdbarch *gdbarch, int regno, void set_tdesc_architecture (struct target_desc *, const struct bfd_arch_info *); -void set_tdesc_osabi (struct target_desc *, enum gdb_osabi osabi); void set_tdesc_property (struct target_desc *, const char *key, const char *value); void tdesc_add_compatible (struct target_desc *, diff --git a/gdbserver/tdesc.cc b/gdbserver/tdesc.cc index 7f11120c318..d052f43c76e 100644 --- a/gdbserver/tdesc.cc +++ b/gdbserver/tdesc.cc @@ -179,8 +179,9 @@ tdesc_osabi_name (const struct target_desc *target_desc) /* See gdbsupport/tdesc.h. */ void -set_tdesc_osabi (struct target_desc *target_desc, const char *name) +set_tdesc_osabi (struct target_desc *target_desc, enum gdb_osabi osabi) { + const char *name = gdbarch_osabi_name (osabi); target_desc->osabi = make_unique_xstrdup (name); } diff --git a/gdbsupport/tdesc.h b/gdbsupport/tdesc.h index fa9431b5b65..0a9be1dc4d1 100644 --- a/gdbsupport/tdesc.h +++ b/gdbsupport/tdesc.h @@ -18,6 +18,8 @@ #ifndef COMMON_TDESC_H #define COMMON_TDESC_H +#include "gdbsupport/osabi-common.h" + struct tdesc_feature; struct tdesc_type; struct tdesc_type_builtin; @@ -339,7 +341,7 @@ void set_tdesc_architecture (target_desc *target_desc, const char *tdesc_architecture_name (const struct target_desc *target_desc); /* Set TARGET_DESC's osabi by NAME. */ -void set_tdesc_osabi (target_desc *target_desc, const char *name); +void set_tdesc_osabi (target_desc *target_desc, enum gdb_osabi osabi); /* Return the osabi associated with this target description as a string, or NULL if no osabi was specified. */