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