From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id KV0GLo9t62gHcCsAWB0awg (envelope-from ) for ; Sun, 12 Oct 2025 04:57:51 -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=MC3wZ1ZD; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id B6C7C1E0B6; Sun, 12 Oct 2025 04:57:51 -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 E7CCD1E04C for ; Sun, 12 Oct 2025 04:57:50 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 48E2D3857400 for ; Sun, 12 Oct 2025 08:57:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 48E2D3857400 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=MC3wZ1ZD 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 886A43858D3C for ; Sun, 12 Oct 2025 08:57:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 886A43858D3C 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 886A43858D3C 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=1760259433; cv=none; b=RPXUtPNn8HCByXZXk8/Nm2SYCssiRV0euvxbGcFdwqKcUsYk1y6eFVtnxA54LkZjNTqOZv0UdCw9SjncSARH8URML85zvpQWgnWnI244g2crhdfGj1lJ4UM/91ON4shpen0HMOcqY5N/wx097mBsuPB3TVHGfqQgChvOqvTvmTY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1760259433; c=relaxed/simple; bh=4VX7kR7NwaCQy3tRS/dXxJ17u1ofnB+4UtmVnl02YGU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=hXusn8G0Rv2QCU9vPjjS0jJSp/YB6DhPR/4bI6qRsjjV2ah7SzRBq2Cz0cVIpsbkhUBsyO2A7zXtdzztajfX5GU5BN32qnuUeZGqwyEU5dh5/D3P5rVZPCFwcFV/jmEriwH3yX5RIPWUUamctVLLWEykeK35c+gbSObJZ7F6WXc= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 886A43858D3C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1760259433; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=qgW/vaHxw6Q0GOqtEaLPjjnFeH+fAe0TymD5Wk30ccc=; b=MC3wZ1ZD1FeE3SbuKUsFQ5N+esk348wOAV1tWR+G7Kol16iCJoRbnJdrExiny0OVJvAH5b eRpcmTNTWTukWEz8THwtRnXpqTmW/HOMkaBQbXr6IILr6/hbd6mAUW78xCABn2NC+E/4Kf J32C65F5D/k+3ss0q6h08aGJPap76HI= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-530-ybXEMiZzPtydVR8z_c7-qQ-1; Sun, 12 Oct 2025 04:57:11 -0400 X-MC-Unique: ybXEMiZzPtydVR8z_c7-qQ-1 X-Mimecast-MFC-AGG-ID: ybXEMiZzPtydVR8z_c7-qQ_1760259430 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-3ee1317b132so1960571f8f.0 for ; Sun, 12 Oct 2025 01:57:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760259430; x=1760864230; h=mime-version:message-id:date:references:in-reply-to:subject:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=qgW/vaHxw6Q0GOqtEaLPjjnFeH+fAe0TymD5Wk30ccc=; b=knWy0204eC4Qr43MuNJQ11JxmDIWX1Zh1rWWeH+JY8fTjI/CAm6KSTduZI5nBlWeYn MCLmKGPUJoSsxRCw6IxeA9Sx9rrA/aTISsjDTH5/V2f/pBOJyUhS9LeCKVidpGOVrhyN noygpHzlAIgzmpnFOsM3qxfE23TOTMCCURky0zXVJ3N7DiZkfxgMarhCdVnmR4Ie9OsB XENkcCTvRfieGX926A8bG6CShYjVBAuxjtq4faQtUfMPFK6tepIbfd7iRn7M9HE6DXBr EWDBdXhN4YH3p1rrwvEYHg2KxYoGdVzUwcJlhvHSgmMAu71jTohODICyb2ogOdf2y5dZ J2Yg== X-Forwarded-Encrypted: i=1; AJvYcCUnGnCxBtV1wGnG3u3U6O1b0FEB4gspA0tcZEtHRiqhg4O97KHAUJdvsTP+GmD6NIHsMX93ZZuVCnJoRA==@sourceware.org X-Gm-Message-State: AOJu0YwJKmuRxTz9kEQSv0L2SSY2MnPXS/gjxhO2d3szOhms9Kl9+uo7 1zxfDzS85p28SaqdoLfUXEBpBV/uc6bEI5THT7710hj3FuYph4WyOXolhSYvhfACM3s2P2F8lLN xAePu/rdY7okVo5jIdKpQlRwb2CwDEPeBOlINJfT9Y1yaFzUAM7XiT6/HNJyAGwIskncsO7U= X-Gm-Gg: ASbGncvzCUHjvv/43ft2sURy0mNhq+sX/F9DJ/5JIv+7n94291/oe0gDWAT6x54Ygkd NVmK8WLO5UHE6sxVp/RQdD966EoWk5cWiI3dERW/uQNFb4xi/UfPgCGNbkaLvnb94UBL73r0hba C92q8cd4C+4p9DO0/1o5thjfcHtr5jxaWTsjVCJ+Ttclf3aan3t3yUwIVfl5lBvesg5/NH6No+u bIN1sGn592h4COGGYn9eCvseRbMMGBwcvOcZ2pWhBOAH7I1PuCN8+k5F1SfOpE19tvwyjYsYsDl 0sZUtK5L9ek8N5rji8FI8kmDW4H6g6KDY/8= X-Received: by 2002:a5d:584b:0:b0:3ee:1461:1654 with SMTP id ffacd0b85a97d-4266e8d92e8mr11793569f8f.50.1760259429801; Sun, 12 Oct 2025 01:57:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHhMlbvYdwyy4x3Y/VcP9Po2ikUjH28mP6iqC8HHXU3fN9T04/tbJ1OWY3XNCd6ucrHVsR1BQ== X-Received: by 2002:a5d:584b:0:b0:3ee:1461:1654 with SMTP id ffacd0b85a97d-4266e8d92e8mr11793557f8f.50.1760259429110; Sun, 12 Oct 2025 01:57:09 -0700 (PDT) Received: from localhost ([31.111.84.207]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-426ce5e10e8sm12223741f8f.39.2025.10.12.01.57.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Oct 2025 01:57:08 -0700 (PDT) From: Andrew Burgess To: Simon Marchi , gdb-patches@sourceware.org Subject: Re: [PATCH 1/2] gdb/remote: replace use of std::pair with an actual struct In-Reply-To: <469655a7-2bcc-4f27-b2d7-3fa8808ca5b5@simark.ca> References: <40cbbd9f0082b07e9767656fe044bbe9280983a3.1759763251.git.aburgess@redhat.com> <469655a7-2bcc-4f27-b2d7-3fa8808ca5b5@simark.ca> Date: Sun, 12 Oct 2025 09:57:07 +0100 Message-ID: <87jz104hwc.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 0CgyIpCDlBnHhtrhPTKJQJ3MnnkXAYDfKK-MzSkzsfI_1760259430 X-Mimecast-Originator: redhat.com Content-Type: text/plain 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 Simon Marchi writes: > On 2025-10-11 09:34, Andrew Burgess wrote: >> 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. > > Thanks, this LGTM. > > Approved-By: Simon Marchi > > I would just like to point out that if we ever add more fields to this > structure (this the remote target needs to record per-pspace), then it > would probably make sense to rename to to "remote_per_pspace" or > something like that, since it would no longer be only used to hold > remote exec information. But as of now, it's correct. Ask and you shall receive! The update below names the struct remote_per_progspace, and moves the exec file information into a nested struct. Is this better? Thanks, Andrew --- commit ce25366de1752c28513aa5e78adfca2c558218e4 Author: Andrew Burgess Date: Sat Oct 11 14:03:39 2025 +0100 gdb/remote: replace use of std::pair with an actual struct 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[1][2] 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. [1] https://inbox.sourceware.org/gdb-patches/69681489-d556-4496-9e3b-8273cab3d8f5@simark.ca [2] https://inbox.sourceware.org/gdb-patches/469655a7-2bcc-4f27-b2d7-3fa8808ca5b5@simark.ca diff --git a/gdb/remote.c b/gdb/remote.c index 2e706e2d45b..858076bfa42 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -1640,30 +1640,44 @@ 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 for each remote target. */ - 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_per_progspace +{ + /* The following represents the remote exec-file filename. This value + can be set directly by the user with 'set remote exec-file', but can + also be set automatically when connecting to a remote target. We + track both the filename value, and also the source of this value, as + where the value came from determines when the filename value can be + auto-generated from other sources, or when a remote target can + override the current value. See show_remote_exec_file for details. */ + struct exec_info + { + /* The 'remote exec-file' filename value. This will start empty. 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 FILENAME came from, or what an empty + VALUE means. */ + remote_exec_source source = remote_exec_source::DEFAULT_VALUE; + } exec_info; +}; /* Per-program-space data key. */ -static const registry::key +static const registry::key remote_pspace_data; -/* Retrieve the remote_exec_file_info object for PSPACE. If no such object - yet exists then create a new one using the default constructor. */ +/* Retrieve the remote_per_progspace object for PSPACE. If no such object + yet exists then create a new one using the default constructor and + return that. */ -static remote_exec_file_info & -get_remote_exec_file_info (program_space *pspace) +static remote_per_progspace & +get_remote_progspace_info (program_space *pspace) { - remote_exec_file_info *info = remote_pspace_data.get (pspace); + remote_per_progspace *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; } @@ -1999,21 +2013,22 @@ remote_target::get_remote_state () static const std::string & get_remote_exec_file () { - const remote_exec_file_info &info - = get_remote_exec_file_info (current_program_space); - return info.first; + const remote_per_progspace &info + = get_remote_progspace_info (current_program_space); + return info.exec_info.filename; } -/* Set the remote exec file for PSPACE. */ +/* Set the remote exec file for PSPACE. FILENAME is the new exec file + value, and SOURCE describes where FILENAME came from. */ static void set_pspace_remote_exec_file (struct program_space *pspace, const std::string &filename, remote_exec_source source) { - remote_exec_file_info &info = get_remote_exec_file_info (pspace); - info.first = filename; - info.second = source; + remote_per_progspace &info = get_remote_progspace_info (pspace); + info.exec_info.filename = filename; + info.exec_info.source = source; } /* The "set remote exec-file" callback. */ @@ -2031,19 +2046,19 @@ static void show_remote_exec_file (struct ui_file *file, int from_tty, struct cmd_list_element *cmd, const char *value) { - const remote_exec_file_info &info - = get_remote_exec_file_info (current_program_space); + const struct remote_per_progspace::exec_info &info + = get_remote_progspace_info (current_program_space).exec_info; - 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 @@ -5481,27 +5496,27 @@ remote_target::start_remote_1 (int from_tty, int extended_p) current_inferior ()->set_args (exec_and_args.args ()); if (!exec_and_args.exec ().empty ()) { - 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 ()) + struct remote_per_progspace::exec_info &info + = get_remote_progspace_info (current_program_space).exec_info; + 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) + struct remote_per_progspace::exec_info &info + = get_remote_progspace_info (current_program_space).exec_info; + 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; } } @@ -6490,12 +6505,12 @@ remote_unpush_target (remote_target *target) assumption is that the user is, or will, be debugging the same executable again in the future, so clearing an existing value 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) + struct remote_per_progspace::exec_info &exec_info + = get_remote_progspace_info (inf->pspace).exec_info; + 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);