Fix dwfl_core_file_report return value when link_map failed after sniffing succeeded.
authorRoland McGrath <roland@redhat.com>
Tue, 4 May 2010 23:31:43 +0000 (16:31 -0700)
committerRoland McGrath <roland@redhat.com>
Tue, 4 May 2010 23:31:43 +0000 (16:31 -0700)
libdwfl/ChangeLog
libdwfl/core-file.c

index a9f36d9..9f4a745 100644 (file)
@@ -1,3 +1,9 @@
+2010-05-04  Roland McGrath  <roland@redhat.com>
+
+       * core-file.c (dwfl_core_file_report): Return any nonzero count of
+       modules reported, even if link_map grovelling failed and only sniffing
+       found anything.
+
 2010-04-26  Roland McGrath  <roland@redhat.com>
 
        * relocate.c (relocate_section): Treat R_*_NONE reloc as no reloc.
index 2f0ca8a..1b556dd 100644 (file)
@@ -419,6 +419,7 @@ dwfl_core_file_report (Dwfl *dwfl, Elf *elf)
     return ndx;
 
   /* Now sniff segment contents for modules.  */
+  int sniffed = 0;
   ndx = 0;
   do
     {
@@ -427,7 +428,13 @@ dwfl_core_file_report (Dwfl *dwfl, Elf *elf)
                                            core_file_read_eagerly, elf);
       if (unlikely (seg < 0))
        return seg;
-      ndx = seg > ndx ? seg : ndx + 1;
+      if (seg > ndx)
+       {
+         ndx = seg;
+         ++sniffed;
+       }
+      else
+       ++ndx;
     }
   while (ndx < (int) phnum);
 
@@ -465,7 +472,13 @@ dwfl_core_file_report (Dwfl *dwfl, Elf *elf)
   /* Now we have NT_AUXV contents.  From here on this processing could be
      used for a live process with auxv read from /proc.  */
 
-  return dwfl_link_map_report (dwfl, auxv, auxv_size,
-                              dwfl_elf_phdr_memory_callback, elf);
+  int listed = dwfl_link_map_report (dwfl, auxv, auxv_size,
+                                    dwfl_elf_phdr_memory_callback, elf);
+
+  /* We return the number of modules we found if we found any.
+     If we found none, we return -1 instead of 0 if there was an
+     error rather than just nothing found.  If link_map handling
+     failed, we still have the sniffed modules.  */
+  return sniffed == 0 || listed > sniffed ? listed : sniffed;
 }
 INTDEF (dwfl_core_file_report)