[06/10] gdb: make use of is_target_filename

Message ID eacb536dcaf8adc823016d30f611c8b100beaf5b.1692200989.git.aburgess@redhat.com
State New
Headers
Series Improve GDB/gdbserver experience when using a local gdbserver |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 fail Patch failed to apply
linaro-tcwg-bot/tcwg_gdb_build--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_gdb_check--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 fail Patch failed to apply

Commit Message

Andrew Burgess Aug. 16, 2023, 3:55 p.m. UTC
  Spotted a place where is_target_filename could be used, except that
is_target_filename takes 'const char *' and in the location I spotted
we have a std::string.  So I've added an overload for
is_target_filename that takes a std::string.

There should be no user visible change after this commit.
---
 gdb/build-id.c | 2 +-
 gdb/gdb_bfd.h  | 8 ++++++++
 2 files changed, 9 insertions(+), 1 deletion(-)
  

Comments

Mark Wielaard Aug. 23, 2023, 1:35 p.m. UTC | #1
Hi Andrew,

On Wed, 2023-08-16 at 16:55 +0100, Andrew Burgess wrote:
> Spotted a place where is_target_filename could be used, except that
> is_target_filename takes 'const char *' and in the location I spotted
> we have a std::string.  So I've added an overload for
> is_target_filename that takes a std::string.
> 
> There should be no user visible change after this commit.

This makes sense to me given that all is_target_filename really does
is: return startswith (name, TARGET_SYSROOT_PREFIX);
So this just moves the logic in one place.

Reviewed-by: Mark Wielaard <mark@klomp.org>

> ---
>  gdb/build-id.c | 2 +-
>  gdb/gdb_bfd.h  | 8 ++++++++
>  2 files changed, 9 insertions(+), 1 deletion(-)
> 
> 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 d15b1106d9a..5e9468dcdfd 100644
> --- a/gdb/gdb_bfd.h
> +++ b/gdb/gdb_bfd.h
> @@ -44,6 +44,14 @@ struct registry_accessor<bfd>
>  
>  int is_target_filename (const char *name);
>  
> +/* Like the above, but for std::string.  */
> +
> +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.  */
>
  

Patch

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 d15b1106d9a..5e9468dcdfd 100644
--- a/gdb/gdb_bfd.h
+++ b/gdb/gdb_bfd.h
@@ -44,6 +44,14 @@  struct registry_accessor<bfd>
 
 int is_target_filename (const char *name);
 
+/* Like the above, but for std::string.  */
+
+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.  */