]>
Commit | Line | Data |
---|---|---|
ecd75fc8 | 1 | /* Copyright 2013-2014 Free Software Foundation, Inc. |
681f229a NB |
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 | #include <stdlib.h> | |
17 | #include <stdio.h> | |
18 | ||
19 | #include "sym-file-loader.h" | |
20 | ||
21 | void | |
22 | gdb_add_symbol_file (void *addr, const char *file) | |
23 | { | |
24 | return; | |
25 | } | |
26 | ||
27 | void | |
28 | gdb_remove_symbol_file (void *addr) | |
29 | { | |
30 | return; | |
31 | } | |
32 | ||
33 | /* Load a shared library without relying on the standard | |
34 | loader to test GDB's commands for adding and removing | |
35 | symbol files at runtime. */ | |
36 | ||
37 | int | |
38 | main (int argc, const char *argv[]) | |
39 | { | |
40 | const char *file = SHLIB_NAME; | |
41 | Elf_External_Ehdr *ehdr = NULL; | |
42 | struct segment *head_seg = NULL; | |
43 | Elf_External_Shdr *text; | |
44 | char *text_addr = NULL; | |
45 | int (*pbar) () = NULL; | |
46 | int (*pfoo) (int) = NULL; | |
47 | ||
48 | if (load_shlib (file, &ehdr, &head_seg) != 0) | |
49 | return -1; | |
50 | ||
51 | /* Get the text section. */ | |
52 | text = find_shdr (ehdr, ".text"); | |
53 | if (text == NULL) | |
54 | return -1; | |
55 | ||
56 | /* Notify GDB to add the symbol file. */ | |
57 | if (translate_offset (GET (text, sh_offset), head_seg, (void **) &text_addr) | |
58 | != 0) | |
59 | return -1; | |
60 | ||
61 | gdb_add_symbol_file (text_addr, file); | |
62 | ||
63 | /* Call bar from SHLIB_NAME. */ | |
64 | if (lookup_function ("bar", ehdr, head_seg, (void *) &pbar) != 0) | |
65 | return -1; | |
66 | ||
67 | (*pbar) (); | |
68 | ||
69 | /* Call foo from SHLIB_NAME. */ | |
70 | if (lookup_function ("foo", ehdr, head_seg, (void *) &pfoo) != 0) | |
71 | return -1; | |
72 | ||
73 | (*pfoo) (2); | |
74 | ||
75 | /* Notify GDB to remove the symbol file. */ | |
76 | gdb_remove_symbol_file (text_addr); | |
77 | ||
78 | return 0; | |
79 | } |