From patchwork Tue Oct 8 17:11:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 98550 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 A0947384F4BF for ; Tue, 8 Oct 2024 17:13:15 +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.133.124]) by sourceware.org (Postfix) with ESMTP id 87F2F385C6CC for ; Tue, 8 Oct 2024 17:11:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 87F2F385C6CC 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 87F2F385C6CC Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728407520; cv=none; b=eSlix2S9dWBYjIkwuFTGOZpxk7LcuwpVZtvaVw3Xb2wFxV8Yk0Qs7D49PP5x19qTPngpaVDTilQd8n4Rqlnjbic9liVAIlejOw9UzpHZbrkBMmaRfXZU7EBnyQkTmHMbLJVY0K23Btj8qPOlqADevjR8lADHx+UX8pgHK6TRbJM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728407520; c=relaxed/simple; bh=K4pLoN9LawWLso3be2F4WfWLXg9ugM8SdqBEVgbTWcQ=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=QUsrf0pina9ZodpcPS/jDyB19dwZsSPpqQB8GB29rwHdqU9G8I/lml36+TUmi9dd2o+0xVQesKCYba6K3UgXmgGn6c0n1/OfpDUZ3TzcWlxFW8egutiFk3MIcMnK0Kp8zEN8b2cIQwVPYP9sK4iZ2PdB8WL2CkQ2hV57Nkcgk08= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728407518; 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=Z0D/UPRVAa9qiKwFp647bvU0AzoroKJtVSwwBV4mjRs=; b=KebaZ/EAGZMVqKCtvQ0TRYGmx5mXDIXtlWDEN0LXMIHrLfIOXCXMzlXQ6z8XnAdkaGx7G6 7Nbdffoc4h5cMYJmTioJp+glfMb9P5mzD2Q3plbNz2OXZ/bPWZUhyETJnP1DS8uXm1w8dG tR204tBvkA5EsN9B8203LqtLUpTuSKI= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-582-tB4IVd4bPqm8Dz7n5FUJQA-1; Tue, 08 Oct 2024 13:11:57 -0400 X-MC-Unique: tB4IVd4bPqm8Dz7n5FUJQA-1 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-a9946fff3adso185657566b.2 for ; Tue, 08 Oct 2024 10:11:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728407514; x=1729012314; 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=Z0D/UPRVAa9qiKwFp647bvU0AzoroKJtVSwwBV4mjRs=; b=n7GpkL8slu1VZgCaRcyz4pD3L1huKjPW11ZOEhCe0NQ13jnjcCthSLy5+JFREQfSbB VFKLFOk45JYIef42GSiO8JXtWj14Kkf6fnx+hlPR7DK9B6gSx28mCgqmASRhKIKFPYy3 qQCSTFBcZVutefglInt0xHtSoPzDCTnxw3JXbUr1Kbxh9tTyvzBP5+sQvLcyuhlM4d+v PQEtb4FyUJsQjJalYNXBIZZ5auV0QU394yl9f0rVvEIAdFXjDR/jyyBvY2GLcMP3to9Y dfJdqBK48iY/332p8n1BEV6meUwcbbU3YVBvSEP9R3Nitu+/lctgE6d8s3ZSTwmx1yy/ B1Mg== X-Gm-Message-State: AOJu0Yyu+IGkD37BTN2FaZEjEMeoYIAH7BfOVPquyYSczkxTNeDteuAK l6H+ldtQ/YRwryzH5Dehea8UrwWLGRYqNGsAiWgBGs4hXGaQqmylm1OBDkIM/wF5gjm6RTUryGO Jmp1sPBgBhYATVr3S5xMXa77v5mB2HM/x/s/AY1Ux2Nzot8X94YwxhJpj2KkX8/TysFhjml7pdJ 21KRrH23XUZy8OAGKSpOCMuO7X21acL/lG2gHoQAJwhuM= X-Received: by 2002:a17:907:6d04:b0:a99:7b6f:c8a7 with SMTP id a640c23a62f3a-a997b6fca8emr233863066b.46.1728407513868; Tue, 08 Oct 2024 10:11:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGW/TJXKun+N0kfDhYEKD+YMpqYb0O+uLEATyBN3sQIpb80O7+lVoAc0T1vJ3m6+MHsEtas2Q== X-Received: by 2002:a17:907:6d04:b0:a99:7b6f:c8a7 with SMTP id a640c23a62f3a-a997b6fca8emr233860066b.46.1728407513382; Tue, 08 Oct 2024 10:11:53 -0700 (PDT) Received: from localhost ([195.213.152.26]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a994a4294c8sm380659266b.123.2024.10.08.10.11.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Oct 2024 10:11:53 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess , Luis Machado , Tom Tromey Subject: [PATCH 1/5] gdbserver: make arch and osabi names gdb::unique_xmalloc_ptr Date: Tue, 8 Oct 2024 18:11:46 +0100 Message-Id: <642bc25ebd1e94f3378e109256b1c1229fb5f624.1728407374.git.aburgess@redhat.com> 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, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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 Convert target_desc::arch and target_desc::osabi from 'const char*' to gdb::unique_xmalloc_ptr. This also allows us to remove the user defined ~target_desc destructor. I doubt it ever actually occurred, but in theory at least, there was a memory leak in set_tdesc_architecture and set_tdesc_osabi where the member variables were assigned without freeing any previous value... but I suspect that usually these fields are only set once. There should be no user visible changes after this commit. Approved-By: Tom Tromey --- gdbserver/tdesc.cc | 16 +++++----------- gdbserver/tdesc.h | 6 ++---- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/gdbserver/tdesc.cc b/gdbserver/tdesc.cc index 3265793da96..7f11120c318 100644 --- a/gdbserver/tdesc.cc +++ b/gdbserver/tdesc.cc @@ -20,12 +20,6 @@ #ifndef IN_PROCESS_AGENT -target_desc::~target_desc () -{ - xfree ((char *) arch); - xfree ((char *) osabi); -} - bool target_desc::operator== (const target_desc &other) const { if (reg_defs != other.reg_defs) @@ -162,7 +156,7 @@ tdesc_compatible_info_arch_name (const tdesc_compatible_info_up &c_info) const char * tdesc_architecture_name (const struct target_desc *target_desc) { - return target_desc->arch; + return target_desc->arch.get (); } /* See gdbsupport/tdesc.h. */ @@ -171,7 +165,7 @@ void set_tdesc_architecture (struct target_desc *target_desc, const char *name) { - target_desc->arch = xstrdup (name); + target_desc->arch = make_unique_xstrdup (name); } /* See gdbsupport/tdesc.h. */ @@ -179,7 +173,7 @@ set_tdesc_architecture (struct target_desc *target_desc, const char * tdesc_osabi_name (const struct target_desc *target_desc) { - return target_desc->osabi; + return target_desc->osabi.get (); } /* See gdbsupport/tdesc.h. */ @@ -187,7 +181,7 @@ tdesc_osabi_name (const struct target_desc *target_desc) void set_tdesc_osabi (struct target_desc *target_desc, const char *name) { - target_desc->osabi = xstrdup (name); + target_desc->osabi = make_unique_xstrdup (name); } /* See gdbsupport/tdesc.h. */ @@ -198,7 +192,7 @@ tdesc_get_features_xml (const target_desc *tdesc) /* Either .xmltarget or .features is not NULL. */ gdb_assert (tdesc->xmltarget != NULL || (!tdesc->features.empty () - && tdesc->arch != NULL)); + && tdesc_architecture_name (tdesc) != nullptr)); if (tdesc->xmltarget == NULL) { diff --git a/gdbserver/tdesc.h b/gdbserver/tdesc.h index 534b8b000f5..6fc37d038bc 100644 --- a/gdbserver/tdesc.h +++ b/gdbserver/tdesc.h @@ -54,18 +54,16 @@ struct target_desc final : tdesc_element mutable const char *xmltarget = NULL; /* The value of element in the XML, replying GDB. */ - const char *arch = NULL; + gdb::unique_xmalloc_ptr arch = nullptr; /* The value of element in the XML, replying GDB. */ - const char *osabi = NULL; + gdb::unique_xmalloc_ptr osabi = nullptr; public: target_desc () : registers_size (0) {} - ~target_desc (); - bool operator== (const target_desc &other) const; bool operator!= (const target_desc &other) const From patchwork Tue Oct 8 17:11:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 98547 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 98A363861039 for ; Tue, 8 Oct 2024 17:12:40 +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.133.124]) by sourceware.org (Postfix) with ESMTP id 019F6385DDCA for ; Tue, 8 Oct 2024 17:11:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 019F6385DDCA 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 019F6385DDCA Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728407523; cv=none; b=iIH1Q78JubqMwd/ttATEU+B6HdZ8mXZrhXXwo7Xh0AGJaGrAUklHF5VUGjzJZ3PTQrnNUNjDBFLT/7lo27d/g1hQTj+JIoXJGz1JmyLnEacRufw9X1OFDaxgCoM/Bwt1KMmt+d5ZvpLSbCmAhsaB3aM+FgnEc7MsfuCL94Xu6Ik= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728407523; c=relaxed/simple; bh=t6uhWWI/vqTstW28v+jXjcST9fe0S7HdZwUMb7GRY0E=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=p5Q3NlUoH0kq8lfRsc3g1/7LjYhP+Ao/DEFgEo/Ey7BEgnFDhw0bT+CHW+/p2DydV77gNoP2tHEJ2UEz2sNSSb/AShk+4RtQ0kSMib0Vn7HiOO7qBcY2iTzzMoT5KpJarqZDwl5SlYlQ2ssCj/sR/Ib51rxSIJ4fQYEO8JPZEF4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728407518; 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=dIgwktIVqCU5G1Gu7LT2IL4aSsdbkhd0tHCgYyK49Yw=; b=fnTn1kD5c/yenNZgGWucQwwJHWxQPAmqs2pPTMAFWWh6IH84nBlKapnn7gPRX7eMQ6Ml2Z /ySXduBMOCat8r9iYZaT2j7/el+MZBaPNIGoRcOCwlX1f6+fafzoCRllg3D3h5WK56vrHJ l74NFFqgr8Ydqk9+8fL3CfcY5wzykbE= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-614-rt7-o7bhOk605Tm9MWZ2Og-1; Tue, 08 Oct 2024 13:11:57 -0400 X-MC-Unique: rt7-o7bhOk605Tm9MWZ2Og-1 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-a9959657eb9so141418066b.0 for ; Tue, 08 Oct 2024 10:11:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728407516; x=1729012316; 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=dIgwktIVqCU5G1Gu7LT2IL4aSsdbkhd0tHCgYyK49Yw=; b=rUlNBiQ+NN3vp4Oiwmj+04sq1k2wTdIO8EQNq79v4fhleXwU58sJLZnQt5o0pBt32f TZOqIAJTdd1KGgKnLwKNmnqrTR/DQNltHh1PbOeRFuJnmSpHiaBtfOsdS5v0Gb73yeec S6R7TzHWfyk96O62lRYuXQvcPW933Cb1ToH88huuYusaCu0+4AGhZsKIyw2kddufqkCz fpUlAbTvjnLJSahCyXt+9jRgBCiYCQycvMYwSMvQ2hJufpZECWegeEM6xIQshwfUr5Oy MhKKzxhVy7gnuJveBbn5afhCVE1TRZtGp+pCndtPEjFGYwa+Jx2r5RE78IopeTxUSL6P Ds7A== X-Gm-Message-State: AOJu0Yw+YUxiLDESU/LcutHNZleBLhN5OMyHf1vUxCXCBITomgPDVZAE jZWV/PzyTHwv59ByJnfGeRRLFPrrTio4XZ9CKHWv81RozOeRYAGIODDms248JWUVtT11LKyxqVt epMhdWDKxfFI+oicQiHxdDv1MruVIW4HH3OCz39NjrY81X2yfMryCropjT3yyKW2klOEqRmhdZQ y+peVgKTXbqMQJt2fUTil6xH3IZhGmY8SdX8Md/dI6Nvg= X-Received: by 2002:a17:906:7946:b0:a91:a5f:c9ce with SMTP id a640c23a62f3a-a991c077dc5mr1552141766b.62.1728407515601; Tue, 08 Oct 2024 10:11:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEN31TPPxMQJSaW+zk7hdqps37wJrMaShnBCkyE8yKSV3SxLh/qDRGxfRSY7hsw7Zwhn41DHg== X-Received: by 2002:a17:906:7946:b0:a91:a5f:c9ce with SMTP id a640c23a62f3a-a991c077dc5mr1552139166b.62.1728407515103; Tue, 08 Oct 2024 10:11:55 -0700 (PDT) Received: from localhost ([195.213.152.26]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a992e5d007esm527541966b.29.2024.10.08.10.11.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Oct 2024 10:11:54 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess , Luis Machado , Tom Tromey Subject: [PATCH 2/5] gdb: make use of set_tdesc_osabi overload in features/ files Date: Tue, 8 Oct 2024 18:11:47 +0100 Message-Id: <92ff2aaf4d9804491ca5c31849ff51025f2b6186.1728407374.git.aburgess@redhat.com> 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.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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 are two versions of the set_tdesc_osabi function in GDB: 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) { target_desc->osabi = osabi; } In the gdb/features/ files we call the second of these functions, like this: set_tdesc_osabi (result.get (), osabi_from_tdesc_string ("GNU/Linux")); This can be replaced with a call to the first set_tdesc_osabi function, so lets do that. I think that this makes the features/ code slightly simpler and easier to understand. There should be no user visible changes after this commit. Approved-By: Tom Tromey --- 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/target-descriptions.c | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/gdb/features/mips-dsp-linux.c b/gdb/features/mips-dsp-linux.c index d8e40283caf..17d30aac68f 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 (), osabi_from_tdesc_string ("GNU/Linux")); + set_tdesc_osabi (result.get (), "GNU/Linux"); struct tdesc_feature *feature; diff --git a/gdb/features/mips-linux.c b/gdb/features/mips-linux.c index f93eef5e41d..a43526db24e 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 (), osabi_from_tdesc_string ("GNU/Linux")); + set_tdesc_osabi (result.get (), "GNU/Linux"); struct tdesc_feature *feature; diff --git a/gdb/features/or1k-linux.c b/gdb/features/or1k-linux.c index 24731458de2..551b38f59c0 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 (), osabi_from_tdesc_string ("GNU/Linux")); + set_tdesc_osabi (result.get (), "GNU/Linux"); struct tdesc_feature *feature; diff --git a/gdb/features/sparc/sparc32-solaris.c b/gdb/features/sparc/sparc32-solaris.c index dce96851f96..ce57abaaaf2 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 (), osabi_from_tdesc_string ("Solaris")); + set_tdesc_osabi (result.get (), "Solaris"); struct tdesc_feature *feature; diff --git a/gdb/features/sparc/sparc64-solaris.c b/gdb/features/sparc/sparc64-solaris.c index d030df63c6c..92cc88cd5cf 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 (), osabi_from_tdesc_string ("Solaris")); + set_tdesc_osabi (result.get (), "Solaris"); struct tdesc_feature *feature; diff --git a/gdb/target-descriptions.c b/gdb/target-descriptions.c index d78da14918f..c165750c6c5 100644 --- a/gdb/target-descriptions.c +++ b/gdb/target-descriptions.c @@ -1318,7 +1318,7 @@ class print_c_tdesc : public tdesc_element_visitor && tdesc_osabi (e) < GDB_OSABI_INVALID) { gdb_printf - (" set_tdesc_osabi (result.get (), osabi_from_tdesc_string (\"%s\"));\n", + (" set_tdesc_osabi (result.get (), \"%s\");\n", gdbarch_osabi_name (tdesc_osabi (e))); gdb_printf ("\n"); } From patchwork Tue Oct 8 17:11:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 98551 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 CA6EC386183D for ; Tue, 8 Oct 2024 17:13:46 +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 B2D56385DDDD for ; Tue, 8 Oct 2024 17:12:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B2D56385DDDD 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 B2D56385DDDD 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=1728407527; cv=none; b=pCSKWGAIR5JxvdaIMDID4nht5sXUo8faGGwGf17g6zK8JU1yne1b5GZ+UTEtkn7IDHAU2uVUtGKkHDJ+DC+xuG0KD9Md9jwl17sV0FY/zSp6d/1v07iNHnwUrPn19/pm6kQ7xfBvIugGHecg3AiMItiZFrIYwS9NoesVPC73C6A= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728407527; c=relaxed/simple; bh=tUcNKxfe+KnPgYvPe+2ijszWSFJAxV+3vg+mCXTfMHU=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=JVjRcowhoCSE/RweTcxZDBqjNU5WuJzsaS5mOwRY8XLu1n0TJDVg6TEC/2aKTANEDIa5EvhTh6Ynj68J4lI7rhjXaEFtjxAdZ+6Yfcxe2zZfnSX2jPa9DyEG4K0mPqH622W/BtSyTfOXbMXLAN5F236pMAIHQKzbP09afjGs6co= 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=gjdjKpuLjuAtydjhOfFD6awEjJ1eLXw+nsEl8qgmQI0=; b=C9kRNHA9mMOCaoKvdRZwp7U72oshQ6HR/Ny2tD3XJWlNUO1KO6yFJS3PaFtPpGUPHzuT8v mPLa4wKhcgctRylw4kjg7xmBhPc28rdgO0jZtt7OznrJeI7Autxc9FDkDvE8Q9fALsf/qZ kPvPAylYjdYP7o/vEVggAtVYXX8bcRE= Received: from mail-lf1-f71.google.com (mail-lf1-f71.google.com [209.85.167.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-477-mu5KIGlyOaKWd3Y31V-6Og-1; Tue, 08 Oct 2024 13:11:59 -0400 X-MC-Unique: mu5KIGlyOaKWd3Y31V-6Og-1 Received: by mail-lf1-f71.google.com with SMTP id 2adb3069b0e04-5398b8cb3cdso4376900e87.1 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=1728407517; x=1729012317; 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=gjdjKpuLjuAtydjhOfFD6awEjJ1eLXw+nsEl8qgmQI0=; b=VbX4VgsJ2t+lg/El/brrVg9IaCvOgJvpkP64MAt2ZKkCyxOF5gYz5Kh5Rif9bsszZc /nYou34G2qbDH5q52bK4mwIB6DE/1MaFNAQ1UC6cP7gOjKvV9FFptDNtDCeiDwL08PZL AFxa6ujgvdVuZd8TWLzOlI0m0PMSZHTv8Gdo4ggkvvuc4cDy+pBznVqg+tyblblxOyXV lcL9bRGB4PSTQh1b+6MYrQ9y9/94Rrjy5oj45vHVUeJiYXwnr2OFQTOS2o4LWhkjofq2 Y8bDIQ4zG9er6Uih/lx1nl7aVjQ057neJCtEkUQnK41JdQARNziKzP/Zj7UQsefnrTS6 AUqg== X-Gm-Message-State: AOJu0Yy5mj4ANhgeqiyDYWaafv6T/pVjjLbzXfjrXyW9ax8up9I3cL9U /iAWUjoDQS1qcPkzwTXe9P+JSw0TB83M+NXqOzeHTbP3h09WJSSjAU/e85gfc71tXI5po3sdEb4 RxcjxXijJsJ9trddEFRx+cu73RvxH+j4+P2fCACMk3LjvMgwP7MbYeMHpV2NtVonF4YP1+euaqR nQ9AO7mjtRWzFluKaGV0ECiJXpm0y7rKUIRfVojZX7jnw= X-Received: by 2002:a05:6512:3190:b0:52e:be84:225c with SMTP id 2adb3069b0e04-539ab88af0fmr7560009e87.33.1728407516831; Tue, 08 Oct 2024 10:11:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFgdWksUHx9OZhIW7hMDsZPJ21VB00/1kNo5oWjwJ9xAP+WM60m6plgKpQFBoQ5KArfIY3fOA== X-Received: by 2002:a05:6512:3190:b0:52e:be84:225c with SMTP id 2adb3069b0e04-539ab88af0fmr7559976e87.33.1728407516094; Tue, 08 Oct 2024 10:11:56 -0700 (PDT) Received: from localhost ([195.213.152.26]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a996274deeesm175885866b.103.2024.10.08.10.11.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Oct 2024 10:11:55 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess , Luis Machado Subject: [PATCH 3/5] gdb: split osabi support between gdb/ and gdbsupport/ directories Date: Tue, 8 Oct 2024 18:11:48 +0100 Message-Id: <63b58681b3abc4ef52c2b17c10bcb26a1a5033ea.1728407374.git.aburgess@redhat.com> 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.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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 In future commits I want to call set_tdesc_osabi from gdbserver/ code. Currently the only version of set_tdesc_osabi available to gdbserver takes a string representing the osabi. The problem with this is that, having lots of calls to set_tdesc_osabi which all take a string is an invite for a typo to slip in. This typo could potentially go unnoticed until someone tries to debug the wrong combination of GDB and gdbserver, at which point GDB will fail to find the correct gdbarch because it doesn't understand the osabi string. It would be better if the set_tdesc_osabi calls in gdbserver could take an 'enum gdb_osabi' value and then convert this to the "correct" string internally. In this was we are guaranteed to always have a valid, known, osabi string. This commit splits the osabi related code, which currently lives entirely on the GDB wide, between gdb/ and gdbsupport/. I've moved the enum definition along with the array of osabi names into gdbsupport/. Then all the functions that access the names list, and which convert between names and enum values are also moved. I've taken the opportunity of this move to add a '.def' file which contains all the enum names along with the name strings. This '.def' file is then used to create 'enum gdb_osabi' as well as the array of osabi name strings. By using a '.def' file we know that the enum order will always match the name string array. This commit is just a refactor, there are no user visible changes after this commit. This commit doesn't change how gdbserver sets the target description osabi string, that will come in the next commit. --- gdb/osabi.c | 91 ---------------------------------- gdb/osabi.h | 41 +--------------- gdbsupport/Makefile.am | 1 + gdbsupport/Makefile.in | 15 +++--- gdbsupport/osabi-common.cc | 98 +++++++++++++++++++++++++++++++++++++ gdbsupport/osabi-common.def | 57 +++++++++++++++++++++ gdbsupport/osabi-common.h | 54 ++++++++++++++++++++ 7 files changed, 220 insertions(+), 137 deletions(-) create mode 100644 gdbsupport/osabi-common.cc create mode 100644 gdbsupport/osabi-common.def create mode 100644 gdbsupport/osabi-common.h diff --git a/gdb/osabi.c b/gdb/osabi.c index 8a1efce4599..6c00228fb4a 100644 --- a/gdb/osabi.c +++ b/gdb/osabi.c @@ -42,93 +42,6 @@ static const char *gdb_osabi_available_names[GDB_OSABI_INVALID + 3] = { }; static const char *set_osabi_string; -/* Names associated with each osabi. */ - -struct osabi_names -{ - /* The "pretty" name. */ - - const char *pretty; - - /* The triplet regexp, or NULL if not known. */ - - const char *regexp; -}; - -/* This table matches the indices assigned to enum gdb_osabi. Keep - them in sync. */ -static const struct osabi_names gdb_osabi_names[] = -{ - { "unknown", NULL }, - { "none", NULL }, - - { "SVR4", NULL }, - { "GNU/Hurd", NULL }, - { "Solaris", NULL }, - { "GNU/Linux", "linux(-gnu[^-]*)?" }, - { "FreeBSD", NULL }, - { "NetBSD", NULL }, - { "OpenBSD", NULL }, - { "WindowsCE", NULL }, - { "DJGPP", NULL }, - { "Cygwin", NULL }, - { "Windows", NULL }, - { "AIX", NULL }, - { "DICOS", NULL }, - { "Darwin", NULL }, - { "OpenVMS", NULL }, - { "LynxOS178", NULL }, - { "Newlib", NULL }, - { "SDE", NULL }, - { "PikeOS", NULL }, - - { "", NULL } -}; - -const char * -gdbarch_osabi_name (enum gdb_osabi osabi) -{ - if (osabi >= GDB_OSABI_UNKNOWN && osabi < GDB_OSABI_INVALID) - return gdb_osabi_names[osabi].pretty; - - return gdb_osabi_names[GDB_OSABI_INVALID].pretty; -} - -/* See osabi.h. */ - -const char * -osabi_triplet_regexp (enum gdb_osabi osabi) -{ - if (osabi >= GDB_OSABI_UNKNOWN && osabi < GDB_OSABI_INVALID) - return gdb_osabi_names[osabi].regexp; - - return gdb_osabi_names[GDB_OSABI_INVALID].regexp; -} - -/* Lookup the OS ABI corresponding to the specified target description - string. */ - -enum gdb_osabi -osabi_from_tdesc_string (const char *name) -{ - int i; - - for (i = 0; i < ARRAY_SIZE (gdb_osabi_names); i++) - if (strcmp (name, gdb_osabi_names[i].pretty) == 0) - { - /* See note above: the name table matches the indices assigned - to enum gdb_osabi. */ - enum gdb_osabi osabi = (enum gdb_osabi) i; - - if (osabi == GDB_OSABI_INVALID) - return GDB_OSABI_UNKNOWN; - else - return osabi; - } - - return GDB_OSABI_UNKNOWN; -} - /* Handler for a given architecture/OS ABI pair. There should be only one handler for a given OS ABI each architecture family. */ struct gdb_osabi_handler @@ -671,10 +584,6 @@ void _initialize_gdb_osabi (); void _initialize_gdb_osabi () { - if (strcmp (gdb_osabi_names[GDB_OSABI_INVALID].pretty, "") != 0) - internal_error - (_("_initialize_gdb_osabi: gdb_osabi_names[] is inconsistent")); - /* Register a generic sniffer for ELF flavoured files. */ gdbarch_register_osabi_sniffer (bfd_arch_unknown, bfd_target_elf_flavour, diff --git a/gdb/osabi.h b/gdb/osabi.h index d2b1a359098..984bdd4e5dc 100644 --- a/gdb/osabi.h +++ b/gdb/osabi.h @@ -19,35 +19,7 @@ #ifndef OSABI_H #define OSABI_H -/* * List of known OS ABIs. If you change this, make sure to update the - table in osabi.c. */ -enum gdb_osabi -{ - GDB_OSABI_UNKNOWN = 0, /* keep this zero */ - GDB_OSABI_NONE, - - GDB_OSABI_SVR4, - GDB_OSABI_HURD, - GDB_OSABI_SOLARIS, - GDB_OSABI_LINUX, - GDB_OSABI_FREEBSD, - GDB_OSABI_NETBSD, - GDB_OSABI_OPENBSD, - GDB_OSABI_WINCE, - GDB_OSABI_GO32, - GDB_OSABI_CYGWIN, - GDB_OSABI_WINDOWS, - GDB_OSABI_AIX, - GDB_OSABI_DICOS, - GDB_OSABI_DARWIN, - GDB_OSABI_OPENVMS, - GDB_OSABI_LYNXOS178, - GDB_OSABI_NEWLIB, - GDB_OSABI_SDE, - GDB_OSABI_PIKEOS, - - GDB_OSABI_INVALID /* keep this last */ -}; +#include "gdbsupport/osabi-common.h" /* Register an OS ABI sniffer. Each arch/flavour may have more than one sniffer. This is used to e.g. differentiate one OS's a.out from @@ -69,23 +41,12 @@ void gdbarch_register_osabi (enum bfd_architecture, unsigned long, /* Lookup the OS ABI corresponding to the specified BFD. */ enum gdb_osabi gdbarch_lookup_osabi (bfd *); -/* Lookup the OS ABI corresponding to the specified target description - string. */ -enum gdb_osabi osabi_from_tdesc_string (const char *text); - /* Return true if there's an OS ABI handler for INFO. */ bool has_gdb_osabi_handler (struct gdbarch_info info); /* Initialize the gdbarch for the specified OS ABI variant. */ void gdbarch_init_osabi (struct gdbarch_info, struct gdbarch *); -/* Return the name of the specified OS ABI. */ -const char *gdbarch_osabi_name (enum gdb_osabi); - -/* Return a regular expression that matches the OS part of a GNU - configury triplet for the given OSABI. */ -const char *osabi_triplet_regexp (enum gdb_osabi osabi); - /* Helper routine for ELF file sniffers. This looks at ABI tag note sections to determine the OS ABI from the note. */ void generic_elf_osabi_sniff_abi_tag_sections (bfd *, asection *, diff --git a/gdbsupport/Makefile.am b/gdbsupport/Makefile.am index 36e561e015d..d2e2299cc3f 100644 --- a/gdbsupport/Makefile.am +++ b/gdbsupport/Makefile.am @@ -76,6 +76,7 @@ libgdbsupport_a_SOURCES = \ job-control.cc \ netstuff.cc \ new-op.cc \ + osabi-common.cc \ pathstuff.cc \ print-utils.cc \ ptid.cc \ diff --git a/gdbsupport/Makefile.in b/gdbsupport/Makefile.in index 9cff86bd987..c0d406c3a35 100644 --- a/gdbsupport/Makefile.in +++ b/gdbsupport/Makefile.in @@ -162,12 +162,13 @@ am_libgdbsupport_a_OBJECTS = agent.$(OBJEXT) btrace-common.$(OBJEXT) \ gdb-dlfcn.$(OBJEXT) gdb_obstack.$(OBJEXT) gdb_regex.$(OBJEXT) \ gdb_tilde_expand.$(OBJEXT) gdb_wait.$(OBJEXT) \ gdb_vecs.$(OBJEXT) job-control.$(OBJEXT) netstuff.$(OBJEXT) \ - new-op.$(OBJEXT) pathstuff.$(OBJEXT) print-utils.$(OBJEXT) \ - ptid.$(OBJEXT) rsp-low.$(OBJEXT) run-time-clock.$(OBJEXT) \ - safe-strerror.$(OBJEXT) scoped_mmap.$(OBJEXT) search.$(OBJEXT) \ - signals.$(OBJEXT) signals-state-save-restore.$(OBJEXT) \ - task-group.$(OBJEXT) tdesc.$(OBJEXT) thread-pool.$(OBJEXT) \ - xml-utils.$(OBJEXT) $(am__objects_1) $(am__objects_2) + new-op.$(OBJEXT) osabi-common.$(OBJEXT) pathstuff.$(OBJEXT) \ + print-utils.$(OBJEXT) ptid.$(OBJEXT) rsp-low.$(OBJEXT) \ + run-time-clock.$(OBJEXT) safe-strerror.$(OBJEXT) \ + scoped_mmap.$(OBJEXT) search.$(OBJEXT) signals.$(OBJEXT) \ + signals-state-save-restore.$(OBJEXT) task-group.$(OBJEXT) \ + tdesc.$(OBJEXT) thread-pool.$(OBJEXT) xml-utils.$(OBJEXT) \ + $(am__objects_1) $(am__objects_2) libgdbsupport_a_OBJECTS = $(am_libgdbsupport_a_OBJECTS) AM_V_P = $(am__v_P_@AM_V@) am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) @@ -433,6 +434,7 @@ libgdbsupport_a_SOURCES = \ job-control.cc \ netstuff.cc \ new-op.cc \ + osabi-common.cc \ pathstuff.cc \ print-utils.cc \ ptid.cc \ @@ -542,6 +544,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/job-control.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/netstuff.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/new-op.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/osabi-common.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pathstuff.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/print-utils.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ptid.Po@am__quote@ diff --git a/gdbsupport/osabi-common.cc b/gdbsupport/osabi-common.cc new file mode 100644 index 00000000000..785eb478664 --- /dev/null +++ b/gdbsupport/osabi-common.cc @@ -0,0 +1,98 @@ +/* OS ABI variant handling for GDB and gdbserver. + + Copyright (C) 2001-2024 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include "gdbsupport/osabi-common.h" + +/* Names associated with each osabi. */ + +struct osabi_names +{ + /* The "pretty" name. */ + + const char *pretty; + + /* The triplet regexp, or NULL if not known. */ + + const char *regexp; +}; + +/* This table matches the indices assigned to enum gdb_osabi. Keep + them in sync. */ +static const struct osabi_names gdb_osabi_names[] = +{ +#define GDB_OSABI_DEF_FIRST(Enum, Name, Regex) \ + { Name, Regex }, + +#define GDB_OSABI_DEF(Enum, Name, Regex) \ + { Name, Regex }, + +#define GDB_OSABI_DEF_LAST(Enum, Name, Regex) \ + { Name, Regex } + +#include "gdbsupport/osabi-common.def" + +#undef GDB_OSABI_DEF_LAST +#undef GDB_OSABI_DEF +#undef GDB_OSABI_DEF_FIRST +}; + +/* See gdbsupport/osabi-common.h. */ + +const char * +gdbarch_osabi_name (enum gdb_osabi osabi) +{ + if (osabi >= GDB_OSABI_UNKNOWN && osabi < GDB_OSABI_INVALID) + return gdb_osabi_names[osabi].pretty; + + return gdb_osabi_names[GDB_OSABI_INVALID].pretty; +} + +/* See gdbsupport/osabi-commomn.h. */ + +enum gdb_osabi +osabi_from_tdesc_string (const char *name) +{ + int i; + + for (i = 0; i < ARRAY_SIZE (gdb_osabi_names); i++) + if (strcmp (name, gdb_osabi_names[i].pretty) == 0) + { + /* See note above: the name table matches the indices assigned + to enum gdb_osabi. */ + enum gdb_osabi osabi = (enum gdb_osabi) i; + + if (osabi == GDB_OSABI_INVALID) + return GDB_OSABI_UNKNOWN; + else + return osabi; + } + + return GDB_OSABI_UNKNOWN; +} + +/* See gdbsupport/osabi-common.h. */ + +const char * +osabi_triplet_regexp (enum gdb_osabi osabi) +{ + if (osabi >= GDB_OSABI_UNKNOWN && osabi < GDB_OSABI_INVALID) + return gdb_osabi_names[osabi].regexp; + + return gdb_osabi_names[GDB_OSABI_INVALID].regexp; +} diff --git a/gdbsupport/osabi-common.def b/gdbsupport/osabi-common.def new file mode 100644 index 00000000000..637da26a050 --- /dev/null +++ b/gdbsupport/osabi-common.def @@ -0,0 +1,57 @@ +/* OS ABI variant definitions for GDB and gdbserver. + + Copyright (C) 2001-2024 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Each definition in this file is an osabi known to GDB. + + The first argument is used to create the enum name and is appended + to 'GDB_OSABI_'. + + The second argument is the osabi name. These strings can't be + changed _ever_ as gdbserver will emit these. Changing these + strings would break compatibility with already released versions of + GDB and/or gdbserver. + + The third argument is a regexp which matches against a target + triplet. */ + +GDB_OSABI_DEF_FIRST (UNKNOWN, "unknown", nullptr) + +GDB_OSABI_DEF (NONE, "none", nullptr) + +GDB_OSABI_DEF (SVR4, "SVR4", nullptr) +GDB_OSABI_DEF (HURD, "GNU/Hurd", nullptr) +GDB_OSABI_DEF (SOLARIS, "Solaris", nullptr) +GDB_OSABI_DEF (LINUX, "GNU/Linux", "linux(-gnu[^-]*)?") +GDB_OSABI_DEF (FREEBSD, "FreeBSD", nullptr) +GDB_OSABI_DEF (NETBSD, "NetBSD", nullptr) +GDB_OSABI_DEF (OPENBSD, "OpenBSD", nullptr) +GDB_OSABI_DEF (WINCE, "WindowsCE", nullptr) +GDB_OSABI_DEF (GO32, "DJGPP", nullptr) +GDB_OSABI_DEF (CYGWIN, "Cygwin", nullptr) +GDB_OSABI_DEF (WINDOWS, "Windows", nullptr) +GDB_OSABI_DEF (AIX, "AIX", nullptr) +GDB_OSABI_DEF (DICOS, "DICOS", nullptr) +GDB_OSABI_DEF (DARWIN, "Darwin", nullptr) +GDB_OSABI_DEF (OPENVMS, "OpenVMS", nullptr) +GDB_OSABI_DEF (LYNXOS178, "LynxOS178", nullptr) +GDB_OSABI_DEF (NEWLIB, "Newlib", nullptr) +GDB_OSABI_DEF (SDE, "SDE", nullptr) +GDB_OSABI_DEF (PIKEOS, "PikeOS", nullptr) + +GDB_OSABI_DEF_LAST (INVALID, "", nullptr) diff --git a/gdbsupport/osabi-common.h b/gdbsupport/osabi-common.h new file mode 100644 index 00000000000..99318eb0ca7 --- /dev/null +++ b/gdbsupport/osabi-common.h @@ -0,0 +1,54 @@ +/* OS ABI variant handling for GDB and gdbserver. + + Copyright (C) 2001-2024 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#ifndef OSABI_COMMON_H +#define OSABI_COMMON_H + +/* List of known OS ABIs. If you change this, make sure to update the + table in osabi-common.cc. */ +enum gdb_osabi +{ +#define GDB_OSABI_DEF_FIRST(Enum, Name, Regex) \ + GDB_OSABI_ ## Enum = 0, + +#define GDB_OSABI_DEF(Enum, Name, Regex) \ + GDB_OSABI_ ## Enum, + +#define GDB_OSABI_DEF_LAST(Enum, Name, Regex) \ + GDB_OSABI_ ## Enum + +#include "gdbsupport/osabi-common.def" + +#undef GDB_OSABI_DEF_LAST +#undef GDB_OSABI_DEF +#undef GDB_OSABI_DEF_FIRST +}; + +/* Lookup the OS ABI corresponding to the specified target description + string. */ +enum gdb_osabi osabi_from_tdesc_string (const char *text); + +/* Return the name of the specified OS ABI. */ +const char *gdbarch_osabi_name (enum gdb_osabi); + +/* Return a regular expression that matches the OS part of a GNU + configury triplet for the given OSABI. */ +const char *osabi_triplet_regexp (enum gdb_osabi osabi); + +#endif /* OSABI_COMMON_H */ 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. */ From patchwork Tue Oct 8 17:11:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 98549 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 32721384F4B8 for ; Tue, 8 Oct 2024 17:13:12 +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.133.124]) by sourceware.org (Postfix) with ESMTP id 4B91A385DDF5 for ; Tue, 8 Oct 2024 17:12:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4B91A385DDF5 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 4B91A385DDF5 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728407529; cv=none; b=e0HZ4Sds2zs3y7ZH8/et/2o2NGUiN/5BsbsjlO3KKCcQFh/Lmub//jRHOhAulBkizHMJy8O/TU5sBOxd5sQ3PXZ/Y+yzKmcPrs2uB5KRFxjFSLQgT+JckZfkQcLJXX7Fhh2Hqtyrn2C+4hlIRabrkhZJfCIE+LGAAfNFDnwnbBw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728407529; c=relaxed/simple; bh=4q8Ox2A0lW3KP7GEgDGXipzN7kjh5m/+KZ04GuEeEpk=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=xWfvwtK0XOozR/1DDUa7GGjtT0Gc4LXk44HoZgSUDmUigtqvfLXmL+Kf6Ea+XzKvhP+PAbe2GAwxmEbaS/Boo25KqntApzG7x2xnl7PsK6PsaKiYjwy0HEZY53KDKucSz91LAdVlh0MJyrL78HOAR4Q1iujYiSCVG31Y2keh5cg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728407527; 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=bPEJYem4WgFmclWuNHvA8qA4XIRsM4W1JKmmn/giCzQ=; b=Q/60wIYHaPjfnTveqIIydL9HALNgs6totEEP6XnF2APmdGUFgCCGltQ2hYoDXq5qDvT/9j IR4XXJ7qjTwRo0SGpgG+TrpTaIIL+u3/7b3f/XX/2uud6tk4NS46MVHls3HU866NSXzFmo bTK7zDdPgxlftXOZNJovt/u+/UQ7WeA= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-56-L-aoKhOhMkyrOiEbvOVinw-1; Tue, 08 Oct 2024 13:12:00 -0400 X-MC-Unique: L-aoKhOhMkyrOiEbvOVinw-1 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-a998130e58eso27487466b.3 for ; Tue, 08 Oct 2024 10:12:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728407519; x=1729012319; 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=bPEJYem4WgFmclWuNHvA8qA4XIRsM4W1JKmmn/giCzQ=; b=kegluRwoB0fToHhScNIzj5DWBmXjvmnco8WLoi5P793tFUQBLmcG4bSr8tjWR6V/fw MD0S9B3mHKlFMKUKqvYcPPCmRII1JUt6hz9LeT1KPmIHz6SvpKPPYiGMPgr7sixAVf1/ 7ZAC6OM5LWQSMRzZAOURhu3Vw/2neeDoyKEiluzN4RE9u7z9jW2TMreOpjTlDt6rb0tN FELmqmPCwZpjkNFZUYztQOlI6mnKkNBssUCAVAVzLaWZLhLISezuqV4OPuUMIlE2y1eT KdCxonHYAgZO+/tDETw/RQrP41MsSY0INTfP2my3qs0cB6V6SCrCe1Q6GKhIG29u/dIc V3tw== X-Gm-Message-State: AOJu0YzcKQS18OsNZgSOjuY29nxdxBqC6S7/sQtv0D4RuIGuPxnDB/i1 kEXHuJxl2ir8Zo2k8BdQx/5fMu6oNlzsplxbQYzNcr0hzzP1pIUNcmGfhV2/PuHFDeF195F/Mfu LIB5kFW1cURMseC/wkEgdOYi5dlk5R7UrOOaIiAhJHxZDxU4bcrDxqaP99MJtH9LnTtPLY8AB/8 d5Z/kcK3AkNx8ONCPtvXeePqOnUrUxF0aGNd9cVVfS5gs= X-Received: by 2002:a17:907:1c15:b0:a99:5eee:f2eb with SMTP id a640c23a62f3a-a995eeef599mr614888866b.5.1728407518960; Tue, 08 Oct 2024 10:11:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGDB8ghdGYtOV5jTnN8wrcYSnPIYpdJxkilUjySm9DdvejQnqdBOukSSTTZaG0FvHTkj1hfNg== X-Received: by 2002:a17:907:1c15:b0:a99:5eee:f2eb with SMTP id a640c23a62f3a-a995eeef599mr614885466b.5.1728407518403; Tue, 08 Oct 2024 10:11:58 -0700 (PDT) Received: from localhost ([195.213.152.26]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a994cf480a6sm357124766b.100.2024.10.08.10.11.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Oct 2024 10:11:58 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess , Luis Machado Subject: [PATCH 5/5] gdbserver: pass osabi to GDB in target description Date: Tue, 8 Oct 2024 18:11:50 +0100 Message-Id: <77fa25e6f6fd213f89ebceb7c1fcf33010cc8e39.1728407374.git.aburgess@redhat.com> 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.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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 On a Windows machine I built gdbserver, configured for the target 'x86_64-w64-mingw32', then on a GNU/Linux machine I built GDB with support for all target (--enable-targets=all). On the Windows machine I start gdbserver with a small test binary: $ gdbserver 192.168.129.25:54321 C:\some\directory\executable.exe On the GNU/Linux machine I start GDB without the test binary, and connect to gdbserver. As I have not given GDB the test binary, my expectation is that GDB would connect to gdbserver and then download the file over the remote protocol, but instead I was presented with this message: (gdb) target remote 192.168.129.25:54321 Remote debugging using 192.168.129.25:54321 warning: C:\some\directory\executable.exe: No such file or directory. 0x00007ffa3e1e1741 in ?? () (gdb) What I found is that if I told GDB where to find the binary, like this: (gdb) file target:C:/some/directory/executable.exe A program is being debugged already. Are you sure you want to change the file? (y or n) y Reading C:/some/directory/executable.exe from remote target... warning: File transfers from remote targets can be slow. Use "set sysroot" to access files locally instead. Reading C:/some/directory/executable.exe from remote target... Reading symbols from target:C:/some/directory/executable.exe... (gdb) then GDB would download the executable. I eventually tracked the problem down to exec_file_find (solib.c). The remote target was passing an absolute Windows filename (beginning with "C:/" in this case), but in exec_file_find GDB was failing the IS_TARGET_ABSOLUTE_PATH call, and so was treating the filename as relative. The IS_TARGET_ABSOLUTE_PATH call was failing because GDB thought that the file system kind was "unix", and as the filename didn't start with a "/" it assumed the filename was not absolute. But I'm connecting to a Windows target, my 'target-file-system-kind' was set to "auto", so should be figuring out that my file-system is "dos-based". Looking in effective_target_file_system_kind (filesystem.c), we find that the logic of "auto" is delegated to the current gdbarch. However in windows-tdep.c we see: set_gdbarch_has_dos_based_file_system (gdbarch, 1); So if we are using a Windows gdbarch we should have "dos-based" filesystems. What this means is that after connecting to the remote target GDB has selected the wrong gdbarch. What's happening is that the target description sent back by the remote target only includes the x86-64 registers. There's no information about which OS we're on. As a consequence, GDB picks the first x86-64 gdbarch which can handle the provided register set, which happens to be a GNU/Linux gdbarch. And indeed, there doesn't appear to be anywhere in gdbserver that sets the osabi on the target descriptions, though some target descriptions do have their osabi set when the description is created, e.g. in: gdb/arch/amd64.c - Sets GNU/Linux osabi when appropriate. gdb/arch/i386.c - Likewise. gdb/arch/tic6x.c - Always set GNU/Linux osabi. Most target descriptions are created without an osabi, gdbserver does nothing to fix this, and the description is returned to GDB without an osabi included. I propose that we always set the osabi name on the target descriptions returned from gdbserver. We could try to do this when the description is first created, but that would mean passing extra flags into the tdesc creation code (or just passing the osabi string in), and I don't think that's really necessary. If we consider the tdesc creation as being about figuring out which registers are on the target, then it makes sense that the osabi information is injected later. So what I've done is require the osabi name to be passed to the init_target_desc function. This is called, I believe, for all targets, in the gdbserver code. Now when I connect to the Windows remote the target description returned includes the osabi name. With this extra information GDB selects the correct gdbarch object, which means that GDB understands the target has a "dos-based" file-system. With that correct GDB understands that the filename it was given is absolute, and so fetches the file from the remote as we'd like. --- gdbserver/linux-aarch32-tdesc.cc | 2 +- gdbserver/linux-aarch64-tdesc.cc | 3 ++- gdbserver/linux-arc-low.cc | 2 +- gdbserver/linux-arm-tdesc.cc | 2 +- gdbserver/linux-csky-low.cc | 2 +- gdbserver/linux-loongarch-low.cc | 2 +- gdbserver/linux-riscv-low.cc | 2 +- gdbserver/linux-tic6x-low.cc | 2 +- gdbserver/linux-x86-tdesc.cc | 15 +++++++++++++-- gdbserver/netbsd-aarch64-low.cc | 2 +- gdbserver/netbsd-amd64-low.cc | 2 +- gdbserver/netbsd-i386-low.cc | 2 +- gdbserver/tdesc.cc | 5 ++++- gdbserver/tdesc.h | 5 +++-- gdbserver/win32-i386-low.cc | 4 ++-- gdbserver/win32-low.h | 7 +++++++ 16 files changed, 41 insertions(+), 18 deletions(-) diff --git a/gdbserver/linux-aarch32-tdesc.cc b/gdbserver/linux-aarch32-tdesc.cc index b8987752b9f..441fe668e6a 100644 --- a/gdbserver/linux-aarch32-tdesc.cc +++ b/gdbserver/linux-aarch32-tdesc.cc @@ -34,7 +34,7 @@ aarch32_linux_read_description () tdesc_aarch32 = aarch32_create_target_description (false); static const char *expedite_regs[] = { "r11", "sp", "pc", 0 }; - init_target_desc (tdesc_aarch32, expedite_regs); + init_target_desc (tdesc_aarch32, expedite_regs, GDB_OSABI_LINUX); } return tdesc_aarch32; } diff --git a/gdbserver/linux-aarch64-tdesc.cc b/gdbserver/linux-aarch64-tdesc.cc index 31ec7854cc0..39d5bccdce1 100644 --- a/gdbserver/linux-aarch64-tdesc.cc +++ b/gdbserver/linux-aarch64-tdesc.cc @@ -67,7 +67,8 @@ aarch64_linux_read_description (const aarch64_features &features) expedited_registers.push_back (nullptr); - init_target_desc (tdesc, (const char **) expedited_registers.data ()); + init_target_desc (tdesc, (const char **) expedited_registers.data (), + GDB_OSABI_LINUX); tdesc_aarch64_map[features] = tdesc; } diff --git a/gdbserver/linux-arc-low.cc b/gdbserver/linux-arc-low.cc index dda224f0a74..798c535aee8 100644 --- a/gdbserver/linux-arc-low.cc +++ b/gdbserver/linux-arc-low.cc @@ -114,7 +114,7 @@ arc_linux_read_description (void) target_desc_up tdesc = arc_create_target_description (features); static const char *expedite_regs[] = { "sp", "status32", nullptr }; - init_target_desc (tdesc.get (), expedite_regs); + init_target_desc (tdesc.get (), expedite_regs, GDB_OSABI_LINUX); return tdesc.release (); } diff --git a/gdbserver/linux-arm-tdesc.cc b/gdbserver/linux-arm-tdesc.cc index 559f9b0f3dc..fff2e948f81 100644 --- a/gdbserver/linux-arm-tdesc.cc +++ b/gdbserver/linux-arm-tdesc.cc @@ -37,7 +37,7 @@ arm_linux_read_description (arm_fp_type fp_type) tdesc = arm_create_target_description (fp_type, false); static const char *expedite_regs[] = { "r11", "sp", "pc", 0 }; - init_target_desc (tdesc, expedite_regs); + init_target_desc (tdesc, expedite_regs, GDB_OSABI_LINUX); tdesc_arm_list[fp_type] = tdesc; } diff --git a/gdbserver/linux-csky-low.cc b/gdbserver/linux-csky-low.cc index 2eb5a2df17b..18a0d152b5a 100644 --- a/gdbserver/linux-csky-low.cc +++ b/gdbserver/linux-csky-low.cc @@ -133,7 +133,7 @@ csky_target::low_arch_setup () if (tdesc->expedite_regs.empty ()) { - init_target_desc (tdesc.get (), expedite_regs); + init_target_desc (tdesc.get (), expedite_regs, GDB_OSABI_LINUX); gdb_assert (!tdesc->expedite_regs.empty ()); } diff --git a/gdbserver/linux-loongarch-low.cc b/gdbserver/linux-loongarch-low.cc index 584ea64a7d9..cf7d6c0743c 100644 --- a/gdbserver/linux-loongarch-low.cc +++ b/gdbserver/linux-loongarch-low.cc @@ -85,7 +85,7 @@ loongarch_target::low_arch_setup () if (tdesc->expedite_regs.empty ()) { - init_target_desc (tdesc.get (), expedite_regs); + init_target_desc (tdesc.get (), expedite_regs, GDB_OSABI_LINUX); gdb_assert (!tdesc->expedite_regs.empty ()); } current_process ()->tdesc = tdesc.release (); diff --git a/gdbserver/linux-riscv-low.cc b/gdbserver/linux-riscv-low.cc index c4554c507a8..7170ad9922e 100644 --- a/gdbserver/linux-riscv-low.cc +++ b/gdbserver/linux-riscv-low.cc @@ -91,7 +91,7 @@ riscv_target::low_arch_setup () if (tdesc->expedite_regs.empty ()) { - init_target_desc (tdesc.get (), expedite_regs); + init_target_desc (tdesc.get (), expedite_regs, GDB_OSABI_LINUX); gdb_assert (!tdesc->expedite_regs.empty ()); } diff --git a/gdbserver/linux-tic6x-low.cc b/gdbserver/linux-tic6x-low.cc index 707be2e7b0f..754dd00590c 100644 --- a/gdbserver/linux-tic6x-low.cc +++ b/gdbserver/linux-tic6x-low.cc @@ -228,7 +228,7 @@ tic6x_read_description (enum c6x_feature feature) { *tdesc = tic6x_create_target_description (feature); static const char *expedite_regs[] = { "A15", "PC", NULL }; - init_target_desc (*tdesc, expedite_regs); + init_target_desc (*tdesc, expedite_regs, GDB_OSABI_LINUX); } return *tdesc; diff --git a/gdbserver/linux-x86-tdesc.cc b/gdbserver/linux-x86-tdesc.cc index 13c80762605..6aa5c4ab970 100644 --- a/gdbserver/linux-x86-tdesc.cc +++ b/gdbserver/linux-x86-tdesc.cc @@ -26,10 +26,21 @@ void x86_linux_post_init_tdesc (target_desc *tdesc, bool is_64bit) { + enum gdb_osabi osabi = GDB_OSABI_LINUX; + +#ifndef IN_PROCESS_AGENT + /* x86 target descriptions are created with the osabi already set. + However, init_target_desc requires us to override the already set + value. That's fine, out new string should match the old one. */ + gdb_assert (tdesc_osabi_name (tdesc) != nullptr); + gdb_assert (strcmp (tdesc_osabi_name (tdesc), + gdbarch_osabi_name (osabi)) == 0); +#endif /* ! IN_PROCESS_AGENT */ + #ifdef __x86_64__ if (is_64bit) - init_target_desc (tdesc, amd64_expedite_regs); + init_target_desc (tdesc, amd64_expedite_regs, osabi); else #endif - init_target_desc (tdesc, i386_expedite_regs); + init_target_desc (tdesc, i386_expedite_regs, osabi); } diff --git a/gdbserver/netbsd-aarch64-low.cc b/gdbserver/netbsd-aarch64-low.cc index f20a1a71773..8834e0ad894 100644 --- a/gdbserver/netbsd-aarch64-low.cc +++ b/gdbserver/netbsd-aarch64-low.cc @@ -98,7 +98,7 @@ netbsd_aarch64_target::low_arch_setup () = aarch64_create_target_description ({}); static const char *expedite_regs_aarch64[] = { "x29", "sp", "pc", NULL }; - init_target_desc (tdesc, expedite_regs_aarch64); + init_target_desc (tdesc, expedite_regs_aarch64, GDB_OSABI_NETBSD); current_process ()->tdesc = tdesc; } diff --git a/gdbserver/netbsd-amd64-low.cc b/gdbserver/netbsd-amd64-low.cc index b3f3aab5ec3..ad7cb430b92 100644 --- a/gdbserver/netbsd-amd64-low.cc +++ b/gdbserver/netbsd-amd64-low.cc @@ -193,7 +193,7 @@ netbsd_amd64_target::low_arch_setup () target_desc *tdesc = amd64_create_target_description (X86_XSTATE_SSE_MASK, false, false, false); - init_target_desc (tdesc, amd64_expedite_regs); + init_target_desc (tdesc, amd64_expedite_regs, GDB_OSABI_NETBSD); current_process ()->tdesc = tdesc; } diff --git a/gdbserver/netbsd-i386-low.cc b/gdbserver/netbsd-i386-low.cc index 247a39797c4..ea6fce4c6f9 100644 --- a/gdbserver/netbsd-i386-low.cc +++ b/gdbserver/netbsd-i386-low.cc @@ -142,7 +142,7 @@ netbsd_i386_target::low_arch_setup () target_desc *tdesc = i386_create_target_description (X86_XSTATE_SSE_MASK, false, false); - init_target_desc (tdesc, i386_expedite_regs); + init_target_desc (tdesc, i386_expedite_regs, GDB_OSABI_NETBSD); current_process ()->tdesc = tdesc; } diff --git a/gdbserver/tdesc.cc b/gdbserver/tdesc.cc index d052f43c76e..da1287abbbe 100644 --- a/gdbserver/tdesc.cc +++ b/gdbserver/tdesc.cc @@ -53,7 +53,8 @@ void target_desc::accept (tdesc_element_visitor &v) const void init_target_desc (struct target_desc *tdesc, - const char **expedite_regs) + const char **expedite_regs, + enum gdb_osabi osabi) { int offset = 0; @@ -88,6 +89,8 @@ init_target_desc (struct target_desc *tdesc, int expedite_count = 0; while (expedite_regs[expedite_count] != nullptr) tdesc->expedite_regs.push_back (expedite_regs[expedite_count++]); + + set_tdesc_osabi (tdesc, osabi); #endif } diff --git a/gdbserver/tdesc.h b/gdbserver/tdesc.h index 6fc37d038bc..80d9a9bebcb 100644 --- a/gdbserver/tdesc.h +++ b/gdbserver/tdesc.h @@ -81,10 +81,11 @@ void copy_target_description (struct target_desc *dest, const struct target_desc *src); /* Initialize TDESC, and then set its expedite_regs field to - EXPEDITE_REGS. */ + EXPEDITE_REGS. The osabi of TDESC is set to OSABI. */ void init_target_desc (struct target_desc *tdesc, - const char **expedite_regs); + const char **expedite_regs, + enum gdb_osabi osabi); /* Return the current inferior's target description. Never returns NULL. */ diff --git a/gdbserver/win32-i386-low.cc b/gdbserver/win32-i386-low.cc index 0a761ca58ef..13f9aca99b1 100644 --- a/gdbserver/win32-i386-low.cc +++ b/gdbserver/win32-i386-low.cc @@ -596,12 +596,12 @@ i386_arch_setup (void) #ifdef __x86_64__ tdesc = amd64_create_target_description (X86_XSTATE_SSE_MASK, false, false, false); - init_target_desc (tdesc, amd64_expedite_regs); + init_target_desc (tdesc, amd64_expedite_regs, WINDOWS_OSABI); win32_tdesc = tdesc; #endif tdesc = i386_create_target_description (X86_XSTATE_SSE_MASK, false, false); - init_target_desc (tdesc, i386_expedite_regs); + init_target_desc (tdesc, i386_expedite_regs, WINDOWS_OSABI); #ifdef __x86_64__ wow64_win32_tdesc = tdesc; #else diff --git a/gdbserver/win32-low.h b/gdbserver/win32-low.h index ff997df0a66..e0a09674518 100644 --- a/gdbserver/win32-low.h +++ b/gdbserver/win32-low.h @@ -21,6 +21,7 @@ #include #include "nat/windows-nat.h" +#include "gdbsupport/osabi-common.h" struct target_desc; @@ -31,6 +32,12 @@ extern const struct target_desc *win32_tdesc; extern const struct target_desc *wow64_win32_tdesc; #endif +#ifdef __CYGWIN__ +constexpr enum gdb_osabi WINDOWS_OSABI = GDB_OSABI_CYGWIN; +#else +constexpr enum gdb_osabi WINDOWS_OSABI = GDB_OSABI_WINDOWS; +#endif + struct win32_target_ops { /* Architecture-specific setup. */