public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Use TARGET_SYSROOT_PREFIX in more places
@ 2023-12-10 23:11 Tom Tromey
  2023-12-11 13:27 ` Andrew Burgess
  0 siblings, 1 reply; 2+ messages in thread
From: Tom Tromey @ 2023-12-10 23:11 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

I found some spots using "target:"; I think it's better to use the
define everywhere, so this changes these to use TARGET_SYSROOT_PREFIX.
In some spots, is_target_filename is used rather than an explicit
check.
---
 gdb/build-id.c |  2 +-
 gdb/gdb_bfd.h  |  8 ++++++++
 gdb/symfile.c  | 18 ++++++++++--------
 3 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/gdb/build-id.c b/gdb/build-id.c
index f68384f0197..6abf04ffacd 100644
--- a/gdb/build-id.c
+++ b/gdb/build-id.c
@@ -90,7 +90,7 @@ build_id_to_debug_bfd_1 (const std::string &link, size_t build_id_len,
   /* lrealpath() is expensive even for the usually non-existent files.  */
   gdb::unique_xmalloc_ptr<char> filename_holder;
   const char *filename = nullptr;
-  if (startswith (link, TARGET_SYSROOT_PREFIX))
+  if (is_target_filename (link))
     filename = link.c_str ();
   else if (access (link.c_str (), F_OK) == 0)
     {
diff --git a/gdb/gdb_bfd.h b/gdb/gdb_bfd.h
index 604365b61b1..eeb782edcfc 100644
--- a/gdb/gdb_bfd.h
+++ b/gdb/gdb_bfd.h
@@ -45,6 +45,14 @@ struct registry_accessor<bfd>
 
 int is_target_filename (const char *name);
 
+/* An overload for strings.  */
+
+static inline int
+is_target_filename (const std::string &name)
+{
+  return is_target_filename (name.c_str ());
+}
+
 /* Returns nonzero if the filename associated with ABFD starts with
    TARGET_SYSROOT_PREFIX, zero otherwise.  */
 
diff --git a/gdb/symfile.c b/gdb/symfile.c
index 09aa70be1d5..2bfe36ee6ef 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -1413,8 +1413,9 @@ find_separate_debug_file (const char *dir,
      Keep backward compatibility so that DEBUG_FILE_DIRECTORY being "" will
      cause "/..." lookups.  */
 
-  bool target_prefix = startswith (dir, "target:");
-  const char *dir_notarget = target_prefix ? dir + strlen ("target:") : dir;
+  bool target_prefix = is_target_filename (dir);
+  const char *dir_notarget
+    = target_prefix ? dir + strlen (TARGET_SYSROOT_PREFIX) : dir;
   std::vector<gdb::unique_xmalloc_ptr<char>> debugdir_vec
     = dirnames_to_char_ptr_vec (debug_file_directory.c_str ());
   gdb::unique_xmalloc_ptr<char> canon_sysroot
@@ -1443,7 +1444,7 @@ find_separate_debug_file (const char *dir,
 
   for (const gdb::unique_xmalloc_ptr<char> &debugdir : debugdir_vec)
     {
-      debugfile = target_prefix ? "target:" : "";
+      debugfile = target_prefix ? TARGET_SYSROOT_PREFIX : "";
       debugfile += debugdir;
       debugfile += "/";
       debugfile += drive;
@@ -1465,7 +1466,7 @@ find_separate_debug_file (const char *dir,
 	{
 	  /* If the file is in the sysroot, try using its base path in
 	     the global debugfile directory.  */
-	  debugfile = target_prefix ? "target:" : "";
+	  debugfile = target_prefix ? TARGET_SYSROOT_PREFIX : "";
 	  debugfile += debugdir;
 	  debugfile += "/";
 	  debugfile += base_path;
@@ -1481,12 +1482,13 @@ find_separate_debug_file (const char *dir,
 	     prefix -- but if that would yield the empty string, we
 	     don't bother at all, because that would just give the
 	     same result as above.  */
-	  if (gdb_sysroot != "target:")
+	  if (gdb_sysroot != TARGET_SYSROOT_PREFIX)
 	    {
-	      debugfile = target_prefix ? "target:" : "";
-	      if (startswith (gdb_sysroot, "target:"))
+	      debugfile = target_prefix ? TARGET_SYSROOT_PREFIX : "";
+	      if (is_target_filename (gdb_sysroot))
 		{
-		  std::string root = gdb_sysroot.substr (strlen ("target:"));
+		  std::string root
+		    = gdb_sysroot.substr (strlen (TARGET_SYSROOT_PREFIX));
 		  gdb_assert (!root.empty ());
 		  debugfile += root;
 		}
-- 
2.43.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Use TARGET_SYSROOT_PREFIX in more places
  2023-12-10 23:11 [PATCH] Use TARGET_SYSROOT_PREFIX in more places Tom Tromey
@ 2023-12-11 13:27 ` Andrew Burgess
  0 siblings, 0 replies; 2+ messages in thread
From: Andrew Burgess @ 2023-12-11 13:27 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches; +Cc: Tom Tromey

