public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 1/6] gdb: add getter/setter for compunit_symtab::objfile
@ 2021-12-01 15:47 Simon Marchi
  2021-12-01 15:47 ` [PATCH 2/6] gdb: remove COMPUNIT_OBJFILE macro Simon Marchi
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Simon Marchi @ 2021-12-01 15:47 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

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

Rename the field to m_objfile, and add a getter and a setter.  Update
all users.

Change-Id: If7e2f763ee3e70570140d9af9261b1b056253317
---
 gdb/symfile.c |  8 ++++----
 gdb/symmisc.c |  2 +-
 gdb/symtab.c  |  2 +-
 gdb/symtab.h  | 14 ++++++++++++--
 4 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/gdb/symfile.c b/gdb/symfile.c
index 9e5c2d488812..e15df3fed739 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -2757,7 +2757,7 @@ deduce_language_from_filename (const char *filename)
 struct symtab *
 allocate_symtab (struct compunit_symtab *cust, const char *filename)
 {
-  struct objfile *objfile = cust->objfile;
+  struct objfile *objfile = cust->objfile ();
   struct symtab *symtab
     = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symtab);
 
@@ -2815,7 +2815,7 @@ allocate_compunit_symtab (struct objfile *objfile, const char *name)
 					       struct compunit_symtab);
   const char *saved_name;
 
-  cu->objfile = objfile;
+  cu->set_objfile (objfile);
 
   /* The name we record here is only for display/debugging purposes.
      Just save the basename to avoid path issues (too long for display,
@@ -2841,8 +2841,8 @@ allocate_compunit_symtab (struct objfile *objfile, const char *name)
 void
 add_compunit_symtab_to_objfile (struct compunit_symtab *cu)
 {
-  cu->next = cu->objfile->compunit_symtabs;
-  cu->objfile->compunit_symtabs = cu;
+  cu->next = cu->objfile ()->compunit_symtabs;
+  cu->objfile ()->compunit_symtabs = cu;
 }
 \f
 
diff --git a/gdb/symmisc.c b/gdb/symmisc.c
index e38ceb6bda12..68ab1fab78a2 100644
--- a/gdb/symmisc.c
+++ b/gdb/symmisc.c
@@ -965,7 +965,7 @@ maintenance_print_one_line_table (struct symtab *symtab, void *data)
   struct linetable *linetable;
   struct objfile *objfile;
 
-  objfile = symtab->compunit_symtab->objfile;
+  objfile = symtab->compunit_symtab->objfile ();
   printf_filtered (_("objfile: %s ((struct objfile *) %s)\n"),
 		   objfile_name (objfile),
 		   host_address_to_string (objfile));
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 3f2eb64a7c42..7e1030512b56 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -338,7 +338,7 @@ compunit_symtab::find_call_site (CORE_ADDR pc) const
     return nullptr;
 
   CORE_ADDR delta
-    = this->objfile->section_offsets[COMPUNIT_BLOCK_LINE_SECTION (this)];
+    = this->objfile ()->section_offsets[COMPUNIT_BLOCK_LINE_SECTION (this)];
   CORE_ADDR unrelocated_pc = pc - delta;
 
   struct call_site call_site_local (unrelocated_pc, nullptr, nullptr);
diff --git a/gdb/symtab.h b/gdb/symtab.h
index 61f20b25a7bd..d56671e0a9e8 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -1449,6 +1449,16 @@ struct symtab
 
 struct compunit_symtab
 {
+  struct objfile *objfile () const
+  {
+    return m_objfile;
+  }
+
+  void set_objfile (struct objfile *objfile)
+  {
+    m_objfile = objfile;
+  }
+
   /* Set m_call_site_htab.  */
   void set_call_site_htab (htab_t call_site_htab);
 
@@ -1459,7 +1469,7 @@ struct compunit_symtab
   struct compunit_symtab *next;
 
   /* Object file from which this symtab information was read.  */
-  struct objfile *objfile;
+  struct objfile *m_objfile;
 
   /* Name of the symtab.
      This is *not* intended to be a usable filename, and is
@@ -1535,7 +1545,7 @@ struct compunit_symtab
 
 using compunit_symtab_range = next_range<compunit_symtab>;
 
-#define COMPUNIT_OBJFILE(cust) ((cust)->objfile)
+#define COMPUNIT_OBJFILE(cust) ((cust)->objfile ())
 #define COMPUNIT_FILETABS(cust) ((cust)->filetabs)
 #define COMPUNIT_DEBUGFORMAT(cust) ((cust)->debugformat)
 #define COMPUNIT_PRODUCER(cust) ((cust)->producer)
-- 
2.33.1


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

* [PATCH 2/6] gdb: remove COMPUNIT_OBJFILE macro
  2021-12-01 15:47 [PATCH 1/6] gdb: add getter/setter for compunit_symtab::objfile Simon Marchi
@ 2021-12-01 15:47 ` Simon Marchi
  2021-12-01 15:47 ` [PATCH 3/6] gdb: rename compunit_primary_filetab to compunit_symtab::primary_filetab Simon Marchi
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Simon Marchi @ 2021-12-01 15:47 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

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

Remove the macro, update all users to use the getter directly.

Change-Id: I3f0fd6f4455d1c4ebd5da73b561eb18a979ef1f6
---
 gdb/block.c               | 2 +-
 gdb/buildsym-legacy.c     | 2 +-
 gdb/dwarf2/read.c         | 6 +++---
 gdb/guile/scm-block.c     | 6 +++---
 gdb/python/py-progspace.c | 6 +++---
 gdb/source.c              | 2 +-
 gdb/symtab.h              | 3 +--
 7 files changed, 13 insertions(+), 14 deletions(-)

diff --git a/gdb/block.c b/gdb/block.c
index 90c0c5b32508..68b3481e482a 100644
--- a/gdb/block.c
+++ b/gdb/block.c
@@ -51,7 +51,7 @@ block_objfile (const struct block *block)
     return symbol_objfile (BLOCK_FUNCTION (block));
 
   global_block = (struct global_block *) block_global_block (block);
-  return COMPUNIT_OBJFILE (global_block->compunit_symtab);
+  return global_block->compunit_symtab->objfile ();
 }
 
 /* See block.  */
diff --git a/gdb/buildsym-legacy.c b/gdb/buildsym-legacy.c
index f32fb9de13ba..3a00b355f5e9 100644
--- a/gdb/buildsym-legacy.c
+++ b/gdb/buildsym-legacy.c
@@ -301,7 +301,7 @@ restart_symtab (struct compunit_symtab *cust,
   gdb_assert (buildsym_compunit == nullptr);
 
   buildsym_compunit
-    = new struct buildsym_compunit (COMPUNIT_OBJFILE (cust),
+    = new struct buildsym_compunit (cust->objfile (),
 				    name,
 				    COMPUNIT_DIRNAME (cust),
 				    compunit_language (cust),
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 57538fc0adf9..552b54ed7cec 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -10747,7 +10747,7 @@ dwarf2_cu::setup_type_unit_groups (struct die_info *die)
 	  gdb_assert (m_builder == nullptr);
 	  struct compunit_symtab *cust = tug_unshare->compunit_symtab;
 	  m_builder.reset (new struct buildsym_compunit
-			   (COMPUNIT_OBJFILE (cust), "",
+			   (cust->objfile (), "",
 			    COMPUNIT_DIRNAME (cust),
 			    compunit_language (cust),
 			    0, cust));
@@ -10769,7 +10769,7 @@ dwarf2_cu::setup_type_unit_groups (struct die_info *die)
 	 time.  */
 
       tug_unshare->symtabs
-	= XOBNEWVEC (&COMPUNIT_OBJFILE (cust)->objfile_obstack,
+	= XOBNEWVEC (&cust->objfile ()->objfile_obstack,
 		     struct symtab *, line_header->file_names_size ());
 
       auto &file_names = line_header->file_names ();
@@ -10799,7 +10799,7 @@ dwarf2_cu::setup_type_unit_groups (struct die_info *die)
       gdb_assert (m_builder == nullptr);
       struct compunit_symtab *cust = tug_unshare->compunit_symtab;
       m_builder.reset (new struct buildsym_compunit
-		       (COMPUNIT_OBJFILE (cust), "",
+		       (cust->objfile (), "",
 			COMPUNIT_DIRNAME (cust),
 			compunit_language (cust),
 			0, cust));
diff --git a/gdb/guile/scm-block.c b/gdb/guile/scm-block.c
index e7a1083fdc99..25d16bdcc0c1 100644
--- a/gdb/guile/scm-block.c
+++ b/gdb/guile/scm-block.c
@@ -685,7 +685,7 @@ gdbscm_lookup_block (SCM pc_scm)
     {
       cust = find_pc_compunit_symtab (pc);
 
-      if (cust != NULL && COMPUNIT_OBJFILE (cust) != NULL)
+      if (cust != NULL && cust->objfile () != NULL)
 	block = block_for_pc (pc);
     }
   catch (const gdb_exception &except)
@@ -694,14 +694,14 @@ gdbscm_lookup_block (SCM pc_scm)
     }
 
   GDBSCM_HANDLE_GDB_EXCEPTION (exc);
-  if (cust == NULL || COMPUNIT_OBJFILE (cust) == NULL)
+  if (cust == NULL || cust->objfile () == NULL)
     {
       gdbscm_out_of_range_error (FUNC_NAME, SCM_ARG1, pc_scm,
 				 _("cannot locate object file for block"));
     }
 
   if (block != NULL)
-    return bkscm_scm_from_block (block, COMPUNIT_OBJFILE (cust));
+    return bkscm_scm_from_block (block, cust->objfile ());
   return SCM_BOOL_F;
 }
 \f
diff --git a/gdb/python/py-progspace.c b/gdb/python/py-progspace.c
index d8df9c31d804..ec9dfe55ec99 100644
--- a/gdb/python/py-progspace.c
+++ b/gdb/python/py-progspace.c
@@ -388,7 +388,7 @@ pspy_block_for_pc (PyObject *o, PyObject *args)
       set_current_program_space (self->pspace);
       cust = find_pc_compunit_symtab (pc);
 
-      if (cust != NULL && COMPUNIT_OBJFILE (cust) != NULL)
+      if (cust != NULL && cust->objfile () != NULL)
 	block = block_for_pc (pc);
     }
   catch (const gdb_exception &except)
@@ -396,11 +396,11 @@ pspy_block_for_pc (PyObject *o, PyObject *args)
       GDB_PY_HANDLE_EXCEPTION (except);
     }
 
-  if (cust == NULL || COMPUNIT_OBJFILE (cust) == NULL)
+  if (cust == NULL || cust->objfile () == NULL)
     Py_RETURN_NONE;
 
   if (block)
-    return block_to_block_object (block, COMPUNIT_OBJFILE (cust));
+    return block_to_block_object (block, cust->objfile ());
 
   Py_RETURN_NONE;
 }
diff --git a/gdb/source.c b/gdb/source.c
index 3810af83042d..55fd1fd2b9b5 100644
--- a/gdb/source.c
+++ b/gdb/source.c
@@ -1194,7 +1194,7 @@ open_source_file (struct symtab *s)
     {
       if (SYMTAB_COMPUNIT (s) != nullptr)
 	{
-	  const objfile *ofp = COMPUNIT_OBJFILE (SYMTAB_COMPUNIT (s));
+	  const objfile *ofp = SYMTAB_COMPUNIT (s)->objfile ();
 
 	  std::string srcpath;
 	  if (IS_ABSOLUTE_PATH (s->filename))
diff --git a/gdb/symtab.h b/gdb/symtab.h
index d56671e0a9e8..65a3d1626ce8 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -1407,7 +1407,7 @@ struct symtab
 #define SYMTAB_BLOCKVECTOR(symtab) \
   COMPUNIT_BLOCKVECTOR (SYMTAB_COMPUNIT (symtab))
 #define SYMTAB_OBJFILE(symtab) \
-  COMPUNIT_OBJFILE (SYMTAB_COMPUNIT (symtab))
+  (SYMTAB_COMPUNIT (symtab)->objfile ())
 #define SYMTAB_PSPACE(symtab) (SYMTAB_OBJFILE (symtab)->pspace)
 #define SYMTAB_DIRNAME(symtab) \
   COMPUNIT_DIRNAME (SYMTAB_COMPUNIT (symtab))
@@ -1545,7 +1545,6 @@ struct compunit_symtab
 
 using compunit_symtab_range = next_range<compunit_symtab>;
 
-#define COMPUNIT_OBJFILE(cust) ((cust)->objfile ())
 #define COMPUNIT_FILETABS(cust) ((cust)->filetabs)
 #define COMPUNIT_DEBUGFORMAT(cust) ((cust)->debugformat)
 #define COMPUNIT_PRODUCER(cust) ((cust)->producer)
-- 
2.33.1


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

* [PATCH 3/6] gdb: rename compunit_primary_filetab to compunit_symtab::primary_filetab
  2021-12-01 15:47 [PATCH 1/6] gdb: add getter/setter for compunit_symtab::objfile Simon Marchi
  2021-12-01 15:47 ` [PATCH 2/6] gdb: remove COMPUNIT_OBJFILE macro Simon Marchi
