From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id D7BF13858C2D for ; Fri, 25 Aug 2023 15:34:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D7BF13858C2D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1692977693; 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=uTxwtCFQC15O+9FQbomKPQ3svoYgZEHhRq2u2EHvT/8=; b=W5fpjCrTWcwy558weUvrDBlmt/YFFVlshkZk9uqNW0RO+8/G7yig6Cci3SnttKqgdxg8so c91rQald9UAVIVfdzrJjeTYyw1t382CBnbPBKhk6B0cb1hNWTGciNoJd54XM5AHaxAKzsc HV7TPETi9+d0EKErxi/D6Q3/iZODS/0= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-592-OTKOVXkIPnKT_3nGxf_mLw-1; Fri, 25 Aug 2023 11:34:52 -0400 X-MC-Unique: OTKOVXkIPnKT_3nGxf_mLw-1 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-31c4096874bso730327f8f.2 for ; Fri, 25 Aug 2023 08:34:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692977690; x=1693582490; 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=uTxwtCFQC15O+9FQbomKPQ3svoYgZEHhRq2u2EHvT/8=; b=RtHfhzb+1+2CEvDk/1piub5fDMCpYar1jbMFLaPRBtu/IEcYZ0yilf8P7+VyITGesK r7OqRiyhLnUllzKi+HS/G7tvvvS/z8McBuyiPXz4DYCi66WmOjxacILh2+nqDRbDDmIs /ECQuGSqvPpyR+zBVonMohanoYSDtzzLXVuWZ8kmXpLTZmMaeKyYdtcSGUqBBjAg5RNA zJBEBb4apvVktqvnC1NnVPESjBoXfBrKVjdL/4GBOx891+UHSqSW2KSIbEjiv26THl8k 0fKxlSd8o8Cq8/Oh3wcYa3HaERrOIz7q2tQfflPOwGWQTbY6Dntr4Lpd/Uszv32Ya6rW VHTg== X-Gm-Message-State: AOJu0Ywo5XmIW/DzdAI9MG8dP4NFTsxn4saXtkJBhR6gFYAzJO/Coyah j5FSW87OyTqu25kaxcpIoB64LECw2a7Kbw2HMTeQzMri3ZeUzV8RWUtjbAtXdq16krUs6EMKZDc LxfwLDZNM7dF243wbtLbcIRItB1oyfV7M9xRAlEnzlHuaFQ6wJ7dqF40lXvm2uQsyD1ZlPOvSDB YHAh/xjg== X-Received: by 2002:adf:dd90:0:b0:315:9e1b:4ea6 with SMTP id x16-20020adfdd90000000b003159e1b4ea6mr14309034wrl.58.1692977690369; Fri, 25 Aug 2023 08:34:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFxGDl5WHipNam4OAUOpZAcf3V8MWzTMXEPIeE1ebJCjSP3+iOjow0hHwyLDigUTvLJV5cAjA== X-Received: by 2002:adf:dd90:0:b0:315:9e1b:4ea6 with SMTP id x16-20020adfdd90000000b003159e1b4ea6mr14309017wrl.58.1692977690008; Fri, 25 Aug 2023 08:34:50 -0700 (PDT) Received: from localhost ([31.111.84.232]) by smtp.gmail.com with ESMTPSA id p14-20020a5d638e000000b0031971ab70c9sm2519203wru.73.2023.08.25.08.34.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Aug 2023 08:34:49 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv2 02/10] gdb: improve how 'remote exec-file' is stored and accessed Date: Fri, 25 Aug 2023 16:34:35 +0100 Message-Id: <39f6895059cd00cfae75ee30405e224871eb49ba.1692977354.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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-11.9 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_H4,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 List-Id: This commit makes two related changes. The goal of the commit is to update the 'remote exec-file' setting to work correctly in a multi-inferior setup. To do this I have switched from the older style add_setshow_* function, which uses a single backing variable, to the newer style add_setshow_* functions that uses a get/set callback. The get/set callbacks now directly access the state held in the progspace which ensures that the correct value is always returned. However, the new get/set API requires that the get callback return a reference to the setting's value, which in this case needs to be a std::string. Currently the 'remote exec-file' setting is stored as a 'char *' string, which isn't going to work. And so, this commit also changes 'remote exec-file' to be stored as a std::string within the progspace. Now, when switching between multiple inferiors, GDB can correctly inform the user about the value of the 'remote exec-file' setting. --- gdb/remote.c | 70 ++++++++++++------------ gdb/testsuite/gdb.multi/gdb-settings.exp | 13 +++++ 2 files changed, 47 insertions(+), 36 deletions(-) diff --git a/gdb/remote.c b/gdb/remote.c index bbe81ccb54f..8a3bb629837 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -1223,7 +1223,7 @@ class remote_target : public process_stratum_target void remote_kill_k (); void extended_remote_disable_randomization (int val); - int extended_remote_run (const char *remote_exec_file, + int extended_remote_run (const std::string &remote_exec_file, const std::string &args); void send_environment_packet (const char *action, @@ -1340,14 +1340,7 @@ is_remote_target (process_stratum_target *target) } /* Per-program-space data key. */ -static const registry::key> - remote_pspace_data; - -/* The variable registered as the control variable used by the - remote exec-file commands. While the remote exec-file setting is - per-program-space, the set/show machinery uses this as the - location of the remote exec-file value. */ -static std::string remote_exec_file_var; +static const registry::key remote_pspace_data; /* The size to align memory write packets, when practical. The protocol does not guarantee any alignment, and gdb will generate short @@ -1669,47 +1662,50 @@ remote_target::get_remote_state () /* Fetch the remote exec-file from the current program space. */ -static const char * +static const std::string & get_remote_exec_file (void) { - char *remote_exec_file; - - remote_exec_file = remote_pspace_data.get (current_program_space); - if (remote_exec_file == NULL) - return ""; - - return remote_exec_file; + const std::string *remote_exec_file + = remote_pspace_data.get (current_program_space); + if (remote_exec_file == nullptr) + remote_exec_file = remote_pspace_data.emplace (current_program_space); + return *remote_exec_file; } /* Set the remote exec file for PSPACE. */ static void set_pspace_remote_exec_file (struct program_space *pspace, - const char *remote_exec_file) + const std::string &filename) { - char *old_file = remote_pspace_data.get (pspace); - - xfree (old_file); - remote_pspace_data.set (pspace, xstrdup (remote_exec_file)); + remote_pspace_data.clear (pspace); + remote_pspace_data.emplace (pspace, filename); } -/* The "set/show remote exec-file" set command hook. */ +/* The "set remote exec-file" callback. */ static void -set_remote_exec_file (const char *ignored, int from_tty, - struct cmd_list_element *c) +set_remote_exec_file_cb (const std::string &filename) { set_pspace_remote_exec_file (current_program_space, - remote_exec_file_var.c_str ()); + filename); +} + +/* Get the value for the 'set remote exec-file' user setting. */ + +static const std::string & +get_remote_exec_file_cb () +{ + return get_remote_exec_file (); } -/* The "set/show remote exec-file" show command hook. */ +/* Implement the "show remote exec-file" command. */ static void show_remote_exec_file (struct ui_file *file, int from_tty, struct cmd_list_element *cmd, const char *value) { - gdb_printf (file, "%s\n", get_remote_exec_file ()); + gdb_printf (file, "%s\n", get_remote_exec_file ().c_str ()); } static int @@ -10449,7 +10445,7 @@ remote_target::extended_remote_disable_randomization (int val) } int -remote_target::extended_remote_run (const char *remote_exec_file, +remote_target::extended_remote_run (const std::string &remote_exec_file, const std::string &args) { struct remote_state *rs = get_remote_state (); @@ -10463,10 +10459,11 @@ remote_target::extended_remote_run (const char *remote_exec_file, strcpy (rs->buf.data (), "vRun;"); len = strlen (rs->buf.data ()); - if (strlen (remote_exec_file) * 2 + len >= get_remote_packet_size ()) + if (remote_exec_file.size () * 2 + len >= get_remote_packet_size ()) error (_("Remote file name too long for run packet")); - len += 2 * bin2hex ((gdb_byte *) remote_exec_file, rs->buf.data () + len, - strlen (remote_exec_file)); + len += 2 * bin2hex ((gdb_byte *) remote_exec_file.data (), + rs->buf.data () + len, + remote_exec_file.size ()); if (!args.empty ()) { @@ -10501,7 +10498,7 @@ remote_target::extended_remote_run (const char *remote_exec_file, "try \"set remote exec-file\"?")); else error (_("Running \"%s\" on the remote target failed"), - remote_exec_file); + remote_exec_file.c_str ()); default: gdb_assert_not_reached ("bad switch"); } @@ -10618,7 +10615,7 @@ extended_remote_target::create_inferior (const char *exec_file, int run_worked; char *stop_reply; struct remote_state *rs = get_remote_state (); - const char *remote_exec_file = get_remote_exec_file (); + const std::string &remote_exec_file = get_remote_exec_file (); /* If running asynchronously, register the target file descriptor with the event loop. */ @@ -15481,10 +15478,11 @@ Transfer files to and from the remote target system."), &remote_cmdlist); add_setshow_string_noescape_cmd ("exec-file", class_files, - &remote_exec_file_var, _("\ + _("\ Set the remote pathname for \"run\"."), _("\ Show the remote pathname for \"run\"."), NULL, - set_remote_exec_file, + set_remote_exec_file_cb, + get_remote_exec_file_cb, show_remote_exec_file, &remote_set_cmdlist, &remote_show_cmdlist); diff --git a/gdb/testsuite/gdb.multi/gdb-settings.exp b/gdb/testsuite/gdb.multi/gdb-settings.exp index 0ebd2bf2998..e5922221d47 100644 --- a/gdb/testsuite/gdb.multi/gdb-settings.exp +++ b/gdb/testsuite/gdb.multi/gdb-settings.exp @@ -71,6 +71,7 @@ foreach_with_prefix inf $inferiors { gdb_test_no_output "set args inf${inf}-args" gdb_test_no_output "set cwd /inf${inf}-cwd" gdb_test_no_output "set inferior-tty /inf${inf}-tty" + gdb_test_no_output "set remote exec-file /inf${inf}-remote-exec" } # Check settings are still correct for each inferior. @@ -88,6 +89,9 @@ foreach_with_prefix inf $inferiors { gdb_test "with inferior-tty tmp-value -- print 1" " = 1" gdb_test "show inferior-tty" "/inf${inf}-tty.*" + gdb_test "with remote exec-file tmp-value -- print 1" " = 1" + gdb_test "show remote exec-file" "/inf${inf}-remote-exec" + # If the inferiors are running check $_gdb_setting_str and # $_gdb_setting return the correct values. if { $run } { @@ -101,6 +105,11 @@ foreach_with_prefix inf $inferiors { "\"/inf${inf}-tty\"" gdb_test {print $_gdb_setting("inferior-tty")} \ "\"/inf${inf}-tty\"" + + gdb_test {print $_gdb_setting_str("remote exec-file")} \ + "\"/inf${inf}-remote-exec\"" + gdb_test {print $_gdb_setting("remote exec-file")} \ + "\"/inf${inf}-remote-exec\"" } # Check the settings can be read from Python. @@ -109,6 +118,8 @@ foreach_with_prefix inf $inferiors { gdb_test "python print(gdb.parameter('cwd'))" "/inf${inf}-cwd" gdb_test "python print(gdb.parameter('inferior-tty'))" \ "/inf${inf}-tty" + gdb_test "python print(gdb.parameter('remote exec-file'))" \ + "/inf${inf}-remote-exec" } # Check the settings can be read from Guile. @@ -119,5 +130,7 @@ foreach_with_prefix inf $inferiors { "/inf${inf}-cwd" gdb_test "guile (print (parameter-value \"inferior-tty\"))" \ "/inf${inf}-tty" + gdb_test "guile (print (parameter-value \"remote exec-file\"))" \ + "/inf${inf}-remote-exec" } } -- 2.25.4