]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/valgrind/src/valgrind-3.6.0-svn/coregrind/l4re/myelf.h
Some minor fixes.
[l4.git] / l4 / pkg / valgrind / src / valgrind-3.6.0-svn / coregrind / l4re / myelf.h
1 /*
2  * This file is part of the Valgrind port to L4Re.
3  *
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)
7  */
8 #pragma once
9 #include <elf.h>
10 #include <string.h>
11
12 #include "pub_core_basics.h"
13 #include "pub_l4re.h"
14 #include "pub_l4re_consts.h"
15 #include "pub_tool_libcbase.h"
16 #include "pub_core_libcprint.h"
17
18 typedef struct global
19 {
20         Elf32_Ehdr *elf_hdr;
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;
26
27
28 static inline void hexdump(void *a, unsigned num)
29 {
30         unsigned i = 0;
31         for ( ; i < num; ++i) {
32                 VG_(printf)("%02x ", *((unsigned char*)a + i));
33         }
34 }
35
36
37 static inline int elf_check_magic(Elf32_Ehdr *e)
38 {
39         static const char elf_mag[4] = {ELFMAG0, ELFMAG1, ELFMAG2, ELFMAG3};
40
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");
44                 return 0;
45         }
46
47         return 1;
48 }
49
50
51 static inline void print_Ehdr_info(Elf32_Ehdr* e)
52 {
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);
60 }
61
62 /*****************************************************************************
63  *                            Section lookup                                 *
64  *****************************************************************************/
65
66 /*
67  * Locate the section containing section name strings.
68  */
69 int melf_locate_section_string_table(melf_global_elf_info *inf);
70
71 /*
72  * Locate a section with a specific type.
73  */
74 Elf32_Shdr *melf_find_section_by_type(melf_global_elf_info *inf, unsigned type);
75
76 /*
77  * Locate a section with a specific name.
78  */
79 Elf32_Shdr *melf_find_section_by_name(melf_global_elf_info *inf, char const *name);
80
81
82 /*****************************************************************************
83  *                            Symbol lookup                                  *
84  *****************************************************************************/
85
86 /*
87  * Find the address of a symbol with a given name
88  */
89 char *melf_find_symbol_by_name(melf_global_elf_info *elf, char *name);
90
91 /*
92  * Display list of all symbols and their addresses
93  */
94 void melf_show_symbols(melf_global_elf_info *elf);
95
96 /*
97  * Parse ELF file (mmap()ped to address a) and return a melf_global_elf_info
98  * descriptor for it.
99  */
100 int melf_parse_elf(void *a, melf_global_elf_info *info);