Tom Tromey <tom@tromey.com> writes:

> I found some spots using "target:"; I think it's better to use the
> define everywhere, so this changes these to use TARGET_SYSROOT_PREFIX.
> In some spots, is_target_filename is used rather than an explicit
> check.

Looks good.

Approved-By: Andrew Burgess <aburgess@redhat.com>

Thanks,
Andrew


> ---
>  gdb/build-id.c |  2 +-
>  gdb/gdb_bfd.h  |  8 ++++++++
>  gdb/symfile.c  | 18 ++++++++++--------
>  3 files changed, 19 insertions(+), 9 deletions(-)
>
> diff --git a/gdb/build-id.c b/gdb/build-id.c
> index f68384f0197..6abf04ffacd 100644
> --- a/gdb/build-id.c
> +++ b/gdb/build-id.c
> @@ -90,7 +90,7 @@ build_id_to_debug_bfd_1 (const std::string &link, size_t build_id_len,
>    /* lrealpath() is expensive even for the usually non-existent files.  */
>    gdb::unique_xmalloc_ptr<char> filename_holder;
>    const char *filename = nullptr;
> -  if (startswith (link, TARGET_SYSROOT_PREFIX))
> +  if (is_target_filename (link))
>      filename = link.c_str ();
>    else if (access (link.c_str (), F_OK) == 0)
>      {
> diff --git a/gdb/gdb_bfd.h b/gdb/gdb_bfd.h
> index 604365b61b1..eeb782edcfc 100644
> --- a/gdb/gdb_bfd.h
> +++ b/gdb/gdb_bfd.h
> @@ -45,6 +45,14 @@ struct registry_accessor<bfd>
>  
>  int is_target_filename (const char *name);
>  
> +/* An overload for strings.  */
> +
> +static inline int
> +is_target_filename (const std::string &name)
> +{
> +  return is_target_filename (name.c_str ());
> +}
> +
>  /* Returns nonzero if the filename associated with ABFD starts with
>     TARGET_SYSROOT_PREFIX, zero otherwise.  */
>  
> diff --git a/gdb/symfile.c b/gdb/symfile.c
> index 09aa70be1d5..2bfe36ee6ef 100644
> --- a/gdb/symfile.c
> +++ b/gdb/symfile.c
> @@ -1413,8 +1413,9 @@ find_separate_debug_file (const char *dir,
>       Keep backward compatibility so that DEBUG_FILE_DIRECTORY being "" will
>       cause "/..." lookups.  */
>  
> -  bool target_prefix = startswith (dir, "target:");
> -  const char *dir_notarget = target_prefix ? dir + strlen ("target:") : dir;
> +  bool target_prefix = is_target_filename (dir);
> +  const char *dir_notarget
> +    = target_prefix ? dir + strlen (TARGET_SYSROOT_PREFIX) : dir;
>    std::vector<gdb::unique_xmalloc_ptr<char>> debugdir_vec
>      = dirnames_to_char_ptr_vec (debug_file_directory.c_str ());
>    gdb::unique_xmalloc_ptr<char> canon_sysroot
> @@ -1443,7 +1444,7 @@ find_separate_debug_file (const char *dir,
>  
>    for (const gdb::unique_xmalloc_ptr<char> &debugdir : debugdir_vec)
>      {
> -      debugfile = target_prefix ? "target:" : "";
> +      debugfile = target_prefix ? TARGET_SYSROOT_PREFIX : "";
>        debugfile += debugdir;
>        debugfile += "/";
>        debugfile += drive;
> @@ -1465,7 +1466,7 @@ find_separate_debug_file (const char *dir,
>  	{
>  	  /* If the file is in the sysroot, try using its base path in
>  	     the global debugfile directory.  */
> -	  debugfile = target_prefix ? "target:" : "";
> +	  debugfile = target_prefix ? TARGET_SYSROOT_PREFIX : "";
>  	  debugfile += debugdir;
>  	  debugfile += "/";
>  	  debugfile += base_path;
> @@ -1481,12 +1482,13 @@ find_separate_debug_file (const char *dir,
>  	     prefix -- but if that would yield the empty string, we
>  	     don't bother at all, because that would just give the
>  	     same result as above.  */
> -	  if (gdb_sysroot != "target:")
> +	  if (gdb_sysroot != TARGET_SYSROOT_PREFIX)
>  	    {
> -	      debugfile = target_prefix ? "target:" : "";
> -	      if (startswith (gdb_sysroot, "target:"))
> +	      debugfile = target_prefix ? TARGET_SYSROOT_PREFIX : "";
> +	      if (is_target_filename (gdb_sysroot))
>  		{
> -		  std::string root = gdb_sysroot.substr (strlen ("target:"));
> +		  std::string root
> +		    = gdb_sysroot.substr (strlen (TARGET_SYSROOT_PREFIX));
>  		  gdb_assert (!root.empty ());
>  		  debugfile += root;
>  		}
> -- 
> 2.43.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-12-11 13:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-10 23:11 [PATCH] Use TARGET_SYSROOT_PREFIX in more places Tom Tromey
2023-12-11 13:27 ` 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).