From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1879) id 6EA61385803E; Tue, 12 Apr 2022 18:21:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6EA61385803E Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Simon Marchi To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb: change subfile::name and buildsym_compunit::m_comp_dir to strings X-Act-Checkin: binutils-gdb X-Git-Author: Simon Marchi X-Git-Refname: refs/heads/master X-Git-Oldrev: 71bc95ed2032567e2a7aebc3efe1c55a77abb7b2 X-Git-Newrev: ebd4e6d017f972cbba5d889310a09506bec4dbf4 Message-Id: <20220412182101.6EA61385803E@sourceware.org> Date: Tue, 12 Apr 2022 18:21:01 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Apr 2022 18:21:01 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Debd4e6d017f9= 72cbba5d889310a09506bec4dbf4 commit ebd4e6d017f972cbba5d889310a09506bec4dbf4 Author: Simon Marchi Date: Fri Apr 8 11:04:24 2022 -0400 gdb: change subfile::name and buildsym_compunit::m_comp_dir to strings =20 Change subfile::name to be a string, for easier memory management. Change buildsym_compunit::m_comp_dir as well, since we move one in to the other at some point in patch_subfile_names, so it's easier to do both at the same time. There are various NULL checks for both fields currently, replace them with empty checks, I think it ends up equivalent. =20 I can't test the change in xcoffread.c, it's best-effort. =20 Change-Id: I62b5fb08b2089e096768a090627ac7617e90a016 Diff: --- gdb/buildsym.c | 64 +++++++++++++++++++++++++--------------------------= ---- gdb/buildsym.h | 8 +++---- gdb/dwarf2/read.c | 10 ++++----- gdb/xcoffread.c | 3 +-- 4 files changed, 38 insertions(+), 47 deletions(-) diff --git a/gdb/buildsym.c b/gdb/buildsym.c index aedc3c67b9a..034db598735 100644 --- a/gdb/buildsym.c +++ b/gdb/buildsym.c @@ -63,7 +63,7 @@ buildsym_compunit::buildsym_compunit (struct objfile *obj= file_, CORE_ADDR last_addr) : m_objfile (objfile_), m_last_source_file (name =3D=3D nullptr ? nullptr : xstrdup (name)), - m_comp_dir (comp_dir_ =3D=3D nullptr ? nullptr : xstrdup (comp_dir_)), + m_comp_dir (comp_dir_ =3D=3D nullptr ? "" : comp_dir_), m_language (language_), m_last_source_start_addr (last_addr) { @@ -95,7 +95,6 @@ buildsym_compunit::~buildsym_compunit () subfile =3D nextsub) { nextsub =3D subfile->next; - xfree (subfile->name); xfree (subfile->line_vector); delete subfile; } @@ -503,45 +502,40 @@ buildsym_compunit::make_blockvector () void buildsym_compunit::start_subfile (const char *name) { - const char *subfile_dirname; - - subfile_dirname =3D m_comp_dir.get (); - /* See if this subfile is already registered. */ =20 for (subfile *subfile =3D m_subfiles; subfile; subfile =3D subfile->next) { - char *subfile_name; + std::string subfile_name_holder; + const char *subfile_name; =20 /* If NAME is an absolute path, and this subfile is not, then attempt to create an absolute path to compare. */ if (IS_ABSOLUTE_PATH (name) && !IS_ABSOLUTE_PATH (subfile->name) - && subfile_dirname !=3D NULL) - subfile_name =3D concat (subfile_dirname, SLASH_STRING, - subfile->name, (char *) NULL); + && !m_comp_dir.empty ()) + { + subfile_name_holder =3D string_printf ("%s/%s", m_comp_dir.c_str (), + subfile->name.c_str ()); + subfile_name =3D subfile_name_holder.c_str (); + } else - subfile_name =3D subfile->name; + subfile_name =3D subfile->name.c_str (); =20 if (FILENAME_CMP (subfile_name, name) =3D=3D 0) { m_current_subfile =3D subfile; - if (subfile_name !=3D subfile->name) - xfree (subfile_name); return; } - if (subfile_name !=3D subfile->name) - xfree (subfile_name); } =20 /* This subfile is not known. Add an entry for it. */ =20 subfile_up subfile (new struct subfile); + subfile->name =3D name; =20 m_current_subfile =3D subfile.get (); =20 - subfile->name =3D xstrdup (name); - /* Initialize line-number recording for this subfile. */ subfile->line_vector =3D NULL; =20 @@ -556,7 +550,7 @@ buildsym_compunit::start_subfile (const char *name) until after all the symbols have been processed for a given source file. */ =20 - subfile->language =3D deduce_language_from_filename (subfile->name); + subfile->language =3D deduce_language_from_filename (subfile->name.c_str= ()); if (subfile->language =3D=3D language_unknown && m_subfiles !=3D nullptr) subfile->language =3D m_subfiles->language; =20 @@ -565,10 +559,10 @@ buildsym_compunit::start_subfile (const char *name) any other C++ suffixes accepted by deduce_language_from_filename. */ /* Likewise for f2c. */ =20 - if (subfile->name) + if (!subfile->name.empty ()) { struct subfile *s; - enum language sublang =3D deduce_language_from_filename (subfile->na= me); + language sublang =3D deduce_language_from_filename (subfile->name.c_= str ()); =20 if (sublang =3D=3D language_cplus || sublang =3D=3D language_fortran) for (s =3D m_subfiles; s !=3D NULL; s =3D s->next) @@ -605,12 +599,12 @@ buildsym_compunit::patch_subfile_names (struct subfil= e *subfile, const char *name) { if (subfile !=3D NULL - && m_comp_dir =3D=3D NULL - && subfile->name !=3D NULL - && IS_DIR_SEPARATOR (subfile->name[strlen (subfile->name) - 1])) + && m_comp_dir.empty () + && !subfile->name.empty () + && IS_DIR_SEPARATOR (subfile->name.back ())) { - m_comp_dir.reset (subfile->name); - subfile->name =3D xstrdup (name); + m_comp_dir =3D std::move (subfile->name); + subfile->name =3D name; set_last_source_file (name); =20 /* Default the source language to whatever can be deduced from @@ -624,7 +618,8 @@ buildsym_compunit::patch_subfile_names (struct subfile = *subfile, symbols, since symtabs aren't allocated until after all the symbols have been processed for a given source file. */ =20 - subfile->language =3D deduce_language_from_filename (subfile->name); + subfile->language + =3D deduce_language_from_filename (subfile->name.c_str ()); if (subfile->language =3D=3D language_unknown && subfile->next !=3D NULL) { @@ -642,8 +637,8 @@ void buildsym_compunit::push_subfile () { gdb_assert (m_current_subfile !=3D NULL); - gdb_assert (m_current_subfile->name !=3D NULL); - m_subfile_stack.push_back (m_current_subfile->name); + gdb_assert (!m_current_subfile->name.empty ()); + m_subfile_stack.push_back (m_current_subfile->name.c_str ()); } =20 const char * @@ -746,7 +741,7 @@ buildsym_compunit::watch_main_source_file_lossage () if (mainsub->line_vector =3D=3D NULL && mainsub->symtab =3D=3D NULL) { - const char *mainbase =3D lbasename (mainsub->name); + const char *mainbase =3D lbasename (mainsub->name.c_str ()); int nr_matches =3D 0; struct subfile *prevsub; struct subfile *mainsub_alias =3D NULL; @@ -759,7 +754,7 @@ buildsym_compunit::watch_main_source_file_lossage () { if (subfile =3D=3D mainsub) continue; - if (filename_cmp (lbasename (subfile->name), mainbase) =3D=3D 0) + if (filename_cmp (lbasename (subfile->name.c_str ()), mainbase) =3D=3D = 0) { ++nr_matches; mainsub_alias =3D subfile; @@ -784,7 +779,6 @@ buildsym_compunit::watch_main_source_file_lossage () m_subfiles =3D mainsub_alias->next; else prev_mainsub_alias->next =3D mainsub_alias->next; - xfree (mainsub_alias->name); =20 delete mainsub_alias; } @@ -967,7 +961,8 @@ buildsym_compunit::end_compunit_symtab_with_blockvector =20 /* Allocate a symbol table if necessary. */ if (subfile->symtab =3D=3D NULL) - subfile->symtab =3D allocate_symtab (cu, subfile->name); + subfile->symtab =3D allocate_symtab (cu, subfile->name.c_str ()); + struct symtab *symtab =3D subfile->symtab; =20 /* Fill in its components. */ @@ -997,12 +992,11 @@ buildsym_compunit::end_compunit_symtab_with_blockvect= or =20 /* Fill out the compunit symtab. */ =20 - if (m_comp_dir !=3D NULL) + if (!m_comp_dir.empty ()) { /* Reallocate the dirname on the symbol obstack. */ - const char *comp_dir =3D m_comp_dir.get (); cu->set_dirname (obstack_strdup (&m_objfile->objfile_obstack, - comp_dir)); + m_comp_dir.c_str ())); } =20 /* Save the debug format string (if any) in the symtab. */ diff --git a/gdb/buildsym.h b/gdb/buildsym.h index 50ecd33d544..6284aafc878 100644 --- a/gdb/buildsym.h +++ b/gdb/buildsym.h @@ -52,9 +52,7 @@ struct subfile DISABLE_COPY_AND_ASSIGN (subfile); =20 struct subfile *next =3D nullptr; - - /* Space for this is malloc'd. */ - char *name =3D nullptr; + std::string name; =20 /* Space for this is malloc'd. */ struct linetable *line_vector =3D nullptr; @@ -154,7 +152,7 @@ struct buildsym_compunit CORE_ADDR last_addr, struct compunit_symtab *cust) : m_objfile (objfile_), m_last_source_file (name =3D=3D nullptr ? nullptr : xstrdup (name)), - m_comp_dir (comp_dir_ =3D=3D nullptr ? nullptr : xstrdup (comp_dir_)= ), + m_comp_dir (comp_dir_ =3D=3D nullptr ? "" : comp_dir_), m_compunit_symtab (cust), m_language (language_), m_last_source_start_addr (last_addr) @@ -342,7 +340,7 @@ private: gdb::unique_xmalloc_ptr m_last_source_file; =20 /* E.g., DW_AT_comp_dir if DWARF. Space for this is malloc'd. */ - gdb::unique_xmalloc_ptr m_comp_dir; + std::string m_comp_dir; =20 /* Space for this is not malloc'd, and is assumed to have at least the same lifetime as objfile. */ diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 7c148aecdf5..698720276a9 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -9740,8 +9740,8 @@ dwarf2_cu::setup_type_unit_groups (struct die_info *d= ie) assume there's a simple mapping from cu->line_header->file_names to subfiles, plus cu->line_header->file_names may contain dups. */ - b->get_current_subfile ()->symtab - =3D allocate_symtab (cust, b->get_current_subfile ()->name); + const char *name =3D b->get_current_subfile ()->name.c_str (); + b->get_current_subfile ()->symtab =3D allocate_symtab (cust, name); } =20 fe.symtab =3D b->get_current_subfile ()->symtab; @@ -20083,7 +20083,7 @@ dwarf_record_line_1 (struct gdbarch *gdbarch, struc= t subfile *subfile, { gdb_printf (gdb_stdlog, "Recording line %u, file %s, address %s\n", - line, lbasename (subfile->name), + line, lbasename (subfile->name.c_str ()), paddress (gdbarch, address)); } =20 @@ -20107,7 +20107,7 @@ dwarf_finish_line (struct gdbarch *gdbarch, struct = subfile *subfile, { gdb_printf (gdb_stdlog, "Finishing current line, file %s, address %s\n", - lbasename (subfile->name), + lbasename (subfile->name.c_str ()), paddress (gdbarch, address)); } =20 @@ -20500,7 +20500,7 @@ dwarf_decode_lines (struct line_header *lh, struct = dwarf2_cu *cu, { builder->get_current_subfile ()->symtab =3D allocate_symtab (cust, - builder->get_current_subfile ()->name); + builder->get_current_subfile ()->name.c_str ()); } fe.symtab =3D builder->get_current_subfile ()->symtab; } diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c index 296e71356dd..894a12ea865 100644 --- a/gdb/xcoffread.c +++ b/gdb/xcoffread.c @@ -766,10 +766,9 @@ process_linenos (CORE_ADDR start, CORE_ADDR end) if (fakename =3D=3D NULL) fakename =3D " ?"; start_subfile (fakename); - xfree (get_current_subfile ()->name); } struct subfile *current_subfile =3D get_current_subfile (); - current_subfile->name =3D xstrdup (inclTable[ii].name); + current_subfile->name =3D inclTable[ii].name; #endif =20 if (lv =3D=3D lineTb)