@ 2021-12-01 15:47 ` Simon Marchi
  2021-12-01 15:47 ` [PATCH 4/6] gdb: add compunit_symtab::add_filetab method Simon Marchi
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Simon Marchi @ 2021-12-01 15:47 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

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

Make compunit_primary_filetab a method of compunit_symtab.

Change-Id: Iee3c4f7e36d579bf763c5bba146e5e10d6766768
---
 gdb/dwarf2/read.c     |  2 +-
 gdb/guile/scm-block.c |  2 +-
 gdb/psymtab.c         |  2 +-
 gdb/symfile-debug.c   |  6 +++---
 gdb/symmisc.c         |  2 +-
 gdb/symtab.c          | 10 +++++-----
 gdb/symtab.h          |  8 +++-----
 7 files changed, 15 insertions(+), 17 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 552b54ed7cec..9c7076e20f32 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -3129,7 +3129,7 @@ dwarf2_base_index_functions::find_last_source_symtab (struct objfile *objfile)
   if (cust == NULL)
     return NULL;
 
-  return compunit_primary_filetab (cust);
+  return cust->primary_filetab ();
 }
 
 /* See read.h.  */
diff --git a/gdb/guile/scm-block.c b/gdb/guile/scm-block.c
index 25d16bdcc0c1..e36db28b1385 100644
--- a/gdb/guile/scm-block.c
+++ b/gdb/guile/scm-block.c
@@ -554,7 +554,7 @@ bkscm_print_block_syms_progress_smob (SCM self, SCM port,
 		    : i_smob->iter.d.compunit_symtab->includes[i_smob->iter.idx]);
 	    gdbscm_printf (port, " %s",
 			   symtab_to_filename_for_display
-			     (compunit_primary_filetab (cust)));
+			     (cust->primary_filetab ()));
 	    break;
 	  }
 	case FIRST_LOCAL_BLOCK:
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index e09537d8f5ef..093ce397f9a0 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -630,7 +630,7 @@ psymbol_functions::find_last_source_symtab (struct objfile *ofp)
 
 	  if (cust == NULL)
 	    return NULL;
