Handle files without aranges information.
authorUlrich Drepper <drepper@redhat.com>
Mon, 22 May 2006 18:16:45 +0000 (18:16 +0000)
committerUlrich Drepper <drepper@redhat.com>
Mon, 22 May 2006 18:16:45 +0000 (18:16 +0000)
libdw/ChangeLog
libdw/dwarf_getaranges.c
libdwfl/ChangeLog
libdwfl/cu.c

index d904e42..c6ee77a 100644 (file)
@@ -1,3 +1,8 @@
+2006-05-22  Ulrich Drepper  <drepper@redhat.com>
+
+       * dwarf_getaranges.c (dwarf_getaranges): Handle files without
+       aranges information.
+
 2006-05-21  Ulrich Drepper  <drepper@redhat.com>
 
        * libdw.h: Add nonnull attributes to dwarf_tag, dwarf_getattrs,
index 61eb4f7..d2294ea 100644 (file)
@@ -1,5 +1,5 @@
 /* Return list address ranges.
-   Copyright (C) 2000, 2001, 2002, 2004, 2005 Red Hat, Inc.
+   Copyright (C) 2000, 2001, 2002, 2004, 2005, 2006 Red Hat, Inc.
    This file is part of Red Hat elfutils.
    Written by Ulrich Drepper <drepper@redhat.com>, 2000.
 
@@ -89,6 +89,15 @@ dwarf_getaranges (dbg, aranges, naranges)
       return 0;
     }
 
+  if (dbg->sectiondata[IDX_debug_aranges] == NULL)
+    {
+      /* No such section.  */
+      *aranges = NULL;
+      if (naranges != NULL)
+       *naranges = 0;
+      return 0;
+    }
+
   if (dbg->sectiondata[IDX_debug_aranges]->d_buf == NULL)
     return -1;
 
index d78194a..34f8f46 100644 (file)
@@ -1,3 +1,7 @@
+2006-05-22  Ulrich Drepper  <drepper@redhat.com>
+
+       * cu.c (addrarange): Handle files without aranges information.
+
 2006-05-16  Ulrich Drepper  <drepper@redhat.com>
 
        * dwfl_addrmodule.c (dwfl_addrmodule): Also return NULL of
index e8dbf32..4c6d876 100644 (file)
@@ -1,5 +1,5 @@
 /* Keeping track of DWARF compilation units in libdwfl.
-   Copyright (C) 2005 Red Hat, Inc.
+   Copyright (C) 2005, 2006 Red Hat, Inc.
    This file is part of Red Hat elfutils.
 
    Red Hat elfutils is free software; you can redistribute it and/or modify
@@ -65,32 +65,38 @@ addrarange (Dwfl_Module *mod, Dwarf_Addr addr, struct dwfl_arange **arange)
 {
   if (mod->aranges == NULL)
     {
-      Dwarf_Aranges *dwaranges;
-      if (INTUSE(dwarf_getaranges) (mod->dw, &dwaranges, NULL) != 0)
+      struct dwfl_arange *aranges = NULL;
+      Dwarf_Aranges *dwaranges = NULL;
+      size_t naranges;
+      if (INTUSE(dwarf_getaranges) (mod->dw, &dwaranges, &naranges) != 0)
        return DWFL_E_LIBDW;
 
-      struct dwfl_arange *aranges = malloc (dwaranges->naranges
-                                           * sizeof *aranges);
-      if (unlikely (aranges == NULL))
-       return DWFL_E_NOMEM;
-
-      /* libdw has sorted its list by address, which is how we want it.
-        But the sorted list is full of not-quite-contiguous runs pointing
-        to the same CU.  We don't care about the little gaps inside the
-        module, we'll consider them part of the surrounding CU anyway.
-        Collect our own array with just one record for each run of ranges
-        pointing to one CU.  */
-
-      size_t naranges = 0;
-      Dwarf_Off lastcu = 0;
-      for (size_t i = 0; i < dwaranges->naranges; ++i)
-       if (i == 0 || dwaranges->info[i].offset != lastcu)
-         {
-           aranges[naranges].arange = i;
-           aranges[naranges].cu = NULL;
-           ++naranges;
-           lastcu = dwaranges->info[i].offset;
-         }
+      /* If the module has no aranges (when no code is included) we
+        allocate nothing.  */
+      if (naranges != 0)
+       {
+         aranges = malloc (naranges * sizeof *aranges);
+         if (unlikely (aranges == NULL))
+           return DWFL_E_NOMEM;
+
+         /* libdw has sorted its list by address, which is how we want it.
+            But the sorted list is full of not-quite-contiguous runs pointing
+            to the same CU.  We don't care about the little gaps inside the
+            module, we'll consider them part of the surrounding CU anyway.
+            Collect our own array with just one record for each run of ranges
+            pointing to one CU.  */
+
+         naranges = 0;
+         Dwarf_Off lastcu = 0;
+         for (size_t i = 0; i < dwaranges->naranges; ++i)
+           if (i == 0 || dwaranges->info[i].offset != lastcu)
+             {
+               aranges[naranges].arange = i;
+               aranges[naranges].cu = NULL;
+               ++naranges;
+               lastcu = dwaranges->info[i].offset;
+             }
+       }
 
       /* Store the final array, which is probably much smaller than before.  */
       mod->naranges = naranges;