summaryrefslogtreecommitdiff
path: root/libdwfl/dwfl_module_getdwarf.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2007-03-30 19:14:59 +0000
committerUlrich Drepper <drepper@redhat.com>2007-03-30 19:14:59 +0000
commitc07fbb3ff74a8c7b4916ff8155060a35f4b08aaa (patch)
treec8a1484501cecd7309fae583e2009c31983c72be /libdwfl/dwfl_module_getdwarf.c
parent6258e7486eb3eed6e50005946795c5fbf73aa106 (diff)
downloadelfutils-c07fbb3ff74a8c7b4916ff8155060a35f4b08aaa.tar.gz
propagate from branch 'com.redhat.elfutils.roland.pending' (head b584b7056d679db0fc272b47667047d07737ca55)
to branch 'com.redhat.elfutils' (head 5f150a0b2f07e8c60913d4e6ad833ef026ccd26e)
Diffstat (limited to 'libdwfl/dwfl_module_getdwarf.c')
-rw-r--r--libdwfl/dwfl_module_getdwarf.c111
1 files changed, 57 insertions, 54 deletions
diff --git a/libdwfl/dwfl_module_getdwarf.c b/libdwfl/dwfl_module_getdwarf.c
index 3a22c3be..c0aeadd1 100644
--- a/libdwfl/dwfl_module_getdwarf.c
+++ b/libdwfl/dwfl_module_getdwarf.c
@@ -115,74 +115,77 @@ find_file (Dwfl_Module *mod)
mod->elferr = open_elf (mod, &mod->main);
}
-/* Find the separate debuginfo file for this module and open libelf on it.
- When we return success, MOD->debug is set up. */
-static Dwfl_Error
-find_debuginfo (Dwfl_Module *mod)
+/* Search an ELF file for a ".gnu_debuglink" section. */
+static const char *
+find_debuglink (Elf *elf, GElf_Word *crc)
{
- if (mod->debug.elf != NULL)
- return DWFL_E_NOERROR;
-
size_t shstrndx;
- if (elf_getshstrndx (mod->main.elf, &shstrndx) < 0)
- return DWFL_E_LIBELF;
+ if (elf_getshstrndx (elf, &shstrndx) < 0)
+ return NULL;
- Elf_Scn *scn = elf_getscn (mod->main.elf, 0);
- if (scn == NULL)
- return DWFL_E_LIBELF;
- do
+ Elf_Scn *scn = NULL;
+ while ((scn = elf_nextscn (elf, scn)) != NULL)
{
- GElf_Shdr shdr_mem, *shdr = gelf_getshdr (scn, &shdr_mem);
+ GElf_Shdr shdr_mem;
+ GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem);
if (shdr == NULL)
- return DWFL_E_LIBELF;
+ return NULL;
- const char *name = elf_strptr (mod->main.elf, shstrndx, shdr->sh_name);
+ const char *name = elf_strptr (elf, shstrndx, shdr->sh_name);
if (name == NULL)
- return DWFL_E_LIBELF;
+ return NULL;
if (!strcmp (name, ".gnu_debuglink"))
break;
+ }
- scn = elf_nextscn (mod->main.elf, scn);
- } while (scn != NULL);
+ if (scn == NULL)
+ return NULL;
- const char *debuglink_file = NULL;
- GElf_Word debuglink_crc = 0;
- if (scn != NULL)
+ /* Found the .gnu_debuglink section. Extract its contents. */
+ Elf_Data *rawdata = elf_rawdata (scn, NULL);
+ if (rawdata == NULL)
+ return NULL;
+
+ Elf_Data crcdata =
{
- /* Found the .gnu_debuglink section. Extract its contents. */
- Elf_Data *rawdata = elf_rawdata (scn, NULL);
- if (rawdata == NULL)
- return DWFL_E_LIBELF;
+ .d_type = ELF_T_WORD,
+ .d_buf = crc,
+ .d_size = sizeof *crc,
+ .d_version = EV_CURRENT,
+ };
+ Elf_Data conv =
+ {
+ .d_type = ELF_T_WORD,
+ .d_buf = rawdata->d_buf + rawdata->d_size - sizeof *crc,
+ .d_size = sizeof *crc,
+ .d_version = EV_CURRENT,
+ };
+
+ GElf_Ehdr ehdr_mem;
+ GElf_Ehdr *ehdr = gelf_getehdr (elf, &ehdr_mem);
+ if (ehdr == NULL)
+ return NULL;
- Elf_Data crcdata =
- {
- .d_type = ELF_T_WORD,
- .d_buf = &debuglink_crc,
- .d_size = sizeof debuglink_crc,
- .d_version = EV_CURRENT,
- };
- Elf_Data conv =
- {
- .d_type = ELF_T_WORD,
- .d_buf = rawdata->d_buf + rawdata->d_size - sizeof debuglink_crc,
- .d_size = sizeof debuglink_crc,
- .d_version = EV_CURRENT,
- };
-
- GElf_Ehdr ehdr_mem;
- GElf_Ehdr *ehdr = gelf_getehdr (mod->main.elf, &ehdr_mem);
- if (ehdr == NULL)
- return DWFL_E_LIBELF;
-
- Elf_Data *d = gelf_xlatetom (mod->main.elf, &crcdata, &conv,
- ehdr->e_ident[EI_DATA]);
- if (d == NULL)
- return DWFL_E_LIBELF;
- assert (d == &crcdata);
-
- debuglink_file = rawdata->d_buf;
- }
+ Elf_Data *d = gelf_xlatetom (elf, &crcdata, &conv, ehdr->e_ident[EI_DATA]);
+ if (d == NULL)
+ return NULL;
+ assert (d == &crcdata);
+
+ return rawdata->d_buf;
+}
+
+
+/* Find the separate debuginfo file for this module and open libelf on it.
+ When we return success, MOD->debug is set up. */
+static Dwfl_Error
+find_debuginfo (Dwfl_Module *mod)
+{
+ if (mod->debug.elf != NULL)
+ return DWFL_E_NOERROR;
+
+ GElf_Word debuglink_crc = 0;
+ const char *debuglink_file = find_debuglink (mod->main.elf, &debuglink_crc);
mod->debug.fd = (*mod->dwfl->callbacks->find_debuginfo) (MODCB_ARGS (mod),
mod->main.name,