public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/4] Remove some symtab accessors
@ 2022-04-06 14:42 Simon Marchi
  2022-04-06 14:42 ` [PATCH 1/4] gdb: remove symtab::dirname Simon Marchi
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Simon Marchi @ 2022-04-06 14:42 UTC (permalink / raw)
  To: gdb-patches

I am playing with symtabs currently and was a bit confused with some
accessors that make some things appear as if they are symtab-specific,
when they are not.  These accessors forward to the symtab's parent
objects.  I don't think they are very useful and just hide the real
object structure of GDB, so I suggest removing them.

Simon Marchi (4):
  gdb: remove symtab::dirname
  gdb: remove symtab::blockvector
  gdb: remove symtab::objfile
  gdb: remove symtab::pspace

 gdb/ada-exp.y                     |  3 +-
 gdb/ada-lang.c                    |  8 ++--
 gdb/annotate.c                    |  4 +-
 gdb/breakpoint.c                  |  9 +++--
 gdb/c-exp.y                       |  5 ++-
 gdb/cli/cli-cmds.c                |  8 ++--
 gdb/coffread.c                    |  2 +-
 gdb/compile/compile-object-load.c |  2 +-
 gdb/compile/compile.c             |  2 +-
 gdb/guile/scm-symtab.c            | 12 +++---
 gdb/linespec.c                    | 63 ++++++++++++++++++-------------
 gdb/mdebugread.c                  | 16 ++++----
 gdb/mi/mi-symbol-cmds.c           |  2 +-
 gdb/objfiles.c                    |  2 +-
 gdb/p-exp.y                       |  5 ++-
 gdb/parse.c                       |  2 +-
 gdb/python/py-symtab.c            | 24 ++++++------
 gdb/source-cache.c                |  5 ++-
 gdb/source.c                      | 19 +++++-----
 gdb/symmisc.c                     | 10 ++---
 gdb/symtab.c                      | 14 ++-----
 gdb/symtab.h                      | 26 -------------
 gdb/tui/tui-source.c              |  2 +-
 gdb/tui/tui-winsource.c           |  2 +-
 24 files changed, 116 insertions(+), 131 deletions(-)


base-commit: 7fb56b98937a2feef5a3e12d8b00506ff4d132be
-- 
2.35.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/4] gdb: remove symtab::dirname
  2022-04-06 14:42 [PATCH 0/4] Remove some symtab accessors Simon Marchi
@ 2022-04-06 14:42 ` Simon Marchi
  2022-04-06 14:42 ` [PATCH 2/4] gdb: remove symtab::blockvector Simon Marchi
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Simon Marchi @ 2022-04-06 14:42 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

From: Simon Marchi <simon.marchi@efficios.com>

I think the symtab::dirname method is bogus, or at least very
misleading.  It makes you think that it returns the directory that was
used to find that symtab's file during compilation (i.e. the directory
the file refers to in the DWARF line header file table), or the
directory part of the symtab's filename maybe.  In fact, it returns the
compilation unit's directory, which is the CWD of the compiler, at
compilation time.  At least for DWARF, if the symtab's filename is
relative, it will be relative to that directory.  But if the symtab's
filename is absolute, then the directory returned by symtab::dirname has
nothing to do with the symtab's filename.

Remove symtab::dirname to avoid this confusion, change all users to
fetch the same information through the compunit.  At least, it will be
clear that this is a compunit property, not a symtab property.

Change-Id: I2894c3bf3789d7359a676db3c58be2c10763f5f0
---
 gdb/cli/cli-cmds.c |  4 ++--
 gdb/source.c       | 15 ++++++++-------
 gdb/symmisc.c      |  4 ++--
 gdb/symtab.h       |  8 --------
 4 files changed, 12 insertions(+), 19 deletions(-)

diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index 945fd354d52e..31b493e1c500 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -2050,8 +2050,8 @@ ambiguous_line_spec (gdb::array_view<const symtab_and_line> sals,
 static int
 cmp_symtabs (const symtab_and_line &sala, const symtab_and_line &salb)
 {
-  const char *dira = sala.symtab->dirname ();
-  const char *dirb = salb.symtab->dirname ();
+  const char *dira = sala.symtab->compunit ()->dirname ();
+  const char *dirb = salb.symtab->compunit ()->dirname ();
   int r;
 
   if (dira == NULL)
diff --git a/gdb/source.c b/gdb/source.c
index 020e94d4ae95..2025c93e93e3 100644
--- a/gdb/source.c
+++ b/gdb/source.c
@@ -713,8 +713,8 @@ info_source_command (const char *ignore, int from_tty)
 
   cust = s->compunit ();
   gdb_printf (_("Current source file is %s\n"), s->filename);
-  if (s->dirname () != NULL)
-    gdb_printf (_("Compilation directory is %s\n"), s->dirname ());
+  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);
   const std::vector<off_t> *offsets;
@@ -1180,7 +1180,7 @@ open_source_file (struct symtab *s)
 
   gdb::unique_xmalloc_ptr<char> fullname (s->fullname);
   s->fullname = NULL;
-  scoped_fd fd = find_and_open_source (s->filename, s->dirname (),
+  scoped_fd fd = find_and_open_source (s->filename, s->compunit ()->dirname (),
 				       &fullname);
 
   if (fd.get () < 0)
@@ -1192,9 +1192,9 @@ open_source_file (struct symtab *s)
 	  std::string srcpath;
 	  if (IS_ABSOLUTE_PATH (s->filename))
 	    srcpath = s->filename;
-	  else if (s->dirname () != nullptr)
+	  else if (s->compunit ()->dirname () != nullptr)
 	    {
-	      srcpath = s->dirname ();
+	      srcpath = s->compunit ()->dirname ();
 	      srcpath += SLASH_STRING;
 	      srcpath += s->filename;
 	    }
@@ -1268,10 +1268,11 @@ symtab_to_fullname (struct symtab *s)
 	  /* rewrite_source_path would be applied by find_and_open_source, we
 	     should report the pathname where GDB tried to find the file.  */
 
-	  if (s->dirname () == NULL || IS_ABSOLUTE_PATH (s->filename))
+	  if (s->compunit ()->dirname () == nullptr
+	      || IS_ABSOLUTE_PATH (s->filename))
 	    fullname.reset (xstrdup (s->filename));
 	  else
-	    fullname.reset (concat (s->dirname (), SLASH_STRING,
+	    fullname.reset (concat (s->compunit ()->dirname (), SLASH_STRING,
 				    s->filename, (char *) NULL));
 
 	  s->fullname = rewrite_source_path (fullname.get ()).release ();
diff --git a/gdb/symmisc.c b/gdb/symmisc.c
index e8092e8af08a..5d8d641fa275 100644
--- a/gdb/symmisc.c
+++ b/gdb/symmisc.c
@@ -249,9 +249,9 @@ dump_symtab_1 (struct symtab *symtab, struct ui_file *outfile)
 	      symtab_to_filename_for_display (symtab),
 	      host_address_to_string (symtab));
 
-  if (symtab->dirname () != NULL)
+  if (symtab->compunit ()->dirname () != NULL)
     gdb_printf (outfile, "Compilation directory is %s\n",
-		symtab->dirname ());
+		symtab->compunit ()->dirname ());
   gdb_printf (outfile, "Read from object file %s (%s)\n",
 	      objfile_name (objfile),
 	      host_address_to_string (objfile));
diff --git a/gdb/symtab.h b/gdb/symtab.h
index 25b4f7d2704b..567c0fcce7c0 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -1482,8 +1482,6 @@ struct symtab
 
   program_space *pspace () const;
 
-  const char *dirname () const;
-
   /* Unordered chain of all filetabs in the compunit,  with the exception
      that the "main" source file is the first entry in the list.  */
 
@@ -1769,12 +1767,6 @@ symtab::objfile () const
   return this->compunit ()->objfile ();
 }
 
-inline const char *
-symtab::dirname () const
-{
-  return this->compunit ()->dirname ();
-}
-
 /* Return the language of CUST.  */
 
 extern enum language compunit_language (const struct compunit_symtab *cust);
-- 
2.35.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 2/4] gdb: remove symtab::blockvector
  2022-04-06 14:42 [PATCH 0/4] Remove some symtab accessors Simon Marchi
  2022-04-06 14:42 ` [PATCH 1/4] gdb: remove symtab::dirname Simon Marchi
