Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Shared library support for RS/6000 (xcoff) object files, for GDB. |
0fb0cc75 | 2 | Copyright (C) 1991, 1992, 1995, 1996, 1999, 2000, 2001, 2007, 2008, 2009 |
b6ba6518 | 3 | Free Software Foundation, Inc. |
c906108c SS |
4 | Contributed by IBM Corporation. |
5 | ||
c5aa993b | 6 | This file is part of GDB. |
c906108c | 7 | |
c5aa993b JM |
8 | This program is free software; you can redistribute it and/or modify |
9 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 10 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 11 | (at your option) any later version. |
c906108c | 12 | |
c5aa993b JM |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
c906108c | 17 | |
c5aa993b | 18 | You should have received a copy of the GNU General Public License |
a9762ec7 | 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c | 20 | |
c906108c SS |
21 | #include "defs.h" |
22 | #include "bfd.h" | |
23 | #include "xcoffsolib.h" | |
24 | #include "inferior.h" | |
63f58cc5 PS |
25 | #include "gdbcmd.h" |
26 | #include "symfile.h" | |
27 | #include "frame.h" | |
28 | #include "gdb_regex.h" | |
c5aa993b | 29 | |
c906108c | 30 | |
a8079a9b PS |
31 | /* If ADDR lies in a shared library, return its name. |
32 | Note that returned name points to static data whose content is overwritten | |
33 | by each call. */ | |
c906108c SS |
34 | |
35 | char * | |
a8079a9b | 36 | xcoff_solib_address (CORE_ADDR addr) |
c906108c | 37 | { |
a8079a9b | 38 | static char *buffer = NULL; |
c5aa993b JM |
39 | struct vmap *vp = vmap; |
40 | ||
a8079a9b PS |
41 | /* The first vmap entry is for the exec file. */ |
42 | ||
43 | if (vp == NULL) | |
44 | return NULL; | |
45 | for (vp = vp->nxt; vp; vp = vp->nxt) | |
c5aa993b JM |
46 | if (vp->tstart <= addr && addr < vp->tend) |
47 | { | |
a8079a9b | 48 | xfree (buffer); |
b435e160 AC |
49 | buffer = xstrprintf ("%s%s%s%s", |
50 | vp->name, | |
51 | *vp->member ? "(" : "", | |
52 | vp->member, | |
53 | *vp->member ? ")" : ""); | |
c906108c | 54 | return buffer; |
c5aa993b | 55 | } |
a8079a9b | 56 | return NULL; |
c906108c SS |
57 | } |
58 | ||
a14ed312 | 59 | static void solib_info (char *, int); |
63f58cc5 | 60 | static void sharedlibrary_command (char *pattern, int from_tty); |
c906108c SS |
61 | |
62 | static void | |
fba45db2 | 63 | solib_info (char *args, int from_tty) |
c906108c SS |
64 | { |
65 | struct vmap *vp = vmap; | |
66 | ||
67 | /* Check for new shared libraries loaded with load (). */ | |
39f77062 KB |
68 | if (! ptid_equal (inferior_ptid, null_ptid)) |
69 | xcoff_relocate_symtab (PIDGET (inferior_ptid)); | |
c906108c SS |
70 | |
71 | if (vp == NULL || vp->nxt == NULL) | |
72 | { | |
c5aa993b | 73 | printf_unfiltered ("No shared libraries loaded at this time.\n"); |
c906108c SS |
74 | return; |
75 | } | |
76 | ||
77 | /* Skip over the first vmap, it is the main program, always loaded. */ | |
78 | vp = vp->nxt; | |
79 | ||
80 | printf_unfiltered ("\ | |
81 | Text Range Data Range Syms Shared Object Library\n"); | |
82 | ||
83 | for (; vp != NULL; vp = vp->nxt) | |
84 | { | |
d4f3574e SS |
85 | printf_unfiltered ("0x%s-0x%s 0x%s-0x%s %s %s%s%s%s\n", |
86 | paddr (vp->tstart),paddr (vp->tend), | |
87 | paddr (vp->dstart), paddr (vp->dend), | |
c906108c | 88 | vp->loaded ? "Yes" : "No ", |
a8079a9b | 89 | vp->name, |
c906108c SS |
90 | *vp->member ? "(" : "", |
91 | vp->member, | |
a8079a9b | 92 | *vp->member ? ")" : ""); |
c906108c SS |
93 | } |
94 | } | |
95 | ||
63f58cc5 PS |
96 | static void |
97 | sharedlibrary_command (char *pattern, int from_tty) | |
c906108c SS |
98 | { |
99 | dont_repeat (); | |
100 | ||
101 | /* Check for new shared libraries loaded with load (). */ | |
39f77062 KB |
102 | if (! ptid_equal (inferior_ptid, null_ptid)) |
103 | xcoff_relocate_symtab (PIDGET (inferior_ptid)); | |
63f58cc5 PS |
104 | |
105 | if (pattern) | |
106 | { | |
107 | char *re_err = re_comp (pattern); | |
c906108c | 108 | |
63f58cc5 | 109 | if (re_err) |
8a3fe4f8 | 110 | error (_("Invalid regexp: %s"), re_err); |
63f58cc5 PS |
111 | } |
112 | ||
113 | /* Walk the list of currently loaded shared libraries, and read | |
114 | symbols for any that match the pattern --- or any whose symbols | |
115 | aren't already loaded, if no pattern was given. */ | |
116 | { | |
117 | int any_matches = 0; | |
118 | int loaded_any_symbols = 0; | |
119 | struct vmap *vp = vmap; | |
120 | ||
121 | if (!vp) | |
122 | return; | |
123 | ||
124 | /* skip over the first vmap, it is the main program, always loaded. */ | |
125 | for (vp = vp->nxt; vp; vp = vp->nxt) | |
126 | if (! pattern | |
127 | || re_exec (vp->name) | |
128 | || (*vp->member && re_exec (vp->member))) | |
129 | { | |
130 | any_matches = 1; | |
131 | ||
132 | if (vp->loaded) | |
133 | { | |
134 | if (from_tty) | |
135 | printf_unfiltered ("Symbols already loaded for %s\n", | |
136 | vp->name); | |
137 | } | |
138 | else | |
139 | { | |
140 | if (vmap_add_symbols (vp)) | |
141 | loaded_any_symbols = 1; | |
142 | } | |
143 | } | |
144 | ||
145 | if (from_tty && pattern && ! any_matches) | |
146 | printf_unfiltered | |
147 | ("No loaded shared libraries match the pattern `%s'.\n", pattern); | |
148 | ||
149 | if (loaded_any_symbols) | |
150 | { | |
151 | /* Getting new symbols may change our opinion about what is | |
152 | frameless. */ | |
153 | reinit_frame_cache (); | |
154 | } | |
155 | } | |
c906108c SS |
156 | } |
157 | ||
158 | void | |
fb39c8f3 | 159 | _initialize_xcoffsolib (void) |
c906108c SS |
160 | { |
161 | add_com ("sharedlibrary", class_files, sharedlibrary_command, | |
1bedd215 | 162 | _("Load shared object library symbols for files matching REGEXP.")); |
c5aa993b | 163 | add_info ("sharedlibrary", solib_info, |
1bedd215 | 164 | _("Status of loaded shared object libraries")); |
63f58cc5 | 165 | |
5bf193a2 AC |
166 | add_setshow_boolean_cmd ("auto-solib-add", class_support, |
167 | &auto_solib_add, _("\ | |
168 | Set autoloading of shared library symbols."), _("\ | |
169 | Show autoloading of shared library symbols."), _("\ | |
b7209cb4 FF |
170 | If \"on\", symbols from all shared object libraries will be loaded\n\ |
171 | automatically when the inferior begins execution, when the dynamic linker\n\ | |
172 | informs gdb that a new library has been loaded, or when attaching to the\n\ | |
5bf193a2 AC |
173 | inferior. Otherwise, symbols must be loaded manually, using `sharedlibrary'."), |
174 | NULL, | |
175 | NULL, /* FIXME: i18n: */ | |
176 | &setlist, &showlist); | |
c906108c | 177 | } |