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