]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/sym-file-loader.h
Test adding and removing a symbol file at runtime.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / sym-file-loader.h
1 /* Copyright 2013 Free Software Foundation, Inc.
2 This program is free software; you can redistribute it and/or modify
3 it under the terms of the GNU General Public License as published by
4 the Free Software Foundation; either version 3 of the License, or
5 (at your option) any later version.
6
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
11
12 You should have received a copy of the GNU General Public License
13 along with this program. If not, see <http://www.gnu.org/licenses/>.
14 */
15
16 #ifndef __SYM_FILE_LOADER__
17 #define __SYM_FILE_LOADER__
18
19 #include <inttypes.h>
20 #include <ansidecl.h>
21 #include <elf/common.h>
22 #include <elf/external.h>
23
24 #ifdef TARGET_LP64
25
26 typedef Elf64_External_Phdr Elf_External_Phdr;
27 typedef Elf64_External_Ehdr Elf_External_Ehdr;
28 typedef Elf64_External_Shdr Elf_External_Shdr;
29 typedef Elf64_External_Sym Elf_External_Sym;
30 typedef uint64_t Elf_Addr;
31
32 #elif defined TARGET_ILP32
33
34 typedef Elf32_External_Phdr Elf_External_Phdr;
35 typedef Elf32_External_Ehdr Elf_External_Ehdr;
36 typedef Elf32_External_Shdr Elf_External_Shdr;
37 typedef Elf32_External_Sym Elf_External_Sym;
38 typedef uint32_t Elf_Addr;
39
40 #endif
41
42 #define GET(hdr, field) (\
43 sizeof ((hdr)->field) == 1 ? (uint64_t) (hdr)->field[0] : \
44 sizeof ((hdr)->field) == 2 ? (uint64_t) *(uint16_t *) (hdr)->field : \
45 sizeof ((hdr)->field) == 4 ? (uint64_t) *(uint32_t *) (hdr)->field : \
46 sizeof ((hdr)->field) == 8 ? *(uint64_t *) (hdr)->field : \
47 *(uint64_t *) NULL)
48
49 #define GETADDR(hdr, field) (\
50 sizeof ((hdr)->field) == sizeof (Elf_Addr) ? *(Elf_Addr *) (hdr)->field : \
51 *(Elf_Addr *) NULL)
52
53 struct segment
54 {
55 uint8_t *mapped_addr;
56 Elf_External_Phdr *phdr;
57 struct segment *next;
58 };
59
60 /* Mini shared library loader. No reallocation is performed
61 for the sake of simplicity. */
62
63 int
64 load_shlib (const char *file, Elf_External_Ehdr **ehdr_out,
65 struct segment **seg_out);
66
67 /* Return the section-header table. */
68
69 Elf_External_Shdr *find_shdrtab (Elf_External_Ehdr *ehdr);
70
71 /* Return the string table of the section headers. */
72
73 const char *find_shstrtab (Elf_External_Ehdr *ehdr, uint64_t *size);
74
75 /* Return the string table named SECTION. */
76
77 const char *find_strtab (Elf_External_Ehdr *ehdr,
78 const char *section, uint64_t *strtab_size);
79
80 /* Return the section header named SECTION. */
81
82 Elf_External_Shdr *find_shdr (Elf_External_Ehdr *ehdr, const char *section);
83
84 /* Return the symbol table. */
85
86 Elf_External_Sym *find_symtab (Elf_External_Ehdr *ehdr,
87 uint64_t *symtab_size);
88
89 /* Translate a file offset to an address in a loaded segment. */
90
91 int translate_offset (uint64_t file_offset, struct segment *seg, void **addr);
92
93 /* Lookup the address of FUNC. */
94
95 int
96 lookup_function (const char *func, Elf_External_Ehdr* ehdr,
97 struct segment *seg, void **addr);
98
99 #endif