Fix test step-and-next-inline.cc
[binutils-gdb.git] / gas / dwarf2dbg.c
index c6303ba94a66e9d15a017eb02fb9199b8c0b0011..c6e439aa86267363ef51af7ede4b4bd02ccf7410 100644 (file)
@@ -730,9 +730,9 @@ allocate_filenum (const char * pathname)
        }
       else
        {
-         if (filename_ncmp (pathname, dirname, last_used_dir_len) == 0
-             && IS_DIR_SEPARATOR (pathname [last_used_dir_len])
-             && filename_cmp (pathname + last_used_dir_len + 1,
+         if (filename_ncmp (pathname, dirname, last_used_dir_len - 1) == 0
+             && IS_DIR_SEPARATOR (pathname [last_used_dir_len - 1])
+             && filename_cmp (pathname + last_used_dir_len,
                               files[last_used].filename) == 0)
            return last_used;
        }
@@ -782,6 +782,36 @@ do_allocate_filenum (struct line_entry *e)
   while (e);
 }
 
+/* Remove any generated line entries.  These don't live comfortably
+   with compiler generated line info.  */
+
+static void
+purge_generated_debug (void)
+{
+  struct line_seg *s;
+
+  for (s = all_segs; s; s = s->next)
+    {
+      struct line_subseg *lss;
+
+      for (lss = s->head; lss; lss = lss->next)
+       {
+         struct line_entry *e, *next;
+
+         for (e = lss->head; e; e = next)
+           {
+             know (e->loc.filenum == -1u);
+             next = e->next;
+             free (e);
+           }
+
+         lss->head = NULL;
+         lss->ptail = &lss->head;
+         lss->pmove_tail = &lss->head;
+       }
+    }
+}
+
 /* Allocate slot NUM in the .debug_line file table to FILENAME.
    If DIRNAME is not NULL or there is a directory component to FILENAME
    then this will be stored in the directory table, if not already present.
@@ -1146,6 +1176,8 @@ dwarf2_directive_filename (void)
 
   /* A .file directive implies compiler generated debug information is
      being supplied.  Turn off gas generated debug info.  */
+  if (debug_type == DEBUG_DWARF2)
+    purge_generated_debug ();
   debug_type = DEBUG_NONE;
 
   if (num != (unsigned int) num
@@ -2414,7 +2446,7 @@ out_debug_line (segT line_seg)
   for (s = all_segs; s; s = s->next)
     /* Paranoia - this check should have already have
        been handled in dwarf2_gen_line_info_1().  */
-    if (SEG_NORMAL (s->seg))
+    if (s->head->head && SEG_NORMAL (s->seg))
       process_entries (s->seg, s->head->head);
 
   if (flag_dwarf_sections)
@@ -2859,15 +2891,21 @@ dwarf2_finish (void)
                             SEC_READONLY | SEC_DEBUGGING | SEC_OCTETS);
     }
 
+  for (s = all_segs; s; s = s->next)
+    {
+      struct line_subseg *lss;
+
+      for (lss = s->head; lss; lss = lss->next)
+       if (lss->head)
+         do_allocate_filenum (lss->head);
+    }
+
   /* For each subsection, chain the debug entries together.  */
   for (s = all_segs; s; s = s->next)
     {
       struct line_subseg *lss = s->head;
       struct line_entry **ptail = lss->ptail;
 
-      if (lss->head && SEG_NORMAL (s->seg))
-       do_allocate_filenum (lss->head);
-
       /* Reset the initial view of the first subsection of the
         section.  */
       if (lss->head && lss->head->loc.u.view)