[20/24] gdb: make so_list::{so_original_name, so_name} std::strings

Message ID 20231010204213.111285-21-simon.marchi@efficios.com
State New
Headers
Series C++ification of struct so_list |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Testing passed

Commit Message

Simon Marchi Oct. 10, 2023, 8:40 p.m. UTC
  Change these two fields, simplifying memory management and copying.

Change-Id: If2559284c515721e71e1ef56ada8b64667eebe55
---
 gdb/break-catch-load.c |  2 +-
 gdb/breakpoint.c       |  2 +-
 gdb/bsd-uthread.c      |  8 +++----
 gdb/mi/mi-cmd-file.c   |  2 +-
 gdb/solib-aix.c        |  8 +++----
 gdb/solib-darwin.c     |  5 ++---
 gdb/solib-dsbt.c       |  5 ++---
 gdb/solib-frv.c        |  6 ++----
 gdb/solib-rocm.c       |  8 ++-----
 gdb/solib-svr4.c       | 25 ++++++++++------------
 gdb/solib-target.c     | 18 ++++++----------
 gdb/solib.c            | 47 +++++++++++++++++++++++-------------------
 gdb/solist.h           |  4 ++--
 13 files changed, 63 insertions(+), 77 deletions(-)
  

Comments

Lancelot SIX Oct. 13, 2023, 10:28 p.m. UTC | #1
Hi Simon,

