Commit | Line | Data |
---|---|---|
b811d2c2 | 1 | /* Copyright 2013-2020 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; | |
35e5d2f0 | 41 | struct library *lib; |
681f229a NB |
42 | char *text_addr = NULL; |
43 | int (*pbar) () = NULL; | |
44 | int (*pfoo) (int) = NULL; | |
08351840 PA |
45 | int (*pbaz) () = NULL; |
46 | int i; | |
681f229a | 47 | |
35e5d2f0 PA |
48 | lib = load_shlib (file); |
49 | if (lib == NULL) | |
50 | return 1; | |
681f229a | 51 | |
35e5d2f0 PA |
52 | if (get_text_addr (lib, (void **) &text_addr) != 0) |
53 | return 1; | |
681f229a NB |
54 | |
55 | gdb_add_symbol_file (text_addr, file); | |
56 | ||
57 | /* Call bar from SHLIB_NAME. */ | |
35e5d2f0 PA |
58 | if (lookup_function (lib, "bar", (void *) &pbar) != 0) |
59 | return 1; | |
681f229a NB |
60 | |
61 | (*pbar) (); | |
62 | ||
63 | /* Call foo from SHLIB_NAME. */ | |
35e5d2f0 PA |
64 | if (lookup_function (lib, "foo", (void *) &pfoo) != 0) |
65 | return 1; | |
681f229a NB |
66 | |
67 | (*pfoo) (2); | |
68 | ||
08351840 PA |
69 | /* Unload the library, invalidating all memory breakpoints. */ |
70 | unload_shlib (lib); | |
71 | ||
72 | /* Notify GDB to remove the symbol file. Also check that GDB | |
73 | doesn't complain that it can't remove breakpoints from the | |
74 | unmapped library. */ | |
681f229a NB |
75 | gdb_remove_symbol_file (text_addr); |
76 | ||
08351840 PA |
77 | /* Reload the library. */ |
78 | lib = load_shlib (file); /* reload lib here */ | |
79 | if (lib == NULL) | |
80 | return 1; | |
81 | ||
82 | if (get_text_addr (lib, (void **) &text_addr) != 0) | |
83 | return 1; | |
84 | ||
85 | gdb_add_symbol_file (text_addr, file); | |
86 | ||
87 | if (lookup_function (lib, "baz", (void *) &pbaz) != 0) | |
88 | return 1; | |
89 | ||
90 | (*pbaz) (); | |
91 | ||
92 | return 0; /* end here */ | |
681f229a | 93 | } |