gdb: use std::string in partial_symtab::partial_symtab / allocate_symtab
authorSimon Marchi <simon.marchi@polymtl.ca>
Fri, 2 Apr 2021 15:39:55 +0000 (11:39 -0400)
committerSimon Marchi <simon.marchi@polymtl.ca>
Fri, 2 Apr 2021 15:39:55 +0000 (11:39 -0400)
This simplifies the code a bit.

gdb/ChangeLog:

* psymtab.c (partial_symtab::partial_symtab): Change
last_objfile_name to be an std::string.
* symfile.c (allocate_symtab): Likewise.

Change-Id: I3dfe217233ed9346c2abc04a9b1be0df69a90af8

gdb/ChangeLog
gdb/psymtab.c
gdb/symfile.c

index ac64f5c7609954f97c06f7859abc54aa908f8531..6d61a2cc7c1bfa986f7e0b75a9c8998e9a728a3a 100644 (file)
@@ -1,3 +1,9 @@
+2021-04-02  Simon Marchi  <simon.marchi@polymtl.ca>
+
+       * psymtab.c (partial_symtab::partial_symtab): Change
+       last_objfile_name to be an std::string.
+       * symfile.c (allocate_symtab): Likewise.
+
 2021-04-02  Simon Marchi  <simon.marchi@polymtl.ca>
 
        * objfiles.h (struct objfile_per_bfd_storage) <intern>: New
index b51881d3bd6fdac2134553b3179a86d0408f0056..26ea35ea40c2706ab0b2b82daea567091e49522a 100644 (file)
@@ -1574,16 +1574,15 @@ partial_symtab::partial_symtab (const char *filename_,
     {
       /* Be a bit clever with debugging messages, and don't print objfile
         every time, only when it changes.  */
-      static char *last_objfile_name = NULL;
+      static std::string last_objfile_name;
+      const char *this_objfile_name = objfile_name (objfile);
 
-      if (last_objfile_name == NULL
-         || strcmp (last_objfile_name, objfile_name (objfile)) != 0)
+      if (last_objfile_name.empty () || last_objfile_name != this_objfile_name)
        {
-         xfree (last_objfile_name);
-         last_objfile_name = xstrdup (objfile_name (objfile));
+         last_objfile_name = this_objfile_name;
          fprintf_filtered (gdb_stdlog,
                            "Creating one or more psymtabs for objfile %s ...\n",
-                           last_objfile_name);
+                           this_objfile_name);
        }
       fprintf_filtered (gdb_stdlog,
                        "Created psymtab %s for module %s.\n",
index b71eb1915d287db0914dea15d7b6717f79aeed9b..673451148523420e7c2abd6c531c7e3531cf11b5 100644 (file)
@@ -2770,16 +2770,15 @@ allocate_symtab (struct compunit_symtab *cust, const char *filename)
     {
       /* Be a bit clever with debugging messages, and don't print objfile
         every time, only when it changes.  */
-      static char *last_objfile_name = NULL;
+      static std::string last_objfile_name;
+      const char *this_objfile_name = objfile_name (objfile);
 
-      if (last_objfile_name == NULL
-         || strcmp (last_objfile_name, objfile_name (objfile)) != 0)
+      if (last_objfile_name.empty () || last_objfile_name != this_objfile_name)
        {
-         xfree (last_objfile_name);
-         last_objfile_name = xstrdup (objfile_name (objfile));
+         last_objfile_name = this_objfile_name;
          fprintf_filtered (gdb_stdlog,
                            "Creating one or more symtabs for objfile %s ...\n",
-                           last_objfile_name);
+                           this_objfile_name);
        }
       fprintf_filtered (gdb_stdlog,
                        "Created symtab %s for module %s.\n",