1 /* Copyright 2013-2019 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.
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.
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/>.
19 #include "sym-file-loader.h"
22 gdb_add_symbol_file (void *addr
, const char *file
)
28 gdb_remove_symbol_file (void *addr
)
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. */
38 main (int argc
, const char *argv
[])
40 const char *file
= SHLIB_NAME
;
42 char *text_addr
= NULL
;
43 int (*pbar
) () = NULL
;
44 int (*pfoo
) (int) = NULL
;
45 int (*pbaz
) () = NULL
;
48 lib
= load_shlib (file
);
52 if (get_text_addr (lib
, (void **) &text_addr
) != 0)
55 gdb_add_symbol_file (text_addr
, file
);
57 /* Call bar from SHLIB_NAME. */
58 if (lookup_function (lib
, "bar", (void *) &pbar
) != 0)
63 /* Call foo from SHLIB_NAME. */
64 if (lookup_function (lib
, "foo", (void *) &pfoo
) != 0)
69 /* Unload the library, invalidating all memory breakpoints. */
72 /* Notify GDB to remove the symbol file. Also check that GDB
73 doesn't complain that it can't remove breakpoints from the
75 gdb_remove_symbol_file (text_addr
);
77 /* Reload the library. */
78 lib
= load_shlib (file
); /* reload lib here */
82 if (get_text_addr (lib
, (void **) &text_addr
) != 0)
85 gdb_add_symbol_file (text_addr
, file
);
87 if (lookup_function (lib
, "baz", (void *) &pbaz
) != 0)
92 return 0; /* end here */