On Tue, Oct 10, 2023 at 04:40:15PM -0400, Simon Marchi wrote:
> Change these two fields, simplifying memory management and copying.
> 
> Change-Id: If2559284c515721e71e1ef56ada8b64667eebe55
> ---
>  gdb/break-catch-load.c |  2 +-
>  gdb/breakpoint.c       |  2 +-
>  gdb/bsd-uthread.c      |  8 +++----
>  gdb/mi/mi-cmd-file.c   |  2 +-
>  gdb/solib-aix.c        |  8 +++----
>  gdb/solib-darwin.c     |  5 ++---
>  gdb/solib-dsbt.c       |  5 ++---
>  gdb/solib-frv.c        |  6 ++----
>  gdb/solib-rocm.c       |  8 ++-----
>  gdb/solib-svr4.c       | 25 ++++++++++------------
>  gdb/solib-target.c     | 18 ++++++----------
>  gdb/solib.c            | 47 +++++++++++++++++++++++-------------------
>  gdb/solist.h           |  4 ++--
>  13 files changed, 63 insertions(+), 77 deletions(-)
> 
> diff --git a/gdb/mi/mi-cmd-file.c b/gdb/mi/mi-cmd-file.c
> index 822d3df40005..5f63ce4494cb 100644
> --- a/gdb/mi/mi-cmd-file.c
> +++ b/gdb/mi/mi-cmd-file.c
> @@ -167,7 +167,7 @@ mi_cmd_file_list_shared_libraries (const char *command,
>      {
>        if (so->so_name[0] == '\0')

I think this should become "so->so_name.empty ()".

>  	continue;
> -      if (pattern != NULL && !re_exec (so->so_name))
> +      if (pattern != NULL && !re_exec (so->so_name.c_str ()))
>  	continue;
>  
>        ui_out_emit_tuple tuple_emitter (uiout, NULL);
> diff --git a/gdb/solib.c b/gdb/solib.c
> index 6b7f0da0498d..1815b0910208 100644
> --- a/gdb/solib.c
> +++ b/gdb/solib.c
> @@ -1088,7 +1093,7 @@ info_sharedlibrary_command (const char *pattern, int from_tty)
>      {
>        if (so->so_name[0])

Similar here.

>  	{
> -	  if (pattern && ! re_exec (so->so_name))
> +	  if (pattern && ! re_exec (so->so_name.c_str ()))
>  	    continue;
>  	  ++nr_libs;
>  	}
> @@ -1109,7 +1114,7 @@ info_sharedlibrary_command (const char *pattern, int from_tty)
>        {
>  	if (! so->so_name[0])

And here it should be "!so->empty ()".

>  	  continue;
> -	if (pattern && ! re_exec (so->so_name))
> +	if (pattern && ! re_exec (so->so_name.c_str ()))
>  	  continue;
>  
>  	ui_out_emit_tuple tuple_emitter (uiout, "lib");

I might have missed other patterns, I'll need to get back to it with
fresher eyes.

Best,
Lancelot.
  
Simon Marchi Oct. 14, 2023, 8:01 p.m. UTC | #2
On 10/13/23 18:28, Lancelot SIX wrote:
> Hi Simon,
> 
> On Tue, Oct 10, 2023 at 04:40:15PM -0400, Simon Marchi wrote:
>> Change these two fields, simplifying memory management and copying.
>>
>> Change-Id: If2559284c515721e71e1ef56ada8b64667eebe55
>> ---
>>  gdb/break-catch-load.c |  2 +-
>>  gdb/breakpoint.c       |  2 +-
>>  gdb/bsd-uthread.c      |  8 +++----
>>  gdb/mi/mi-cmd-file.c   |  2 +-
>>  gdb/solib-aix.c        |  8 +++----
>>  gdb/solib-darwin.c     |  5 ++---
>>  gdb/solib-dsbt.c       |  5 ++---
>>  gdb/solib-frv.c        |  6 ++----
>>  gdb/solib-rocm.c       |  8 ++-----
>>  gdb/solib-svr4.c       | 25 ++++++++++------------
>>  gdb/solib-target.c     | 18 ++++++----------
>>  gdb/solib.c            | 47 +++++++++++++++++++++++-------------------
>>  gdb/solist.h           |  4 ++--
>>  13 files changed, 63 insertions(+), 77 deletions(-)
>>
>> diff --git a/gdb/mi/mi-cmd-file.c b/gdb/mi/mi-cmd-file.c
>> index 822d3df40005..5f63ce4494cb 100644
>> --- a/gdb/mi/mi-cmd-file.c
>> +++ b/gdb/mi/mi-cmd-file.c
>> @@ -167,7 +167,7 @@ mi_cmd_file_list_shared_libraries (const char *command,
>>      {
>>        if (so->so_name[0] == '\0')
> 
> I think this should become "so->so_name.empty ()".

I believe that it's functionally equivalent, but I agree, I will fix
these up.

Simon
  
Lancelot SIX Oct. 19, 2023, 11:08 a.m. UTC | #3
Hi Simon,

Some other minor NULL -> nullptr possible conversions below.

On Tue, Oct 10, 2023 at 04:40:15PM -0400, Simon Marchi wrote:
> Change these two fields, simplifying memory management and copying.
> 
> Change-Id: If2559284c515721e71e1ef56ada8b64667eebe55
> ---
>  gdb/break-catch-load.c |  2 +-
>  gdb/breakpoint.c       |  2 +-
>  gdb/bsd-uthread.c      |  8 +++----
>  gdb/mi/mi-cmd-file.c   |  2 +-
>  gdb/solib-aix.c        |  8 +++----
>  gdb/solib-darwin.c     |  5 ++---
>  gdb/solib-dsbt.c       |  5 ++---
>  gdb/solib-frv.c        |  6 ++----
>  gdb/solib-rocm.c       |  8 ++-----
>  gdb/solib-svr4.c       | 25 ++++++++++------------
>  gdb/solib-target.c     | 18 ++++++----------
>  gdb/solib.c            | 47 +++++++++++++++++++++++-------------------
>  gdb/solist.h           |  4 ++--
>  13 files changed, 63 insertions(+), 77 deletions(-)
> 
> diff --git a/gdb/break-catch-load.c b/gdb/break-catch-load.c
> index 94d8b420d327..999de874d5f6 100644
> --- a/gdb/break-catch-load.c
> +++ b/gdb/break-catch-load.c
> @@ -120,7 +120,7 @@ solib_catchpoint::check_status (struct bpstat *bs)
>        for (so_list *iter : current_program_space->added_solibs)
>  	{
>  	  if (!regex
> -	      || compiled->exec (iter->so_name, 0, NULL, 0) == 0)
> +	      || compiled->exec (iter->so_name.c_str (), 0, NULL, 0) == 0)

While at touching this line, s/NULL/nullptr.

>  	    return;
>  	}
>      }
> diff --git a/gdb/mi/mi-cmd-file.c b/gdb/mi/mi-cmd-file.c
> index 822d3df40005..5f63ce4494cb 100644
> --- a/gdb/mi/mi-cmd-file.c
> +++ b/gdb/mi/mi-cmd-file.c
> @@ -167,7 +167,7 @@ mi_cmd_file_list_shared_libraries (const char *command,
>      {
>        if (so->so_name[0] == '\0')
>  	continue;
> -      if (pattern != NULL && !re_exec (so->so_name))
> +      if (pattern != NULL && !re_exec (so->so_name.c_str ()))

Same.

>  	continue;
>  
>        ui_out_emit_tuple tuple_emitter (uiout, NULL);
> diff --git a/gdb/solib.c b/gdb/solib.c
> index 6b7f0da0498d..1815b0910208 100644
> --- a/gdb/solib.c
> +++ b/gdb/solib.c
> @@ -705,9 +708,10 @@ solib_read_symbols (so_list &so, symfile_add_flags flags)
>  	      section_addr_info sap
>  		= build_section_addr_info_from_section_table (so.sections);
>  	      gdb_bfd_ref_ptr tmp_bfd = so.abfd;
> -	      so.objfile = symbol_file_add_from_bfd (tmp_bfd, so.so_name,
> -						      flags, &sap,
> -						      OBJF_SHARED, NULL);
> +	      so.objfile = symbol_file_add_from_bfd (tmp_bfd,
> +						     so.so_name.c_str (),
> +						     flags, &sap,
> +						     OBJF_SHARED, NULL);

Same.

>  	      so.objfile->addr_low = so.addr_low;
>  	    }
>  

Best,
Lancelot.
  
Simon Marchi Oct. 19, 2023, 2:55 p.m. UTC | #4
On 10/19/23 07:08, Lancelot SIX wrote:
> Hi Simon,
> 
> Some other minor NULL -> nullptr possible conversions below.
> 
> On Tue, Oct 10, 2023 at 04:40:15PM -0400, Simon Marchi wrote:
>> Change these two fields, simplifying memory management and copying.
>>
>> Change-Id: If2559284c515721e71e1ef56ada8b64667eebe55
>> ---
>>  gdb/break-catch-load.c |  2 +-
>>  gdb/breakpoint.c       |  2 +-
>>  gdb/bsd-uthread.c      |  8 +++----
>>  gdb/mi/mi-cmd-file.c   |  2 +-
>>  gdb/solib-aix.c        |  8 +++----
>>  gdb/solib-darwin.c     |  5 ++---
>>  gdb/solib-dsbt.c       |  5 ++---
>>  gdb/solib-frv.c        |  6 ++----
>>  gdb/solib-rocm.c       |  8 ++-----
>>  gdb/solib-svr4.c       | 25 ++++++++++------------
>>  gdb/solib-target.c     | 18 ++++++----------
>>  gdb/solib.c            | 47 +++++++++++++++++++++++-------------------
>>  gdb/solist.h           |  4 ++--
>>  13 files changed, 63 insertions(+), 77 deletions(-)
>>
>> diff --git a/gdb/break-catch-load.c b/gdb/break-catch-load.c
>> index 94d8b420d327..999de874d5f6 100644
>> --- a/gdb/break-catch-load.c
>> +++ b/gdb/break-catch-load.c
>> @@ -120,7 +120,7 @@ solib_catchpoint::check_status (struct bpstat *bs)
>>        for (so_list *iter : current_program_space->added_solibs)
>>  	{
>>  	  if (!regex
>> -	      || compiled->exec (iter->so_name, 0, NULL, 0) == 0)
>> +	      || compiled->exec (iter->so_name.c_str (), 0, NULL, 0) == 0)
> 
> While at touching this line, s/NULL/nullptr.
> 
>>  	    return;
>>  	}
>>      }
>> diff --git a/gdb/mi/mi-cmd-file.c b/gdb/mi/mi-cmd-file.c
>> index 822d3df40005..5f63ce4494cb 100644
>> --- a/gdb/mi/mi-cmd-file.c
>> +++ b/gdb/mi/mi-cmd-file.c
>> @@ -167,7 +167,7 @@ mi_cmd_file_list_shared_libraries (const char *command,
>>      {
>>        if (so->so_name[0] == '\0')
>>  	continue;
>> -      if (pattern != NULL && !re_exec (so->so_name))
>> +      if (pattern != NULL && !re_exec (so->so_name.c_str ()))
> 
> Same.
> 
>>  	continue;
>>  
>>        ui_out_emit_tuple tuple_emitter (uiout, NULL);
>> diff --git a/gdb/solib.c b/gdb/solib.c
>> index 6b7f0da0498d..1815b0910208 100644
>> --- a/gdb/solib.c
>> +++ b/gdb/solib.c
>> @@ -705,9 +708,10 @@ solib_read_symbols (so_list &so, symfile_add_flags flags)
>>  	      section_addr_info sap
>>  		= build_section_addr_info_from_section_table (so.sections);
>>  	      gdb_bfd_ref_ptr tmp_bfd = so.abfd;
>> -	      so.objfile = symbol_file_add_from_bfd (tmp_bfd, so.so_name,
>> -						      flags, &sap,
>> -						      OBJF_SHARED, NULL);
>> +	      so.objfile = symbol_file_add_from_bfd (tmp_bfd,
>> +						     so.so_name.c_str (),
>> +						     flags, &sap,
>> +						     OBJF_SHARED, NULL);
> 
> Same.

Done.

Simon
  

Patch

diff --git a/gdb/break-catch-load.c b/gdb/break-catch-load.c
index 94d8b420d327..999de874d5f6 100644
--- a/gdb/break-catch-load.c
+++ b/gdb/break-catch-load.c
@@ -120,7 +120,7 @@  solib_catchpoint::check_status (struct bpstat *bs)
       for (so_list *iter : current_program_space->added_solibs)
 	{
 	  if (!regex
-	      || compiled->exec (iter->so_name, 0, NULL, 0) == 0)
+	      || compiled->exec (iter->so_name.c_str (), 0, NULL, 0) == 0)
 	    return;
 	}
     }
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 75691935553d..3ddd1623cf00 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -8052,7 +8052,7 @@  disable_breakpoints_in_unloaded_shlib (program_space *pspace,
 	      target_terminal::ours_for_output ();
 	      warning (_("Temporarily disabling breakpoints "
 			 "for unloaded shared library \"%s\""),
-		       solib.so_name);
+		       solib.so_name.c_str ());
 	    }
 	  disabled_shlib_breaks = true;
 	}
diff --git a/gdb/bsd-uthread.c b/gdb/bsd-uthread.c
index 6435a5291958..8144f8cc64b7 100644
--- a/gdb/bsd-uthread.c
+++ b/gdb/bsd-uthread.c
@@ -149,7 +149,7 @@  static int bsd_uthread_thread_next_offset = -1;
 static int bsd_uthread_thread_ctx_offset;
 
 /* Name of shared threads library.  */
-static const char *bsd_uthread_solib_name;
+static std::string bsd_uthread_solib_name;
 
 /* Non-zero if the thread stratum implemented by this module is active.  */
 static int bsd_uthread_active;
@@ -245,7 +245,7 @@  bsd_uthread_target::close ()
   bsd_uthread_thread_state_offset = 0;
   bsd_uthread_thread_next_offset = 0;
   bsd_uthread_thread_ctx_offset = 0;
-  bsd_uthread_solib_name = NULL;
+  bsd_uthread_solib_name.clear ();
 }
 
 /* Deactivate the thread stratum implemented by this module.  */
