2 * This file is part of the Valgrind port to L4Re.
4 * (c) 2009-2010 Aaron Pohle <apohle@os.inf.tu-dresden.de>,
5 * Bjoern Doebel <doebel@os.inf.tu-dresden.de>
6 * economic rights: Technische Universitaet Dresden (Germany)
12 #include "pub_core_basics.h"
14 #include "pub_l4re_consts.h"
15 #include "pub_tool_libcbase.h"
16 #include "pub_core_libcprint.h"
21 char *section_string_table;
22 char *symbol_string_table;
23 Elf32_Sym *symbol_section;
24 unsigned symbol_section_size;
25 } melf_global_elf_info;
28 static inline void hexdump(void *a, unsigned num)
31 for ( ; i < num; ++i) {
32 VG_(printf)("%02x ", *((unsigned char*)a + i));
37 static inline int elf_check_magic(Elf32_Ehdr *e)
39 static const char elf_mag[4] = {ELFMAG0, ELFMAG1, ELFMAG2, ELFMAG3};
41 if (VG_(memcmp)(&e->e_ident, elf_mag, 4)) {
42 VG_(printf)("ident: "); hexdump(e, EI_NIDENT); VG_(printf)("\n");
43 VG_(printf)("header mismatch\n");
51 static inline void print_Ehdr_info(Elf32_Ehdr* e)
53 VG_(printf)(" --- valid ELF file\n");
54 VG_(printf)(" --- phoff: 0x%x\n", e->e_phoff);
55 VG_(printf)(" --- phnum: %u\n", e->e_phnum);
56 VG_(printf)(" --- shoff: 0x%x\n", e->e_shoff);
57 VG_(printf)(" --- shnum: %u\n", e->e_shnum);
58 VG_(printf)(" --- ehsize: 0x%x\n", e->e_ehsize);
59 VG_(printf)(" --- string table section: %d\n", e->e_shstrndx);
62 /*****************************************************************************
64 *****************************************************************************/
67 * Locate the section containing section name strings.
69 int melf_locate_section_string_table(melf_global_elf_info *inf);
72 * Locate a section with a specific type.
74 Elf32_Shdr *melf_find_section_by_type(melf_global_elf_info *inf, unsigned type);
77 * Locate a section with a specific name.
79 Elf32_Shdr *melf_find_section_by_name(melf_global_elf_info *inf, char const *name);
82 /*****************************************************************************
84 *****************************************************************************/
87 * Find the address of a symbol with a given name
89 char *melf_find_symbol_by_name(melf_global_elf_info *elf, char *name);
92 * Display list of all symbols and their addresses
94 void melf_show_symbols(melf_global_elf_info *elf);
97 * Parse ELF file (mmap()ped to address a) and return a melf_global_elf_info
100 int melf_parse_elf(void *a, melf_global_elf_info *info);