diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 0c6cdc653f5..7f150295798 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -3519,8 +3519,8 @@ sort_choices (std::vector &syms) if (!b.symbol->is_objfile_owned ()) return true; - const char *fna = a.symbol->symtab ()->filename; - const char *fnb = b.symbol->symtab ()->filename; + const char *fna = a.symbol->symtab ()->filename (); + const char *fnb = b.symbol->symtab ()->filename (); /* First sort by basename. This is done because, depending on how GNAT was invoked, different sources @@ -11927,7 +11927,7 @@ is_known_support_routine (const frame_info_ptr &frame) for (i = 0; known_runtime_file_name_patterns[i] != NULL; i += 1) { re_comp (known_runtime_file_name_patterns[i]); - if (re_exec (lbasename (sal.symtab->filename))) + if (re_exec (lbasename (sal.symtab->filename ()))) return 1; if (sal.symtab->compunit ()->objfile () != NULL && re_exec (objfile_name (sal.symtab->compunit ()->objfile ()))) diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c index 1374481cc99..6656f393580 100644 --- a/gdb/cli/cli-cmds.c +++ b/gdb/cli/cli-cmds.c @@ -2228,7 +2228,7 @@ cmp_symtabs (const symtab_and_line &sala, const symtab_and_line &salb) return r; } - r = filename_cmp (sala.symtab->filename, salb.symtab->filename); + r = filename_cmp (sala.symtab->filename (), salb.symtab->filename ()); if (r) return r; diff --git a/gdb/compile/compile-c-symbols.c b/gdb/compile/compile-c-symbols.c index 65789775fc4..a71f84be52c 100644 --- a/gdb/compile/compile-c-symbols.c +++ b/gdb/compile/compile-c-symbols.c @@ -56,7 +56,7 @@ convert_one_symbol (compile_c_instance *context, int is_local) { gcc_type sym_type; - const char *filename = sym.symbol->symtab ()->filename; + const char *filename = sym.symbol->symtab ()->filename (); unsigned int line = sym.symbol->line (); context->error_symbol_once (sym.symbol); diff --git a/gdb/compile/compile-cplus-symbols.c b/gdb/compile/compile-cplus-symbols.c index 96ebd84887a..5b43ba1cc51 100644 --- a/gdb/compile/compile-cplus-symbols.c +++ b/gdb/compile/compile-cplus-symbols.c @@ -48,7 +48,7 @@ convert_one_symbol (compile_cplus_instance *instance, { /* Squash compiler warning. */ gcc_type sym_type = 0; - const char *filename = sym.symbol->symtab ()->filename; + const char *filename = sym.symbol->symtab ()->filename (); unsigned int line = sym.symbol->line (); instance->error_symbol_once (sym.symbol); diff --git a/gdb/compile/compile-cplus-types.c b/gdb/compile/compile-cplus-types.c index cf70fe484d7..66e5ddd36fc 100644 --- a/gdb/compile/compile-cplus-types.c +++ b/gdb/compile/compile-cplus-types.c @@ -624,7 +624,7 @@ compile_cplus_convert_struct_or_union_members we can do but ignore this member. */ continue; } - const char *filename = sym.symbol->symtab ()->filename; + const char *filename = sym.symbol->symtab ()->filename (); unsigned int line = sym.symbol->line (); physaddr = sym.symbol->value_address (); @@ -763,7 +763,7 @@ compile_cplus_convert_struct_or_union_methods (compile_cplus_instance *instance, continue; } - const char *filename = sym.symbol->symtab ()->filename; + const char *filename = sym.symbol->symtab ()->filename (); unsigned int line = sym.symbol->line (); CORE_ADDR address = sym.symbol->value_block()->start (); const char *kind; diff --git a/gdb/infrun.c b/gdb/infrun.c index 824479dd75a..81764e6b1a2 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -4842,7 +4842,7 @@ set_step_info (thread_info *tp, const frame_info_ptr &frame, infrun_debug_printf ("symtab = %s, line = %d, step_frame_id = %s, step_stack_frame_id = %s", - tp->current_symtab != nullptr ? tp->current_symtab->filename : "", + tp->current_symtab != nullptr ? tp->current_symtab->filename () : "", tp->current_line, tp->control.step_frame_id.to_string ().c_str (), tp->control.step_stack_frame_id.to_string ().c_str ()); diff --git a/gdb/linespec.c b/gdb/linespec.c index 08f7fdd0daa..277b45b4b7f 100644 --- a/gdb/linespec.c +++ b/gdb/linespec.c @@ -2005,7 +2005,7 @@ create_sals_line_offset (struct linespec_state *self, set_default_source_symtab_and_line (); initialize_defaults (&self->default_symtab, &self->default_line); ls->file_symtabs - = collect_symtabs_from_filename (self->default_symtab->filename, + = collect_symtabs_from_filename (self->default_symtab->filename (), self->search_pspace); use_default = true; } @@ -2291,7 +2291,7 @@ convert_linespec_to_sals (struct linespec_state *state, linespec *ls) /* Make sure we have a filename for canonicalization. */ if (ls->explicit_loc.source_filename == NULL) { - const char *filename = state->default_symtab->filename; + const char *filename = state->default_symtab->filename (); /* It may be more appropriate to keep DEFAULT_SYMTAB in its symtab form so that displaying SOURCE_FILENAME can follow the current diff --git a/gdb/macroscope.c b/gdb/macroscope.c index 563ef9931b3..32499fe5d21 100644 --- a/gdb/macroscope.c +++ b/gdb/macroscope.c @@ -51,7 +51,8 @@ sal_macro_scope (struct symtab_and_line sal) macro_scope ms; main_file = macro_main (cust->macro_table ()); - inclusion = macro_lookup_inclusion (main_file, sal.symtab->filename_for_id); + inclusion = macro_lookup_inclusion (main_file, + sal.symtab->filename_for_id ()); if (inclusion) { diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c index 9fd1fd013d2..7eb4e41a507 100644 --- a/gdb/python/py-breakpoint.c +++ b/gdb/python/py-breakpoint.c @@ -1644,7 +1644,7 @@ bploc_filepath (struct symtab *bploc_symtab) { } - return host_string_to_python_string (bploc_symtab->filename); + return host_string_to_python_string (bploc_symtab->filename ()); } /* Python function to get the source file name path and line number @@ -1763,7 +1763,7 @@ bplocpy_repr (PyObject *py_self) paddress (self->bp_loc->owner->gdbarch, self->bp_loc->requested_address)); if (self->bp_loc->symtab != nullptr) - str += string_printf (" source=%s:%d", self->bp_loc->symtab->filename, + str += string_printf (" source=%s:%d", self->bp_loc->symtab->filename (), self->bp_loc->line_number); const auto fn_name = self->bp_loc->function_name.get (); diff --git a/gdb/skip.c b/gdb/skip.c index a9ee223c277..a56b3555d17 100644 --- a/gdb/skip.c +++ b/gdb/skip.c @@ -488,20 +488,20 @@ skiplist_entry::do_skip_file_p (const symtab_and_line &function_sal) const if (debug_skip) gdb_printf (gdb_stdlog, "skip: checking if file %s matches non-glob %s...", - function_sal.symtab->filename, m_file.c_str ()); + function_sal.symtab->filename (), m_file.c_str ()); bool result; /* Check first sole SYMTAB->FILENAME. It may not be a substring of symtab_to_fullname as it may contain "./" etc. */ - if (compare_filenames_for_search (function_sal.symtab->filename, + if (compare_filenames_for_search (function_sal.symtab->filename (), m_file.c_str ())) result = true; /* Before we invoke realpath, which can get expensive when many files are involved, do a quick comparison of the basenames. */ else if (!basenames_may_differ - && filename_cmp (lbasename (function_sal.symtab->filename), + && filename_cmp (lbasename (function_sal.symtab->filename ()), lbasename (m_file.c_str ())) != 0) result = false; else @@ -524,13 +524,13 @@ skiplist_entry::do_skip_gfile_p (const symtab_and_line &function_sal) const if (debug_skip) gdb_printf (gdb_stdlog, "skip: checking if file %s matches glob %s...", - function_sal.symtab->filename, m_file.c_str ()); + function_sal.symtab->filename (), m_file.c_str ()); bool result; /* Check first sole SYMTAB->FILENAME. It may not be a substring of symtab_to_fullname as it may contain "./" etc. */ - if (gdb_filename_fnmatch (m_file.c_str (), function_sal.symtab->filename, + if (gdb_filename_fnmatch (m_file.c_str (), function_sal.symtab->filename (), FNM_NOESCAPE) == 0) result = true; @@ -541,7 +541,7 @@ skiplist_entry::do_skip_gfile_p (const symtab_and_line &function_sal) const isn't much of a win. Oh well. */ else if (!basenames_may_differ && gdb_filename_fnmatch (lbasename (m_file.c_str ()), - lbasename (function_sal.symtab->filename), + lbasename (function_sal.symtab->filename ()), FNM_NOESCAPE) != 0) result = false; else diff --git a/gdb/source.c b/gdb/source.c index e56f2b5d736..a47176cd9a5 100644 --- a/gdb/source.c +++ b/gdb/source.c @@ -342,7 +342,7 @@ select_source_symtab () { for (symtab *symtab : cu.filetabs ()) { - const char *name = symtab->filename; + const char *name = symtab->filename (); int len = strlen (name); if (!(len > 2 && (strcmp (&name[len - 2], ".h") == 0 @@ -683,7 +683,7 @@ info_source_command (const char *ignore, int from_tty) } cust = s->compunit (); - gdb_printf (_("Current source file is %s\n"), s->filename); + 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 () != nullptr) @@ -1119,7 +1119,8 @@ open_source_file (struct symtab *s) return scoped_fd (-EINVAL); gdb::unique_xmalloc_ptr fullname = s->release_fullname (); - scoped_fd fd = find_and_open_source (s->filename, s->compunit ()->dirname (), + scoped_fd fd = find_and_open_source (s->filename (), + s->compunit ()->dirname (), &fullname); if (fd.get () < 0) @@ -1129,13 +1130,13 @@ open_source_file (struct symtab *s) const objfile *ofp = s->compunit ()->objfile (); std::string srcpath; - if (IS_ABSOLUTE_PATH (s->filename)) - srcpath = s->filename; + if (IS_ABSOLUTE_PATH (s->filename ())) + srcpath = s->filename (); else if (s->compunit ()->dirname () != nullptr) { srcpath = s->compunit ()->dirname (); srcpath += SLASH_STRING; - srcpath += s->filename; + srcpath += s->filename (); } const struct bfd_build_id *build_id @@ -1220,11 +1221,11 @@ symtab_to_fullname (struct symtab *s) should report the pathname where GDB tried to find the file. */ if (s->compunit ()->dirname () == nullptr - || IS_ABSOLUTE_PATH (s->filename)) - fullname.reset (xstrdup (s->filename)); + || IS_ABSOLUTE_PATH (s->filename ())) + fullname.reset (xstrdup (s->filename ())); else fullname.reset (concat (s->compunit ()->dirname (), SLASH_STRING, - s->filename, (char *) NULL)); + s->filename (), (char *) NULL)); s->set_fullname (rewrite_source_path (fullname.get ())); if (s->fullname () == nullptr) @@ -1241,11 +1242,11 @@ const char * symtab_to_filename_for_display (struct symtab *symtab) { if (filename_display_string == filename_display_basename) - return lbasename (symtab->filename); + return lbasename (symtab->filename ()); else if (filename_display_string == filename_display_absolute) return symtab_to_fullname (symtab); else if (filename_display_string == filename_display_relative) - return symtab->filename; + return symtab->filename (); else internal_error (_("invalid filename_display_string")); } diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c index b402a87b7a7..e5ea7264997 100644 --- a/gdb/symfile-debug.c +++ b/gdb/symfile-debug.c @@ -184,7 +184,7 @@ iterate_over_one_compunit_symtab (const char *name, for (symtab *s : cust->filetabs ()) { - if (compare_filenames_for_search (s->filename, name)) + if (compare_filenames_for_search (s->filename (), name)) { if (callback (s)) return true; @@ -194,7 +194,7 @@ iterate_over_one_compunit_symtab (const char *name, /* Before we invoke realpath, which can get expensive when many files are involved, do a quick comparison of the basenames. */ if (! basenames_may_differ - && FILENAME_CMP (base_name, lbasename (s->filename)) != 0) + && FILENAME_CMP (base_name, lbasename (s->filename ())) != 0) continue; if (compare_filenames_for_search (symtab_to_fullname (s), name)) diff --git a/gdb/symfile.c b/gdb/symfile.c index 806547d9d6f..85827cf3d49 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -2830,11 +2830,11 @@ allocate_symtab (struct compunit_symtab *cust, const char *filename, { struct objfile *objfile = cust->objfile (); struct symtab *symtab - = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symtab); - - symtab->filename = objfile->intern (filename); - symtab->filename_for_id = objfile->intern (filename_for_id); - symtab->set_language (deduce_language_from_filename (filename)); + = obstack_new (&objfile->objfile_obstack, + cust, + objfile->intern (filename), + objfile->intern (filename_for_id), + deduce_language_from_filename (filename)); /* This can be very verbose with lots of headers. Only print at higher debug levels. */ @@ -2860,9 +2860,6 @@ allocate_symtab (struct compunit_symtab *cust, const char *filename, /* Add it to CUST's list of symtabs. */ cust->add_filetab (symtab); - /* Backlink to the containing compunit symtab. */ - symtab->set_compunit (cust); - return symtab; } diff --git a/gdb/symtab.c b/gdb/symtab.c index 3b0687c0750..3195cd2e2ae 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -3309,7 +3309,7 @@ find_line_symtab (symtab *sym_tab, int line, int *index) const struct linetable *l; int ind; - if (FILENAME_CMP (sym_tab->filename, s->filename) != 0) + if (FILENAME_CMP (sym_tab->filename (), s->filename ()) != 0) continue; if (FILENAME_CMP (symtab_to_fullname (sym_tab), symtab_to_fullname (s)) != 0) @@ -4627,8 +4627,8 @@ symbol_search::compare_search_syms (const symbol_search &sym_a, { int c; - c = FILENAME_CMP (sym_a.symbol->symtab ()->filename, - sym_b.symbol->symtab ()->filename); + c = FILENAME_CMP (sym_a.symbol->symtab ()->filename (), + sym_b.symbol->symtab ()->filename ()); if (c != 0) return c; @@ -4802,9 +4802,9 @@ global_symbol_searcher::add_matching_symbols /* Check first sole REAL_SYMTAB->FILENAME. It does not need to be a substring of symtab_to_fullname as it may contain "./" etc. */ - if (!(file_matches (real_symtab->filename, m_filenames, false) + if (!(file_matches (real_symtab->filename (), m_filenames, false) || ((basenames_may_differ - || file_matches (lbasename (real_symtab->filename), + || file_matches (lbasename (real_symtab->filename ()), m_filenames, true)) && file_matches (symtab_to_fullname (real_symtab), m_filenames, false)))) @@ -6220,14 +6220,14 @@ make_source_files_completion_list (const char *text) { for (symtab *s : cu.filetabs ()) { - if (not_interesting_fname (s->filename)) + if (not_interesting_fname (s->filename ())) continue; - if (!filenames_seen.seen (s->filename) - && filename_ncmp (s->filename, text, text_len) == 0) + if (!filenames_seen.seen (s->filename ()) + && filename_ncmp (s->filename (), text, text_len) == 0) { /* This file matches for a completion; add it to the current list of matches. */ - add_filename_to_list (s->filename, text, text, &list); + add_filename_to_list (s->filename (), text, text, &list); } else { @@ -6235,8 +6235,8 @@ make_source_files_completion_list (const char *text) debug info records leading directories, but not the other way around. This is what subroutines of breakpoint command do when they parse file names. */ - base_name = lbasename (s->filename); - if (base_name != s->filename + base_name = lbasename (s->filename ()); + if (base_name != s->filename () && !filenames_seen.seen (base_name) && filename_ncmp (base_name, text, text_len) == 0) add_filename_to_list (base_name, text, text, &list); diff --git a/gdb/symtab.h b/gdb/symtab.h index e47033efd01..486b99d123a 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -1698,16 +1698,23 @@ typedef std::vector section_offsets; struct symtab { + symtab (struct compunit_symtab *cust, const char *filename, + const char *filename_for_id, enum language language) + : m_filename (filename), + m_filename_for_id (filename_for_id), + m_compunit (cust), + m_language (language) + { + gdb_assert (m_filename != nullptr); + gdb_assert (m_filename_for_id != nullptr); + gdb_assert (m_compunit != nullptr); + } + struct compunit_symtab *compunit () const { return m_compunit; } - void set_compunit (struct compunit_symtab *compunit) - { - m_compunit = compunit; - } - const struct linetable *linetable () const { return m_linetable; @@ -1749,16 +1756,24 @@ struct symtab m_fullname = name.release (); } + const char *filename () const + { return m_filename; } + + const char *filename_for_id () const + { return m_filename_for_id; } + /* Unordered chain of all filetabs in the compunit, with the exception that the "main" source file is the first entry in the list. */ - struct symtab *next; + struct symtab *next = nullptr; + +private: /* Name of this source file, in a form appropriate to print to the user. - This pointer is never nullptr. */ + This pointer is never nullptr and is set from the constructor. */ - const char *filename; + const char *m_filename; /* Filename for this source file, used as an identifier to link with related objects such as associated macro_source_file objects. It must @@ -1767,28 +1782,29 @@ struct symtab follow that rule, or another form of the same file name, this is up to the specific debug info reader. - This pointer is never nullptr.*/ - const char *filename_for_id; + This pointer is never nullptr, and is set from the constructor. */ + const char *m_filename_for_id; -private: + /* Backlink to containing compunit symtab. - /* Backlink to containing compunit symtab. */ + This pointer is never nullptr, and is set from the constructor. */ struct compunit_symtab *m_compunit; /* Table mapping core addresses to line numbers for this file. Can be NULL if none. Never shared between different symtabs. */ - const struct linetable *m_linetable; + const struct linetable *m_linetable = nullptr; - /* Language of this source file. */ + /* Language of this source file. This is set in the object + constructor. */ enum language m_language; /* Full name of file as found by searching the source path. NULL if not yet known. */ - char *m_fullname; + char *m_fullname = nullptr; }; /* A range adapter to allowing iterating over all the file tables in a list. */