@@ -297,10 +297,10 @@  bsd_uthread_solib_loaded (so_list &so)
 static void
 bsd_uthread_solib_unloaded (program_space *pspace, const so_list &so)
 {
-  if (!bsd_uthread_solib_name)
+  if (bsd_uthread_solib_name.empty ())
     return;
 
-  if (strcmp (so.so_original_name, bsd_uthread_solib_name) == 0)
+  if (so.so_original_name == bsd_uthread_solib_name)
     bsd_uthread_deactivate ();
 }
 
diff --git a/gdb/mi/mi-cmd-file.c b/gdb/mi/mi-cmd-file.c
index 822d3df40005..5f63ce4494cb 100644
--- a/gdb/mi/mi-cmd-file.c
+++ b/gdb/mi/mi-cmd-file.c
@@ -167,7 +167,7 @@  mi_cmd_file_list_shared_libraries (const char *command,
     {
       if (so->so_name[0] == '\0')
 	continue;
-      if (pattern != NULL && !re_exec (so->so_name))
+      if (pattern != NULL && !re_exec (so->so_name.c_str ()))
 	continue;
 
       ui_out_emit_tuple tuple_emitter (uiout, NULL);
diff --git a/gdb/solib-aix.c b/gdb/solib-aix.c
index a9931a60f336..e5e86c49e712 100644
--- a/gdb/solib-aix.c
+++ b/gdb/solib-aix.c
@@ -482,11 +482,9 @@  solib_aix_current_sos (void)
 	 so_name = string_printf ("%s(%s)", info.filename.c_str (),
 				  info.member_name.c_str ());
 	}
-      strncpy (new_solib->so_original_name, so_name.c_str (),
-	       SO_NAME_MAX_PATH_SIZE - 1);
-      new_solib->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
-      memcpy (new_solib->so_name, new_solib->so_original_name,
-	      SO_NAME_MAX_PATH_SIZE);
+
+      new_solib->so_original_name = so_name;
+      new_solib->so_name = so_name;
       new_solib->lm_info = gdb::make_unique<lm_info_aix> (info);
 
       /* Add it to the list.  */
diff --git a/gdb/solib-darwin.c b/gdb/solib-darwin.c
index e97c693052bc..2c62e16d386a 100644
--- a/gdb/solib-darwin.c
+++ b/gdb/solib-darwin.c
@@ -277,9 +277,8 @@  darwin_current_sos (void)
 
       auto li = gdb::make_unique<lm_info_darwin> ();
 
-      strncpy (newobj->so_name, file_path.get (), SO_NAME_MAX_PATH_SIZE - 1);
-      newobj->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
-      strcpy (newobj->so_original_name, newobj->so_name);
+      newobj->so_name = file_path.get ();
+      newobj->so_original_name = newobj->so_name;
       li->lm_addr = load_addr;
 
       newobj->lm_info = std::move (li);
diff --git a/gdb/solib-dsbt.c b/gdb/solib-dsbt.c
index 6f4de80782a9..d3566b9590db 100644
--- a/gdb/solib-dsbt.c
+++ b/gdb/solib-dsbt.c
@@ -612,9 +612,8 @@  dsbt_current_sos (void)
 		gdb_printf (gdb_stdlog, "current_sos: name = %s\n",
 			    name_buf.get ());
 
-	      strncpy (sop->so_name, name_buf.get (), SO_NAME_MAX_PATH_SIZE - 1);
-	      sop->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
-	      strcpy (sop->so_original_name, sop->so_name);
+	      sop->so_name = name_buf.get ();
+	      sop->so_original_name = sop->so_name;
 	    }
 
 	  sop->lm_info = std::move (li);
