diff options
-rw-r--r-- | gdb/annotate.c | 2 | ||||
-rw-r--r-- | gdb/python/py-breakpoint.c | 4 | ||||
-rw-r--r-- | gdb/source.c | 21 | ||||
-rw-r--r-- | gdb/symfile-debug.c | 8 | ||||
-rw-r--r-- | gdb/symfile.c | 1 | ||||
-rw-r--r-- | gdb/symmisc.c | 4 | ||||
-rw-r--r-- | gdb/symtab.h | 23 |
7 files changed, 38 insertions, 25 deletions
diff --git a/gdb/annotate.c b/gdb/annotate.c index 4ff3eb8..8818029 100644 --- a/gdb/annotate.c +++ b/gdb/annotate.c @@ -451,7 +451,7 @@ annotate_source_line (struct symtab *s, int line, int mid_statement, if (line > offsets->size ()) return false; - annotate_source (s->fullname, line, (int) (*offsets)[line - 1], + annotate_source (s->fullname (), line, (int) (*offsets)[line - 1], mid_statement, s->compunit ()->objfile ()->arch (), pc); diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c index fdc2483..e7dd470 100644 --- a/gdb/python/py-breakpoint.c +++ b/gdb/python/py-breakpoint.c @@ -1716,10 +1716,10 @@ bplocpy_get_fullname (PyObject *py_self, void *closure) BPPY_REQUIRE_VALID (self->owner); BPLOCPY_REQUIRE_VALID (self->owner, self); const auto symtab = self->bp_loc->symtab; - if (symtab != nullptr && symtab->fullname != nullptr) + if (symtab != nullptr && symtab->fullname () != nullptr) { gdbpy_ref<> fullname - = host_string_to_python_string (symtab->fullname); + = host_string_to_python_string (symtab->fullname ()); return fullname.release (); } Py_RETURN_NONE; diff --git a/gdb/source.c b/gdb/source.c index 24a8769..9e528d3 100644 --- a/gdb/source.c +++ b/gdb/source.c @@ -685,8 +685,8 @@ info_source_command (const char *ignore, int from_tty) gdb_printf (_("Current source file is %s\n"), s->filename); if (s->compunit ()->dirname () != NULL) gdb_printf (_("Compilation directory is %s\n"), s->compunit ()->dirname ()); - if (s->fullname) - gdb_printf (_("Located in %s\n"), s->fullname); + if (s->fullname () != nullptr) + gdb_printf (_("Located in %s\n"), s->fullname ()); const std::vector<off_t> *offsets; if (g_source_cache.get_line_charpos (s, &offsets)) gdb_printf (_("Contains %d line%s.\n"), (int) offsets->size (), @@ -1145,8 +1145,7 @@ open_source_file (struct symtab *s) if (!s) return scoped_fd (-EINVAL); - gdb::unique_xmalloc_ptr<char> fullname (s->fullname); - s->fullname = NULL; + gdb::unique_xmalloc_ptr<char> fullname = s->release_fullname (); scoped_fd fd = find_and_open_source (s->filename, s->compunit ()->dirname (), &fullname); @@ -1182,14 +1181,14 @@ open_source_file (struct symtab *s) It handles the reporting of its own errors. */ if (query_fd.get () >= 0) { - s->fullname = fullname.release (); + s->set_fullname (std::move (fullname)); return query_fd; } } } } - s->fullname = fullname.release (); + s->set_fullname (std::move (fullname)); return fd; } @@ -1236,7 +1235,7 @@ symtab_to_fullname (struct symtab *s) /* Use cached copy if we have it. We rely on forget_cached_source_info being called appropriately to handle cases like the file being moved. */ - if (s->fullname == NULL) + if (s->fullname () == nullptr) { scoped_fd fd = open_source_file (s); @@ -1254,13 +1253,13 @@ symtab_to_fullname (struct symtab *s) fullname.reset (concat (s->compunit ()->dirname (), SLASH_STRING, s->filename, (char *) NULL)); - s->fullname = rewrite_source_path (fullname.get ()).release (); - if (s->fullname == NULL) - s->fullname = fullname.release (); + s->set_fullname (rewrite_source_path (fullname.get ())); + if (s->fullname () == nullptr) + s->set_fullname (std::move (fullname)); } } - return s->fullname; + return s->fullname (); } /* See commentary in source.h. */ diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c index 86c7010..3912889 100644 --- a/gdb/symfile-debug.c +++ b/gdb/symfile-debug.c @@ -156,13 +156,7 @@ objfile::forget_cached_source_info () for (compunit_symtab *cu : compunits ()) { for (symtab *s : cu->filetabs ()) - { - if (s->fullname != NULL) - { - xfree (s->fullname); - s->fullname = NULL; - } - } + s->release_fullname (); } for (const auto &iter : qf) diff --git a/gdb/symfile.c b/gdb/symfile.c index 5a03def..b0510b4 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -2803,7 +2803,6 @@ allocate_symtab (struct compunit_symtab *cust, const char *filename, symtab->filename = objfile->intern (filename); symtab->filename_for_id = objfile->intern (filename_for_id); - symtab->fullname = NULL; symtab->set_language (deduce_language_from_filename (filename)); /* This can be very verbose with lots of headers. diff --git a/gdb/symmisc.c b/gdb/symmisc.c index 2956ad9..b4e0360 100644 --- a/gdb/symmisc.c +++ b/gdb/symmisc.c @@ -811,8 +811,8 @@ maintenance_info_symtabs (const char *regexp, int from_tty) gdb_printf ("((struct symtab *) %s)\n", host_address_to_string (symtab)); gdb_printf ("\t fullname %s\n", - symtab->fullname != NULL - ? symtab->fullname + symtab->fullname () != nullptr + ? symtab->fullname () : "(null)"); gdb_printf ("\t " "linetable ((struct linetable *) %s)\n", diff --git a/gdb/symtab.h b/gdb/symtab.h index 3d766fd..e75c638 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -1739,6 +1739,27 @@ struct symtab m_language = language; } + /* Return the current full name of this symtab. */ + const char *fullname () const + { return m_fullname; } + + /* Transfer ownership of the current full name to the caller. The + full name is reset to nullptr. */ + gdb::unique_xmalloc_ptr<char> release_fullname () + { + gdb::unique_xmalloc_ptr<char> result (m_fullname); + m_fullname = nullptr; + return result; + } + + /* Set the current full name to NAME, transferring ownership to this + symtab. */ + void set_fullname (gdb::unique_xmalloc_ptr<char> name) + { + gdb_assert (m_fullname == nullptr); + m_fullname = name.release (); + } + /* Unordered chain of all filetabs in the compunit, with the exception that the "main" source file is the first entry in the list. */ @@ -1776,7 +1797,7 @@ struct symtab /* Full name of file as found by searching the source path. NULL if not yet known. */ - char *fullname; + char *m_fullname; }; /* A range adapter to allowing iterating over all the file tables in a list. */ |