This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFA 2/2] Constify the line table


From: Tom Tromey <tromey@redhat.com>

Now that linetables aren't relocated, we can make them immutable in
the symbol table.  This patch applies "const" there and then fixes up
the fallout.

gdb/ChangeLog
2018-03-21  Tom Tromey  <tom@tromey.com>

	* record-btrace.c (btrace_find_line_range): Constify.
	* buildsym.c (end_symtab_from_static_block): Update.
	* disasm.c (do_mixed_source_and_assembly, gdb_disassembly):
	Update.
	* jit.c (finalize_symtab): Update and rearrange for
	constification.
	* linespec.c (create_sals_line_offset): Update.
	(decode_digits_ordinary): Make "best_entry" const.
	* mdebugread.c (psymtab_to_symtab_1): Update.
	(new_symtab): Add "lines" parameter.
	* mi/mi-symbol-cmds.c (mi_cmd_symbol_list_lines): Update.
	* python/py-linetable.c (ltpy_get_pcs_for_line, ltpy_has_line)
	(ltpy_get_all_source_lines, ltpy_iternext): Update.
	* symmisc.c (dump_symtab_1, maintenance_print_one_line_table):
	Update.
	* symtab.c (find_pc_sect_line, find_line_symtab)
	(find_pcs_for_symtab_line, find_line_common)
	(skip_prologue_using_lineinfo, skip_prologue_using_sal): Update.
	* symtab.h (struct symtab) <linetable>: Now const.
	(find_pcs_for_symtab_line): Update.
---
 gdb/ChangeLog             | 23 +++++++++++++++++++++++
 gdb/buildsym.c            |  6 +++---
 gdb/disasm.c              |  2 +-
 gdb/jit.c                 |  8 ++++----
 gdb/linespec.c            |  6 +++---
 gdb/mdebugread.c          | 22 +++++++++-------------
 gdb/mi/mi-symbol-cmds.c   |  2 +-
 gdb/python/py-linetable.c |  9 +++++----
 gdb/record-btrace.c       |  4 ++--
 gdb/symmisc.c             |  6 +++---
 gdb/symtab.c              | 39 ++++++++++++++++++++-------------------
 gdb/symtab.h              |  5 +++--
 12 files changed, 77 insertions(+), 55 deletions(-)