diff --git a/gdb/solib-frv.c b/gdb/solib-frv.c
index 2ed6280b5879..d92c35339523 100644
--- a/gdb/solib-frv.c
+++ b/gdb/solib-frv.c
@@ -395,10 +395,8 @@  frv_current_sos (void)
 	    warning (_("Can't read pathname for link map entry."));
 	  else
 	    {
-	      strncpy (sop->so_name, name_buf.get (),
-		       SO_NAME_MAX_PATH_SIZE - 1);
-	      sop->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
-	      strcpy (sop->so_original_name, sop->so_name);
+	      sop->so_name = name_buf.get ();
+	      sop->so_original_name = sop->so_name;
 	    }
 
 	  sop->lm_info = std::move (li);
diff --git a/gdb/solib-rocm.c b/gdb/solib-rocm.c
index 9a9bfa36fddb..bdd458995c21 100644
--- a/gdb/solib-rocm.c
+++ b/gdb/solib-rocm.c
@@ -215,12 +215,8 @@  so_list_from_rocm_sos (const std::vector<rocm_so> &sos)
       so_list *newobj = new so_list;
       newobj->lm_info = gdb::make_unique<lm_info_svr4> (*so.lm_info);
 
-      strncpy (newobj->so_name, so.name.c_str (), sizeof (newobj->so_name));
-      newobj->so_name[sizeof (newobj->so_name) - 1] = '\0';
-
-      strncpy (newobj->so_original_name, so.unique_name.c_str (),
-	       sizeof (newobj->so_original_name));
-      newobj->so_original_name[sizeof (newobj->so_original_name) - 1] = '\0';
+      newobj->so_name = so.name;
+      newobj->so_original_name = so.unique_name;
 
       newobj->next = nullptr;
       *link = newobj;
diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
index 6a54cd332085..b90b4ca2f680 100644
--- a/gdb/solib-svr4.c
+++ b/gdb/solib-svr4.c
@@ -193,8 +193,8 @@  svr4_same (const so_list &gdb, const so_list &inferior)
   auto *lmi
     = gdb::checked_static_cast<const lm_info_svr4 *> (inferior.lm_info.get ());
 
-  return svr4_same (gdb.so_original_name, inferior.so_original_name,
-		    *lmg, *lmi);
+  return svr4_same (gdb.so_original_name.c_str (),
+		    inferior.so_original_name.c_str (), *lmg, *lmi);
 }
 
 static lm_info_svr4_up
@@ -316,7 +316,7 @@  lm_addr_check (const so_list &so, bfd *abfd)
 		gdb_printf (_("Using PIC (Position Independent Code) "
 			      "prelink displacement %s for \"%s\".\n"),
 			    paddress (current_inferior ()->arch (), l_addr),
-			    so.so_name);
+			    so.so_name.c_str ());
 	    }
 	  else
 	    {
@@ -331,7 +331,8 @@  lm_addr_check (const so_list &so, bfd *abfd)
 
 	      warning (_(".dynamic section for \"%s\" "
 			 "is not at the expected address "
-			 "(wrong library or version mismatch?)"), so.so_name);
+			 "(wrong library or version mismatch?)"),
+			 so.so_name.c_str ());
 	    }
 	}
 
