* [PATCH 0/2] string type overloads for some path manipulation functions
@ 2024-06-20 13:33 Andrew Burgess
2024-06-20 13:33 ` [PATCH 1/2] gdb: add overloads of gdb_abspath Andrew Burgess
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Andrew Burgess @ 2024-06-20 13:33 UTC (permalink / raw)
To: gdb-patches; +Cc: Andrew Burgess
Two small refactoring patches that add string type overloads for some
path manipulation functions.
These mean we (developers) don't need to care what string type
gdb_abspath or gdb_tilde_expand take, you can now pass them 'const
char *', 'std::string', or 'gdb::unique_xmalloc_ptr<char>' and it'll
"Just Work".
--
Andrew Burgess (2):
gdb: add overloads of gdb_abspath
gdb: add overloads of gdb_tilde_expand
gdb/bsd-kvm.c | 2 +-
gdb/completer.c | 2 +-
gdb/corelow.c | 2 +-
gdb/dwarf2/index-cache.c | 2 +-
gdb/main.c | 2 +-
gdb/nat/fork-inferior.c | 2 +-
gdb/top.c | 2 +-
gdb/tracefile-tfile.c | 2 +-
gdbserver/server.cc | 2 +-
gdbserver/win32-low.cc | 2 +-
gdbsupport/gdb_tilde_expand.h | 18 ++++++++++++++++--
gdbsupport/pathstuff.h | 16 ++++++++++++++++
12 files changed, 42 insertions(+), 12 deletions(-)
base-commit: a8651ef51822f91ec86d0d5caffbf2e50b174c23
--
2.25.4
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] gdb: add overloads of gdb_abspath
2024-06-20 13:33 [PATCH 0/2] string type overloads for some path manipulation functions Andrew Burgess
@ 2024-06-20 13:33 ` Andrew Burgess
2024-06-20 13:33 ` [PATCH 2/2] gdb: add overloads of gdb_tilde_expand Andrew Burgess
2024-06-24 15:50 ` [PATCH 0/2] string type overloads for some path manipulation functions Tom Tromey
2 siblings, 0 replies; 5+ messages in thread
From: Andrew Burgess @ 2024-06-20 13:33 UTC (permalink / raw)
To: gdb-patches; +Cc: Andrew Burgess
Add two overloads of gdb_abspath, one which takes std::string and one
which takes gdb::unique_xmalloc_ptr<char>, then make use of these
overloads throughout GDB and gdbserver.
There should be no user visible changes after this commit.
---
gdb/bsd-kvm.c | 2 +-
gdb/corelow.c | 2 +-
gdb/dwarf2/index-cache.c | 2 +-
gdb/main.c | 2 +-
gdb/top.c | 2 +-
gdb/tracefile-tfile.c | 2 +-
gdbserver/server.cc | 2 +-
gdbsupport/pathstuff.h | 16 ++++++++++++++++
8 files changed, 23 insertions(+), 7 deletions(-)
diff --git a/gdb/bsd-kvm.c b/gdb/bsd-kvm.c
index 7ef8c349a6e..19353eb97dc 100644
--- a/gdb/bsd-kvm.c
+++ b/gdb/bsd-kvm.c
@@ -117,7 +117,7 @@ bsd_kvm_target_open (const char *arg, int from_tty)
{
filename = gdb_tilde_expand (arg);
if (!IS_ABSOLUTE_PATH (filename))
- filename = gdb_abspath (filename.c_str ());
+ filename = gdb_abspath (filename);
}
const char *execfile = current_program_space->exec_filename ();
diff --git a/gdb/corelow.c b/gdb/corelow.c
index 49da9be07ef..2b7a3550fc1 100644
--- a/gdb/corelow.c
+++ b/gdb/corelow.c
@@ -626,7 +626,7 @@ core_target_open (const char *arg, int from_tty)
gdb::unique_xmalloc_ptr<char> filename (tilde_expand (arg));
if (strlen (filename.get ()) != 0
&& !IS_ABSOLUTE_PATH (filename.get ()))
- filename = make_unique_xstrdup (gdb_abspath (filename.get ()).c_str ());
+ filename = make_unique_xstrdup (gdb_abspath (filename).c_str ());
flags = O_BINARY | O_LARGEFILE;
if (write_files)
diff --git a/gdb/dwarf2/index-cache.c b/gdb/dwarf2/index-cache.c
index 1720e925ee6..c11b0164aa4 100644
--- a/gdb/dwarf2/index-cache.c
+++ b/gdb/dwarf2/index-cache.c
@@ -324,7 +324,7 @@ set_index_cache_directory_command (const char *arg, int from_tty,
cmd_list_element *element)
{
/* Make sure the index cache directory is absolute and tilde-expanded. */
- index_cache_directory = gdb_abspath (index_cache_directory.c_str ());
+ index_cache_directory = gdb_abspath (index_cache_directory);
global_index_cache.set_directory (index_cache_directory);
}
diff --git a/gdb/main.c b/gdb/main.c
index 4dd68f3d976..e4a40c51023 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -121,7 +121,7 @@ set_gdb_data_directory (const char *new_datadir)
"../foo" and "../foo" doesn't exist then we'll record $(pwd)/../foo which
isn't canonical, but that's ok. */
if (!IS_ABSOLUTE_PATH (gdb_datadir.c_str ()))
- gdb_datadir = gdb_abspath (gdb_datadir.c_str ());
+ gdb_datadir = gdb_abspath (gdb_datadir);
}
/* Relocate a file or directory. PROGNAME is the name by which gdb
diff --git a/gdb/top.c b/gdb/top.c
index 6239c190627..d6bf1d448d5 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -2097,7 +2097,7 @@ set_history_filename (const char *args,
that was read. */
if (!history_filename.empty ()
&& !IS_ABSOLUTE_PATH (history_filename.c_str ()))
- history_filename = gdb_abspath (history_filename.c_str ());
+ history_filename = gdb_abspath (history_filename);
}
/* Whether we're in quiet startup mode. */
diff --git a/gdb/tracefile-tfile.c b/gdb/tracefile-tfile.c
index eb879c17970..4a4c4a2d32a 100644
--- a/gdb/tracefile-tfile.c
+++ b/gdb/tracefile-tfile.c
@@ -467,7 +467,7 @@ tfile_target_open (const char *arg, int from_tty)
gdb::unique_xmalloc_ptr<char> filename (tilde_expand (arg));
if (!IS_ABSOLUTE_PATH (filename.get ()))
- filename = make_unique_xstrdup (gdb_abspath (filename.get ()).c_str ());
+ filename = make_unique_xstrdup (gdb_abspath (filename).c_str ());
flags = O_BINARY | O_LARGEFILE;
flags |= O_RDONLY;
diff --git a/gdbserver/server.cc b/gdbserver/server.cc
index ab9a33f40fd..30d05177452 100644
--- a/gdbserver/server.cc
+++ b/gdbserver/server.cc
@@ -109,7 +109,7 @@ static struct {
its name with CURRENT_DIRECTORY. Otherwise, we leave the
name as-is because we'll try searching for it in $PATH. */
if (is_regular_file (m_path.c_str (), ®_file_errno))
- m_path = gdb_abspath (m_path.c_str ());
+ m_path = gdb_abspath (m_path);
}
}
diff --git a/gdbsupport/pathstuff.h b/gdbsupport/pathstuff.h
index 170a2c5e724..a61ce23efde 100644
--- a/gdbsupport/pathstuff.h
+++ b/gdbsupport/pathstuff.h
@@ -56,6 +56,22 @@ extern std::string gdb_realpath_keepfile (const char *filename);
extern std::string gdb_abspath (const char *path);
+/* Overload of gdb_abspath which takes std::string. */
+
+static inline std::string
+gdb_abspath (const std::string &path)
+{
+ return gdb_abspath (path.c_str ());
+}
+
+/* Overload of gdb_abspath which takes gdb::unique_xmalloc_ptr<char>. */
+
+static inline std::string
+gdb_abspath (const gdb::unique_xmalloc_ptr<char> &path)
+{
+ return gdb_abspath (path.get ());
+}
+
/* If the path in CHILD is a child of the path in PARENT, return a
pointer to the first component in the CHILD's pathname below the
PARENT. Otherwise, return NULL. */
--
2.25.4
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 2/2] gdb: add overloads of gdb_tilde_expand
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
2024-06-24 15:50 ` [PATCH 0/2] string type overloads for some path manipulation functions Tom Tromey
2 siblings, 0 replies; 5+ messages in thread
From: Andrew Burgess @ 2024-06-20 13:33 UTC (permalink / raw)
To: gdb-patches; +Cc: Andrew Burgess
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 0/2] string type overloads for some path manipulation functions
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 ` [PATCH 2/2] gdb: add overloads of gdb_tilde_expand Andrew Burgess
@ 2024-06-24 15:50 ` Tom Tromey
2024-06-27 14:22 ` Andrew Burgess
2 siblings, 1 reply; 5+ messages in thread
From: Tom Tromey @ 2024-06-24 15:50 UTC (permalink / raw)
To: Andrew Burgess; +Cc: gdb-patches
>>>>> "Andrew" == Andrew Burgess <aburgess@redhat.com> writes:
Andrew> Two small refactoring patches that add string type overloads for some
Andrew> path manipulation functions.
Andrew> These mean we (developers) don't need to care what string type
Andrew> gdb_abspath or gdb_tilde_expand take, you can now pass them 'const
Andrew> char *', 'std::string', or 'gdb::unique_xmalloc_ptr<char>' and it'll
Andrew> "Just Work".
Thanks, this seems like a good idea to me.
Approved-By: Tom Tromey <tom@tromey.com>
Tom
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 0/2] string type overloads for some path manipulation functions
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
0 siblings, 0 replies; 5+ messages in thread
From: Andrew Burgess @ 2024-06-27 14:22 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
Tom Tromey <tom@tromey.com> writes:
>>>>>> "Andrew" == Andrew Burgess <aburgess@redhat.com> writes:
>
> Andrew> Two small refactoring patches that add string type overloads for some
> Andrew> path manipulation functions.
>
> Andrew> These mean we (developers) don't need to care what string type
> Andrew> gdb_abspath or gdb_tilde_expand take, you can now pass them 'const
> Andrew> char *', 'std::string', or 'gdb::unique_xmalloc_ptr<char>' and it'll
> Andrew> "Just Work".
>
> Thanks, this seems like a good idea to me.
> Approved-By: Tom Tromey <tom@tromey.com>
Pushed.
Thanks,
Andrew
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-06-27 14:22 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 2/2] gdb: add overloads of gdb_tilde_expand Andrew Burgess
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
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).