Hi.
This patch cleans up the dwarf method.
Thanks
Ken'ichi Ohmichi
diff -puN makedumpfile.org/makedumpfile.c makedumpfile/makedumpfile.c
--- makedumpfile.org/makedumpfile.c 2006-10-11 13:08:35.000000000 +0900
+++ makedumpfile/makedumpfile.c 2006-10-11 13:08:47.000000000 +0900
@@ -492,28 +492,30 @@ dump_Elf_pt_load(struct DumpInfo *info,
int
get_elf_info(struct DumpInfo *info)
{
+ int i, j;
+ int rc = FALSE;
+ unsigned long tmp;
Elf *elfd = NULL;
GElf_Ehdr ehdr;
GElf_Phdr load;
- int i, j;
- unsigned long tmp;
- int rc = FALSE;
-
- elfd = elf_begin(info->fd_memory, ELF_C_READ, NULL);
- if (!elfd) {
- ERRMSG("Could not obtain first elf header\n");
+ lseek(info->fd_memory, 0, SEEK_SET);
+ if (!(elfd = elf_begin(info->fd_memory, ELF_C_READ, NULL))) {
+ ERRMSG("Can't get first elf header of %s.\n",
+ info->name_memory);
goto out;
}
-
if (gelf_getehdr(elfd, &ehdr) == NULL) {
- ERRMSG("Could not find file header\n");
+ ERRMSG("Can't find file header of %s.\n",
+ info->name_memory);
goto out;
}
- /* get the ident string */
+ /*
+ * get the ident string
+ */
if (ehdr.e_ident[EI_CLASS] == ELFCLASSNONE) {
- ERRMSG("Elf File has no class\n");
+ ERRMSG("Elf File has no class.\n");
goto out;
}
@@ -534,7 +536,7 @@ get_elf_info(struct DumpInfo *info)
for (i = 0, j = 0; i < ehdr.e_phnum; i++) {
if (gelf_getphdr(elfd, i, &load) == NULL) {
- ERRMSG("Could not find Phdr %d\n", i);
+ ERRMSG("Can't find Phdr %d.\n", i);
goto out;
}
@@ -548,6 +550,7 @@ get_elf_info(struct DumpInfo *info)
}
if (j >= info->num_load_memory)
goto out;
+
if(!dump_Elf_pt_load(info, &load, j))
goto out;
j++;
@@ -568,9 +571,10 @@ get_elf_info(struct DumpInfo *info)
if (info->flag_exclude_free)
info->len_3rd_bitmap = info->len_bitmap / 2;
- if (elf_end(elfd) == 0)
- rc = TRUE;
+ rc = TRUE;
out:
+ if (elfd != NULL)
+ elf_end(elfd);
return rc;
}
@@ -587,34 +591,35 @@ get_symbol_addr(struct DumpInfo *info, c
Elf_Scn *scn = NULL;
char *sym_name = NULL;
- lseek(info->fd_memory,0,SEEK_SET);
+ lseek(dwarf_info.vmlinux_fd, 0, SEEK_SET);
if (!(elfd = elf_begin(dwarf_info.vmlinux_fd, ELF_C_READ, NULL))) {
- ERRMSG(" Could not start elf file\n");
+ ERRMSG("Can't get first elf header of %s.\n",
+ dwarf_info.vmlinux_name);
return FALSE;
}
while ((scn = elf_nextscn(elfd, scn)) != NULL) {
if (gelf_getshdr (scn, &shdr) == NULL) {
- ERRMSG("Could not get section header\n");
+ ERRMSG("Can't get section header.\n");
goto out;
}
if (shdr.sh_type == SHT_SYMTAB)
break;
}
if (!scn) {
- ERRMSG("Could not find symbol table\n");
+ ERRMSG("Can't find symbol table.\n");
goto out;
}
data = elf_getdata(scn, data);
if ((!data) || (data->d_size == 0)) {
- ERRMSG("Zero data in symtab\n");
+ ERRMSG("No data in symbol table.\n");
goto out;
}
for (i = 0; i < (shdr.sh_size/shdr.sh_entsize); i++) {
if (gelf_getsym(data, i, &sym) == NULL) {
- ERRMSG("Unable to get symbol at index %d\n", i);
+ ERRMSG("Can't get symbol at index %d.\n", i);
goto out;
}
sym_name = elf_strptr(elfd, shdr.sh_link, sym.st_name);
@@ -744,10 +749,6 @@ search_die_tree(Dwarf *dwarfd, Dwarf_Die
Dwarf_Die child;
int tag;
const char *name;
- /*
- * We are searching the die tree for the mappings member
- * of the page struct defined in mm.h
- */
/*
* start by looking at the children
@@ -810,20 +811,21 @@ get_debug_info(void)
rc = FALSE;
lseek(dwarf_info.vmlinux_fd, 0, SEEK_SET);
+ if (!(elfd = elf_begin(dwarf_info.vmlinux_fd, ELF_C_READ_MMAP, NULL))) {
+ ERRMSG("Can't get first elf header of %s.\n",
+ dwarf_info.vmlinux_name);
+ return FALSE;
+ }
- elfd = elf_begin(dwarf_info.vmlinux_fd, ELF_C_READ_MMAP, NULL);
-
- if (!elfd)
- goto out_close_elf;
-
- dwarfd = dwarf_begin_elf(elfd, DWARF_C_READ, NULL);
-
- if (!dwarfd)
- goto out_close_dwarf;
-
- if (elf_getshstrndx (elfd, &shstrndx) < 0)
- goto out_close_dwarf;
+ if (!(dwarfd = dwarf_begin_elf(elfd, DWARF_C_READ, NULL))) {
+ ERRMSG("Can't create a handle for a new debug session.\n");
+ goto out;
+ }
+ if (elf_getshstrndx (elfd, &shstrndx) < 0) {
+ ERRMSG("Can't get the section index of the string table.\n");
+ goto out;
+ }
while ((scn = elf_nextscn (elfd, scn)) != NULL) {
scnhdr = gelf_getshdr(scn, &scnhdr_mem);
@@ -837,25 +839,26 @@ get_debug_info(void)
&abbrev_offset, &address_size, &offset_size) == 0) {
off += header_size;
if (dwarf_offdie(dwarfd, off, &cu_die) == NULL)
- goto out_close_dwarf;
+ goto out;
search_die_tree(dwarfd, &cu_die, &found_map);
if (found_map & DWARF_INFO_FOUND_STRUCT)
- goto out_found;
+ break;
off = next_off;
}
+ if (found_map & DWARF_INFO_FOUND_STRUCT)
+ break;
}
-
-out_found:
rc = TRUE;
-
-out_close_dwarf:
- dwarf_end(dwarfd);
-out_close_elf:
- elf_end(elfd);
+out:
+ if (dwarfd != NULL)
+ dwarf_end(dwarfd);
+ if (elfd != NULL)
+ elf_end(elfd);
dwarf_info.status = found_map;
- return rc;
+ return rc;
}
+
/*
* Get the size of structure.
*/
_
_______________________________________________
fastboot mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/fastboot