@@ -999,10 +1000,8 @@  so_list_from_svr4_sos (const std::vector<svr4_so> &sos)
     {
       so_list *newobj = new so_list;
 
-      strncpy (newobj->so_name, so.name.c_str (),
-	       sizeof (newobj->so_name) - 1);                                                                                                                
-      newobj->so_name[sizeof (newobj->so_name) - 1] = 0;                                                                                                                            
-      strcpy (newobj->so_original_name, newobj->so_name);    
+      newobj->so_name = so.name;
+      newobj->so_original_name = so.name;
       newobj->lm_info = gdb::make_unique<lm_info_svr4> (*so.lm_info);
 
       newobj->next = NULL;
@@ -1201,10 +1200,8 @@  svr4_default_sos (svr4_info *info)
   li->l_addr_p = 1;
 
   newobj->lm_info = std::move (li);
-
-  strncpy (newobj->so_name, info->debug_loader_name, SO_NAME_MAX_PATH_SIZE - 1);
-  newobj->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
-  strcpy (newobj->so_original_name, newobj->so_name);
+  newobj->so_name = info->debug_loader_name;
+  newobj->so_original_name = newobj->so_name;
 
   return newobj;
 }
@@ -2374,7 +2371,7 @@  enable_break (struct svr4_info *info, int from_tty)
 	 address from the shared library table.  */
       for (struct so_list *so : current_program_space->solibs ())
 	{
-	  if (svr4_same_1 (interp_name, so->so_original_name))
+	  if (svr4_same_1 (interp_name, so->so_original_name.c_str ()))
 	    {
 	      load_addr_found = 1;
 	      loader_found_in_list = 1;
@@ -3305,7 +3302,7 @@  find_debug_base_for_solib (so_list *solib)
       const std::vector<svr4_so> &sos = tuple.second;
 
       for (const svr4_so &so : sos)
-	if (svr4_same (solib->so_original_name, so.name.c_str (),
+	if (svr4_same (solib->so_original_name.c_str (), so.name.c_str (),
 		       *lm_info, *so.lm_info))
 	  return debug_base;
     }
diff --git a/gdb/solib-target.c b/gdb/solib-target.c
index cccdfa83c9c5..0881d7eda430 100644
--- a/gdb/solib-target.c
+++ b/gdb/solib-target.c
@@ -250,16 +250,10 @@  solib_target_current_sos (void)
   for (lm_info_target_up &info : library_list)
     {
       so_list *new_solib = new so_list;
-      strncpy (new_solib->so_name, info->name.c_str (),
-	       SO_NAME_MAX_PATH_SIZE - 1);
-      new_solib->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
-      strncpy (new_solib->so_original_name, info->name.c_str (),
-	       SO_NAME_MAX_PATH_SIZE - 1);
-      new_solib->so_original_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
-
-      /* We no longer need this copy of the name.  */
-      info->name.clear ();
 
+      /* We don't need a copy of the name in INFO anymore.  */
+      new_solib->so_name = std::move (info->name);
+      new_solib->so_original_name = new_solib->so_name;
       new_solib->lm_info = std::move (info);
 
       /* Add it to the list.  */
@@ -310,7 +304,7 @@  solib_target_relocate_section_addresses (so_list &so, target_section *sec)
 	  if (num_alloc_sections != li->section_bases.size ())
 	    warning (_("\
 Could not relocate shared library \"%s\": wrong number of ALLOC sections"),
-		     so.so_name);
+		     so.so_name.c_str ());
 	  else
 	    {
 	      int bases_index = 0;
@@ -353,7 +347,7 @@  Could not relocate shared library \"%s\": wrong number of ALLOC sections"),
 
 	  if (data == NULL)
 	    warning (_("\
-Could not relocate shared library \"%s\": no segments"), so.so_name);
+Could not relocate shared library \"%s\": no segments"), so.so_name.c_str ());
 	  else
 	    {
 	      ULONGEST orig_delta;
@@ -364,7 +358,7 @@  Could not relocate shared library \"%s\": no segments"), so.so_name);
 						    li->segment_bases.size (),
 						    li->segment_bases.data ()))
 		warning (_("\
-Could not relocate shared library \"%s\": bad offsets"), so.so_name);
+Could not relocate shared library \"%s\": bad offsets"), so.so_name.c_str ());
 
 	      /* Find the range of addresses to report for this library in
 		 "info sharedlibrary".  Report any consecutive segments
diff --git a/gdb/solib.c b/gdb/solib.c
index 6b7f0da0498d..1815b0910208 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -543,10 +543,11 @@  solib_map_sections (so_list &so)
 {
   const target_so_ops *ops = gdbarch_so_ops (current_inferior ()->arch ());
 
-  gdb::unique_xmalloc_ptr<char> filename (tilde_expand (so.so_name));
+  gdb::unique_xmalloc_ptr<char> filename (tilde_expand (so.so_name.c_str ()));
   gdb_bfd_ref_ptr abfd (ops->bfd_open (filename.get ()));
   gdb::unique_xmalloc_ptr<char> build_id_hexstr
-    = get_cbfd_soname_build_id (current_program_space->cbfd, so.so_name);
+    = get_cbfd_soname_build_id (current_program_space->cbfd,
+				so.so_name.c_str ());
 
   /* If we already know the build-id of this solib from a core file, verify
      it matches ABFD's build-id.  If there is a mismatch or the solib wasn't
@@ -566,7 +567,8 @@  solib_map_sections (so_list &so)
 	{
 	  scoped_fd fd = debuginfod_exec_query ((const unsigned char*)
 						build_id_hexstr.get (),
-						0, so.so_name, &filename);
+						0, so.so_name.c_str (),
+						&filename);
 
 	  if (fd.get () >= 0)
 	    abfd = ops->bfd_open (filename.get ());
@@ -590,8 +592,8 @@  solib_map_sections (so_list &so)
      GDB/MI will not provide the correct host-side path.  */
   if (strlen (bfd_get_filename (so.abfd.get ())) >= SO_NAME_MAX_PATH_SIZE)
     error (_("Shared library file name is too long."));
