From: Ulrich Drepper Date: Mon, 22 May 2006 18:16:45 +0000 (+0000) Subject: Handle files without aranges information. X-Git-Tag: elfutils-0.121~26 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e7a73177dfbbc650fb43e5caa3ce29143f02fabd;p=platform%2Fupstream%2Felfutils.git Handle files without aranges information. --- diff --git a/libdw/ChangeLog b/libdw/ChangeLog index d904e42..c6ee77a 100644 --- a/libdw/ChangeLog +++ b/libdw/ChangeLog @@ -1,3 +1,8 @@ +2006-05-22 Ulrich Drepper + + * dwarf_getaranges.c (dwarf_getaranges): Handle files without + aranges information. + 2006-05-21 Ulrich Drepper * libdw.h: Add nonnull attributes to dwarf_tag, dwarf_getattrs, diff --git a/libdw/dwarf_getaranges.c b/libdw/dwarf_getaranges.c index 61eb4f7..d2294ea 100644 --- a/libdw/dwarf_getaranges.c +++ b/libdw/dwarf_getaranges.c @@ -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 , 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; diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog index d78194a..34f8f46 100644 --- a/libdwfl/ChangeLog +++ b/libdwfl/ChangeLog @@ -1,3 +1,7 @@ +2006-05-22 Ulrich Drepper + + * cu.c (addrarange): Handle files without aranges information. + 2006-05-16 Ulrich Drepper * dwfl_addrmodule.c (dwfl_addrmodule): Also return NULL of diff --git a/libdwfl/cu.c b/libdwfl/cu.c index e8dbf32..4c6d876 100644 --- a/libdwfl/cu.c +++ b/libdwfl/cu.c @@ -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;