From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id MSobCDtd6mi/mikAWB0awg (envelope-from ) for ; Sat, 11 Oct 2025 09:35:55 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=iVnv0tmq; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 1DF731E0B6; Sat, 11 Oct 2025 09:35:55 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.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,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (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 8C8BB1E047 for ; Sat, 11 Oct 2025 09:35:54 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3EE673857810 for ; Sat, 11 Oct 2025 13:35:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3EE673857810 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=iVnv0tmq 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 A14523857B9E for ; Sat, 11 Oct 2025 13:34:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A14523857B9E Authentication-Results: sourceware.org; dmarc=pass (p=quarantine 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 A14523857B9E 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=1760189659; cv=none; b=Yo5xm3iFRJOQObi+5bDjptHwq5RH8KxOhZQYTGVgqBaGpxopA8lKBqbYHyfeaZxzSyNJYLeJ//VS6TcfWhesCZuzsR6mAQSp9CoSfokulTS2AVhWSmWIpEdhJwYrTAxPMdmKwjHF0AEed1jzUsTV5noIWtVelu65T8X761mTcdg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1760189659; c=relaxed/simple; bh=FlAA71rCxtm+hN2wXIgg+PB1CulD1Ec/HJuvylpBGWo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=CbX3vxc1r4KX0p1RLtHGP32FLBYIpHij+Thdv0aQv7IE9AASoEoIzAoV4tP47phR86Vi4LeOCqCOzKLWFGL83e9/8rri4AVLr99Bq6udf7tYwdwaRbktiC6/BHIur/2ykACmnjg46M04j43DZQuDd+DPlru0Hdw1mgCvvXg6fyY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A14523857B9E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1760189659; 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=wWXl+xn/Oi24jMbQSodSe2tC0FZSJcP+YXPuyZ56aCs=; b=iVnv0tmqDHpv6qqeVWe7j8nAMj79FuVzaCzNUgTfxMw9DhXd8puaKWe66yHAc4ZBYK/71r N2YmKqrnMX025CEAeN/wcQNYJs0rIi5LPXobPrm5BYreRF3J7MLsYijnaKOqOnAmui/u5B tVcwVaJsTdnPVX08U8s28bG9p14q+jw= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-517-lGybAjREOrOQ4q6qvOYXww-1; Sat, 11 Oct 2025 09:34:18 -0400 X-MC-Unique: lGybAjREOrOQ4q6qvOYXww-1 X-Mimecast-MFC-AGG-ID: lGybAjREOrOQ4q6qvOYXww_1760189657 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-46e38957979so15126395e9.3 for ; Sat, 11 Oct 2025 06:34:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760189657; x=1760794457; 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=wWXl+xn/Oi24jMbQSodSe2tC0FZSJcP+YXPuyZ56aCs=; b=LQtLQjbmqDK8iOyxJ0xLd+OHVHLfH2Xzg+JYOusNlYFy2jfbiFYd1bcx9SSVacX2Sv 0M9ou2kAGyKNu75PPIbvyWSWEcl3frnudjsg7XwR04kpCif7PC+/em4dhcjCcjaPxgFD LHg5pWz5Xk959xM5a2HKl7kchBC2fYPoHlSK9SzvWFrMudbX6+kJkNe5upkKVnfoIE6d o2VfUaYshK2LT+mW+r2FkztRq3zVkXnDTnlZC9hdHENB7OT5Zhn/mHeeikCYuUmsxt+V XI859tLk5wQuWhJvg0koH2XqE2cv7LhaqUBYM3y8KRrCG3Oqhn1uQV9D/YaOVGn3Kfay OnKg== X-Gm-Message-State: AOJu0YwPbxnlLU233711f2bKyB/i28zee/Pyyhfke63cO+k7LCiCf/Y7 PzDTtCmXT9QPwXULM4qcPsny5JeLGQKqbiajuWvHITtAExpoOqBRSSoW4XYfy/+1EdiEzztOd/d UHRPl7tN2doQhlE3B1lfc1Cum9e7MXEwcD5Dj/6feeWZvNnJRIiRAfe+PXPLe2ZAP4CGEazER1S n+ILu9hYNX3suNeb9sERhrTG1SmKngdKXmzhQHi49Khky+A5o= X-Gm-Gg: ASbGncssfCBu1DTv8J4rxNUzBQooPNDNDaaeVWCytsEVhZYHEnBLrkQBbQSaqiPksDp tdO6+Qt7SC3J7+NY3Eq+AyE9XP6qRDs5862HB4q3RgRpUp2xJkKPv4ua4eZc+xaVYc7tqF3Y5A5 QHUyYvpM6D8BSzS++6+woXOnSTbFbEKpkiNB/duJROKBoqGpBvys+wVgxb1u/t8PxP/BXSw8z2c Wb7Ne0TIb9uE7oZEFjJ+1K0n4/LU/v1AYT/ZpxbFByV0+Mzghmx19hGYmM7ktNVt7VqsPAH5Bmc mQlcM5DbXizGUdTU+KSpg0dOD7Sr1s0X9r5Oc+MjZXAAhyGoyk0hFRLpWSvszs+H X-Received: by 2002:a05:600c:1384:b0:46e:45f7:34f3 with SMTP id 5b1f17b1804b1-46fa9a863cfmr96155995e9.8.1760189656681; Sat, 11 Oct 2025 06:34:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEPOxUdDflvcLkRVwIEx5U+5WxCMysJgbat+njVXfPbKByFhuEuSLdpVkUCT4QFc9A/7kLzTA== X-Received: by 2002:a05:600c:1384:b0:46e:45f7:34f3 with SMTP id 5b1f17b1804b1-46fa9a863cfmr96155815e9.8.1760189656155; Sat, 11 Oct 2025 06:34:16 -0700 (PDT) Received: from localhost (92.40.184.126.threembb.co.uk. [92.40.184.126]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-426ce5e81d2sm8978907f8f.49.2025.10.11.06.34.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Oct 2025 06:34:14 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 1/2] gdb/remote: replace use of std::pair with an actual struct Date: Sat, 11 Oct 2025 14:34:03 +0100 Message-ID: X-Mailer: git-send-email 2.47.1 In-Reply-To: References: <40cbbd9f0082b07e9767656fe044bbe9280983a3.1759763251.git.aburgess@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: iSh6HmfxlRvqu2PoehGMClvydGz9ffJGPTPmiEJ7yXQ_1760189657 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true 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 Commit: commit 5edcbe2277db05b77ebf53f9c30b6c889a8729bc Date: Mon Jul 24 17:35:54 2023 +0100 gdb: detect when gdbserver has no default executable set Introduced a use of std::pair as a data structure to hold some per program space information within the program space registry. It was pointed out during review of a later patch that the code would be easier to understand if the std::pair was replaced with a struct with named fields. That is what this commit does. Replace the std::pair with a struct, and update all accesses to use the named fields. There should be no user visible changes after this commit. --- gdb/remote.c | 60 +++++++++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/gdb/remote.c b/gdb/remote.c index 2e706e2d45b..143835ad503 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -1640,15 +1640,22 @@ enum class remote_exec_source UNSET_VALUE, }; -/* Data held per program-space to represent the remote exec-file path. The - first item in the pair is the exec-file path, this is set either by the - user with 'set remote exec-file', or automatically by GDB when - connecting to a remote target. +/* Data held per program-space to represent the remote exec-file path. + This holds the 'remote exec-file' value and an enum to indicate where + the exec-file value came from, or what an empty exec-file value means. + See show_remote_exec_file for details. */ - The second item in the pair is an enum flag that indicates where the - path value came from, or, when the path is the empty string, what this - actually means. See show_remote_exec_file for details. */ -using remote_exec_file_info = std::pair; +struct remote_exec_file_info +{ + /* The 'remote exec-file' value. This will be empty before being set. + This is set either with the 'set remote exec-file' command, or + automatically by GDB when connecting to a remote target. */ + std::string filename; + + /* An enum that indicates where VALUE came from, or what an empty VALUE + means. */ + remote_exec_source source = remote_exec_source::DEFAULT_VALUE; +}; /* Per-program-space data key. */ static const registry::key @@ -1662,8 +1669,7 @@ get_remote_exec_file_info (program_space *pspace) { remote_exec_file_info *info = remote_pspace_data.get (pspace); if (info == nullptr) - info = remote_pspace_data.emplace (pspace, "", - remote_exec_source::DEFAULT_VALUE); + info = remote_pspace_data.emplace (pspace); gdb_assert (info != nullptr); return *info; } @@ -2001,7 +2007,7 @@ get_remote_exec_file () { const remote_exec_file_info &info = get_remote_exec_file_info (current_program_space); - return info.first; + return info.filename; } /* Set the remote exec file for PSPACE. */ @@ -2012,8 +2018,8 @@ set_pspace_remote_exec_file (struct program_space *pspace, remote_exec_source source) { remote_exec_file_info &info = get_remote_exec_file_info (pspace); - info.first = filename; - info.second = source; + info.filename = filename; + info.source = source; } /* The "set remote exec-file" callback. */ @@ -2034,16 +2040,16 @@ show_remote_exec_file (struct ui_file *file, int from_tty, const remote_exec_file_info &info = get_remote_exec_file_info (current_program_space); - if (info.second == remote_exec_source::DEFAULT_VALUE) + if (info.source == remote_exec_source::DEFAULT_VALUE) gdb_printf (file, _("The remote exec-file is unset, the default " "remote executable will be used.\n")); - else if (info.second == remote_exec_source::UNSET_VALUE) + else if (info.source == remote_exec_source::UNSET_VALUE) gdb_printf (file, _("The remote exec-file is unset, the remote has " "no default executable set.\n")); else gdb_printf (file, _("The remote exec-file is \"%ps\".\n"), styled_string (file_name_style.style (), - info.first.c_str ())); + info.filename.c_str ())); } static int @@ -5483,25 +5489,25 @@ remote_target::start_remote_1 (int from_tty, int extended_p) { remote_exec_file_info &info = get_remote_exec_file_info (current_program_space); - if (info.second == remote_exec_source::VALUE_FROM_GDB - && info.first != exec_and_args.exec ()) + if (info.source == remote_exec_source::VALUE_FROM_GDB + && info.filename != exec_and_args.exec ()) warning (_("updating 'remote exec-file' to '%ps' to match " "remote target"), styled_string (file_name_style.style (), exec_and_args.exec ().c_str ())); - info.first = exec_and_args.exec (); - info.second = remote_exec_source::VALUE_FROM_REMOTE; + info.filename = exec_and_args.exec (); + info.source = remote_exec_source::VALUE_FROM_REMOTE; } } else if (exec_and_args.is_unset ()) { remote_exec_file_info &info = get_remote_exec_file_info (current_program_space); - if (info.second == remote_exec_source::DEFAULT_VALUE - || info.second == remote_exec_source::VALUE_FROM_REMOTE) + if (info.source == remote_exec_source::DEFAULT_VALUE + || info.source == remote_exec_source::VALUE_FROM_REMOTE) { - info.first.clear (); - info.second = remote_exec_source::UNSET_VALUE; + info.filename.clear (); + info.source = remote_exec_source::UNSET_VALUE; } } @@ -6492,10 +6498,10 @@ remote_unpush_target (remote_target *target) would be unhelpful. */ remote_exec_file_info &exec_info = get_remote_exec_file_info (inf->pspace); - if (exec_info.second == remote_exec_source::UNSET_VALUE) + if (exec_info.source == remote_exec_source::UNSET_VALUE) { - gdb_assert (exec_info.first.empty ()); - exec_info.second = remote_exec_source::DEFAULT_VALUE; + gdb_assert (exec_info.filename.empty ()); + exec_info.source = remote_exec_source::DEFAULT_VALUE; } inf->pop_all_targets_at_and_above (process_stratum); -- 2.47.1 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 0fj2NXOdHWk0xBIAWB0awg (envelope-from ) for ; Wed, 19 Nov 2025 05:35:31 -0500 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Wdio0hlc; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id D463C1E0B3; Wed, 19 Nov 2025 05:35:31 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.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,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (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 1FE571E0B3 for ; Wed, 19 Nov 2025 05:35:30 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A9B8E385B52F for ; Wed, 19 Nov 2025 10:35:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A9B8E385B52F Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Wdio0hlc 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 AFC5B384D168 for ; Wed, 19 Nov 2025 10:32:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AFC5B384D168 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine 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 AFC5B384D168 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=1763548370; cv=none; b=oJDXOS2h6uP1hCt5t2Pv21Ljy9NIaBTxgJn51CQDUd+ZzcCVntK95QINAGYoN1sWBqXAgZaPvZ4KxNwjL+5LH5LabkAcxLjDiRsieQ2tUGP1If5/ZDdNKAiNGBnL1sKHVxNYavYufiF+6trY7CiX+Tai9V4FXV2OvsFjf43MOw0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1763548370; c=relaxed/simple; bh=FlAA71rCxtm+hN2wXIgg+PB1CulD1Ec/HJuvylpBGWo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=A3AbEyqrCLIL/snUK8e+/qfNQJT5H32uRsLupyJjwr4fmqhmheNl2BqVFEiVZB1k6xqSNSYWZWLYCpwxrvaHSuUUPpzTfOV6mK7TyW6VXBiQ1KykHXsBOBMOszP+strL8madO0ec9nID6a6UmzG4AIXHx8gIaK6Lu2vtO4p8F0c= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AFC5B384D168 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1763548370; 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=wWXl+xn/Oi24jMbQSodSe2tC0FZSJcP+YXPuyZ56aCs=; b=Wdio0hlcvdBTsrtd37c3DMcBTc6qBas8yyqfPB1P9uV7ADuCfPkT/mYFa/ccCK1GXnRLLB +VHYl/LUIl2i5UShZQepQfFWm697l9MLg98badfG66+SVI2CdSTo0pOfZsNSDRmn6T5X3u Oic4HsBMMFR8RyCWK1RBDNDRiZw2U+U= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-373-ztpjKhBVOHyc0ScYy0lZsA-1; Wed, 19 Nov 2025 05:32:49 -0500 X-MC-Unique: ztpjKhBVOHyc0ScYy0lZsA-1 X-Mimecast-MFC-AGG-ID: ztpjKhBVOHyc0ScYy0lZsA_1763548368 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4777b03b90fso31704575e9.1 for ; Wed, 19 Nov 2025 02:32:49 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763548368; x=1764153168; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=wWXl+xn/Oi24jMbQSodSe2tC0FZSJcP+YXPuyZ56aCs=; b=GCqcmGO+eh9lP+NhN08LzN0o6D8JGqOqZc0TnL2BVaDtwul14H6uip6ygBq/LCSLFO R0esVyPLc7VY9+Qg7FhQ9SLifaXmYR8axNZY2wqk4j028OjRNz64uO38gKp0eyNV9VR8 l87zoylIz0w7jSpDwl8jjxzPoBy1/S2YSYuXN7/DQgK/qCghoyctqo6egWdVbJTrEoca 1I2yUsV09QUQOghnjKEFxV3Q+2Qzr842uwjZvWQWTvRxCX6BCc/IPZpaG+9ZhplaRuDV M4Zfu9icSCetZV8QzRn1UNU6Sh0w3NpbYJh1i3H++0FhnHd6tCzI337WD6TTpvKPuXO/ ddHg== X-Gm-Message-State: AOJu0YwO6wGRCgp+n8VReshLWmc3XMxKLtgHgKHSk5GQ638vWTDFidXK nJxWtY5SrdkBAL0XsxHnzkQ3HADSux6Z15ZEacGDveqiitI5F7drIXuYinxRrkspP3pMKavHHJF z/vlEnHZUccspHPAlvd4v237MecFrlgINkBEgbmPnK33yEoKKIPhrmwatBgOYbMkx56jgvngvRu UxruzpL8YafgAAYS0hF9l1zpCDKejJuWjs14lRq7z9ws6lfCE= X-Gm-Gg: ASbGncsF3r3Ac0G74mwdrzdOVJo3PAmdH+Jqjhi/0Qm7KgOjX/fAiXPJqyTpbS0Bavb 9L5+ZGzNzIWiR0OVK8V3rAQLhsEPM7Vspigjf2Y+tiz73MOLeMEitXm3+X1Z8Sv2PQuaXTXIw9z 4QPxVWAipBM6p6Ojv+kdDKxzWF7qyIE0Ev6xtya/9mVVYbjACkEw/+XbqPF53QhzUtg/pd5wcVL Lwyl5h/bBk6GRhoGEvtmkP2Algn7RI683nnnDUL+WLq+C78j6tvd/MXz+YUCo6hp3nECnijme4q JaMXuS8U0agybK8W5SmvsjqM6Ex9WvPgUb6A5nby8X+d4XyBpEwuS71i+YgkVJcf0WFj+l+hxKb weeMj X-Received: by 2002:a05:600c:1caa:b0:477:76cb:4812 with SMTP id 5b1f17b1804b1-4778fe0694amr213812505e9.0.1763548367604; Wed, 19 Nov 2025 02:32:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IFja0x9XmmVVqqWYYB7OFH9YtO58jkAlfTdgav+GJLXOYqqhA+n8kqcz+cW7HUbEuNoTSTc9A== X-Received: by 2002:a05:600c:1caa:b0:477:76cb:4812 with SMTP id 5b1f17b1804b1-4778fe0694amr213812115e9.0.1763548367157; Wed, 19 Nov 2025 02:32:47 -0800 (PST) Received: from localhost ([31.111.84.207]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-477b102a3a1sm39665175e9.9.2025.11.19.02.32.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Nov 2025 02:32:46 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 1/2] gdb/remote: replace use of std::pair with an actual struct Date: Wed, 19 Nov 2025 10:32:38 +0000 Message-ID: X-Mailer: git-send-email 2.47.1 In-Reply-To: References: <40cbbd9f0082b07e9767656fe044bbe9280983a3.1759763251.git.aburgess@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: -SzMih4qPqilXEMnK4DkWheo6Zm60Rfud9vEhBBfMYU_1763548368 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true 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 Message-ID: <20251119103238.uJ90QOpqJJcxGXNjIuaw30BKGHt8oBE0uxmSSmKry-M@z> Commit: commit 5edcbe2277db05b77ebf53f9c30b6c889a8729bc Date: Mon Jul 24 17:35:54 2023 +0100 gdb: detect when gdbserver has no default executable set Introduced a use of std::pair as a data structure to hold some per program space information within the program space registry. It was pointed out during review of a later patch that the code would be easier to understand if the std::pair was replaced with a struct with named fields. That is what this commit does. Replace the std::pair with a struct, and update all accesses to use the named fields. There should be no user visible changes after this commit. --- gdb/remote.c | 60 +++++++++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/gdb/remote.c b/gdb/remote.c index 2e706e2d45b..143835ad503 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -1640,15 +1640,22 @@ enum class remote_exec_source UNSET_VALUE, }; -/* Data held per program-space to represent the remote exec-file path. The - first item in the pair is the exec-file path, this is set either by the - user with 'set remote exec-file', or automatically by GDB when - connecting to a remote target. +/* Data held per program-space to represent the remote exec-file path. + This holds the 'remote exec-file' value and an enum to indicate where + the exec-file value came from, or what an empty exec-file value means. + See show_remote_exec_file for details. */ - The second item in the pair is an enum flag that indicates where the - path value came from, or, when the path is the empty string, what this - actually means. See show_remote_exec_file for details. */ -using remote_exec_file_info = std::pair; +struct remote_exec_file_info +{ + /* The 'remote exec-file' value. This will be empty before being set. + This is set either with the 'set remote exec-file' command, or + automatically by GDB when connecting to a remote target. */ + std::string filename; + + /* An enum that indicates where VALUE came from, or what an empty VALUE + means. */ + remote_exec_source source = remote_exec_source::DEFAULT_VALUE; +}; /* Per-program-space data key. */ static const registry::key @@ -1662,8 +1669,7 @@ get_remote_exec_file_info (program_space *pspace) { remote_exec_file_info *info = remote_pspace_data.get (pspace); if (info == nullptr) - info = remote_pspace_data.emplace (pspace, "", - remote_exec_source::DEFAULT_VALUE); + info = remote_pspace_data.emplace (pspace); gdb_assert (info != nullptr); return *info; } @@ -2001,7 +2007,7 @@ get_remote_exec_file () { const remote_exec_file_info &info = get_remote_exec_file_info (current_program_space); - return info.first; + return info.filename; } /* Set the remote exec file for PSPACE. */ @@ -2012,8 +2018,8 @@ set_pspace_remote_exec_file (struct program_space *pspace, remote_exec_source source) { remote_exec_file_info &info = get_remote_exec_file_info (pspace); - info.first = filename; - info.second = source; + info.filename = filename; + info.source = source; } /* The "set remote exec-file" callback. */ @@ -2034,16 +2040,16 @@ show_remote_exec_file (struct ui_file *file, int from_tty, const remote_exec_file_info &info = get_remote_exec_file_info (current_program_space); - if (info.second == remote_exec_source::DEFAULT_VALUE) + if (info.source == remote_exec_source::DEFAULT_VALUE) gdb_printf (file, _("The remote exec-file is unset, the default " "remote executable will be used.\n")); - else if (info.second == remote_exec_source::UNSET_VALUE) + else if (info.source == remote_exec_source::UNSET_VALUE) gdb_printf (file, _("The remote exec-file is unset, the remote has " "no default executable set.\n")); else gdb_printf (file, _("The remote exec-file is \"%ps\".\n"), styled_string (file_name_style.style (), - info.first.c_str ())); + info.filename.c_str ())); } static int @@ -5483,25 +5489,25 @@ remote_target::start_remote_1 (int from_tty, int extended_p) { remote_exec_file_info &info = get_remote_exec_file_info (current_program_space); - if (info.second == remote_exec_source::VALUE_FROM_GDB - && info.first != exec_and_args.exec ()) + if (info.source == remote_exec_source::VALUE_FROM_GDB + && info.filename != exec_and_args.exec ()) warning (_("updating 'remote exec-file' to '%ps' to match " "remote target"), styled_string (file_name_style.style (), exec_and_args.exec ().c_str ())); - info.first = exec_and_args.exec (); - info.second = remote_exec_source::VALUE_FROM_REMOTE; + info.filename = exec_and_args.exec (); + info.source = remote_exec_source::VALUE_FROM_REMOTE; } } else if (exec_and_args.is_unset ()) { remote_exec_file_info &info = get_remote_exec_file_info (current_program_space); - if (info.second == remote_exec_source::DEFAULT_VALUE - || info.second == remote_exec_source::VALUE_FROM_REMOTE) + if (info.source == remote_exec_source::DEFAULT_VALUE + || info.source == remote_exec_source::VALUE_FROM_REMOTE) { - info.first.clear (); - info.second = remote_exec_source::UNSET_VALUE; + info.filename.clear (); + info.source = remote_exec_source::UNSET_VALUE; } } @@ -6492,10 +6498,10 @@ remote_unpush_target (remote_target *target) would be unhelpful. */ remote_exec_file_info &exec_info = get_remote_exec_file_info (inf->pspace); - if (exec_info.second == remote_exec_source::UNSET_VALUE) + if (exec_info.source == remote_exec_source::UNSET_VALUE) { - gdb_assert (exec_info.first.empty ()); - exec_info.second = remote_exec_source::DEFAULT_VALUE; + gdb_assert (exec_info.filename.empty ()); + exec_info.source = remote_exec_source::DEFAULT_VALUE; } inf->pop_all_targets_at_and_above (process_stratum); -- 2.47.1