Commit | Line | Data |
---|---|---|
c906108c SS |
1 | /* Shared library support for RS/6000 (xcoff) object files, for GDB. |
2 | Copyright 1991, 1992 Free Software Foundation. | |
3 | Contributed by IBM Corporation. | |
4 | ||
c5aa993b | 5 | This file is part of GDB. |
c906108c | 6 | |
c5aa993b JM |
7 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2 of the License, or | |
10 | (at your option) any later version. | |
c906108c | 11 | |
c5aa993b JM |
12 | This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
c906108c | 16 | |
c5aa993b JM |
17 | You should have received a copy of the GNU General Public License |
18 | along with this program; if not, write to the Free Software | |
19 | Foundation, Inc., 59 Temple Place - Suite 330, | |
20 | Boston, MA 02111-1307, USA. */ | |
c906108c SS |
21 | |
22 | #if 0 | |
23 | #include <sys/types.h> | |
24 | #include <sys/ldr.h> | |
25 | #endif | |
26 | ||
27 | #include "defs.h" | |
28 | #include "bfd.h" | |
29 | #include "xcoffsolib.h" | |
30 | #include "inferior.h" | |
31 | #include "command.h" | |
32 | ||
33 | /* Hook to relocate symbols at runtime. If gdb is build natively, this | |
34 | hook is initialized in by rs6000-nat.c. If not, it is currently left | |
35 | NULL and never called. */ | |
36 | ||
37 | void (*xcoff_relocate_symtab_hook) PARAMS ((unsigned int)) = NULL; | |
38 | ||
39 | #ifdef SOLIB_SYMBOLS_MANUAL | |
40 | ||
41 | extern struct symtab *current_source_symtab; | |
c5aa993b | 42 | extern int current_source_line; |
c906108c SS |
43 | |
44 | /* The real work of adding a shared library file to the symtab and | |
45 | the section list. */ | |
46 | ||
47 | void | |
48 | solib_add (arg_string, from_tty, target) | |
49 | char *arg_string; | |
50 | int from_tty; | |
51 | struct target_ops *target; | |
c5aa993b | 52 | { |
c906108c SS |
53 | char *val; |
54 | struct vmap *vp = vmap; | |
55 | struct objfile *obj; | |
56 | struct symtab *saved_symtab; | |
57 | int saved_line; | |
58 | ||
c5aa993b JM |
59 | int loaded = 0; /* true if any shared obj loaded */ |
60 | int matched = 0; /* true if any shared obj matched */ | |
c906108c SS |
61 | |
62 | if (arg_string == 0) | |
c5aa993b JM |
63 | re_comp ("."); |
64 | else if (val = (char *) re_comp (arg_string)) | |
65 | { | |
c906108c | 66 | error ("Invalid regexp: %s", val); |
c5aa993b | 67 | } |
c906108c SS |
68 | if (!vp || !vp->nxt) |
69 | return; | |
70 | ||
71 | /* save current symbol table and line number, in case they get changed | |
72 | in symbol loading process. */ | |
c5aa993b | 73 | |
c906108c SS |
74 | saved_symtab = current_source_symtab; |
75 | saved_line = current_source_line; | |
76 | ||
77 | /* skip over the first vmap, it is the main program, always loaded. */ | |
78 | vp = vp->nxt; | |
79 | ||
c5aa993b JM |
80 | for (; vp; vp = vp->nxt) |
81 | { | |
c906108c | 82 | |
c5aa993b JM |
83 | if (re_exec (vp->name) || (*vp->member && re_exec (vp->member))) |
84 | { | |
85 | ||
86 | matched = 1; | |
87 | ||
88 | /* if already loaded, continue with the next one. */ | |
89 | if (vp->loaded) | |
90 | { | |
91 | ||
92 | printf_unfiltered ("%s%s%s%s: already loaded.\n", | |
93 | *vp->member ? "(" : "", | |
94 | vp->member, | |
95 | *vp->member ? ") " : "", | |
96 | vp->name); | |
97 | continue; | |
98 | } | |
99 | ||
100 | printf_unfiltered ("Loading %s%s%s%s...", | |
101 | *vp->member ? "(" : "", | |
102 | vp->member, | |
103 | *vp->member ? ") " : "", | |
104 | vp->name); | |
105 | gdb_flush (gdb_stdout); | |
106 | ||
107 | /* This is gross and doesn't work. If this code is re-enabled, | |
108 | just stick a objfile member into the struct vmap; that's the | |
109 | way solib.c (for SunOS/SVR4) does it. */ | |
110 | obj = lookup_objfile_bfd (vp->bfd); | |
111 | if (!obj) | |
112 | { | |
113 | warning ("\nObj structure for the shared object not found. Loading failed."); | |
114 | continue; | |
115 | } | |
116 | ||
2acceee2 | 117 | syms_from_objfile (obj, NULL, 0, 0); |
c5aa993b | 118 | new_symfile_objfile (obj, 0, 0); |
8956470d | 119 | vmap_symtab (vp); |
c5aa993b JM |
120 | printf_unfiltered ("Done.\n"); |
121 | loaded = vp->loaded = 1; | |
c906108c | 122 | } |
c906108c | 123 | } |
c906108c | 124 | /* if any shared object is loaded, then misc_func_vector needs sorting. */ |
c5aa993b JM |
125 | if (loaded) |
126 | { | |
c906108c | 127 | #if 0 |
c5aa993b | 128 | sort_misc_function_vector (); |
c906108c | 129 | #endif |
c5aa993b JM |
130 | current_source_symtab = saved_symtab; |
131 | current_source_line = saved_line; | |
c906108c | 132 | |
c5aa993b JM |
133 | /* Getting new symbols might change our opinion about what is frameless. |
134 | Is this correct?? FIXME. */ | |
c906108c | 135 | /* reinit_frame_cache(); */ |
c5aa993b | 136 | } |
c906108c SS |
137 | else if (!matched) |
138 | printf_unfiltered ("No matching shared object found.\n"); | |
139 | } | |
140 | #endif /* SOLIB_SYMBOLS_MANUAL */ | |
141 | ||
142 | /* Return the module name of a given text address. Note that returned buffer | |
143 | is not persistent. */ | |
144 | ||
145 | char * | |
146 | pc_load_segment_name (addr) | |
c5aa993b | 147 | CORE_ADDR addr; |
c906108c | 148 | { |
c5aa993b JM |
149 | static char buffer[BUFSIZ]; |
150 | struct vmap *vp = vmap; | |
151 | ||
152 | buffer[0] = buffer[1] = '\0'; | |
153 | for (; vp; vp = vp->nxt) | |
154 | if (vp->tstart <= addr && addr < vp->tend) | |
155 | { | |
156 | if (*vp->member) | |
157 | { | |
158 | buffer[0] = '('; | |
159 | strcat (&buffer[1], vp->member); | |
160 | strcat (buffer, ")"); | |
161 | } | |
c906108c SS |
162 | strcat (buffer, vp->name); |
163 | return buffer; | |
c5aa993b JM |
164 | } |
165 | return "(unknown load module)"; | |
c906108c SS |
166 | } |
167 | ||
168 | static void solib_info PARAMS ((char *, int)); | |
169 | ||
170 | static void | |
171 | solib_info (args, from_tty) | |
172 | char *args; | |
173 | int from_tty; | |
174 | { | |
175 | struct vmap *vp = vmap; | |
176 | ||
177 | /* Check for new shared libraries loaded with load (). */ | |
178 | if (xcoff_relocate_symtab_hook != NULL) | |
179 | (*xcoff_relocate_symtab_hook) (inferior_pid); | |
180 | ||
181 | if (vp == NULL || vp->nxt == NULL) | |
182 | { | |
c5aa993b | 183 | printf_unfiltered ("No shared libraries loaded at this time.\n"); |
c906108c SS |
184 | return; |
185 | } | |
186 | ||
187 | /* Skip over the first vmap, it is the main program, always loaded. */ | |
188 | vp = vp->nxt; | |
189 | ||
190 | printf_unfiltered ("\ | |
191 | Text Range Data Range Syms Shared Object Library\n"); | |
192 | ||
193 | for (; vp != NULL; vp = vp->nxt) | |
194 | { | |
d4f3574e SS |
195 | printf_unfiltered ("0x%s-0x%s 0x%s-0x%s %s %s%s%s%s\n", |
196 | paddr (vp->tstart),paddr (vp->tend), | |
197 | paddr (vp->dstart), paddr (vp->dend), | |
c906108c SS |
198 | vp->loaded ? "Yes" : "No ", |
199 | *vp->member ? "(" : "", | |
200 | vp->member, | |
201 | *vp->member ? ") " : "", | |
202 | vp->name); | |
203 | } | |
204 | } | |
205 | ||
206 | void | |
207 | sharedlibrary_command (args, from_tty) | |
208 | char *args; | |
209 | int from_tty; | |
210 | { | |
211 | dont_repeat (); | |
212 | ||
213 | /* Check for new shared libraries loaded with load (). */ | |
214 | if (xcoff_relocate_symtab_hook != NULL) | |
215 | (*xcoff_relocate_symtab_hook) (inferior_pid); | |
216 | ||
217 | #ifdef SOLIB_SYMBOLS_MANUAL | |
c5aa993b | 218 | solib_add (args, from_tty, (struct target_ops *) 0); |
c906108c SS |
219 | #endif /* SOLIB_SYMBOLS_MANUAL */ |
220 | } | |
221 | ||
222 | void | |
c5aa993b | 223 | _initialize_solib () |
c906108c SS |
224 | { |
225 | add_com ("sharedlibrary", class_files, sharedlibrary_command, | |
226 | "Load shared object library symbols for files matching REGEXP."); | |
c5aa993b | 227 | add_info ("sharedlibrary", solib_info, |
c906108c SS |
228 | "Status of loaded shared object libraries"); |
229 | } |