diff --git a/gdb/buildsym.c b/gdb/buildsym.c
index 99a92a8e31..a4945aa7aa 100644
--- a/gdb/buildsym.c
+++ b/gdb/buildsym.c
@@ -1373,10 +1373,10 @@ end_symtab_with_blockvector (struct block *static_block,
       if (subfile->line_vector)
 	{
 	  /* Reallocate the line table on the symbol obstack.  */
-	  SYMTAB_LINETABLE (symtab) = (struct linetable *)
+	  linetable *new_table = (struct linetable *)
 	    obstack_alloc (&objfile->objfile_obstack, linetablesize);
-	  memcpy (SYMTAB_LINETABLE (symtab), subfile->line_vector,
-		  linetablesize);
+	  memcpy (new_table, subfile->line_vector, linetablesize);
+	  SYMTAB_LINETABLE (symtab) = new_table;
 	}
       else
 	{
diff --git a/gdb/disasm.c b/gdb/disasm.c
index ec5b8a9b81..3f9d6f8b55 100644
--- a/gdb/disasm.c
+++ b/gdb/disasm.c
@@ -343,7 +343,7 @@ do_mixed_source_and_assembly_deprecated
 {
   int newlines = 0;
   int nlines;
-  struct linetable_entry *le;
+  const struct linetable_entry *le;
   struct deprecated_dis_line_entry *mle;
   struct symtab_and_line sal;
   int i;
diff --git a/gdb/jit.c b/gdb/jit.c
index e5c64cc791..c68ee167a0 100644
--- a/gdb/jit.c
+++ b/gdb/jit.c
@@ -672,10 +672,10 @@ finalize_symtab (struct gdb_symtab *stab, struct objfile *objfile)
       size_t size = ((stab->linetable->nitems - 1)
 		     * sizeof (struct linetable_entry)
 		     + sizeof (struct linetable));
-      SYMTAB_LINETABLE (COMPUNIT_FILETABS (cust))
-	= (struct linetable *) obstack_alloc (&objfile->objfile_obstack, size);
-      memcpy (SYMTAB_LINETABLE (COMPUNIT_FILETABS (cust)), stab->linetable,
-	      size);
+      struct linetable *new_table =
+	(struct linetable *) obstack_alloc (&objfile->objfile_obstack, size);
+      memcpy (new_table, stab->linetable, size);
+      SYMTAB_LINETABLE (COMPUNIT_FILETABS (cust)) = new_table;
     }
 
   blockvector_size = (sizeof (struct blockvector)
diff --git a/gdb/linespec.c b/gdb/linespec.c
index 1236b3f475..9f94f80de5 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -389,7 +389,7 @@ static std::vector<symtab_and_line> decode_digits_ordinary
   (struct linespec_state *self,
    linespec_p ls,
    int line,
-   linetable_entry **best_entry);
+   const linetable_entry **best_entry);
 
 static std::vector<symtab_and_line> decode_digits_list_mode
   (struct linespec_state *self,
@@ -2192,7 +2192,7 @@ create_sals_line_offset (struct linespec_state *self,
     values = decode_digits_list_mode (self, ls, val);
   else
     {
-      struct linetable_entry *best_entry = NULL;
+      const struct linetable_entry *best_entry = NULL;
       int i, j;
 
       std::vector<symtab_and_line> intermediate_results
@@ -4235,7 +4235,7 @@ static std::vector<symtab_and_line>
 decode_digits_ordinary (struct linespec_state *self,
 			linespec_p ls,
 			int line,
-			struct linetable_entry **best_entry)
+			const struct linetable_entry **best_entry)
 {
   int ix;
   struct symtab *elt;
diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c
index c9b29bcc0f..cd53582baf 100644
--- a/gdb/mdebugread.c
+++ b/gdb/mdebugread.c
@@ -236,7 +236,8 @@ enum block_type { FUNCTION_BLOCK, NON_FUNCTION_BLOCK };
 
 static struct block *new_block (enum block_type, enum language);
 
-static struct compunit_symtab *new_symtab (const char *, int, struct objfile *);
+static struct compunit_symtab *new_symtab (const char *, int, struct objfile *,
+					   struct linetable **);
 
 static struct linetable *new_linetable (int);
 
@@ -2177,9 +2178,6 @@ parse_external (EXTR *es, int bigend, struct section_offsets *section_offsets,
    numbers can go back and forth, apparently we can live
    with that and do not need to reorder our linetables.  */
 
-static void parse_lines (FDR *, PDR *, struct linetable *, int,
-			 struct partial_symtab *, CORE_ADDR);
-
 static void
 parse_lines (FDR *fh, PDR *pr, struct linetable *lt, int maxlines,
 	     struct partial_symtab *pst, CORE_ADDR lowest_pdr_addr)
@@ -3919,7 +3917,6 @@ psymtab_to_symtab_1 (struct objfile *objfile,
   int i;
   struct compunit_symtab *cust = NULL;
   FDR *fh;
-  struct linetable *lines;
   CORE_ADDR lowest_pdr_addr = 0;
   int last_symtab_ended = 0;
   struct section_offsets *section_offsets = objfile->section_offsets;
@@ -4159,16 +4156,17 @@ psymtab_to_symtab_1 (struct objfile *objfile,
 
       int maxlines, size;
       EXTR *ext_ptr;
+      struct linetable *lines;
 
       if (fh == 0)
 	{
 	  maxlines = 0;
-	  cust = new_symtab ("unknown", 0, objfile);
+	  cust = new_symtab ("unknown", 0, objfile, &lines);
 	}
       else
 	{
 	  maxlines = 2 * fh->cline;
-	  cust = new_symtab (pst->filename, maxlines, objfile);
+	  cust = new_symtab (pst->filename, maxlines, objfile, &lines);
 
 	  /* The proper language was already determined when building
 	     the psymtab, use it.  */
@@ -4177,8 +4175,6 @@ psymtab_to_symtab_1 (struct objfile *objfile,
 
       psymtab_language = COMPUNIT_FILETABS (cust)->language;
 
-      lines = SYMTAB_LINETABLE (COMPUNIT_FILETABS (cust));
-
       /* Get a new lexical context.  */
 
       push_parse_stack ();
@@ -4712,17 +4708,17 @@ sort_blocks (struct symtab *s)
    linenumbers MAXLINES we'll put in it.  */
 
 static struct compunit_symtab *
-new_symtab (const char *name, int maxlines, struct objfile *objfile)
+new_symtab (const char *name, int maxlines, struct objfile *objfile,
+	    struct linetable **lines)
 {
   struct compunit_symtab *cust = allocate_compunit_symtab (objfile, name);
-  struct symtab *symtab;
   struct blockvector *bv;
   enum language lang;
 
   add_compunit_symtab_to_objfile (cust);
-  symtab = allocate_symtab (cust, name);
+  allocate_symtab (cust, name);
 
-  SYMTAB_LINETABLE (symtab) = new_linetable (maxlines);
+  *lines = new_linetable (maxlines);
   lang = compunit_language (cust);
 
   /* All symtabs must have at least two blocks.  */
diff --git a/gdb/mi/mi-symbol-cmds.c b/gdb/mi/mi-symbol-cmds.c
index 8f3b28e8f8..f42014a2ae 100644
--- a/gdb/mi/mi-symbol-cmds.c
+++ b/gdb/mi/mi-symbol-cmds.c
@@ -34,7 +34,7 @@ mi_cmd_symbol_list_lines (const char *command, char **argv, int argc)
   struct symtab *s;
   int i;
   struct ui_out *uiout = current_uiout;
-  struct linetable *linetable;
+  const struct linetable *linetable;
 
   if (argc != 1)
     error (_("-symbol-list-lines: Usage: SOURCE_FILENAME"));
diff --git a/gdb/python/py-linetable.c b/gdb/python/py-linetable.c
index 5f91804d60..aa4a5982e8 100644
--- a/gdb/python/py-linetable.c
+++ b/gdb/python/py-linetable.c
@@ -158,7 +158,7 @@ ltpy_get_pcs_for_line (PyObject *self, PyObject *args)
 {
   struct symtab *symtab;
   gdb_py_longest py_line;
-  struct linetable_entry *best_entry = NULL;
+  const struct linetable_entry *best_entry = NULL;
   std::vector<CORE_ADDR> pcs;
 
   LTPY_REQUIRE_VALID (self, symtab);
@@ -204,7 +204,8 @@ ltpy_has_line (PyObject *self, PyObject *args)
 
   for (index = 0; index < SYMTAB_LINETABLE (symtab)->nitems; index++)
     {
-      struct linetable_entry *item = &(SYMTAB_LINETABLE (symtab)->item[index]);
+      const struct linetable_entry *item
+	= &(SYMTAB_LINETABLE (symtab)->item[index]);
       if (item->line == py_line)
 	  Py_RETURN_TRUE;
     }
@@ -222,7 +223,7 @@ ltpy_get_all_source_lines (PyObject *self, PyObject *args)
 {
   struct symtab *symtab;
   Py_ssize_t index;
-  struct linetable_entry *item;
+  const struct linetable_entry *item;
 
   LTPY_REQUIRE_VALID (self, symtab);
 
@@ -397,7 +398,7 @@ ltpy_iternext (PyObject *self)
   ltpy_iterator_object *iter_obj = (ltpy_iterator_object *) self;
   struct symtab *symtab;
   PyObject *obj;
-  struct linetable_entry *item;
+  const struct linetable_entry *item;
 
   LTPY_REQUIRE_VALID (iter_obj->source, symtab);
 
diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c
index 0b447292f6..d2ecfea51a 100644
--- a/gdb/record-btrace.c
+++ b/gdb/record-btrace.c
@@ -576,8 +576,8 @@ static struct btrace_line_range
 btrace_find_line_range (CORE_ADDR pc)
 {
   struct btrace_line_range range;
-  struct linetable_entry *lines;
-  struct linetable *ltable;
+  const struct linetable_entry *lines;
+  const struct linetable *ltable;
   struct symtab *symtab;
   int nlines, i;
 
diff --git a/gdb/symmisc.c b/gdb/symmisc.c
index 89506ebfc0..794dc6b41a 100644
--- a/gdb/symmisc.c
+++ b/gdb/symmisc.c
@@ -276,7 +276,7 @@ dump_symtab_1 (struct symtab *symtab, struct ui_file *outfile)
   int i;
   struct dict_iterator iter;
   int len;
-  struct linetable *l;
+  const struct linetable *l;
   const struct blockvector *bv;
   struct symbol *sym;
   struct block *b;
@@ -986,7 +986,7 @@ block_depth (struct block *block)
 static int
 maintenance_print_one_line_table (struct symtab *symtab, void *data)
 {
-  struct linetable *linetable;
+  const struct linetable *linetable;
   struct objfile *objfile;
 
   objfile = symtab->compunit_symtab->objfile;
@@ -1017,7 +1017,7 @@ maintenance_print_one_line_table (struct symtab *symtab, void *data)
 
       for (i = 0; i < linetable->nitems; ++i)
 	{
-	  struct linetable_entry *item;
+	  const struct linetable_entry *item;
 
 	  item = &linetable->item [i];
 	  printf_filtered (_("%-6d %6d %s\n"), i, item->line,
diff --git a/gdb/symtab.c b/gdb/symtab.c
index f57ecafa42..8550f096a7 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -72,7 +72,7 @@
 
 static void rbreak_command (const char *, int);
 
-static int find_line_common (struct linetable *, int, int *, int);
+static int find_line_common (const struct linetable *, int, int *, int);
 
 static struct block_symbol
   lookup_symbol_aux (const char *name,
@@ -3051,16 +3051,16 @@ find_pc_sect_line (CORE_ADDR pc, struct obj_section *section, int notcurrent)
 {
   struct compunit_symtab *cust;
   struct symtab *iter_s;
-  struct linetable *l;
+  const struct linetable *l;
   int len;
   int i;
-  struct linetable_entry *item;
+  const struct linetable_entry *item;
   const struct blockvector *bv;
   struct bound_minimal_symbol msymbol;
 
   /* Info on best line seen so far, and where it starts, and its file.  */
 
-  struct linetable_entry *best = NULL;
+  const struct linetable_entry *best = NULL;
   CORE_ADDR best_end = 0;
   struct symtab *best_symtab = 0;
 
@@ -3069,12 +3069,12 @@ find_pc_sect_line (CORE_ADDR pc, struct obj_section *section, int notcurrent)
      If we don't find a line whose range contains PC,
      we will use a line one less than this,
      with a range from the start of that file to the first line's pc.  */
-  struct linetable_entry *alt = NULL;
+  const struct linetable_entry *alt = NULL;
   struct symtab *alt_symtab = NULL;
 
   /* Info on best line seen in this file.  */
 
-  struct linetable_entry *prev;
+  const struct linetable_entry *prev;
 
   /* If this pc is not from the current frame,
      it is the address of the end of a call instruction.
@@ -3224,8 +3224,8 @@ find_pc_sect_line (CORE_ADDR pc, struct obj_section *section, int notcurrent)
 	return pc < LINETABLE_ENTRY_ADDRESS (iter_s, lhs);
       };
 
-      struct linetable_entry *first = item;
-      struct linetable_entry *last = item + len;
+      const struct linetable_entry *first = item;
+      const struct linetable_entry *last = item + len;
       item = std::upper_bound (first, last, pc, pc_compare);
       if (item != first)
 	prev = item - 1;		/* Found a matching item.  */
@@ -3342,7 +3342,7 @@ find_line_symtab (struct symtab *symtab, int line,
      so far seen.  */
 
   int best_index;
-  struct linetable *best_linetable;
+  const struct linetable *best_linetable;
   struct symtab *best_symtab;
 
   /* First try looking it up in the given symtab.  */
@@ -3381,7 +3381,7 @@ find_line_symtab (struct symtab *symtab, int line,
 
       ALL_FILETABS (objfile, cu, s)
       {
-	struct linetable *l;
+	const struct linetable *l;
 	int ind;
 
 	if (FILENAME_CMP (symtab->filename, s->filename) != 0)
@@ -3428,11 +3428,11 @@ done:
 
 std::vector<CORE_ADDR>
 find_pcs_for_symtab_line (struct symtab *symtab, int line,
-			  struct linetable_entry **best_item)
+			  const struct linetable_entry **best_item)
 {
   int start = 0;
   std::vector<CORE_ADDR> result;
-  struct linetable *linetable = SYMTAB_LINETABLE (symtab);
+  const struct linetable *linetable = SYMTAB_LINETABLE (symtab);
 
   /* First, collect all the PCs that are at this line.  */
   while (1)
@@ -3446,7 +3446,7 @@ find_pcs_for_symtab_line (struct symtab *symtab, int line,
 
       if (!was_exact)
 	{
-	  struct linetable_entry *item = &linetable->item[idx];
+	  const struct linetable_entry *item = &linetable->item[idx];
 
 	  if (*best_item == NULL || item->line < (*best_item)->line)
 	    *best_item = item;
@@ -3470,7 +3470,7 @@ find_pcs_for_symtab_line (struct symtab *symtab, int line,
 int
 find_line_pc (struct symtab *symtab, int line, CORE_ADDR *pc)
 {
-  struct linetable *l;
+  const struct linetable *l;
   int ind;
 
   *pc = 0;
@@ -3535,7 +3535,7 @@ find_line_pc_range (struct symtab_and_line sal, CORE_ADDR *startptr,
    Set *EXACT_MATCH nonzero if the value returned is an exact match.  */
 
 static int
-find_line_common (struct linetable *l, int lineno,
+find_line_common (const struct linetable *l, int lineno,
 		  int *exact_match, int start)
 {
   int i;
@@ -3558,7 +3558,7 @@ find_line_common (struct linetable *l, int lineno,
   len = l->nitems;
   for (i = start; i < len; i++)
     {
-      struct linetable_entry *item = &(l->item[i]);
+      const struct linetable_entry *item = &(l->item[i]);
 
       if (item->line == lineno)
 	{
@@ -3646,7 +3646,7 @@ static CORE_ADDR
 skip_prologue_using_lineinfo (CORE_ADDR func_addr, struct symtab *symtab)
 {
   CORE_ADDR func_start, func_end;
-  struct linetable *l;
+  const struct linetable *l;
   int i;
 
   /* Give up if this symbol has no lineinfo table.  */
@@ -3665,7 +3665,7 @@ skip_prologue_using_lineinfo (CORE_ADDR func_addr, struct symtab *symtab)
      address we are looking for.  */
   for (i = 0; i < l->nitems; i++)
     {
-      struct linetable_entry *item = &(l->item[i]);
+      const struct linetable_entry *item = &(l->item[i]);
 
       /* Don't use line numbers of zero, they mark special entries in
 	 the table.  See the commentary on symtab.h before the
@@ -3889,7 +3889,8 @@ skip_prologue_using_sal (struct gdbarch *gdbarch, CORE_ADDR func_addr)
 	 do this.  */
       if (prologue_sal.symtab->language != language_asm)
 	{
-	  struct linetable *linetable = SYMTAB_LINETABLE (prologue_sal.symtab);
+	  const struct linetable *linetable
+	    = SYMTAB_LINETABLE (prologue_sal.symtab);
 	  int idx = 0;
 
 	  /* Skip any earlier lines, and any end-of-sequence marker
diff --git a/gdb/symtab.h b/gdb/symtab.h
index 2b3d8018a7..33e0ba4c09 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -1316,7 +1316,7 @@ struct symtab
   /* Table mapping core addresses to line numbers for this file.
      Can be NULL if none.  Never shared between different symtabs.  */
 
-  struct linetable *linetable;
+  const struct linetable *linetable;
 
   /* Name of this source file.  This pointer is never NULL.  */
 
@@ -2032,7 +2032,8 @@ void iterate_over_symtabs (const char *name,
 
 
 std::vector<CORE_ADDR> find_pcs_for_symtab_line
-    (struct symtab *symtab, int line, struct linetable_entry **best_entry);
+    (struct symtab *symtab, int line,
+     const struct linetable_entry **best_entry);
 
 /* Prototype for callbacks for LA_ITERATE_OVER_SYMBOLS.  The callback
    is called once per matching symbol SYM.  The callback should return
-- 
2.13.6


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]