diff mbox

[2/2] constify the line table

Message ID 1402602493-22018-3-git-send-email-tromey@redhat.com
State New
Headers show

Commit Message

Tom Tromey June 12, 2014, 7:48 p.m. UTC
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.

2014-06-12  Tom Tromey  <tromey@redhat.com>

	* 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): 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             | 21 +++++++++++++++++++++
 gdb/buildsym.c            |  7 +++++--
 gdb/disasm.c              |  4 ++--
 gdb/jit.c                 |  7 +++++--
 gdb/linespec.c            |  6 +++---
 gdb/mdebugread.c          | 19 ++++++++-----------
 gdb/mi/mi-symbol-cmds.c   |  2 +-
 gdb/python/py-linetable.c |  8 ++++----
 gdb/symmisc.c             |  2 +-
 gdb/symtab.c              | 34 +++++++++++++++++-----------------
 gdb/symtab.h              |  4 ++--
 11 files changed, 69 insertions(+), 45 deletions(-)
diff mbox

Patch

diff --git a/gdb/buildsym.c b/gdb/buildsym.c
index 84f698e..634cd5f 100644
--- a/gdb/buildsym.c
+++ b/gdb/buildsym.c
@@ -1192,10 +1192,13 @@  end_symtab_from_static_block (struct block *static_block,
           symtab->macro_table = pending_macros;
 	  if (subfile->line_vector)
 	    {
+	      struct linetable *new_table;
+
 	      /* Reallocate the line table on the symbol obstack.  */
-	      symtab->linetable = (struct linetable *)
+	      new_table = (struct linetable *)
 		obstack_alloc (&objfile->objfile_obstack, linetablesize);
-	      memcpy (symtab->linetable, subfile->line_vector, linetablesize);
+	      memcpy (new_table, subfile->line_vector, linetablesize);
+	      symtab->linetable = new_table;
 	    }
 	  else
 	    {
diff --git a/gdb/disasm.c b/gdb/disasm.c
index 4cc84c6..eaea72b 100644
--- a/gdb/disasm.c
+++ b/gdb/disasm.c
@@ -195,7 +195,7 @@  dump_insns (struct gdbarch *gdbarch, struct ui_out *uiout,
 static void
 do_mixed_source_and_assembly (struct gdbarch *gdbarch, struct ui_out *uiout,
 			      struct disassemble_info *di, int nlines,
-			      struct linetable_entry *le,
+			      const struct linetable_entry *le,
 			      CORE_ADDR low, CORE_ADDR high,
 			      struct symtab *symtab,
 			      int how_many, int flags, struct ui_file *stb)
@@ -419,7 +419,7 @@  gdb_disassembly (struct gdbarch *gdbarch, struct ui_out *uiout,
   struct disassemble_info di = gdb_disassemble_info (gdbarch, stb);
   /* To collect the instruction outputted from opcodes.  */
   struct symtab *symtab = NULL;
-  struct linetable_entry *le = NULL;
+  const struct linetable_entry *le = NULL;
   int nlines = -1;
 
   /* Assume symtab is valid for whole PC range.  */
diff --git a/gdb/jit.c b/gdb/jit.c
index 411e925..0e80856 100644
--- a/gdb/jit.c
+++ b/gdb/jit.c
@@ -655,8 +655,11 @@  finalize_symtab (struct gdb_symtab *stab, struct objfile *objfile)
       int size = ((stab->linetable->nitems - 1)
                   * sizeof (struct linetable_entry)
                   + sizeof (struct linetable));
-      LINETABLE (symtab) = obstack_alloc (&objfile->objfile_obstack, size);
-      memcpy (LINETABLE (symtab), stab->linetable, size);
+      struct linetable *new_table;
+
+      new_table = obstack_alloc (&objfile->objfile_obstack, size);
+      memcpy (new_table, stab->linetable, size);
+      LINETABLE (symtab) = new_table;
     }
   else
     {
diff --git a/gdb/linespec.c b/gdb/linespec.c
index cb76b9c..0dad675 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -356,7 +356,7 @@  static void decode_digits_ordinary (struct linespec_state *self,
 				    linespec_p ls,
 				    int line,
 				    struct symtabs_and_lines *sals,
-				    struct linetable_entry **best_entry);
+				    const struct linetable_entry **best_entry);
 
 static void decode_digits_list_mode (struct linespec_state *self,
 				     linespec_p ls,
@@ -1895,7 +1895,7 @@  create_sals_line_offset (struct linespec_state *self,
     decode_digits_list_mode (self, ls, &values, val);
   else
     {
-      struct linetable_entry *best_entry = NULL;
+      const struct linetable_entry *best_entry = NULL;
       int *filter;
       struct block **blocks;
       struct cleanup *cleanup;
@@ -3303,7 +3303,7 @@  decode_digits_ordinary (struct linespec_state *self,
 			linespec_p ls,
 			int line,
 			struct symtabs_and_lines *sals,
-			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 ac8bd72..2c73332 100644
--- a/gdb/mdebugread.c
+++ b/gdb/mdebugread.c
@@ -239,7 +239,8 @@  enum block_type { FUNCTION_BLOCK, NON_FUNCTION_BLOCK };
 
 static struct block *new_block (enum block_type);
 
-static struct symtab *new_symtab (const char *, int, struct objfile *);
+static struct symtab *new_symtab (const char *, int, struct objfile *,
+				  struct linetable **);
 
 static struct linetable *new_linetable (int);
 
@@ -2169,9 +2170,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)
@@ -3933,7 +3931,6 @@  psymtab_to_symtab_1 (struct objfile *objfile,
   int i;
   struct symtab *st = NULL;
   FDR *fh;
-  struct linetable *lines;
   CORE_ADDR lowest_pdr_addr = 0;
   int last_symtab_ended = 0;
 
@@ -4174,16 +4171,17 @@  psymtab_to_symtab_1 (struct objfile *objfile,
 
       int maxlines, size;
       EXTR *ext_ptr;
+      struct linetable *lines;
 
       if (fh == 0)
 	{
 	  maxlines = 0;
-	  st = new_symtab ("unknown", 0, objfile);
+	  st = new_symtab ("unknown", 0, objfile, &lines);
 	}
       else
 	{
 	  maxlines = 2 * fh->cline;
-	  st = new_symtab (pst->filename, maxlines, objfile);
+	  st = new_symtab (pst->filename, maxlines, objfile, &lines);
 
 	  /* The proper language was already determined when building
 	     the psymtab, use it.  */
@@ -4192,8 +4190,6 @@  psymtab_to_symtab_1 (struct objfile *objfile,
 
       psymtab_language = st->language;
 
-      lines = LINETABLE (st);
-
       /* Get a new lexical context.  */
 
       push_parse_stack ();
@@ -4725,11 +4721,12 @@  sort_blocks (struct symtab *s)
    linenumbers MAXLINES we'll put in it.  */
 
 static struct 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 symtab *s = allocate_symtab (name, objfile);
 
-  LINETABLE (s) = new_linetable (maxlines);
+  *lines = new_linetable (maxlines);
 
   /* All symtabs must have at least two blocks.  */
   BLOCKVECTOR (s) = new_bvect (2);
diff --git a/gdb/mi/mi-symbol-cmds.c b/gdb/mi/mi-symbol-cmds.c
index e4e23f2..0750e5c 100644
--- a/gdb/mi/mi-symbol-cmds.c
+++ b/gdb/mi/mi-symbol-cmds.c
@@ -35,7 +35,7 @@  mi_cmd_symbol_list_lines (char *command, char **argv, int argc)
   int i;
   struct cleanup *cleanup_stack, *cleanup_tuple;
   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 ce2dd9d..12e673c 100644
--- a/gdb/python/py-linetable.c
+++ b/gdb/python/py-linetable.c
@@ -170,7 +170,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;
   linetable_entry_object *result;
   VEC (CORE_ADDR) *pcs = NULL;
   PyObject *tuple;
@@ -218,7 +218,7 @@  ltpy_has_line (PyObject *self, PyObject *args)
 
   for (index = 0; index < LINETABLE (symtab)->nitems; index++)
     {
-      struct linetable_entry *item = &(symtab->linetable->item[index]);
+      const struct linetable_entry *item = &(symtab->linetable->item[index]);
       if (item->line == py_line)
 	  Py_RETURN_TRUE;
     }
@@ -237,7 +237,7 @@  ltpy_get_all_source_lines (PyObject *self, PyObject *args)
   struct symtab *symtab;
   Py_ssize_t index;
   PyObject *source_list, *source_dict, *line;
-  struct linetable_entry *item;
+  const struct linetable_entry *item;
   Py_ssize_t list_size;
 
   LTPY_REQUIRE_VALID (self, symtab);
@@ -428,7 +428,7 @@  ltpy_iternext (PyObject *self)
   struct symtab *symtab;
   int index;
   PyObject *obj;
-  struct linetable_entry *item;
+  const struct linetable_entry *item;
 
   LTPY_REQUIRE_VALID (iter_obj->source, symtab);
 
diff --git a/gdb/symmisc.c b/gdb/symmisc.c
index 79d4e82..da050c6 100644
--- a/gdb/symmisc.c
+++ b/gdb/symmisc.c
@@ -290,7 +290,7 @@  dump_symtab_1 (struct objfile *objfile, struct symtab *symtab,
   int i;
   struct dict_iterator iter;
   int len;
-  struct linetable *l;
+  const struct linetable *l;
   struct blockvector *bv;
   struct symbol *sym;
   struct block *b;
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 900198a..1d8ceb8 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -75,7 +75,7 @@  static void variables_info (char *, int);
 
 static void sources_info (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 symbol *lookup_symbol_aux (const char *name,
 					 const struct block *block,
@@ -2274,10 +2274,10 @@  struct symtab_and_line
 find_pc_sect_line (CORE_ADDR pc, struct obj_section *section, int notcurrent)
 {
   struct symtab *s;
-  struct linetable *l;
+  const struct linetable *l;
   int len;
   int i;
-  struct linetable_entry *item;
+  const struct linetable_entry *item;
   struct symtab_and_line val;
   struct blockvector *bv;
   struct bound_minimal_symbol msymbol;
@@ -2285,7 +2285,7 @@  find_pc_sect_line (CORE_ADDR pc, struct obj_section *section, int notcurrent)
 
   /* 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;
 
@@ -2294,12 +2294,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.
@@ -2556,7 +2556,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.  */
@@ -2594,7 +2594,7 @@  find_line_symtab (struct symtab *symtab, int line,
 
       ALL_SYMTABS (objfile, s)
       {
-	struct linetable *l;
+	const struct linetable *l;
 	int ind;
 
 	if (FILENAME_CMP (symtab->filename, s->filename) != 0)
@@ -2641,11 +2641,11 @@  done:
 
 VEC (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;
   VEC (CORE_ADDR) *result = NULL;
-  struct linetable *linetable = LINETABLE (symtab);
+  const struct linetable *linetable = LINETABLE (symtab);
 
   /* First, collect all the PCs that are at this line.  */
   while (1)
@@ -2659,7 +2659,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;
@@ -2683,7 +2683,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;
@@ -2748,7 +2748,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;
@@ -2771,7 +2771,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)
 	{
@@ -2811,7 +2811,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.  */
@@ -2830,7 +2830,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
@@ -4954,7 +4954,7 @@  skip_prologue_using_sal (struct gdbarch *gdbarch, CORE_ADDR func_addr)
 	 do this.  */
       if (prologue_sal.symtab->language != language_asm)
 	{
-	  struct linetable *linetable = LINETABLE (prologue_sal.symtab);
+	  const struct linetable *linetable = 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 fcca53a..a8b259c 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -899,7 +899,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;
 
   /* Section in objfile->section_offsets for the blockvector and
      the linetable.  Probably always SECT_OFF_TEXT.  */
@@ -1418,7 +1418,7 @@  void iterate_over_symtabs (const char *name,
 DEF_VEC_I (CORE_ADDR);
 
 VEC (CORE_ADDR) *find_pcs_for_symtab_line (struct symtab *symtab, int line,
-					   struct linetable_entry **best_entry);
+					   const struct linetable_entry **best_entry);
 
 /* Callback for LA_ITERATE_OVER_SYMBOLS.  The callback will be called
    once per matching symbol SYM, with DATA being the argument of the