|
Packit Service |
97d2fb |
/* Iterate through modules.
|
|
Packit Service |
97d2fb |
Copyright (C) 2005, 2008 Red Hat, Inc.
|
|
Packit Service |
97d2fb |
This file is part of elfutils.
|
|
Packit Service |
97d2fb |
|
|
Packit Service |
97d2fb |
This file is free software; you can redistribute it and/or modify
|
|
Packit Service |
97d2fb |
it under the terms of either
|
|
Packit Service |
97d2fb |
|
|
Packit Service |
97d2fb |
* the GNU Lesser General Public License as published by the Free
|
|
Packit Service |
97d2fb |
Software Foundation; either version 3 of the License, or (at
|
|
Packit Service |
97d2fb |
your option) any later version
|
|
Packit Service |
97d2fb |
|
|
Packit Service |
97d2fb |
or
|
|
Packit Service |
97d2fb |
|
|
Packit Service |
97d2fb |
* the GNU General Public License as published by the Free
|
|
Packit Service |
97d2fb |
Software Foundation; either version 2 of the License, or (at
|
|
Packit Service |
97d2fb |
your option) any later version
|
|
Packit Service |
97d2fb |
|
|
Packit Service |
97d2fb |
or both in parallel, as here.
|
|
Packit Service |
97d2fb |
|
|
Packit Service |
97d2fb |
elfutils is distributed in the hope that it will be useful, but
|
|
Packit Service |
97d2fb |
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
97d2fb |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
97d2fb |
General Public License for more details.
|
|
Packit Service |
97d2fb |
|
|
Packit Service |
97d2fb |
You should have received copies of the GNU General Public License and
|
|
Packit Service |
97d2fb |
the GNU Lesser General Public License along with this program. If
|
|
Packit Service |
97d2fb |
not, see <http://www.gnu.org/licenses/>. */
|
|
Packit Service |
97d2fb |
|
|
Packit Service |
97d2fb |
#ifdef HAVE_CONFIG_H
|
|
Packit Service |
97d2fb |
# include <config.h>
|
|
Packit Service |
97d2fb |
#endif
|
|
Packit Service |
97d2fb |
|
|
Packit Service |
97d2fb |
#include "libdwflP.h"
|
|
Packit Service |
97d2fb |
|
|
Packit Service |
97d2fb |
ptrdiff_t
|
|
Packit Service |
97d2fb |
dwfl_getmodules (Dwfl *dwfl,
|
|
Packit Service |
97d2fb |
int (*callback) (Dwfl_Module *, void **,
|
|
Packit Service |
97d2fb |
const char *, Dwarf_Addr, void *),
|
|
Packit Service |
97d2fb |
void *arg,
|
|
Packit Service |
97d2fb |
ptrdiff_t offset)
|
|
Packit Service |
97d2fb |
{
|
|
Packit Service |
97d2fb |
if (dwfl == NULL)
|
|
Packit Service |
97d2fb |
return -1;
|
|
Packit Service |
97d2fb |
|
|
Packit Service |
97d2fb |
/* We iterate through the linked list when it's all we have.
|
|
Packit Service |
97d2fb |
But continuing from an offset is slow that way. So when
|
|
Packit Service |
97d2fb |
DWFL->lookup_module is populated, we can instead keep our
|
|
Packit Service |
97d2fb |
place by jumping directly into the array. Since the actions
|
|
Packit Service |
97d2fb |
of a callback could cause it to get populated, we must
|
|
Packit Service |
97d2fb |
choose the style of place-holder when we return an offset,
|
|
Packit Service |
97d2fb |
and we encode the choice in the low bits of that value. */
|
|
Packit Service |
97d2fb |
|
|
Packit Service |
97d2fb |
Dwfl_Module *m = dwfl->modulelist;
|
|
Packit Service |
97d2fb |
|
|
Packit Service |
97d2fb |
if ((offset & 3) == 1)
|
|
Packit Service |
97d2fb |
{
|
|
Packit Service |
97d2fb |
offset >>= 2;
|
|
Packit Service |
97d2fb |
for (ptrdiff_t pos = 0; pos < offset; ++pos)
|
|
Packit Service |
97d2fb |
if (m == NULL)
|
|
Packit Service |
97d2fb |
return -1;
|
|
Packit Service |
97d2fb |
else
|
|
Packit Service |
97d2fb |
m = m->next;
|
|
Packit Service |
97d2fb |
}
|
|
Packit Service |
97d2fb |
else if (((offset & 3) == 2) && likely (dwfl->lookup_module != NULL))
|
|
Packit Service |
97d2fb |
{
|
|
Packit Service |
97d2fb |
offset >>= 2;
|
|
Packit Service |
97d2fb |
|
|
Packit Service |
97d2fb |
if ((size_t) offset - 1 == dwfl->lookup_elts)
|
|
Packit Service |
97d2fb |
return 0;
|
|
Packit Service |
97d2fb |
|
|
Packit Service |
97d2fb |
if (unlikely ((size_t) offset - 1 > dwfl->lookup_elts))
|
|
Packit Service |
97d2fb |
return -1;
|
|
Packit Service |
97d2fb |
|
|
Packit Service |
97d2fb |
m = dwfl->lookup_module[offset - 1];
|
|
Packit Service |
97d2fb |
if (unlikely (m == NULL))
|
|
Packit Service |
97d2fb |
return -1;
|
|
Packit Service |
97d2fb |
}
|
|
Packit Service |
97d2fb |
else if (offset != 0)
|
|
Packit Service |
97d2fb |
{
|
|
Packit Service |
97d2fb |
__libdwfl_seterrno (DWFL_E_BADSTROFF);
|
|
Packit Service |
97d2fb |
return -1;
|
|
Packit Service |
97d2fb |
}
|
|
Packit Service |
97d2fb |
|
|
Packit Service |
97d2fb |
while (m != NULL)
|
|
Packit Service |
97d2fb |
{
|
|
Packit Service |
97d2fb |
int ok = (*callback) (MODCB_ARGS (m), arg);
|
|
Packit Service |
97d2fb |
++offset;
|
|
Packit Service |
97d2fb |
m = m->next;
|
|
Packit Service |
97d2fb |
if (ok != DWARF_CB_OK)
|
|
Packit Service |
97d2fb |
return ((dwfl->lookup_module == NULL) ? ((offset << 2) | 1)
|
|
Packit Service |
97d2fb |
: (((m == NULL ? (ptrdiff_t) dwfl->lookup_elts + 1
|
|
Packit Service |
97d2fb |
: m->segment + 1) << 2) | 2));
|
|
Packit Service |
97d2fb |
}
|
|
Packit Service |
97d2fb |
return 0;
|
|
Packit Service |
97d2fb |
}
|
|
Packit Service |
97d2fb |
INTDEF (dwfl_getmodules)
|