-  strcpy (so.so_name, bfd_get_filename (so.abfd.get ()));
 
+  so.so_name = bfd_get_filename (so.abfd.get ());
   so.sections = build_section_table (so.abfd.get ());
 
   for (target_section &p : so.sections)
@@ -639,7 +641,7 @@  so_list::clear ()
 
   /* Restore the target-supplied file name.  SO_NAME may be the path
      of the symbol file.  */
-  strcpy (this->so_name, this->so_original_name);
+  this->so_name = this->so_original_name;
 
   /* Do the same for target-specific data.  */
   if (ops->clear_so != NULL)
@@ -693,7 +695,8 @@  solib_read_symbols (so_list &so, symfile_add_flags flags)
 	  so.objfile = nullptr;
 	  for (objfile *objfile : current_program_space->objfiles ())
 	    {
-	      if (filename_cmp (objfile_name (objfile), so.so_name) == 0
+	      if (filename_cmp (objfile_name (objfile),
+				so.so_name.c_str ()) == 0
 		  && objfile->addr_low == so.addr_low)
 		{
 		  so.objfile = objfile;
@@ -705,9 +708,10 @@  solib_read_symbols (so_list &so, symfile_add_flags flags)
 	      section_addr_info sap
 		= build_section_addr_info_from_section_table (so.sections);
 	      gdb_bfd_ref_ptr tmp_bfd = so.abfd;
-	      so.objfile = symbol_file_add_from_bfd (tmp_bfd, so.so_name,
-						      flags, &sap,
-						      OBJF_SHARED, NULL);
+	      so.objfile = symbol_file_add_from_bfd (tmp_bfd,
+						     so.so_name.c_str (),
+						     flags, &sap,
+						     OBJF_SHARED, NULL);
 	      so.objfile->addr_low = so.addr_low;
 	    }
 
@@ -717,7 +721,7 @@  solib_read_symbols (so_list &so, symfile_add_flags flags)
 	{
 	  exception_fprintf (gdb_stderr, e, _("Error while reading shared"
 					      " library symbols for %s:\n"),
-			     so.so_name);
+			     so.so_name.c_str ());
 	}
 
       return true;
@@ -832,7 +836,8 @@  update_solib_list (int from_tty)
 	    }
 	  else
 	    {
-	      if (! filename_cmp (gdb->so_original_name, i->so_original_name))
+	      if (filename_cmp (gdb->so_original_name.c_str (),
+				i->so_original_name.c_str ()) == 0)
 		break;	      
 	    }
 
@@ -901,7 +906,7 @@  update_solib_list (int from_tty)
 		{
 		  not_found++;
 		  if (not_found_filename == NULL)
-		    not_found_filename = i->so_original_name;
+		    not_found_filename = i->so_original_name.c_str ();
 		}
 	    }
 