-	  return compunit_primary_filetab (cust);
+	  return cust->primary_filetab ();
 	}
     }
   return NULL;
diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c
index f3d5a68b72e7..f8bed757e3d7 100644
--- a/gdb/symfile-debug.c
+++ b/gdb/symfile-debug.c
@@ -289,7 +289,7 @@ objfile::lookup_symbol (block_enum kind, const char *name, domain_enum domain)
   if (debug_symfile)
     fprintf_filtered (gdb_stdlog, "qf->lookup_symbol (...) = %s\n",
 		      retval
-		      ? debug_symtab_name (compunit_primary_filetab (retval))
+		      ? debug_symtab_name (retval->primary_filetab ())
 		      : "NULL");
 
   return retval;
@@ -454,7 +454,7 @@ objfile::find_pc_sect_compunit_symtab (struct bound_minimal_symbol msymbol,
     fprintf_filtered (gdb_stdlog,
 		      "qf->find_pc_sect_compunit_symtab (...) = %s\n",
 		      retval
-		      ? debug_symtab_name (compunit_primary_filetab (retval))
+		      ? debug_symtab_name (retval->primary_filetab ())
 		      : "NULL");
 
   return retval;
@@ -495,7 +495,7 @@ objfile::find_compunit_symtab_by_address (CORE_ADDR address)
     fprintf_filtered (gdb_stdlog,
 		      "qf->find_compunit_symtab_by_address (...) = %s\n",
 		      result
-		      ? debug_symtab_name (compunit_primary_filetab (result))
+		      ? debug_symtab_name (result->primary_filetab ())
 		      : "NULL");
 
   return result;
diff --git a/gdb/symmisc.c b/gdb/symmisc.c
index 68ab1fab78a2..dc43ea666739 100644
--- a/gdb/symmisc.c
+++ b/gdb/symmisc.c
@@ -868,7 +868,7 @@ maintenance_check_symtabs (const char *ignore, int from_tty)
 	for (compunit_symtab *cust : objfile->compunits ())
 	  {
 	    int found_something = 0;
-	    struct symtab *symtab = compunit_primary_filetab (cust);
+	    struct symtab *symtab = cust->primary_filetab ();
 
 	    QUIT;
 
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 7e1030512b56..025a772431ce 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -362,12 +362,12 @@ compunit_symtab::set_call_site_htab (htab_t call_site_htab)
 /* See symtab.h.  */
 
 struct symtab *
-compunit_primary_filetab (const struct compunit_symtab *cust)
+compunit_symtab::primary_filetab () const
 {
-  gdb_assert (COMPUNIT_FILETABS (cust) != NULL);
+  gdb_assert (this->filetabs != nullptr);
 
   /* The primary file symtab is the first one in the list.  */
-  return COMPUNIT_FILETABS (cust);
+  return this->filetabs;
 }
 
 /* See symtab.h.  */
@@ -375,7 +375,7 @@ compunit_primary_filetab (const struct compunit_symtab *cust)
 enum language
 compunit_language (const struct compunit_symtab *cust)
 {
-  struct symtab *symtab = compunit_primary_filetab (cust);
+  struct symtab *symtab = cust->primary_filetab ();
 
 /* The language of the compunit symtab is the language of its primary
    source file.  */
@@ -2376,7 +2376,7 @@ Internal: %s symbol `%s' found in %s psymtab but not in symtab.\n\
 (if a template, try specifying an instantiation: %s<type>)."),
 	 block_index == GLOBAL_BLOCK ? "global" : "static",
 	 name,
-	 symtab_to_filename_for_display (compunit_primary_filetab (cust)),
+	 symtab_to_filename_for_display (cust->primary_filetab ()),
 	 name, name);
 }
 
diff --git a/gdb/symtab.h b/gdb/symtab.h
index 65a3d1626ce8..424b7852ab49 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -1459,6 +1459,9 @@ struct compunit_symtab
     m_objfile = objfile;
   }
 
+  /* Return the primary filetab of the compunit.  */
+  symtab *primary_filetab () const;
+
   /* Set m_call_site_htab.  */
   void set_call_site_htab (htab_t call_site_htab);
 
@@ -1566,11 +1569,6 @@ compunit_filetabs (compunit_symtab *cu)
   return symtab_range (cu->filetabs);
 }
 
-/* Return the primary symtab of CUST.  */
-
-extern struct symtab *
-  compunit_primary_filetab (const struct compunit_symtab *cust);
-
 /* Return the language of CUST.  */
 
 extern enum language compunit_language (const struct compunit_symtab *cust);
-- 
2.33.1


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

* [PATCH 4/6] gdb: add compunit_symtab::add_filetab method
  2021-12-01 15:47 [PATCH 1/6] gdb: add getter/setter for compunit_symtab::objfile Simon Marchi
  2021-12-01 15:47 ` [PATCH 2/6] gdb: remove COMPUNIT_OBJFILE macro Simon Marchi
  2021-12-01 15:47 ` [PATCH 3/6] gdb: rename compunit_primary_filetab to compunit_symtab::primary_filetab Simon Marchi
@ 2021-12-01 15:47 ` Simon Marchi
  2021-12-01 15:47 ` [PATCH 5/6] gdb: add compunit_symtab::set_primary_filetab method Simon Marchi
  2021-12-01 15:47 ` [PATCH 6/6] gdb: move compunit_filetabs to compunit_symtab::filetabs Simon Marchi
  4 siblings, 0 replies; 6+ messages in thread
From: Simon Marchi @ 2021-12-01 15:47 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

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

Add a method to append a filetab/symtab to a compunit_symtab.  There is
a single place where this is done currently, in allocate_symtab.

Change-Id: Ie86c6e34d175728173d1cffdce44acd6cff6c31d
---
 gdb/symfile.c | 11 +----------
 gdb/symtab.h  | 14 ++++++++++++++
 2 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/gdb/symfile.c b/gdb/symfile.c
index e15df3fed739..16d8448ae5ce 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -2787,16 +2787,7 @@ allocate_symtab (struct compunit_symtab *cust, const char *filename)
     }
 
   /* Add it to CUST's list of symtabs.  */
-  if (cust->filetabs == NULL)
-    {
-      cust->filetabs = symtab;
-      cust->last_filetab = symtab;
-    }
-  else
-    {
-      cust->last_filetab->next = symtab;
-      cust->last_filetab = symtab;
-    }
+  cust->add_filetab (symtab);
 
   /* Backlink to the containing compunit symtab.  */
   symtab->compunit_symtab = cust;
diff --git a/gdb/symtab.h b/gdb/symtab.h
index 424b7852ab49..91e730a12ad0 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -1459,6 +1459,20 @@ struct compunit_symtab
     m_objfile = objfile;
   }
 
+  void add_filetab (symtab *filetab)
+  {
+    if (this->filetabs == nullptr)
+      {
+	this->filetabs = filetab;
+	this->last_filetab = filetab;
+      }
+    else
+      {
+	this->last_filetab->next = filetab;
+	this->last_filetab = filetab;
+      }
+  }
+
   /* Return the primary filetab of the compunit.  */
   symtab *primary_filetab () const;
 
-- 
2.33.1


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

* [PATCH 5/6] gdb: add compunit_symtab::set_primary_filetab method
  2021-12-01 15:47 [PATCH 1/6] gdb: add getter/setter for compunit_symtab::objfile Simon Marchi
                   ` (2 preceding siblings ...)
  2021-12-01 15:47 ` [PATCH 4/6] gdb: add compunit_symtab::add_filetab method Simon Marchi
@ 2021-12-01 15:47 ` Simon Marchi
  2021-12-01 15:47 ` [PATCH 6/6] gdb: move compunit_filetabs to compunit_symtab::filetabs Simon Marchi
  4 siblings, 0 replies; 6+ messages in thread
From: Simon Marchi @ 2021-12-01 15:47 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

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

Add a method to set the primary filetab of the CU.  This is currently
done in buildsym_compunit::end_symtab_with_blockvector.

Change-Id: I16c51a6b90a4cb4c0c5f183b0f2e12bc64b6fd74
---
 gdb/buildsym.c | 24 ++----------------------
 gdb/symtab.c   | 28 ++++++++++++++++++++++++++++
 gdb/symtab.h   |  6 ++++++
 3 files changed, 36 insertions(+), 22 deletions(-)

diff --git a/gdb/buildsym.c b/gdb/buildsym.c
index 0f7449fed97f..5a34bc91454a 100644
--- a/gdb/buildsym.c
+++ b/gdb/buildsym.c
@@ -996,28 +996,8 @@ buildsym_compunit::end_symtab_with_blockvector (struct block *static_block,
       symtab->language = subfile->language;
     }
 
-  /* Make sure the symtab of main_subfile is the first in its list.  */
-  {
-    struct symtab *main_symtab, *prev_symtab;
-
-    main_symtab = m_main_subfile->symtab;
-    prev_symtab = NULL;
-    for (symtab *symtab : compunit_filetabs (cu))
-      {
-	if (symtab == main_symtab)
-	  {
-	    if (prev_symtab != NULL)
-	      {
-		prev_symtab->next = main_symtab->next;
-		main_symtab->next = COMPUNIT_FILETABS (cu);
-		COMPUNIT_FILETABS (cu) = main_symtab;
-	      }
-	    break;
-	  }
-	prev_symtab = symtab;
-      }
-    gdb_assert (main_symtab == COMPUNIT_FILETABS (cu));
-  }
+  /* Make sure the filetab of main_subfile is the primary filetab of the CU.  */
+  cu->set_primary_filetab (m_main_subfile->symtab);
 
   /* Fill out the compunit symtab.  */
 
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 025a772431ce..47202ae46b96 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -361,6 +361,34 @@ compunit_symtab::set_call_site_htab (htab_t call_site_htab)
 
 /* See symtab.h.  */
 
+void
+compunit_symtab::set_primary_filetab (symtab *primary_filetab)
+{
+  symtab *prev_filetab = nullptr;
+
+  /* Move PRIMARY_FILETAB to the head of the filetab list.  */
+  for (symtab *filetab : compunit_filetabs (this))
+    {
+      if (filetab == primary_filetab)
+	{
+	  if (prev_filetab != nullptr)
+	    {
+	      prev_filetab->next = primary_filetab->next;
+	      primary_filetab->next = this->filetabs;
+	      this->filetabs = primary_filetab;
+	    }
+
+	  break;
+	}
+
+      prev_filetab = filetab;
+    }
+
+  gdb_assert (primary_filetab == this->filetabs);
+}
+
+/* See symtab.h.  */
+
 struct symtab *
 compunit_symtab::primary_filetab () const
 {
diff --git a/gdb/symtab.h b/gdb/symtab.h
index 91e730a12ad0..ba8a94384f69 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -1473,6 +1473,12 @@ struct compunit_symtab
       }
   }
 