@ 2022-04-06 14:42 ` Simon Marchi
  2022-04-06 14:42 ` [PATCH 3/4] gdb: remove symtab::objfile Simon Marchi
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Simon Marchi @ 2022-04-06 14:42 UTC (permalink / raw)
  To: gdb-patches

symtab::blockvector is a wrapper around compunit_symtab::blockvector.
It is a bit misleadnig, as it gives the impression that a symtab has a
blockvector.  Remove it, change all users to fetch the blockvector
through the compunit instead.

Change-Id: Ibd062cd7926112a60d52899dff9224591cbdeebf
---
 gdb/ada-exp.y                     |  3 ++-
 gdb/ada-lang.c                    |  4 ++--
 gdb/c-exp.y                       |  5 +++--
 gdb/coffread.c                    |  2 +-
 gdb/compile/compile-object-load.c |  2 +-
 gdb/compile/compile.c             |  2 +-
 gdb/guile/scm-symtab.c            |  4 ++--
 gdb/linespec.c                    | 10 +++++-----
 gdb/mdebugread.c                  | 16 +++++++++-------
 gdb/p-exp.y                       |  5 +++--
 gdb/parse.c                       |  2 +-
 gdb/python/py-symtab.c            |  4 ++--
 gdb/symmisc.c                     |  2 +-
 gdb/symtab.h                      |  8 --------
 14 files changed, 33 insertions(+), 36 deletions(-)

diff --git a/gdb/ada-exp.y b/gdb/ada-exp.y
index 5099e40f6772..a2755d7501ed 100644
--- a/gdb/ada-exp.y
+++ b/gdb/ada-exp.y
@@ -1369,7 +1369,8 @@ block_lookup (const struct block *context, const char *raw_name)
     symtab = NULL;
 
   if (symtab != NULL)