@@ -961,7 +966,7 @@  libpthread_name_p (const char *name)
 static bool
 libpthread_solib_p (const so_list &so)
 {
-  return libpthread_name_p (so.so_name);
+  return libpthread_name_p (so.so_name.c_str ());
 }
 
 /* Read in symbolic information for any shared objects whose names
@@ -1011,7 +1016,7 @@  solib_add (const char *pattern, int from_tty, int readsyms)
 	add_flags |= SYMFILE_VERBOSE;
 
     for (struct so_list *gdb : current_program_space->solibs ())
-      if (! pattern || re_exec (gdb->so_name))
+      if (! pattern || re_exec (gdb->so_name.c_str ()))
 	{
 	  /* Normally, we would read the symbols from that library
 	     only if READSYMS is set.  However, we're making a small
@@ -1030,7 +1035,7 @@  solib_add (const char *pattern, int from_tty, int readsyms)
 		     libraries we have already loaded.  */
 		  if (pattern && (from_tty || info_verbose))
 		    gdb_printf (_("Symbols already loaded for %s\n"),
-				gdb->so_name);
+				gdb->so_name.c_str ());
 		}
 	      else if (solib_read_symbols (*gdb, add_flags))
 		loaded_any_symbols = true;
@@ -1088,7 +1093,7 @@  info_sharedlibrary_command (const char *pattern, int from_tty)
     {
       if (so->so_name[0])
 	{
-	  if (pattern && ! re_exec (so->so_name))
+	  if (pattern && ! re_exec (so->so_name.c_str ()))
 	    continue;
 	  ++nr_libs;
 	}
@@ -1109,7 +1114,7 @@  info_sharedlibrary_command (const char *pattern, int from_tty)
       {
 	if (! so->so_name[0])
 	  continue;
-	if (pattern && ! re_exec (so->so_name))
+	if (pattern && ! re_exec (so->so_name.c_str ()))
 	  continue;
 
 	ui_out_emit_tuple tuple_emitter (uiout, "lib");
@@ -1187,7 +1192,7 @@  solib_name_from_address (struct program_space *pspace, CORE_ADDR address)
 
   for (so = pspace->so_list; so; so = so->next)
     if (solib_contains_address_p (*so, address))
-      return (so->so_name);
+      return so->so_name.c_str ();
 
   return (0);
 }
@@ -1327,7 +1332,7 @@  reload_shared_libraries_1 (int from_tty)
 	add_flags |= SYMFILE_VERBOSE;
 
       gdb::unique_xmalloc_ptr<char> filename
-	(tilde_expand (so->so_original_name));
+	(tilde_expand (so->so_original_name.c_str ()));
       gdb_bfd_ref_ptr abfd (solib_bfd_open (filename.get ()));
       if (abfd != NULL)
 	found_pathname = bfd_get_filename (abfd.get ());
@@ -1336,7 +1341,7 @@  reload_shared_libraries_1 (int from_tty)
 	 symbol file, close that.  */
       if ((found_pathname == NULL && was_loaded)
 	  || (found_pathname != NULL
-	      && filename_cmp (found_pathname, so->so_name) != 0))
+	      && filename_cmp (found_pathname, so->so_name.c_str ()) != 0))
 	{
 	  if (so->objfile && ! (so->objfile->flags & OBJF_USERLOADED)
 	      && !solib_used (so))
@@ -1349,7 +1354,7 @@  reload_shared_libraries_1 (int from_tty)
 	 file, open it.  */
       if (found_pathname != NULL
 	  && (!was_loaded
-	      || filename_cmp (found_pathname, so->so_name) != 0))
+	      || filename_cmp (found_pathname, so->so_name.c_str ()) != 0))
 	{
 	  bool got_error = false;
 
diff --git a/gdb/solist.h b/gdb/solist.h
index 671f8812916c..9320acb7fd3e 100644
--- a/gdb/solist.h
+++ b/gdb/solist.h
@@ -65,10 +65,10 @@  struct so_list
      which needs to be looked up in LD_LIBRARY_PATH, etc.  We use it
      to tell which entries in the inferior's dynamic linker's link
      map we've already loaded.  */
-  char so_original_name[SO_NAME_MAX_PATH_SIZE] {};
+  std::string so_original_name;
 
   /* Shared object file name, expanded to something GDB can open.  */
-  char so_name[SO_NAME_MAX_PATH_SIZE] {};
+  std::string so_name;
 
   /* The following fields of the structure are built from
      information gathered from the shared object file itself, and