From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 5A5773858C60 for ; Thu, 30 May 2024 18:55:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5A5773858C60 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=efficios.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=efficios.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5A5773858C60 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=158.69.221.121 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1717095309; cv=none; b=Rsg+AuNcZCMIkbP67FKQo9EyOq+ptRCVc6WbtuMQFwHnaVG7+11I2hP7U4wALU9upcfqGMKmt7byu9mv6+ooYr1/A6K2xFCW9i40Ma1YNw6Q3rKz2YWYOSp815wrZvWPm++PcfPlCTwe8MTAUFqC+7vIfpM4rGiB5XUEJtYD7Dc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1717095309; c=relaxed/simple; bh=J4DyjQEHw2ID+5Hfco4TUzisVSXwEn6ChDN12YPahJM=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=aTtFxHXQhVdiSjd57EJR6OKZrCmyk/YP28zLNKRmRIfo7wUihyULgQVAe+Cd6owebVmXc5aAnP3FD3F0+gE3/ztcCJXn/gvix9LjaiBWa5sAQUnix0hibNzL8mRI6UaPjtYxmji/k3yLDud+Xou7FvhieKU20yxNrOiCqdaSko0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from localhost.localdomain (unknown [142.169.16.229]) (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 ESMTPSA id C85981E0C0; Thu, 30 May 2024 14:55:05 -0400 (EDT) From: Simon Marchi To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 1/4] gdb: make progspace::exec_filename private, add getter / setter Date: Thu, 30 May 2024 14:53:53 -0400 Message-ID: <20240530185509.265901-2-simon.marchi@efficios.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240530185509.265901-1-simon.marchi@efficios.com> References: <20240530185509.265901-1-simon.marchi@efficios.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1171.3 required=5.0 tests=BAYES_00,GIT_PATCH_0,KAM_DMARC_NONE,KAM_DMARC_STATUS,RCVD_IN_BARRACUDACENTRAL,SPF_HELO_PASS,SPF_SOFTFAIL,TXREP,T_SCC_BODY_TEXT_LINE 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: Just like the title says... I think this makes things a bit clearer, for instance where the exec filename is set. It also makes the read call sites a bit nicer, avoiding the `.get ()`. Change-Id: If8b58ae8f6270c8a34b868f6ca06128c6671ea3c --- gdb/corefile.c | 5 +++-- gdb/exec.c | 12 ++++++------ gdb/inferior.c | 8 ++++---- gdb/mi/mi-main.c | 7 ++----- gdb/progspace.c | 14 +++++++------- gdb/progspace.h | 16 ++++++++++++---- gdb/python/py-progspace.c | 2 +- 7 files changed, 35 insertions(+), 29 deletions(-) diff --git a/gdb/corefile.c b/gdb/corefile.c index 044c084ab6f3..3ae3fc7b6337 100644 --- a/gdb/corefile.c +++ b/gdb/corefile.c @@ -81,8 +81,9 @@ validate_files (void) const char * get_exec_file (int err) { - if (current_program_space->exec_filename != nullptr) - return current_program_space->exec_filename.get (); + if (current_program_space->exec_filename () != nullptr) + return current_program_space->exec_filename (); + if (!err) return NULL; diff --git a/gdb/exec.c b/gdb/exec.c index 88915260d609..4fe4d3bb50ad 100644 --- a/gdb/exec.c +++ b/gdb/exec.c @@ -456,15 +456,15 @@ exec_file_attach (const char *filename, int from_tty) /* gdb_realpath_keepfile resolves symlinks on the local filesystem and so cannot be used for "target:" files. */ - gdb_assert (current_program_space->exec_filename == nullptr); + gdb_assert (current_program_space->exec_filename () == nullptr); if (load_via_target) - current_program_space->exec_filename - = (make_unique_xstrdup + current_program_space->set_exec_filename + (make_unique_xstrdup (bfd_get_filename (current_program_space->exec_bfd ()))); else - current_program_space->exec_filename - = make_unique_xstrdup (gdb_realpath_keepfile - (scratch_pathname).c_str ()); + current_program_space->set_exec_filename + (make_unique_xstrdup (gdb_realpath_keepfile + (scratch_pathname).c_str ())); if (!bfd_check_format_matches (current_program_space->exec_bfd (), bfd_object, &matching)) diff --git a/gdb/inferior.c b/gdb/inferior.c index 0522cb5c14d5..6a197679902b 100644 --- a/gdb/inferior.c +++ b/gdb/inferior.c @@ -519,7 +519,7 @@ void print_selected_inferior (struct ui_out *uiout) { struct inferior *inf = current_inferior (); - const char *filename = inf->pspace->exec_filename.get (); + const char *filename = inf->pspace->exec_filename (); if (filename == NULL) filename = _(""); @@ -613,8 +613,8 @@ print_inferior (struct ui_out *uiout, const char *requested_inferiors) std::string conn = uiout_field_connection (inf->process_target ()); uiout->field_string ("connection-id", conn); - if (inf->pspace->exec_filename != nullptr) - uiout->field_string ("exec", inf->pspace->exec_filename.get (), + if (inf->pspace->exec_filename () != nullptr) + uiout->field_string ("exec", inf->pspace->exec_filename (), file_name_style.style ()); else uiout->field_skip ("exec"); @@ -750,7 +750,7 @@ inferior_command (const char *args, int from_tty) { inf = current_inferior (); gdb_assert (inf != nullptr); - const char *filename = inf->pspace->exec_filename.get (); + const char *filename = inf->pspace->exec_filename (); if (filename == nullptr) filename = _(""); diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c index a758b689ae72..5bcb5f7ee8ce 100644 --- a/gdb/mi/mi-main.c +++ b/gdb/mi/mi-main.c @@ -651,11 +651,8 @@ print_one_inferior (struct inferior *inferior, bool recurse, if (inferior->pid != 0) uiout->field_signed ("pid", inferior->pid); - if (inferior->pspace->exec_filename != nullptr) - { - uiout->field_string ("executable", - inferior->pspace->exec_filename.get ()); - } + if (inferior->pspace->exec_filename () != nullptr) + uiout->field_string ("executable", inferior->pspace->exec_filename ()); if (inferior->pid != 0) { diff --git a/gdb/progspace.c b/gdb/progspace.c index 5be514d45b0d..d5b5ef20023b 100644 --- a/gdb/progspace.c +++ b/gdb/progspace.c @@ -209,7 +209,7 @@ program_space::exec_close () remove_target_sections (saved_ebfd); - exec_filename.reset (nullptr); + m_exec_filename.reset (); } } @@ -223,8 +223,8 @@ clone_program_space (struct program_space *dest, struct program_space *src) set_current_program_space (dest); - if (src->exec_filename != NULL) - exec_file_attach (src->exec_filename.get (), 0); + if (src->exec_filename () != nullptr) + exec_file_attach (src->exec_filename (), 0); if (src->symfile_object_file != NULL) symbol_file_add_main (objfile_name (src->symfile_object_file), @@ -277,8 +277,8 @@ print_program_space (struct ui_out *uiout, int requested) if (requested != -1 && pspace->num != requested) continue; - if (pspace->exec_filename != nullptr) - longest_exec_name = std::max (strlen (pspace->exec_filename.get ()), + if (pspace->exec_filename () != nullptr) + longest_exec_name = std::max (strlen (pspace->exec_filename ()), longest_exec_name); ++count; @@ -310,8 +310,8 @@ print_program_space (struct ui_out *uiout, int requested) uiout->field_signed ("id", pspace->num); - if (pspace->exec_filename != nullptr) - uiout->field_string ("exec", pspace->exec_filename.get (), + if (pspace->exec_filename () != nullptr) + uiout->field_string ("exec", pspace->exec_filename (), file_name_style.style ()); else uiout->field_skip ("exec"); diff --git a/gdb/progspace.h b/gdb/progspace.h index bc24ef93733c..82c0a743f326 100644 --- a/gdb/progspace.h +++ b/gdb/progspace.h @@ -292,6 +292,15 @@ struct program_space intrusive_list &solibs () { return so_list; } + /* Similar to `bfd_get_filename (exec_bfd ())` but in original form given + by user, without symbolic links and pathname resolved. It is not nullptr + iff `exec_bfd ()` is not nullptr. */ + const char *exec_filename () const + { return m_exec_filename.get (); } + + void set_exec_filename (gdb::unique_xmalloc_ptr filename) + { m_exec_filename = std::move (filename); } + /* Close and clear exec_bfd. If we end up with no target sections to read memory from, this unpushes the exec_ops target. */ void exec_close (); @@ -352,10 +361,6 @@ struct program_space gdb_bfd_ref_ptr ebfd; /* The last-modified time, from when the exec was brought in. */ long ebfd_mtime = 0; - /* Similar to bfd_get_filename (exec_bfd) but in original form given - by user, without symbolic links and pathname resolved. It is not - NULL iff EBFD is not NULL. */ - gdb::unique_xmalloc_ptr exec_filename; /* Binary file diddling handle for the core file. */ gdb_bfd_ref_ptr cbfd; @@ -414,6 +419,9 @@ struct program_space /* The set of target sections matching the sections mapped into this program space. Managed by both exec_ops and solib.c. */ std::vector m_target_sections; + + /* See `exec_filename`. */ + gdb::unique_xmalloc_ptr m_exec_filename; }; /* The list of all program spaces. There's always at least one. */ diff --git a/gdb/python/py-progspace.c b/gdb/python/py-progspace.c index a5b22ce9d5c8..5bc0015d7288 100644 --- a/gdb/python/py-progspace.c +++ b/gdb/python/py-progspace.c @@ -148,7 +148,7 @@ pspy_get_exec_file (PyObject *self, void *closure) PSPY_REQUIRE_VALID (obj); - const char *filename = obj->pspace->exec_filename.get (); + const char *filename = obj->pspace->exec_filename (); if (filename != nullptr) return host_string_to_python_string (filename).release (); -- 2.45.1