-    result = BLOCKVECTOR_BLOCK (symtab->blockvector (), STATIC_BLOCK);
+    result = BLOCKVECTOR_BLOCK (symtab->compunit ()->blockvector (),
+				STATIC_BLOCK);
   else if (syms.empty () || syms[0].symbol->aclass () != LOC_BLOCK)
     {
       if (context == NULL)
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index f80ec5b1e046..3a1624e9d26e 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -4709,9 +4709,9 @@ cache_symbol (const char *name, domain_enum domain, struct symbol *sym,
      the symbol is local or not, we check the block where we found it
      against the global and static blocks of its associated symtab.  */
   if (sym
-      && BLOCKVECTOR_BLOCK (symbol_symtab (sym)->blockvector (),
+      && BLOCKVECTOR_BLOCK (symbol_symtab (sym)->compunit ()->blockvector (),
 			    GLOBAL_BLOCK) != block
-      && BLOCKVECTOR_BLOCK (symbol_symtab (sym)->blockvector (),
+      && BLOCKVECTOR_BLOCK (symbol_symtab (sym)->compunit ()->blockvector (),
 			    STATIC_BLOCK) != block)
     return;
 
diff --git a/gdb/c-exp.y b/gdb/c-exp.y
index de29d2f70e23..4ed661e587b1 100644
--- a/gdb/c-exp.y
+++ b/gdb/c-exp.y
@@ -3109,8 +3109,9 @@ classify_name (struct parser_state *par_state, const struct block *block,
 	  symtab = lookup_symtab (copy.c_str ());
 	  if (symtab)
 	    {
-	      yylval.bval = BLOCKVECTOR_BLOCK (symtab->blockvector (),
-					       STATIC_BLOCK);
+	      yylval.bval
+		= BLOCKVECTOR_BLOCK (symtab->compunit ()->blockvector (),
+				     STATIC_BLOCK);
 	      return FILENAME;
 	    }
 	}
diff --git a/gdb/coffread.c b/gdb/coffread.c
index 1de2a79a0d94..253ba9c095f8 100644
--- a/gdb/coffread.c
+++ b/gdb/coffread.c
@@ -1483,7 +1483,7 @@ patch_opaque_types (struct symtab *s)
   struct symbol *real_sym;
 
   /* Go through the per-file symbols only.  */
-  b = BLOCKVECTOR_BLOCK (s->blockvector (), STATIC_BLOCK);
+  b = BLOCKVECTOR_BLOCK (s->compunit ()->blockvector (), STATIC_BLOCK);
   ALL_BLOCK_SYMBOLS (b, iter, real_sym)
     {
       /* Find completed typedefs to use to fix opaque ones.
diff --git a/gdb/compile/compile-object-load.c b/gdb/compile/compile-object-load.c
index b62a841d82a5..7364a4ae8b24 100644
--- a/gdb/compile/compile-object-load.c
+++ b/gdb/compile/compile-object-load.c
@@ -421,7 +421,7 @@ get_out_value_type (struct symbol *func_sym, struct objfile *objfile,
   lookup_name_info func_matcher (GCC_FE_WRAPPER_FUNCTION,
 				 symbol_name_match_type::SEARCH_NAME);
 
-  bv = func_sym->owner.symtab->blockvector ();
+  bv = func_sym->owner.symtab->compunit ()->blockvector ();
   nblocks = BLOCKVECTOR_NBLOCKS (bv);
 
   gdb_ptr_type_sym = NULL;
diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c
index 7983d1df1b51..2a1f0f1bd6b9 100644
--- a/gdb/compile/compile.c
+++ b/gdb/compile/compile.c
@@ -484,7 +484,7 @@ get_expr_block_and_pc (CORE_ADDR *pc)
       struct symtab_and_line cursal = get_current_source_symtab_and_line ();
 
       if (cursal.symtab)
-	block = BLOCKVECTOR_BLOCK (cursal.symtab->blockvector (),
+	block = BLOCKVECTOR_BLOCK (cursal.symtab->compunit ()->blockvector (),
 				   STATIC_BLOCK);
       if (block != NULL)
 	*pc = BLOCK_ENTRY_PC (block);
diff --git a/gdb/guile/scm-symtab.c b/gdb/guile/scm-symtab.c
index d1a5056aac86..386ccf569564 100644
--- a/gdb/guile/scm-symtab.c
+++ b/gdb/guile/scm-symtab.c
@@ -363,7 +363,7 @@ gdbscm_symtab_global_block (SCM self)
   const struct blockvector *blockvector;
   const struct block *block;
 
-  blockvector = symtab->blockvector ();
+  blockvector = symtab->compunit ()->blockvector ();
   block = BLOCKVECTOR_BLOCK (blockvector, GLOBAL_BLOCK);
 
   return bkscm_scm_from_block (block, symtab->objfile ());
@@ -381,7 +381,7 @@ gdbscm_symtab_static_block (SCM self)
   const struct blockvector *blockvector;
   const struct block *block;
 
-  blockvector = symtab->blockvector ();
+  blockvector = symtab->compunit ()->blockvector ();
   block = BLOCKVECTOR_BLOCK (blockvector, STATIC_BLOCK);
 
   return bkscm_scm_from_block (block, symtab->objfile ());
diff --git a/gdb/linespec.c b/gdb/linespec.c
index 4d41f74ab2fb..5a6b620b33b7 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -1188,12 +1188,11 @@ iterate_over_all_matching_symtabs
 		{
 		  const struct block *block;
 		  int i;
+		  const blockvector *bv = symtab->compunit ()->blockvector ();
 
-		  for (i = FIRST_LOCAL_BLOCK;
-		       i < BLOCKVECTOR_NBLOCKS (symtab->blockvector ());
-		       i++)
+		  for (i = FIRST_LOCAL_BLOCK; i < BLOCKVECTOR_NBLOCKS (bv); i++)
 		    {
-		      block = BLOCKVECTOR_BLOCK (symtab->blockvector (), i);
+		      block = BLOCKVECTOR_BLOCK (bv, i);
 		      state->language->iterate_over_symbols
 			(block, lookup_name, name_domain,
 			 [&] (block_symbol *bsym)
@@ -1232,7 +1231,8 @@ iterate_over_file_blocks
 {
   const struct block *block;
 
-  for (block = BLOCKVECTOR_BLOCK (symtab->blockvector (), STATIC_BLOCK);
+  for (block = BLOCKVECTOR_BLOCK (symtab->compunit ()->blockvector (),
+				  STATIC_BLOCK);
        block != NULL;
        block = BLOCK_SUPERBLOCK (block))
     current_language->iterate_over_symbols (block, name, domain, callback);
diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c
index eae80648e4c3..67630b793327 100644
--- a/gdb/mdebugread.c
+++ b/gdb/mdebugread.c
@@ -628,7 +628,7 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
       break;
 
     case stGlobal:		/* External symbol, goes into global block.  */
-      b = BLOCKVECTOR_BLOCK (top_stack->cur_st->blockvector (),
+      b = BLOCKVECTOR_BLOCK (top_stack->cur_st->compunit ()->blockvector (),
 			     GLOBAL_BLOCK);
       s = new_symbol (name);
       SET_SYMBOL_VALUE_ADDRESS (s, (CORE_ADDR) sh->value);
@@ -771,7 +771,7 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
       if (sh->st == stProc)
 	{
 	  const struct blockvector *bv
-	    = top_stack->cur_st->blockvector ();
+	    = top_stack->cur_st->compunit ()->blockvector ();
 
 	  /* The next test should normally be true, but provides a
 	     hook for nested functions (which we don't want to make
@@ -1144,7 +1144,7 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
 	{
 	  /* Finished with procedure */
 	  const struct blockvector *bv
-	    = top_stack->cur_st->blockvector ();
+	    = top_stack->cur_st->compunit ()->blockvector ();
 	  struct mdebug_extra_func_info *e;
 	  struct block *cblock = top_stack->cur_block;
 	  struct type *ftype = top_stack->cur_type;
@@ -4187,7 +4187,7 @@ mdebug_expand_psymtab (legacy_psymtab *pst, struct objfile *objfile)
 	 FIXME, Maybe quit once we have found the right number of ext's?  */
       top_stack->cur_st = cust->primary_filetab ();
       top_stack->cur_block
-	= BLOCKVECTOR_BLOCK (top_stack->cur_st->blockvector (),
+	= BLOCKVECTOR_BLOCK (top_stack->cur_st->compunit ()->blockvector (),
 			     GLOBAL_BLOCK);
       top_stack->blocktype = stFile;
 
@@ -4497,13 +4497,14 @@ add_block (struct block *b, struct symtab *s)
 {
   /* Cast away "const", but that's ok because we're building the
      symtab and blockvector here.  */
-  struct blockvector *bv = (struct blockvector *) s->blockvector ();
+  struct blockvector *bv
+    = (struct blockvector *) s->compunit ()->blockvector ();
 
   bv = (struct blockvector *) xrealloc ((void *) bv,
 					(sizeof (struct blockvector)
 					 + BLOCKVECTOR_NBLOCKS (bv)
 					 * sizeof (bv->block)));
-  if (bv != s->blockvector ())
+  if (bv != s->compunit ()->blockvector ())
     s->compunit ()->set_blockvector (bv);
 
   BLOCKVECTOR_BLOCK (bv, BLOCKVECTOR_NBLOCKS (bv)++) = b;
@@ -4567,7 +4568,8 @@ sort_blocks (struct symtab *s)
 {
   /* We have to cast away const here, but this is ok because we're
      constructing the blockvector in this code.  */
-  struct blockvector *bv = (struct blockvector *) s->blockvector ();
+  struct blockvector *bv
+    = (struct blockvector *) s->compunit ()->blockvector ();
 
   if (BLOCKVECTOR_NBLOCKS (bv) <= FIRST_LOCAL_BLOCK)
     {
diff --git a/gdb/p-exp.y b/gdb/p-exp.y
index 024a335453a1..adceff286362 100644
--- a/gdb/p-exp.y
+++ b/gdb/p-exp.y
@@ -619,8 +619,9 @@ block	:	BLOCKNAME
 			      struct symtab *tem =
 				  lookup_symtab (copy.c_str ());
 			      if (tem)
-				$$ = BLOCKVECTOR_BLOCK (tem->blockvector (),
-							STATIC_BLOCK);
+				$$ = BLOCKVECTOR_BLOCK
+				  (tem->compunit ()->blockvector (),
+				   STATIC_BLOCK);
 			      else
 				error (_("No file or function \"%s\"."),
 				       copy.c_str ());
diff --git a/gdb/parse.c b/gdb/parse.c
index 7637e5799f78..6d1b3d9d9238 100644
--- a/gdb/parse.c
+++ b/gdb/parse.c
@@ -465,7 +465,7 @@ parse_exp_in_context (const char **stringptr, CORE_ADDR pc,
       struct symtab_and_line cursal = get_current_source_symtab_and_line ();
       if (cursal.symtab)
 	expression_context_block
-	  = BLOCKVECTOR_BLOCK (cursal.symtab->blockvector (),
+	  = BLOCKVECTOR_BLOCK (cursal.symtab->compunit ()->blockvector (),
 			       STATIC_BLOCK);
       if (expression_context_block)
 	expression_context_pc = BLOCK_ENTRY_PC (expression_context_block);
diff --git a/gdb/python/py-symtab.c b/gdb/python/py-symtab.c
index bfda599dddde..7ce4292c325d 100644
--- a/gdb/python/py-symtab.c
+++ b/gdb/python/py-symtab.c
@@ -181,7 +181,7 @@ stpy_global_block (PyObject *self, PyObject *args)
 
   STPY_REQUIRE_VALID (self, symtab);
 
-  blockvector = symtab->blockvector ();
+  blockvector = symtab->compunit ()->blockvector ();
   block = BLOCKVECTOR_BLOCK (blockvector, GLOBAL_BLOCK);
   return block_to_block_object (block, symtab->objfile ());
 }
@@ -197,7 +197,7 @@ stpy_static_block (PyObject *self, PyObject *args)
 
   STPY_REQUIRE_VALID (self, symtab);
 
-  blockvector = symtab->blockvector ();
+  blockvector = symtab->compunit ()->blockvector ();
   block = BLOCKVECTOR_BLOCK (blockvector, STATIC_BLOCK);
   return block_to_block_object (block, symtab->objfile ());
 }
diff --git a/gdb/symmisc.c b/gdb/symmisc.c
index 5d8d641fa275..1843eb87d05e 100644
--- a/gdb/symmisc.c
+++ b/gdb/symmisc.c
@@ -278,7 +278,7 @@ dump_symtab_1 (struct symtab *symtab, struct ui_file *outfile)
   if (is_main_symtab_of_compunit_symtab (symtab))
     {
       gdb_printf (outfile, "\nBlockvector:\n\n");
-      bv = symtab->blockvector ();
+      bv = symtab->compunit ()->blockvector ();
       len = BLOCKVECTOR_NBLOCKS (bv);
       for (i = 0; i < len; i++)
 	{
diff --git a/gdb/symtab.h b/gdb/symtab.h
index 567c0fcce7c0..8852590857e6 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -1476,8 +1476,6 @@ struct symtab
     m_language = language;
   }
 
-  const struct blockvector *blockvector () const;
-
   struct objfile *objfile () const;
 
   program_space *pspace () const;
@@ -1755,12 +1753,6 @@ struct compunit_symtab
 
 using compunit_symtab_range = next_range<compunit_symtab>;
 
-inline const struct blockvector *
-symtab::blockvector () const
-{
-  return this->compunit ()->blockvector ();
-}
-
 inline struct objfile *
 symtab::objfile () const
 {
-- 
2.35.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 3/4] gdb: remove symtab::objfile
  2022-04-06 14:42 [PATCH 0/4] Remove some symtab accessors Simon Marchi
  2022-04-06 14:42 ` [PATCH 1/4] gdb: remove symtab::dirname Simon Marchi
  2022-04-06 14:42 ` [PATCH 2/4] gdb: remove symtab::blockvector Simon Marchi
@ 2022-04-06 14:42 ` Simon Marchi
  2022-04-06 14:42 ` [PATCH 4/4] gdb: remove symtab::pspace Simon Marchi
  2022-04-07 14:08 ` [PATCH 0/4] Remove some symtab accessors Tom Tromey
  4 siblings, 0 replies; 7+ messages in thread
From: Simon Marchi @ 2022-04-06 14:42 UTC (permalink / raw)
  To: gdb-patches

Same idea as previous patch, but for symtab::objfile.  I find
it clearer without this wrapper, as it shows that the objfile is
common to all symtabs of a given compunit.  Otherwise, you could think
that each symtab (of a given compunit) can have a specific objfile.

Change-Id: Ifc0dbc7ec31a06eefa2787c921196949d5a6fcc6
---
 gdb/ada-lang.c          |  4 ++--
 gdb/annotate.c          |  2 +-
 gdb/breakpoint.c        |  9 +++++----
 gdb/cli/cli-cmds.c      |  4 ++--
 gdb/guile/scm-symtab.c  |  8 ++++----
 gdb/linespec.c          |  4 ++--
 gdb/mi/mi-symbol-cmds.c |  2 +-
 gdb/objfiles.c          |  2 +-
 gdb/python/py-symtab.c  | 20 +++++++++++---------
 gdb/source-cache.c      |  5 +++--
 gdb/source.c            |  2 +-
 gdb/symmisc.c           |  4 ++--
 gdb/symtab.c            |  8 ++++----
 gdb/symtab.h            |  8 --------
 gdb/tui/tui-source.c    |  2 +-
 gdb/tui/tui-winsource.c |  2 +-
 16 files changed, 41 insertions(+), 45 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 3a1624e9d26e..d819038e63b6 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -11862,8 +11862,8 @@ is_known_support_routine (struct frame_info *frame)
       re_comp (known_runtime_file_name_patterns[i]);
       if (re_exec (lbasename (sal.symtab->filename)))
 	return 1;
-      if (sal.symtab->objfile () != NULL
-	  && re_exec (objfile_name (sal.symtab->objfile ())))
+      if (sal.symtab->compunit ()->objfile () != NULL
+	  && re_exec (objfile_name (sal.symtab->compunit ()->objfile ())))
 	return 1;
     }
 
diff --git a/gdb/annotate.c b/gdb/annotate.c
index c16eb4651f3b..6ae314572221 100644
--- a/gdb/annotate.c
+++ b/gdb/annotate.c
@@ -448,7 +448,7 @@ annotate_source_line (struct symtab *s, int line, int mid_statement,
 	return false;
 
       annotate_source (s->fullname, line, (int) (*offsets)[line - 1],
-		       mid_statement, s->objfile ()->arch (),
+		       mid_statement, s->compunit ()->objfile ()->arch (),
 		       pc);
 
       /* Update the current symtab and line.  */
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 1b340bd78d1c..b21d83d8019a 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -7209,7 +7209,7 @@ get_sal_arch (struct symtab_and_line sal)
   if (sal.section)
     return sal.section->objfile->arch ();
   if (sal.symtab)
-    return sal.symtab->objfile ()->arch ();
+    return sal.symtab->compunit ()->objfile ()->arch ();
 
   return NULL;
 }
@@ -9251,8 +9251,9 @@ resolve_sal_pc (struct symtab_and_line *sal)
 	  sym = block_linkage_function (b);
 	  if (sym != NULL)
 	    {
-	      fixup_symbol_section (sym, sal->symtab->objfile ());
-	      sal->section = sym->obj_section (sal->symtab->objfile ());
+	      fixup_symbol_section (sym, sal->symtab->compunit ()->objfile ());
+	      sal->section
+		= sym->obj_section (sal->symtab->compunit ()->objfile ());
 	    }
 	  else
 	    {
@@ -14680,7 +14681,7 @@ void
 breakpoint_free_objfile (struct objfile *objfile)
 {
   for (bp_location *loc : all_bp_locations ())
-    if (loc->symtab != NULL && loc->symtab->objfile () == objfile)
+    if (loc->symtab != NULL && loc->symtab->compunit ()->objfile () == objfile)
       loc->symtab = NULL;
 }
 
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index 31b493e1c500..424a8740706c 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -1007,7 +1007,7 @@ edit_command (const char *arg, int from_tty)
 	    error (_("No source file for address %s."),
 		   paddress (get_current_arch (), sal.pc));
 
-	  gdbarch = sal.symtab->objfile ()->arch ();
+	  gdbarch = sal.symtab->compunit ()->objfile ()->arch ();
 	  sym = find_pc_function (sal.pc);
 	  if (sym)
 	    gdb_printf ("%s is in %s (%s:%d).\n",
@@ -1346,7 +1346,7 @@ list_command (const char *arg, int from_tty)
 	error (_("No source file for address %s."),
 	       paddress (get_current_arch (), sal.pc));
 
-      gdbarch = sal.symtab->objfile ()->arch ();
+      gdbarch = sal.symtab->compunit ()->objfile ()->arch ();
       sym = find_pc_function (sal.pc);
       if (sym)
 	gdb_printf ("%s is in %s (%s:%d).\n",
diff --git a/gdb/guile/scm-symtab.c b/gdb/guile/scm-symtab.c
index 386ccf569564..1ba5cb587b1f 100644
--- a/gdb/guile/scm-symtab.c
+++ b/gdb/guile/scm-symtab.c
@@ -109,7 +109,7 @@ stscm_eq_symtab_smob (const void *ap, const void *bp)
 static htab_t
 stscm_objfile_symtab_map (struct symtab *symtab)
 {
-  struct objfile *objfile = symtab->objfile ();
+  struct objfile *objfile = symtab->compunit ()->objfile ();
   htab_t htab = (htab_t) objfile_data (objfile, stscm_objfile_data_key);
 
   if (htab == NULL)
@@ -348,7 +348,7 @@ gdbscm_symtab_objfile (SCM self)
     = stscm_get_valid_symtab_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
   const struct symtab *symtab = st_smob->symtab;
 
-  return ofscm_scm_from_objfile (symtab->objfile ());
+  return ofscm_scm_from_objfile (symtab->compunit ()->objfile ());
 }
 
 /* (symtab-global-block <gdb:symtab>) -> <gdb:block>
@@ -366,7 +366,7 @@ gdbscm_symtab_global_block (SCM self)
   blockvector = symtab->compunit ()->blockvector ();
   block = BLOCKVECTOR_BLOCK (blockvector, GLOBAL_BLOCK);
 
-  return bkscm_scm_from_block (block, symtab->objfile ());
+  return bkscm_scm_from_block (block, symtab->compunit ()->objfile ());
 }
 
 /* (symtab-static-block <gdb:symtab>) -> <gdb:block>
@@ -384,7 +384,7 @@ gdbscm_symtab_static_block (SCM self)
   blockvector = symtab->compunit ()->blockvector ();
   block = BLOCKVECTOR_BLOCK (blockvector, STATIC_BLOCK);
 
-  return bkscm_scm_from_block (block, symtab->objfile ());
+  return bkscm_scm_from_block (block, symtab->compunit ()->objfile ());
 }
 \f
 /* Administrivia for sal (symtab-and-line) smobs.  */
diff --git a/gdb/linespec.c b/gdb/linespec.c
index 5a6b620b33b7..10717ac6c43f 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -4245,10 +4245,10 @@ search_minsyms_for_name (struct collect_info *info,
 	{
 	  set_current_program_space (symtab->pspace ());
 	  iterate_over_minimal_symbols
-	    (symtab->objfile (), name,
+	    (symtab->compunit ()->objfile (), name,
 	     [&] (struct minimal_symbol *msym)
 	       {
-		 add_minsym (msym, symtab->objfile (), symtab,
+		 add_minsym (msym, symtab->compunit ()->objfile (), symtab,
 			     info->state->list_mode, &minsyms);
 		 return false;
 	       });
diff --git a/gdb/mi/mi-symbol-cmds.c b/gdb/mi/mi-symbol-cmds.c
index 1b08854296c0..5d6d34129291 100644
--- a/gdb/mi/mi-symbol-cmds.c
+++ b/gdb/mi/mi-symbol-cmds.c
@@ -50,7 +50,7 @@ mi_cmd_symbol_list_lines (const char *command, char **argv, int argc)
      already sorted by increasing values in the symbol table, so no
      need to perform any other sorting.  */
 
-  gdbarch = s->objfile ()->arch ();
+  gdbarch = s->compunit ()->objfile ()->arch ();
 
   ui_out_emit_list list_emitter (uiout, "lines");
   if (s->linetable () != NULL && s->linetable ()->nitems > 0)
diff --git a/gdb/objfiles.c b/gdb/objfiles.c
index 35b275ad3012..ddd94da42a6f 100644
--- a/gdb/objfiles.c
+++ b/gdb/objfiles.c
@@ -591,7 +591,7 @@ objfile::~objfile ()
   {
     struct symtab_and_line cursal = get_current_source_symtab_and_line ();
 
-    if (cursal.symtab && cursal.symtab->objfile () == this)
+    if (cursal.symtab && cursal.symtab->compunit ()->objfile () == this)
       clear_current_source_symtab_and_line ();
   }
 
diff --git a/gdb/python/py-symtab.c b/gdb/python/py-symtab.c
index 7ce4292c325d..0a6ee014ea73 100644
--- a/gdb/python/py-symtab.c
+++ b/gdb/python/py-symtab.c
@@ -119,7 +119,7 @@ stpy_get_objfile (PyObject *self, void *closure)
 
   STPY_REQUIRE_VALID (self, symtab);
 
-  return objfile_to_objfile_object (symtab->objfile ()).release ();
+  return objfile_to_objfile_object (symtab->compunit ()->objfile ()).release ();
 }
 
 /* Getter function for symtab.producer.  */
@@ -183,7 +183,7 @@ stpy_global_block (PyObject *self, PyObject *args)
 
   blockvector = symtab->compunit ()->blockvector ();
   block = BLOCKVECTOR_BLOCK (blockvector, GLOBAL_BLOCK);
-  return block_to_block_object (block, symtab->objfile ());
+  return block_to_block_object (block, symtab->compunit ()->objfile ());
 }
 
 /* Return the STATIC_BLOCK of the underlying symtab.  */
@@ -199,7 +199,7 @@ stpy_static_block (PyObject *self, PyObject *args)
 
   blockvector = symtab->compunit ()->blockvector ();
   block = BLOCKVECTOR_BLOCK (blockvector, STATIC_BLOCK);
-  return block_to_block_object (block, symtab->objfile ());
+  return block_to_block_object (block, symtab->compunit ()->objfile ());
 }
 
 /* Implementation of gdb.Symtab.linetable (self) -> gdb.LineTable.
@@ -247,7 +247,7 @@ stpy_dealloc (PyObject *obj)
     symtab->prev->next = symtab->next;
   else if (symtab->symtab)
     {
-      set_objfile_data (symtab->symtab->objfile (),
+      set_objfile_data (symtab->symtab->compunit ()->objfile (),
 			stpy_objfile_data_key, symtab->next);
     }
   if (symtab->next)
@@ -330,7 +330,7 @@ salpy_dealloc (PyObject *self)
     self_sal->prev->next = self_sal->next;
   else if (self_sal->symtab != Py_None)
     set_objfile_data
-      (symtab_object_to_symtab (self_sal->symtab)->objfile (),
+      (symtab_object_to_symtab (self_sal->symtab)->compunit ()->objfile (),
        salpy_objfile_data_key, self_sal->next);
 
   if (self_sal->next)
@@ -378,12 +378,12 @@ set_sal (sal_object *sal_obj, struct symtab_and_line sal)
       symtab *symtab = symtab_object_to_symtab (sal_obj->symtab);
 
       sal_obj->next
-	= ((sal_object *) objfile_data (symtab->objfile (),
+	= ((sal_object *) objfile_data (symtab->compunit ()->objfile (),
 					salpy_objfile_data_key));
       if (sal_obj->next)
 	sal_obj->next->prev = sal_obj;
 
-      set_objfile_data (symtab->objfile (),
+      set_objfile_data (symtab->compunit ()->objfile (),
 			salpy_objfile_data_key, sal_obj);
     }
   else
@@ -406,10 +406,12 @@ set_symtab (symtab_object *obj, struct symtab *symtab)
     {
       obj->next
 	= ((symtab_object *)
-	   objfile_data (symtab->objfile (), stpy_objfile_data_key));
+	   objfile_data (symtab->compunit ()->objfile (),
+			 stpy_objfile_data_key));
       if (obj->next)
 	obj->next->prev = obj;
-      set_objfile_data (symtab->objfile (), stpy_objfile_data_key, obj);
+      set_objfile_data (symtab->compunit ()->objfile (),
+			stpy_objfile_data_key, obj);
     }
   else
     obj->next = NULL;
diff --git a/gdb/source-cache.c b/gdb/source-cache.c
index 3f0683b2096d..2cc5b37a8179 100644
--- a/gdb/source-cache.c
+++ b/gdb/source-cache.c
@@ -107,8 +107,9 @@ source_cache::get_plain_source_lines (struct symtab *s,
     perror_with_name (symtab_to_filename_for_display (s));
 
   time_t mtime = 0;
-  if (s->objfile () != NULL && s->objfile ()->obfd != NULL)
-    mtime = s->objfile ()->mtime;
+  if (s->compunit ()->objfile () != NULL
+      && s->compunit ()->objfile ()->obfd != NULL)
+    mtime = s->compunit ()->objfile ()->mtime;
   else if (current_program_space->exec_bfd ())
     mtime = current_program_space->ebfd_mtime;
 
diff --git a/gdb/source.c b/gdb/source.c
index 2025c93e93e3..24f53f68e35b 100644
--- a/gdb/source.c
+++ b/gdb/source.c
@@ -1560,7 +1560,7 @@ info_line_command (const char *arg, int from_tty)
       else if (sal.line > 0
 	       && find_line_pc_range (sal, &start_pc, &end_pc))
 	{
-	  struct gdbarch *gdbarch = sal.symtab->objfile ()->arch ();
+	  gdbarch *gdbarch = sal.symtab->compunit ()->objfile ()->arch ();
 
 	  if (start_pc == end_pc)
 	    {
diff --git a/gdb/symmisc.c b/gdb/symmisc.c
index 1843eb87d05e..1779816348fc 100644
--- a/gdb/symmisc.c
+++ b/gdb/symmisc.c
@@ -131,7 +131,7 @@ dump_objfile (struct objfile *objfile)
 	      gdb_printf ("%s at %s",
 			  symtab_to_filename_for_display (symtab),
 			  host_address_to_string (symtab));
-	      if (symtab->objfile () != objfile)
+	      if (symtab->compunit ()->objfile () != objfile)
 		gdb_printf (", NOT ON CHAIN!");
 	      gdb_printf ("\n");
 	    }
@@ -234,7 +234,7 @@ dump_msymbols (struct objfile *objfile, struct ui_file *outfile)
 static void
 dump_symtab_1 (struct symtab *symtab, struct ui_file *outfile)
 {
-  struct objfile *objfile = symtab->objfile ();
+  struct objfile *objfile = symtab->compunit ()->objfile ();
   struct gdbarch *gdbarch = objfile->arch ();
   int i;
   struct mdict_iterator miter;
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 4204423cb25f..eeb16e4643b8 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -338,7 +338,7 @@ search_domain_name (enum search_domain e)
 program_space *
 symtab::pspace () const
 {
-  return this->objfile ()->pspace;
+  return this->compunit ()->objfile ()->pspace;
 }
 
 /* See symtab.h.  */
@@ -3724,7 +3724,7 @@ find_function_start_sal_1 (CORE_ADDR func_addr, obj_section *section,
       && (sal.symtab->compunit ()->locations_valid ()
 	  || sal.symtab->language () == language_asm))
     {
-      struct gdbarch *gdbarch = sal.symtab->objfile ()->arch ();
+      struct gdbarch *gdbarch = sal.symtab->compunit ()->objfile ()->arch ();
 
       sal.pc = func_addr;
       if (gdbarch_skip_entrypoint_p (gdbarch))
@@ -6593,7 +6593,7 @@ struct objfile *
 symbol_objfile (const struct symbol *symbol)
 {
   gdb_assert (symbol->is_objfile_owned ());
-  return symbol->owner.symtab->objfile ();
+  return symbol->owner.symtab->compunit ()->objfile ();
 }
 
 /* See symtab.h.  */
@@ -6603,7 +6603,7 @@ symbol_arch (const struct symbol *symbol)
 {
   if (!symbol->is_objfile_owned ())
     return symbol->owner.arch;
-  return symbol->owner.symtab->objfile ()->arch ();
+  return symbol->owner.symtab->compunit ()->objfile ()->arch ();
 }
 
 /* See symtab.h.  */
diff --git a/gdb/symtab.h b/gdb/symtab.h
index 8852590857e6..87d483505297 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -1476,8 +1476,6 @@ struct symtab
     m_language = language;
   }
 
-  struct objfile *objfile () const;
-
   program_space *pspace () const;
 
   /* Unordered chain of all filetabs in the compunit,  with the exception
@@ -1753,12 +1751,6 @@ struct compunit_symtab
 
 using compunit_symtab_range = next_range<compunit_symtab>;
 
-inline struct objfile *
-symtab::objfile () const
-{
-  return this->compunit ()->objfile ();
-}
-
 /* Return the language of CUST.  */
 
 extern enum language compunit_language (const struct compunit_symtab *cust);
diff --git a/gdb/tui/tui-source.c b/gdb/tui/tui-source.c
index 294ea1c7f136..208889d0bf7a 100644
--- a/gdb/tui/tui-source.c
+++ b/gdb/tui/tui-source.c
@@ -70,7 +70,7 @@ tui_source_window::set_contents (struct gdbarch *arch,
   m_fullname = make_unique_xstrdup (symtab_to_fullname (s));
 
   cur_line = 0;
-  m_gdbarch = s->objfile ()->arch ();
+  m_gdbarch = s->compunit ()->objfile ()->arch ();
   m_start_line_or_addr.loa = LOA_LINE;
   cur_line_no = m_start_line_or_addr.u.line_no = line_no;
 
diff --git a/gdb/tui/tui-winsource.c b/gdb/tui/tui-winsource.c
index c8a1c1aa64bc..87b8dcff154b 100644
--- a/gdb/tui/tui-winsource.c
+++ b/gdb/tui/tui-winsource.c
@@ -199,7 +199,7 @@ tui_update_source_windows_with_line (struct symtab_and_line sal)
   if (sal.symtab != nullptr)
     {
       find_line_pc (sal.symtab, sal.line, &sal.pc);
-      gdbarch = sal.symtab->objfile ()->arch ();
+      gdbarch = sal.symtab->compunit ()->objfile ()->arch ();
     }
 
   for (struct tui_source_window_base *win_info : tui_source_windows ())
-- 
2.35.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 4/4] gdb: remove symtab::pspace
  2022-04-06 14:42 [PATCH 0/4] Remove some symtab accessors Simon Marchi
                   ` (2 preceding siblings ...)
  2022-04-06 14:42 ` [PATCH 3/4] gdb: remove symtab::objfile Simon Marchi
@ 2022-04-06 14:42 ` Simon Marchi
  2022-04-07 14:08 ` [PATCH 0/4] Remove some symtab accessors Tom Tromey
  4 siblings, 0 replies; 7+ messages in thread
From: Simon Marchi @ 2022-04-06 14:42 UTC (permalink / raw)
  To: gdb-patches

Same idea as previous patch, but for symtab::pspace.

Change-Id: I1023abe622bea75ef648c6a97a01b53775d4104d
---
 gdb/annotate.c |  2 +-
 gdb/linespec.c | 49 +++++++++++++++++++++++++++++--------------------
 gdb/source.c   |  2 +-
 gdb/symtab.c   |  8 --------
 gdb/symtab.h   |  2 --
 5 files changed, 31 insertions(+), 32 deletions(-)

diff --git a/gdb/annotate.c b/gdb/annotate.c
index 6ae314572221..33805dcdb307 100644
--- a/gdb/annotate.c
+++ b/gdb/annotate.c
@@ -453,7 +453,7 @@ annotate_source_line (struct symtab *s, int line, int mid_statement,
 
       /* Update the current symtab and line.  */
       symtab_and_line sal;
-      sal.pspace = s->pspace ();
+      sal.pspace = s->compunit ()->objfile ()->pspace;
       sal.symtab = s;
       sal.line = line;
       set_current_source_symtab_and_line (sal);
diff --git a/gdb/linespec.c b/gdb/linespec.c
index 10717ac6c43f..9d4707cbb4e7 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -2188,7 +2188,7 @@ convert_linespec_to_sals (struct linespec_state *state, linespec *ls)
       for (const auto &sym : ls->labels.label_symbols)
 	{
 	  struct program_space *pspace
-	    = symbol_symtab (sym.symbol)->pspace ();
+	    = symbol_symtab (sym.symbol)->compunit ()->objfile ()->pspace;
 
 	  if (symbol_to_sal (&sal, state->funfirstline, sym.symbol)
 	      && maybe_add_address (state->addr_set, pspace, sal.pc))
@@ -2210,7 +2210,7 @@ convert_linespec_to_sals (struct linespec_state *state, linespec *ls)
 	  for (const auto &sym : ls->function_symbols)
 	    {
 	      program_space *pspace
-		= symbol_symtab (sym.symbol)->pspace ();
+		= symbol_symtab (sym.symbol)->compunit ()->objfile ()->pspace;
 	      set_current_program_space (pspace);
 
 	      /* Don't skip to the first line of the function if we
@@ -3462,8 +3462,10 @@ lookup_prefix_sym (struct linespec_state *state,
 	{
 	  /* Program spaces that are executing startup should have
 	     been filtered out earlier.  */
-	  gdb_assert (!elt->pspace ()->executing_startup);
-	  set_current_program_space (elt->pspace ());
+	  program_space *pspace = elt->compunit ()->objfile ()->pspace;
+
+	  gdb_assert (!pspace->executing_startup);
+	  set_current_program_space (pspace);
 	  iterate_over_file_blocks (elt, lookup_name, STRUCT_DOMAIN, collector);
 	  iterate_over_file_blocks (elt, lookup_name, VAR_DOMAIN, collector);
 	}
@@ -3481,8 +3483,8 @@ compare_symbols (const block_symbol &a, const block_symbol &b)
 {
   uintptr_t uia, uib;
 
-  uia = (uintptr_t) symbol_symtab (a.symbol)->pspace ();
-  uib = (uintptr_t) symbol_symtab (b.symbol)->pspace ();
+  uia = (uintptr_t) symbol_symtab (a.symbol)->compunit ()->objfile ()->pspace;
+  uib = (uintptr_t) symbol_symtab (b.symbol)->compunit ()->objfile ()->pspace;
 
   if (uia < uib)
     return true;
@@ -3606,7 +3608,7 @@ find_method (struct linespec_state *self,
 
       /* Program spaces that are executing startup should have
 	 been filtered out earlier.  */
-      pspace = symbol_symtab (sym)->pspace ();
+      pspace = symbol_symtab (sym)->compunit ()->objfile ()->pspace;
       gdb_assert (!pspace->executing_startup);
       set_current_program_space (pspace);
       t = check_typedef (sym->type ());
@@ -3617,7 +3619,8 @@ find_method (struct linespec_state *self,
 	 sure not to miss the last batch.  */
       if (ix == sym_classes->size () - 1
 	  || (pspace
-	      != symbol_symtab (sym_classes->at (ix + 1).symbol)->pspace ()))
+	      != (symbol_symtab (sym_classes->at (ix + 1).symbol)
+		  ->compunit ()->objfile ()->pspace)))
 	{
 	  /* If we did not find a direct implementation anywhere in
 	     this program space, consider superclasses.  */
@@ -3981,7 +3984,8 @@ find_label_symbols (struct linespec_state *self,
       for (const auto &elt : function_symbols)
 	{
 	  fn_sym = elt.symbol;
-	  set_current_program_space (symbol_symtab (fn_sym)->pspace ());
+	  set_current_program_space
+	    (symbol_symtab (fn_sym)->compunit ()->objfile ()->pspace);
 	  block = SYMBOL_BLOCK_VALUE (fn_sym);
 
 	  find_label_symbols_in_block (block, name, fn_sym, completion_mode,
@@ -4010,13 +4014,14 @@ decode_digits_list_mode (struct linespec_state *self,
       /* The logic above should ensure this.  */
       gdb_assert (elt != NULL);
 
-      set_current_program_space (elt->pspace ());
+      program_space *pspace = elt->compunit ()->objfile ()->pspace;
+      set_current_program_space (pspace);
 
       /* Simplistic search just for the list command.  */
       val.symtab = find_line_symtab (elt, val.line, NULL, NULL);
       if (val.symtab == NULL)
 	val.symtab = elt;
-      val.pspace = elt->pspace ();
+      val.pspace = pspace;
       val.pc = 0;
       val.explicit_line = true;
 
@@ -4044,13 +4049,14 @@ decode_digits_ordinary (struct linespec_state *self,
       /* The logic above should ensure this.  */
       gdb_assert (elt != NULL);
 
-      set_current_program_space (elt->pspace ());
+      program_space *pspace = elt->compunit ()->objfile ()->pspace;
+      set_current_program_space (pspace);
 
       pcs = find_pcs_for_symtab_line (elt, line, best_entry);
       for (CORE_ADDR pc : pcs)
 	{
 	  symtab_and_line sal;
-	  sal.pspace = elt->pspace ();
+	  sal.pspace = pspace;
 	  sal.symtab = elt;
 	  sal.line = line;
 	  sal.explicit_line = true;
@@ -4241,9 +4247,11 @@ search_minsyms_for_name (struct collect_info *info,
     }
   else
     {
-      if (search_pspace == NULL || symtab->pspace () == search_pspace)
+      program_space *pspace = symtab->compunit ()->objfile ()->pspace;
+
+      if (search_pspace == NULL || pspace == search_pspace)
 	{
-	  set_current_program_space (symtab->pspace ());
+	  set_current_program_space (pspace);
 	  iterate_over_minimal_symbols
 	    (symtab->compunit ()->objfile (), name,
 	     [&] (struct minimal_symbol *msym)
@@ -4329,14 +4337,15 @@ add_matching_symbols_to_info (const char *name,
 	    { return info->add_symbol (bsym); });
 	  search_minsyms_for_name (info, lookup_name, pspace, NULL);
 	}
-      else if (pspace == NULL || pspace == elt->pspace ())
+      else if (pspace == NULL || pspace == elt->compunit ()->objfile ()->pspace)
 	{
 	  int prev_len = info->result.symbols->size ();
 
 	  /* Program spaces that are executing startup should have
 	     been filtered out earlier.  */
-	  gdb_assert (!elt->pspace ()->executing_startup);
-	  set_current_program_space (elt->pspace ());
+	  program_space *elt_pspace = elt->compunit ()->objfile ()->pspace;
+	  gdb_assert (!elt_pspace->executing_startup);
+	  set_current_program_space (elt_pspace);
 	  iterate_over_file_blocks (elt, lookup_name, VAR_DOMAIN,
 				    [&] (block_symbol *bsym)
 	    { return info->add_symbol (bsym); });
@@ -4375,7 +4384,7 @@ symbol_to_sal (struct symtab_and_line *result,
 	  result->symbol = sym;
 	  result->line = sym->line ();
 	  result->pc = SYMBOL_VALUE_ADDRESS (sym);
-	  result->pspace = result->symtab->pspace ();
+	  result->pspace = result->symtab->compunit ()->objfile ()->pspace;
 	  result->explicit_pc = 1;
 	  return 1;
 	}
@@ -4391,7 +4400,7 @@ symbol_to_sal (struct symtab_and_line *result,
 	  result->symbol = sym;
 	  result->line = sym->line ();
 	  result->pc = SYMBOL_VALUE_ADDRESS (sym);
-	  result->pspace = result->symtab->pspace ();
+	  result->pspace = result->symtab->compunit ()->objfile ()->pspace;
 	  return 1;
 	}
     }
diff --git a/gdb/source.c b/gdb/source.c
index 24f53f68e35b..e9016573333c 100644
--- a/gdb/source.c
+++ b/gdb/source.c
@@ -311,7 +311,7 @@ select_source_symtab (struct symtab *s)
   if (s)
     {
       current_source_location *loc
-	= get_source_location (s->pspace ());
+	= get_source_location (s->compunit ()->objfile ()->pspace);
       loc->set (s, 1);
       return;
     }
diff --git a/gdb/symtab.c b/gdb/symtab.c
index eeb16e4643b8..3cc2d4f8648c 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -335,14 +335,6 @@ search_domain_name (enum search_domain e)
 
 /* See symtab.h.  */
 
-program_space *
-symtab::pspace () const
-{
-  return this->compunit ()->objfile ()->pspace;
-}
-
-/* See symtab.h.  */
-
 call_site *
 compunit_symtab::find_call_site (CORE_ADDR pc) const
 {
diff --git a/gdb/symtab.h b/gdb/symtab.h
index 87d483505297..a89b0a2e42d7 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -1476,8 +1476,6 @@ struct symtab
     m_language = language;
   }
 
-  program_space *pspace () const;
-
   /* Unordered chain of all filetabs in the compunit,  with the exception
      that the "main" source file is the first entry in the list.  */
 
-- 
2.35.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/4] Remove some symtab accessors
  2022-04-06 14:42 [PATCH 0/4] Remove some symtab accessors Simon Marchi
                   ` (3 preceding siblings ...)
  2022-04-06 14:42 ` [PATCH 4/4] gdb: remove symtab::pspace Simon Marchi
@ 2022-04-07 14:08 ` Tom Tromey
  2022-04-07 17:08   ` Simon Marchi
  4 siblings, 1 reply; 7+ messages in thread
From: Tom Tromey @ 2022-04-07 14:08 UTC (permalink / raw)
  To: Simon Marchi via Gdb-patches

>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:

Simon> I am playing with symtabs currently and was a bit confused with some
Simon> accessors that make some things appear as if they are symtab-specific,
Simon> when they are not.  These accessors forward to the symtab's parent
Simon> objects.  I don't think they are very useful and just hide the real
Simon> object structure of GDB, so I suggest removing them.

I don't really mind the current code, but I also am fine with your
change, and the patches all looked fine to me.

Tom

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/4] Remove some symtab accessors
  2022-04-07 14:08 ` [PATCH 0/4] Remove some symtab accessors Tom Tromey
@ 2022-04-07 17:08   ` Simon Marchi
  0 siblings, 0 replies; 7+ messages in thread
From: Simon Marchi @ 2022-04-07 17:08 UTC (permalink / raw)
  To: Tom Tromey, Simon Marchi via Gdb-patches



On 2022-04-07 10:08, Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:
> 
> Simon> I am playing with symtabs currently and was a bit confused with some
> Simon> accessors that make some things appear as if they are symtab-specific,
> Simon> when they are not.  These accessors forward to the symtab's parent
> Simon> objects.  I don't think they are very useful and just hide the real
> Simon> object structure of GDB, so I suggest removing them.
> 
> I don't really mind the current code, but I also am fine with your
> change, and the patches all looked fine to me.
> 
> Tom

Thanks, pushed.

Simon

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-04-07 17:08 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-06 14:42 [PATCH 0/4] Remove some symtab accessors Simon Marchi
2022-04-06 14:42 ` [PATCH 1/4] gdb: remove symtab::dirname Simon Marchi
2022-04-06 14:42 ` [PATCH 2/4] gdb: remove symtab::blockvector Simon Marchi
2022-04-06 14:42 ` [PATCH 3/4] gdb: remove symtab::objfile Simon Marchi
2022-04-06 14:42 ` [PATCH 4/4] gdb: remove symtab::pspace Simon Marchi
2022-04-07 14:08 ` [PATCH 0/4] Remove some symtab accessors Tom Tromey
2022-04-07 17:08   ` Simon Marchi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).