+  /* Make PRIMARY_FILETAB the primary filetab of this compunit symtab.
+
+     PRIMARY_FILETAB must already be a filetab of this compunit symtab.  */
+
+  void set_primary_filetab (symtab *primary_filetab);
+
   /* Return the primary filetab of the compunit.  */
   symtab *primary_filetab () const;
 
-- 
2.33.1


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

* [PATCH 6/6] gdb: move compunit_filetabs to compunit_symtab::filetabs
  2021-12-01 15:47 [PATCH 1/6] gdb: add getter/setter for compunit_symtab::objfile Simon Marchi
                   ` (3 preceding siblings ...)
  2021-12-01 15:47 ` [PATCH 5/6] gdb: add compunit_symtab::set_primary_filetab method Simon Marchi
@ 2021-12-01 15:47 ` Simon Marchi
  4 siblings, 0 replies; 6+ messages in thread
From: Simon Marchi @ 2021-12-01 15:47 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

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

Make compunit_filetabs, used to iterate a compunit_symtab's filetabs, a
method of compunit_symtab.  The name filetabs conflicts with the current
name of the field.  Rename the field to m_filetabs, since at this point
nothing outside of compunit_symtab uses it, so we should treat it as
private (even though it's not actually private).  Rename the
last_filetab field to m_last_filetab as well (it's only used on
compunit_symtab::add_filetab).

Adjust the COMPUNIT_FILETABS macro to keep its current behavior of
returning the first filetab.

Change-Id: I537b553a44451c52d24b18ee1bfa47e23747cfc3
---
 gdb/coffread.c |  2 +-
 gdb/maint.c    |  4 ++--
 gdb/objfiles.c |  2 +-
 gdb/source.c   |  4 ++--
 gdb/symmisc.c  | 10 +++++-----
 gdb/symtab.c   | 22 +++++++++++-----------
 gdb/symtab.h   | 36 +++++++++++++++++-------------------
 7 files changed, 39 insertions(+), 41 deletions(-)

diff --git a/gdb/coffread.c b/gdb/coffread.c
index 4723662f1408..044cd82d61ae 100644
--- a/gdb/coffread.c
+++ b/gdb/coffread.c
@@ -1177,7 +1177,7 @@ coff_symtab_read (minimal_symbol_reader &reader,
   {
     for (compunit_symtab *cu : objfile->compunits ())
       {
-	for (symtab *s : compunit_filetabs (cu))
+	for (symtab *s : cu->filetabs ())
 	  patch_opaque_types (s);
       }
   }
diff --git a/gdb/maint.c b/gdb/maint.c
index e03abfacdae7..1c6b89f2519b 100644
--- a/gdb/maint.c
+++ b/gdb/maint.c
@@ -947,8 +947,8 @@ count_symtabs_and_blocks (int *nr_symtabs_ptr, int *nr_compunit_symtabs_ptr,
 	    {
 	      ++nr_compunit_symtabs;
 	      nr_blocks += BLOCKVECTOR_NBLOCKS (COMPUNIT_BLOCKVECTOR (cu));
-	      nr_symtabs += std::distance (compunit_filetabs (cu).begin (),
-					   compunit_filetabs (cu).end ());
+	      nr_symtabs += std::distance (cu->filetabs ().begin (),
+					   cu->filetabs ().end ());
 	    }
 	}
     }
diff --git a/gdb/objfiles.c b/gdb/objfiles.c
index 3da6f5211aa1..cd8eb916329b 100644
--- a/gdb/objfiles.c
+++ b/gdb/objfiles.c
@@ -651,7 +651,7 @@ objfile_relocate1 (struct objfile *objfile,
   {
     for (compunit_symtab *cust : objfile->compunits ())
       {
-	for (symtab *s : compunit_filetabs (cust))
+	for (symtab *s : cust->filetabs ())
 	  {
 	    struct linetable *l;
 
diff --git a/gdb/source.c b/gdb/source.c
index 55fd1fd2b9b5..99fe69bdf5bd 100644
--- a/gdb/source.c
+++ b/gdb/source.c
@@ -338,7 +338,7 @@ select_source_symtab (struct symtab *s)
     {
       for (compunit_symtab *cu : ofp->compunits ())
 	{
-	  for (symtab *symtab : compunit_filetabs (cu))
+	  for (symtab *symtab : cu->filetabs ())
 	    {
 	      const char *name = symtab->filename;
 	      int len = strlen (name);
@@ -418,7 +418,7 @@ forget_cached_source_info_for_objfile (struct objfile *objfile)
 {
   for (compunit_symtab *cu : objfile->compunits ())
     {
-      for (symtab *s : compunit_filetabs (cu))
+      for (symtab *s : cu->filetabs ())
 	{
 	  if (s->fullname != NULL)
 	    {
diff --git a/gdb/symmisc.c b/gdb/symmisc.c
index dc43ea666739..be4e350e7b38 100644
--- a/gdb/symmisc.c
+++ b/gdb/symmisc.c
@@ -72,7 +72,7 @@ print_objfile_statistics (void)
 	i = linetables = 0;
 	for (compunit_symtab *cu : objfile->compunits ())
 	  {
-	    for (symtab *s : compunit_filetabs (cu))
+	    for (symtab *s : cu->filetabs ())
 	      {
 		i++;
 		if (SYMTAB_LINETABLE (s) != NULL)
@@ -126,7 +126,7 @@ dump_objfile (struct objfile *objfile)
       printf_filtered ("Symtabs:\n");
       for (compunit_symtab *cu : objfile->compunits ())
 	{
-	  for (symtab *symtab : compunit_filetabs (cu))
+	  for (symtab *symtab : cu->filetabs ())
 	    {
 	      printf_filtered ("%s at ",
 			       symtab_to_filename_for_display (symtab));
@@ -472,7 +472,7 @@ maintenance_print_symbols (const char *args, int from_tty)
 
 	  for (compunit_symtab *cu : objfile->compunits ())
 	    {
-	      for (symtab *s : compunit_filetabs (cu))
+	      for (symtab *s : cu->filetabs ())
 		{
 		  int print_for_source = 0;
 
@@ -764,7 +764,7 @@ maintenance_info_symtabs (const char *regexp, int from_tty)
 	  {
 	    int printed_compunit_symtab_start = 0;
 
-	    for (symtab *symtab : compunit_filetabs (cust))
+	    for (symtab *symtab : cust->filetabs ())
 	      {
 		QUIT;
 
@@ -1030,7 +1030,7 @@ maintenance_info_line_tables (const char *regexp, int from_tty)
       {
 	for (compunit_symtab *cust : objfile->compunits ())
 	  {
-	    for (symtab *symtab : compunit_filetabs (cust))
+	    for (symtab *symtab : cust->filetabs ())
 	      {
 		QUIT;
 
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 47202ae46b96..d48bf11aa00d 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -367,15 +367,15 @@ compunit_symtab::set_primary_filetab (symtab *primary_filetab)
   symtab *prev_filetab = nullptr;
 
   /* Move PRIMARY_FILETAB to the head of the filetab list.  */
-  for (symtab *filetab : compunit_filetabs (this))
+  for (symtab *filetab : this->filetabs ())
     {
       if (filetab == primary_filetab)
 	{
 	  if (prev_filetab != nullptr)
 	    {
 	      prev_filetab->next = primary_filetab->next;
-	      primary_filetab->next = this->filetabs;
-	      this->filetabs = primary_filetab;
+	      primary_filetab->next = m_filetabs;
+	      m_filetabs = primary_filetab;
 	    }
 
 	  break;
@@ -384,7 +384,7 @@ compunit_symtab::set_primary_filetab (symtab *primary_filetab)
       prev_filetab = filetab;
     }
 
-  gdb_assert (primary_filetab == this->filetabs);
+  gdb_assert (primary_filetab == m_filetabs);
 }
 
 /* See symtab.h.  */
@@ -392,10 +392,10 @@ compunit_symtab::set_primary_filetab (symtab *primary_filetab)
 struct symtab *
 compunit_symtab::primary_filetab () const
 {
-  gdb_assert (this->filetabs != nullptr);
+  gdb_assert (m_filetabs != nullptr);
 
   /* The primary file symtab is the first one in the list.  */
-  return this->filetabs;
+  return m_filetabs;
 }
 
 /* See symtab.h.  */
@@ -533,7 +533,7 @@ iterate_over_some_symtabs (const char *name,
 
   for (cust = first; cust != NULL && cust != after_last; cust = cust->next)
     {
-      for (symtab *s : compunit_filetabs (cust))
+      for (symtab *s : cust->filetabs ())
 	{
 	  if (compare_filenames_for_search (s->filename, name))
 	    {
@@ -3282,7 +3282,7 @@ find_pc_sect_line (CORE_ADDR pc, struct obj_section *section, int notcurrent)
      They all have the same apriori range, that we found was right;
      but they have different line tables.  */
 
-  for (symtab *iter_s : compunit_filetabs (cust))
+  for (symtab *iter_s : cust->filetabs ())
     {
       /* Find the best line in this symtab.  */
       l = SYMTAB_LINETABLE (iter_s);
@@ -3483,7 +3483,7 @@ find_line_symtab (struct symtab *sym_tab, int line,
 	{
 	  for (compunit_symtab *cu : objfile->compunits ())
 	    {
-	      for (symtab *s : compunit_filetabs (cu))
+	      for (symtab *s : cu->filetabs ())
 		{
 		  struct linetable *l;
 		  int ind;
@@ -4531,7 +4531,7 @@ info_sources_worker (struct ui_out *uiout,
 
       for (compunit_symtab *cu : objfile->compunits ())
 	{
-	  for (symtab *s : compunit_filetabs (cu))
+	  for (symtab *s : cu->filetabs ())
 	    {
 	      const char *file = symtab_to_filename_for_display (s);
 	      const char *fullname = symtab_to_fullname (s);
@@ -6185,7 +6185,7 @@ make_source_files_completion_list (const char *text, const char *word)
     {
       for (compunit_symtab *cu : objfile->compunits ())
 	{
-	  for (symtab *s : compunit_filetabs (cu))
+	  for (symtab *s : cu->filetabs ())
 	    {
 	      if (not_interesting_fname (s->filename))
 		continue;
diff --git a/gdb/symtab.h b/gdb/symtab.h
index ba8a94384f69..4d5916fbf6cd 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -1401,6 +1401,10 @@ struct symtab
   char *fullname;
 };
 
+/* A range adapter to allowing iterating over all the file tables in a list.  */
+
+using symtab_range = next_range<symtab>;
+
 #define SYMTAB_COMPUNIT(symtab) ((symtab)->compunit_symtab)
 #define SYMTAB_LINETABLE(symtab) ((symtab)->linetable)
 #define SYMTAB_LANGUAGE(symtab) ((symtab)->language)
@@ -1459,17 +1463,22 @@ struct compunit_symtab
     m_objfile = objfile;
   }
 
+  symtab_range filetabs () const
+  {
+    return symtab_range (m_filetabs);
+  }
+
   void add_filetab (symtab *filetab)
   {
-    if (this->filetabs == nullptr)
+    if (m_filetabs == nullptr)
       {
-	this->filetabs = filetab;
-	this->last_filetab = filetab;
+	m_filetabs = filetab;
+	m_last_filetab = filetab;
       }
     else
       {
-	this->last_filetab->next = filetab;
-	this->last_filetab = filetab;
+	m_last_filetab->next = filetab;
+	m_last_filetab = filetab;
       }
   }
 
@@ -1503,14 +1512,14 @@ struct compunit_symtab
      source file (e.g., .c, .cc) is guaranteed to be first.
      Each symtab is a file, either the "main" source file (e.g., .c, .cc)
      or header (e.g., .h).  */
-  struct symtab *filetabs;
+  symtab *m_filetabs;
 
   /* Last entry in FILETABS list.
      Subfiles are added to the end of the list so they accumulate in order,
      with the main source subfile living at the front.
      The main reason is so that the main source file symtab is at the head
      of the list, and the rest appear in order for debugging convenience.  */
-  struct symtab *last_filetab;
+  symtab *m_last_filetab;
 
   /* Non-NULL string that identifies the format of the debugging information,
      such as "stabs", "dwarf 1", "dwarf 2", "coff", etc.  This is mostly useful
@@ -1568,7 +1577,7 @@ struct compunit_symtab
 
 using compunit_symtab_range = next_range<compunit_symtab>;
 
-#define COMPUNIT_FILETABS(cust) ((cust)->filetabs)
+#define COMPUNIT_FILETABS(cust) (*(cust)->filetabs ().begin ())
 #define COMPUNIT_DEBUGFORMAT(cust) ((cust)->debugformat)
 #define COMPUNIT_PRODUCER(cust) ((cust)->producer)
 #define COMPUNIT_DIRNAME(cust) ((cust)->dirname)
@@ -1578,17 +1587,6 @@ using compunit_symtab_range = next_range<compunit_symtab>;
 #define COMPUNIT_EPILOGUE_UNWIND_VALID(cust) ((cust)->epilogue_unwind_valid)
 #define COMPUNIT_MACRO_TABLE(cust) ((cust)->macro_table)
 
-/* A range adapter to allowing iterating over all the file tables
-   within a compunit.  */
-
-using symtab_range = next_range<symtab>;
-
-static inline symtab_range
-compunit_filetabs (compunit_symtab *cu)
-{
-  return symtab_range (cu->filetabs);
-}
-
 /* Return the language of CUST.  */
 
 extern enum language compunit_language (const struct compunit_symtab *cust);
-- 
2.33.1


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

end of thread, other threads:[~2021-12-01 15:47 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-01 15:47 [PATCH 1/6] gdb: add getter/setter for compunit_symtab::objfile Simon Marchi
2021-12-01 15:47 ` [PATCH 2/6] gdb: remove COMPUNIT_OBJFILE macro Simon Marchi
2021-12-01 15:47 ` [PATCH 3/6] gdb: rename compunit_primary_filetab to compunit_symtab::primary_filetab Simon Marchi
2021-12-01 15:47 ` [PATCH 4/6] gdb: add compunit_symtab::add_filetab method Simon Marchi
2021-12-01 15:47 ` [PATCH 5/6] gdb: add compunit_symtab::set_primary_filetab method Simon Marchi
2021-12-01 15:47 ` [PATCH 6/6] gdb: move compunit_filetabs to compunit_symtab::filetabs 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).