import gdb-1999-05-10
[deliverable/binutils-gdb.git] / gdb / coffread.c
index 340e77f84c0bfbb00610879a70cc6285ee23d6a2..ae1decaf728e374b19eee77a66de925fc16845db 100644 (file)
@@ -84,21 +84,6 @@ static CORE_ADDR current_source_end_addr;
 static bfd *nlist_bfd_global;
 static int nlist_nsyms_global;
 
-/* Vector of line number information.  */
-
-static struct linetable *line_vector;
-
-/* Index of next entry to go in line_vector_index.  */
-
-static int line_vector_index;
-
-/* Last line number recorded in the line vector.  */
-
-static int prev_line_number;
-
-/* Number of elements allocated for line_vector currently.  */
-
-static int line_vector_length;
 
 /* Pointers to scratch storage, used for reading raw symbols and auxents.  */
 
@@ -252,8 +237,6 @@ static void complete_symtab PARAMS ((char *, CORE_ADDR, unsigned int));
 
 static void coff_start_symtab PARAMS ((char *));
 
-static void coff_record_line PARAMS ((int, CORE_ADDR));
-
 static struct type *coff_alloc_type PARAMS ((int));
 
 static struct type **coff_lookup_type PARAMS ((int));
@@ -440,30 +423,6 @@ coff_alloc_type (index)
   return type;
 }
 \f
-/* Record a line number entry for line LINE at address PC.
-   FIXME:  Use record_line instead.  */
-
-static void
-coff_record_line (line, pc)
-     int line;
-     CORE_ADDR pc;
-{
-  struct linetable_entry *e;
-  /* Make sure line vector is big enough.  */
-
-  if (line_vector_index + 2 >= line_vector_length)
-    {
-      line_vector_length *= 2;
-      line_vector = (struct linetable *)
-       xrealloc ((char *) line_vector, sizeof (struct linetable)
-                 + (line_vector_length
-                    * sizeof (struct linetable_entry)));
-    }
-
-  e = line_vector->item + line_vector_index++;
-  e->line = line; e->pc = pc;
-}
-\f
 /* Start a new symtab for a new source file.
    This is called when a COFF ".file" symbol is seen;
    it indicates the start of data for one original source file.  */
@@ -484,17 +443,6 @@ coff_start_symtab (name)
                   last_source_start_addr in coff_end_symtab.  */
                0);
   record_debugformat ("COFF");
-
-  /* Initialize the source file line number information for this file.  */
-
-  if (line_vector)             /* Unlikely, but maybe possible? */
-    free ((PTR)line_vector);
-  line_vector_index = 0;
-  line_vector_length = 1000;
-  prev_line_number = -2;       /* Force first line number to be explicit */
-  line_vector = (struct linetable *)
-    xmalloc (sizeof (struct linetable)
-            + line_vector_length * sizeof (struct linetable_entry));
 }
 
 /* Save the vital information from when starting to read a file,
@@ -535,26 +483,12 @@ coff_end_symtab (objfile)
 
   last_source_start_addr = current_source_start_addr;
 
-  /* For no good reason, this file stores the number of entries in a
-     separate variable instead of in line_vector->nitems.  Fix it.  */
-  if (line_vector)
-    line_vector->nitems = line_vector_index;
-
-  /* For COFF, we only have one subfile, so we can just look at
-     subfiles and not worry about there being other elements in the
-     chain.  We fill in various fields now because we didn't know them
-     before (or because doing it now is simply an artifact of how this
-     file used to be written).  */
-  subfiles->line_vector = line_vector;
-
   symtab = end_symtab (current_source_end_addr, objfile, 0);
 
   if (symtab != NULL)
     free_named_symtabs (symtab->filename);
 
   /* Reinitialize for beginning of new file. */
-  line_vector = 0;
-  line_vector_length = -1;
   last_source_file = NULL;
 }
 \f
@@ -683,7 +617,6 @@ coff_symfile_read (objfile, section_offsets, mainline)
 
   /* Set a few file-statics that give us specific information about
      the particular COFF file format we're reading.  */
-  local_linesz   = cdata->local_linesz;
   local_n_btmask = cdata->local_n_btmask;
   local_n_btshft = cdata->local_n_btshft;
   local_n_tmask  = cdata->local_n_tmask;
@@ -753,6 +686,17 @@ coff_symfile_read (objfile, section_offsets, mainline)
 
   if (info->stabsects)
     {
+      if (! info->stabstrsect)
+       {
+         error_begin ();
+         fprintf_filtered
+           (gdb_stderr,
+            ("The debugging information in `%s' is corrupted.\n"
+             "The file has a `.stabs' section, but no `.stabstr' section.\n"),
+            name);
+         return_to_top_level (RETURN_ERROR);
+       }
+
       /* FIXME: dubious.  Why can't we use something normal like
         bfd_get_section_contents?  */
       bfd_seek (abfd, abfd->where, 0);
@@ -820,6 +764,7 @@ coff_symtab_read (symtab_offset, nsyms, section_offsets, objfile)
   char *filestring = "";
   int depth = 0;
   int fcn_first_line = 0;
+  CORE_ADDR fcn_first_line_addr;
   int fcn_last_line = 0;
   int fcn_start_addr = 0;
   long fcn_line_ptr = 0;
@@ -1076,6 +1021,7 @@ coff_symtab_read (symtab_offset, nsyms, section_offsets, objfile)
                if (cs->c_naux != 1)
                  complain (&bf_no_aux_complaint, cs->c_symnum);
                fcn_first_line = main_aux.x_sym.x_misc.x_lnsz.x_lnno;
+               fcn_first_line_addr = cs->c_value;
 
                /* Might want to check that locals are 0 and
                   context_stack_depth is zero, and complain if not.  */
@@ -1118,8 +1064,18 @@ coff_symtab_read (symtab_offset, nsyms, section_offsets, objfile)
                  {
                    fcn_last_line = main_aux.x_sym.x_misc.x_lnsz.x_lnno;
                  }
-               enter_linenos (fcn_line_ptr, fcn_first_line, fcn_last_line,
-                              section_offsets);
+               /* fcn_first_line is the line number of the opening '{'.
+                  Do not record it - because it would affect gdb's idea
+                  of the line number of the first statement of the function -
+                  except for one-line functions, for which it is also the line
+                  number of all the statements and of the closing '}', and
+                  for which we do not have any other statement-line-number. */
+               if (fcn_last_line == 1)
+                 record_line (current_subfile, fcn_first_line,
+                              fcn_first_line_addr);
+               else
+                 enter_linenos (fcn_line_ptr, fcn_first_line, fcn_last_line,
+                                section_offsets);
 
                finish_block (new->name, &local_symbols, new->old_blocks,
                              new->start_addr,
@@ -1458,7 +1414,7 @@ enter_linenos (file_offset, first_line, last_line, section_offsets)
     rawptr += local_linesz;
     /* The next function, or the sentinel, will have L_LNNO32 zero; we exit. */
     if (L_LNNO32 (&lptr) && L_LNNO32 (&lptr) <= last_line)
-      coff_record_line (first_line + L_LNNO32 (&lptr),
+      record_line (current_subfile, first_line + L_LNNO32 (&lptr),
                        lptr.l_addr.l_paddr
                        + ANOFFSET (section_offsets, SECT_OFF_TEXT));
     else
This page took 0.024151 seconds and 4 git commands to generate.