From: Andrew Burgess <aburgess@redhat.com>
To: gdb-patches@sourceware.org
Cc: Andrew Burgess <aburgess@redhat.com>
Subject: [PATCH 2/2] gdb: add overloads of gdb_tilde_expand
Date: Thu, 20 Jun 2024 14:33:07 +0100 [thread overview]
Message-ID: <c2434fc0438568503d04b6fa9f33da902910a437.1718890187.git.aburgess@redhat.com> (raw)
In-Reply-To: <cover.1718890187.git.aburgess@redhat.com>
Like the previous commit, add two overloads of gdb_tilde_expand, one
takes std::string and other takes gdb::unique_xmalloc_ptr<char>. Make
use of these overloads throughout GDB and gdbserver.
There should be no user visible changes after this commit.
---
gdb/completer.c | 2 +-
gdb/nat/fork-inferior.c | 2 +-
gdbserver/win32-low.cc | 2 +-
gdbsupport/gdb_tilde_expand.h | 18 ++++++++++++++++--
4 files changed, 19 insertions(+), 5 deletions(-)
diff --git a/gdb/completer.c b/gdb/completer.c
index f1f44109bdc..dcb4982d7a9 100644
--- a/gdb/completer.c
+++ b/gdb/completer.c
@@ -236,7 +236,7 @@ filename_completer (struct cmd_list_element *ignore,
trailing '/' ourselves now. */
if (!tracker.from_readline ())
{
- std::string expanded = gdb_tilde_expand (p_rl.get ());
+ std::string expanded = gdb_tilde_expand (p_rl);
struct stat finfo;
const bool isdir = (stat (expanded.c_str (), &finfo) == 0
&& S_ISDIR (finfo.st_mode));
diff --git a/gdb/nat/fork-inferior.c b/gdb/nat/fork-inferior.c
index 2fd9cba52ee..41765b102bc 100644
--- a/gdb/nat/fork-inferior.c
+++ b/gdb/nat/fork-inferior.c
@@ -321,7 +321,7 @@ fork_inferior (const char *exec_file, const std::string &allargs, char **env,
{
/* Expand before forking because between fork and exec, the child
process may only execute async-signal-safe operations. */
- inferior_cwd = gdb_tilde_expand (inferior_cwd.c_str ());
+ inferior_cwd = gdb_tilde_expand (inferior_cwd);
}
/* If there's any initialization of the target layers that must
diff --git a/gdbserver/win32-low.cc b/gdbserver/win32-low.cc
index f672e542d1b..41eed201c10 100644
--- a/gdbserver/win32-low.cc
+++ b/gdbserver/win32-low.cc
@@ -501,7 +501,7 @@ create_process (const char *program, char *args,
/* current directory */
(inferior_cwd.empty ()
? NULL
- : gdb_tilde_expand (inferior_cwd.c_str ()).c_str()),
+ : gdb_tilde_expand (inferior_cwd).c_str()),
get_client_state ().disable_randomization,
&si, /* start info */
pi); /* proc info */
diff --git a/gdbsupport/gdb_tilde_expand.h b/gdbsupport/gdb_tilde_expand.h
index fbd410dd133..f16f3a405ee 100644
--- a/gdbsupport/gdb_tilde_expand.h
+++ b/gdbsupport/gdb_tilde_expand.h
@@ -20,7 +20,21 @@
#ifndef COMMON_GDB_TILDE_EXPAND_H
#define COMMON_GDB_TILDE_EXPAND_H
-/* Perform tilde expansion on DIR, and return the full path. */
-extern std::string gdb_tilde_expand (const char *dir);
+/* Perform tilde expansion on PATH, and return the full path. */
+extern std::string gdb_tilde_expand (const char *path);
+
+/* Overload of gdb_tilde_expand that takes std::string. */
+static inline std::string
+gdb_tilde_expand (const std::string &path)
+{
+ return gdb_tilde_expand (path.c_str ());
+}
+
+/* Overload of gdb_tilde_expand that takes gdb::unique_xmalloc_ptr<char>. */
+static inline std::string
+gdb_tilde_expand (const gdb::unique_xmalloc_ptr<char> &path)
+{
+ return gdb_tilde_expand (path.get ());
+}
#endif /* COMMON_GDB_TILDE_EXPAND_H */
--
2.25.4
next prev parent reply other threads:[~2024-06-20 13:33 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-20 13:33 [PATCH 0/2] string type overloads for some path manipulation functions Andrew Burgess
2024-06-20 13:33 ` [PATCH 1/2] gdb: add overloads of gdb_abspath Andrew Burgess
2024-06-20 13:33 ` Andrew Burgess [this message]
2024-06-24 15:50 ` [PATCH 0/2] string type overloads for some path manipulation functions Tom Tromey
2024-06-27 14:22 ` Andrew Burgess
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c2434fc0438568503d04b6fa9f33da902910a437.1718890187.git.aburgess@redhat.com \
--to=aburgess@redhat.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).