1 |
104 |
markom |
/* Handle HP SOM shared libraries for GDB, the GNU Debugger.
|
2 |
|
|
Copyright 1993, 1996, 1999 Free Software Foundation, Inc.
|
3 |
|
|
|
4 |
|
|
This file is part of GDB.
|
5 |
|
|
|
6 |
|
|
This program is free software; you can redistribute it and/or modify
|
7 |
|
|
it under the terms of the GNU General Public License as published by
|
8 |
|
|
the Free Software Foundation; either version 2 of the License, or
|
9 |
|
|
(at your option) any later version.
|
10 |
|
|
|
11 |
|
|
This program is distributed in the hope that it will be useful,
|
12 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
|
|
GNU General Public License for more details.
|
15 |
|
|
|
16 |
|
|
You should have received a copy of the GNU General Public License
|
17 |
|
|
along with this program; if not, write to the Free Software
|
18 |
|
|
Foundation, Inc., 59 Temple Place - Suite 330,
|
19 |
|
|
Boston, MA 02111-1307, USA.
|
20 |
|
|
|
21 |
|
|
Written by the Center for Software Science at the Univerity of Utah
|
22 |
|
|
and by Cygnus Support. */
|
23 |
|
|
|
24 |
|
|
|
25 |
|
|
#include "defs.h"
|
26 |
|
|
|
27 |
|
|
#include "frame.h"
|
28 |
|
|
#include "bfd.h"
|
29 |
|
|
#include "som.h"
|
30 |
|
|
#include "libhppa.h"
|
31 |
|
|
#include "gdbcore.h"
|
32 |
|
|
#include "symtab.h"
|
33 |
|
|
#include "breakpoint.h"
|
34 |
|
|
#include "symfile.h"
|
35 |
|
|
#include "objfiles.h"
|
36 |
|
|
#include "inferior.h"
|
37 |
|
|
#include "gdb-stabs.h"
|
38 |
|
|
#include "gdb_stat.h"
|
39 |
|
|
#include "gdbcmd.h"
|
40 |
|
|
#include "assert.h"
|
41 |
|
|
#include "language.h"
|
42 |
|
|
|
43 |
|
|
#include <fcntl.h>
|
44 |
|
|
|
45 |
|
|
#ifndef O_BINARY
|
46 |
|
|
#define O_BINARY 0
|
47 |
|
|
#endif
|
48 |
|
|
|
49 |
|
|
/* Uncomment this to turn on some debugging output.
|
50 |
|
|
*/
|
51 |
|
|
|
52 |
|
|
/* #define SOLIB_DEBUG
|
53 |
|
|
*/
|
54 |
|
|
|
55 |
|
|
/* Defined in exec.c; used to prevent dangling pointer bug.
|
56 |
|
|
*/
|
57 |
|
|
extern struct target_ops exec_ops;
|
58 |
|
|
|
59 |
|
|
/* This lives in hppa-tdep.c. */
|
60 |
|
|
extern struct unwind_table_entry *find_unwind_entry PARAMS ((CORE_ADDR pc));
|
61 |
|
|
|
62 |
|
|
/* These ought to be defined in some public interface, but aren't. They
|
63 |
|
|
define the meaning of the various bits in the distinguished __dld_flags
|
64 |
|
|
variable that is declared in every debuggable a.out on HP-UX, and that
|
65 |
|
|
is shared between the debugger and the dynamic linker.
|
66 |
|
|
*/
|
67 |
|
|
#define DLD_FLAGS_MAPPRIVATE 0x1
|
68 |
|
|
#define DLD_FLAGS_HOOKVALID 0x2
|
69 |
|
|
#define DLD_FLAGS_LISTVALID 0x4
|
70 |
|
|
#define DLD_FLAGS_BOR_ENABLE 0x8
|
71 |
|
|
|
72 |
|
|
/* TODO:
|
73 |
|
|
|
74 |
|
|
* Most of this code should work for hp300 shared libraries. Does
|
75 |
|
|
anyone care enough to weed out any SOM-isms.
|
76 |
|
|
|
77 |
|
|
* Support for hpux8 dynamic linker. */
|
78 |
|
|
|
79 |
|
|
/* The basic structure which describes a dynamically loaded object. This
|
80 |
|
|
data structure is private to the dynamic linker and isn't found in
|
81 |
|
|
any HPUX include file. */
|
82 |
|
|
|
83 |
|
|
struct som_solib_mapped_entry
|
84 |
|
|
{
|
85 |
|
|
/* The name of the library. */
|
86 |
|
|
char *name;
|
87 |
|
|
|
88 |
|
|
/* Version of this structure (it is expected to change again in hpux10). */
|
89 |
|
|
unsigned char struct_version;
|
90 |
|
|
|
91 |
|
|
/* Binding mode for this library. */
|
92 |
|
|
unsigned char bind_mode;
|
93 |
|
|
|
94 |
|
|
/* Version of this library. */
|
95 |
|
|
short library_version;
|
96 |
|
|
|
97 |
|
|
/* Start of text address,
|
98 |
|
|
* link-time text location (length of text area),
|
99 |
|
|
* end of text address. */
|
100 |
|
|
CORE_ADDR text_addr;
|
101 |
|
|
CORE_ADDR text_link_addr;
|
102 |
|
|
CORE_ADDR text_end;
|
103 |
|
|
|
104 |
|
|
/* Start of data, start of bss and end of data. */
|
105 |
|
|
CORE_ADDR data_start;
|
106 |
|
|
CORE_ADDR bss_start;
|
107 |
|
|
CORE_ADDR data_end;
|
108 |
|
|
|
109 |
|
|
/* Value of linkage pointer (%r19). */
|
110 |
|
|
CORE_ADDR got_value;
|
111 |
|
|
|
112 |
|
|
/* Next entry. */
|
113 |
|
|
struct som_solib_mapped_entry *next;
|
114 |
|
|
|
115 |
|
|
/* There are other fields, but I don't have information as to what is
|
116 |
|
|
contained in them. */
|
117 |
|
|
|
118 |
|
|
/* For versions from HPUX-10.30 and up */
|
119 |
|
|
|
120 |
|
|
/* Address in target of offset from thread-local register of
|
121 |
|
|
* start of this thread's data. I.e., the first thread-local
|
122 |
|
|
* variable in this shared library starts at *(tsd_start_addr)
|
123 |
|
|
* from that area pointed to by cr27 (mpsfu_hi).
|
124 |
|
|
*
|
125 |
|
|
* We do the indirection as soon as we read it, so from then
|
126 |
|
|
* on it's the offset itself.
|
127 |
|
|
*/
|
128 |
|
|
CORE_ADDR tsd_start_addr;
|
129 |
|
|
|
130 |
|
|
/* Following this are longwords holding:
|
131 |
|
|
|
132 |
|
|
* ?, ?, ?, ptr to -1, ptr to-1, ptr to lib name (leaf name),
|
133 |
|
|
* ptr to __data_start, ptr to __data_end
|
134 |
|
|
*/
|
135 |
|
|
|
136 |
|
|
|
137 |
|
|
};
|
138 |
|
|
|
139 |
|
|
/* A structure to keep track of all the known shared objects. */
|
140 |
|
|
struct so_list
|
141 |
|
|
{
|
142 |
|
|
struct som_solib_mapped_entry som_solib;
|
143 |
|
|
struct objfile *objfile;
|
144 |
|
|
bfd *abfd;
|
145 |
|
|
struct section_table *sections;
|
146 |
|
|
struct section_table *sections_end;
|
147 |
|
|
/* elz: added this field to store the address in target space (in the
|
148 |
|
|
library) of the library descriptor (handle) which we read into
|
149 |
|
|
som_solib_mapped_entry structure */
|
150 |
|
|
CORE_ADDR solib_addr;
|
151 |
|
|
struct so_list *next;
|
152 |
|
|
|
153 |
|
|
};
|
154 |
|
|
|
155 |
|
|
static struct so_list *so_list_head;
|
156 |
|
|
|
157 |
|
|
|
158 |
|
|
/* This is the cumulative size in bytes of the symbol tables of all
|
159 |
|
|
shared objects on the so_list_head list. (When we say size, here
|
160 |
|
|
we mean of the information before it is brought into memory and
|
161 |
|
|
potentially expanded by GDB.) When adding a new shlib, this value
|
162 |
|
|
is compared against the threshold size, held by auto_solib_add
|
163 |
|
|
(in megabytes). If adding symbols for the new shlib would cause
|
164 |
|
|
the total size to exceed the threshold, then the new shlib's symbols
|
165 |
|
|
are not loaded.
|
166 |
|
|
*/
|
167 |
|
|
static LONGEST som_solib_total_st_size;
|
168 |
|
|
|
169 |
|
|
/* When the threshold is reached for any shlib, we refuse to add
|
170 |
|
|
symbols for subsequent shlibs, even if those shlibs' symbols would
|
171 |
|
|
be small enough to fit under the threshold. (Although this may
|
172 |
|
|
result in one, early large shlib preventing the loading of later,
|
173 |
|
|
smalller shlibs' symbols, it allows us to issue one informational
|
174 |
|
|
message. The alternative, to issue a message for each shlib whose
|
175 |
|
|
symbols aren't loaded, could be a big annoyance where the threshold
|
176 |
|
|
is exceeded due to a very large number of shlibs.)
|
177 |
|
|
*/
|
178 |
|
|
static int som_solib_st_size_threshold_exceeded;
|
179 |
|
|
|
180 |
|
|
/* These addresses should be filled in by som_solib_create_inferior_hook.
|
181 |
|
|
They are also used elsewhere in this module.
|
182 |
|
|
*/
|
183 |
|
|
typedef struct
|
184 |
|
|
{
|
185 |
|
|
CORE_ADDR address;
|
186 |
|
|
struct unwind_table_entry *unwind;
|
187 |
|
|
}
|
188 |
|
|
addr_and_unwind_t;
|
189 |
|
|
|
190 |
|
|
/* When adding fields, be sure to clear them in _initialize_som_solib. */
|
191 |
|
|
static struct
|
192 |
|
|
{
|
193 |
|
|
boolean is_valid;
|
194 |
|
|
addr_and_unwind_t hook;
|
195 |
|
|
addr_and_unwind_t hook_stub;
|
196 |
|
|
addr_and_unwind_t load;
|
197 |
|
|
addr_and_unwind_t load_stub;
|
198 |
|
|
addr_and_unwind_t unload;
|
199 |
|
|
addr_and_unwind_t unload2;
|
200 |
|
|
addr_and_unwind_t unload_stub;
|
201 |
|
|
}
|
202 |
|
|
dld_cache;
|
203 |
|
|
|
204 |
|
|
|
205 |
|
|
|
206 |
|
|
static void som_sharedlibrary_info_command PARAMS ((char *, int));
|
207 |
|
|
|
208 |
|
|
static void som_solib_sharedlibrary_command PARAMS ((char *, int));
|
209 |
|
|
|
210 |
|
|
static LONGEST
|
211 |
|
|
som_solib_sizeof_symbol_table (filename)
|
212 |
|
|
char *filename;
|
213 |
|
|
{
|
214 |
|
|
bfd *abfd;
|
215 |
|
|
int desc;
|
216 |
|
|
char *absolute_name;
|
217 |
|
|
LONGEST st_size = (LONGEST) 0;
|
218 |
|
|
asection *sect;
|
219 |
|
|
|
220 |
|
|
/* We believe that filename was handed to us by the dynamic linker, and
|
221 |
|
|
is therefore always an absolute path.
|
222 |
|
|
*/
|
223 |
|
|
desc = openp (getenv ("PATH"), 1, filename, O_RDONLY | O_BINARY, 0, &absolute_name);
|
224 |
|
|
if (desc < 0)
|
225 |
|
|
{
|
226 |
|
|
perror_with_name (filename);
|
227 |
|
|
}
|
228 |
|
|
filename = absolute_name;
|
229 |
|
|
|
230 |
|
|
abfd = bfd_fdopenr (filename, gnutarget, desc);
|
231 |
|
|
if (!abfd)
|
232 |
|
|
{
|
233 |
|
|
close (desc);
|
234 |
|
|
make_cleanup (free, filename);
|
235 |
|
|
error ("\"%s\": can't open to read symbols: %s.", filename,
|
236 |
|
|
bfd_errmsg (bfd_get_error ()));
|
237 |
|
|
}
|
238 |
|
|
|
239 |
|
|
if (!bfd_check_format (abfd, bfd_object)) /* Reads in section info */
|
240 |
|
|
{
|
241 |
|
|
bfd_close (abfd); /* This also closes desc */
|
242 |
|
|
make_cleanup (free, filename);
|
243 |
|
|
error ("\"%s\": can't read symbols: %s.", filename,
|
244 |
|
|
bfd_errmsg (bfd_get_error ()));
|
245 |
|
|
}
|
246 |
|
|
|
247 |
|
|
/* Sum the sizes of the various sections that compose debug info. */
|
248 |
|
|
|
249 |
|
|
/* This contains non-DOC information. */
|
250 |
|
|
sect = bfd_get_section_by_name (abfd, "$DEBUG$");
|
251 |
|
|
if (sect)
|
252 |
|
|
st_size += (LONGEST) bfd_section_size (abfd, sect);
|
253 |
|
|
|
254 |
|
|
/* This contains DOC information. */
|
255 |
|
|
sect = bfd_get_section_by_name (abfd, "$PINFO$");
|
256 |
|
|
if (sect)
|
257 |
|
|
st_size += (LONGEST) bfd_section_size (abfd, sect);
|
258 |
|
|
|
259 |
|
|
bfd_close (abfd); /* This also closes desc */
|
260 |
|
|
free (filename);
|
261 |
|
|
|
262 |
|
|
/* Unfortunately, just summing the sizes of various debug info
|
263 |
|
|
sections isn't a very accurate measurement of how much heap
|
264 |
|
|
space the debugger will need to hold them. It also doesn't
|
265 |
|
|
account for space needed by linker (aka "minimal") symbols.
|
266 |
|
|
|
267 |
|
|
Anecdotal evidence suggests that just summing the sizes of
|
268 |
|
|
debug-info-related sections understates the heap space needed
|
269 |
|
|
to represent it internally by about an order of magnitude.
|
270 |
|
|
|
271 |
|
|
Since it's not exactly brain surgery we're doing here, rather
|
272 |
|
|
than attempt to more accurately measure the size of a shlib's
|
273 |
|
|
symbol table in GDB's heap, we'll just apply a 10x fudge-
|
274 |
|
|
factor to the debug info sections' size-sum. No, this doesn't
|
275 |
|
|
account for minimal symbols in non-debuggable shlibs. But it
|
276 |
|
|
all roughly washes out in the end.
|
277 |
|
|
*/
|
278 |
|
|
return st_size * (LONGEST) 10;
|
279 |
|
|
}
|
280 |
|
|
|
281 |
|
|
|
282 |
|
|
static void
|
283 |
|
|
som_solib_add_solib_objfile (so, name, from_tty, text_addr)
|
284 |
|
|
struct so_list *so;
|
285 |
|
|
char *name;
|
286 |
|
|
int from_tty;
|
287 |
|
|
CORE_ADDR text_addr;
|
288 |
|
|
{
|
289 |
|
|
obj_private_data_t *obj_private;
|
290 |
|
|
struct section_addr_info section_addrs;
|
291 |
|
|
|
292 |
|
|
memset (§ion_addrs, 0, sizeof (section_addrs));
|
293 |
|
|
section_addrs.text_addr = text_addr;
|
294 |
|
|
so->objfile = symbol_file_add (name, from_tty, §ion_addrs, 0, OBJF_SHARED);
|
295 |
|
|
so->abfd = so->objfile->obfd;
|
296 |
|
|
|
297 |
|
|
/* Mark this as a shared library and save private data.
|
298 |
|
|
*/
|
299 |
|
|
so->objfile->flags |= OBJF_SHARED;
|
300 |
|
|
|
301 |
|
|
if (so->objfile->obj_private == NULL)
|
302 |
|
|
{
|
303 |
|
|
obj_private = (obj_private_data_t *)
|
304 |
|
|
obstack_alloc (&so->objfile->psymbol_obstack,
|
305 |
|
|
sizeof (obj_private_data_t));
|
306 |
|
|
obj_private->unwind_info = NULL;
|
307 |
|
|
obj_private->so_info = NULL;
|
308 |
|
|
so->objfile->obj_private = (PTR) obj_private;
|
309 |
|
|
}
|
310 |
|
|
|
311 |
|
|
obj_private = (obj_private_data_t *) so->objfile->obj_private;
|
312 |
|
|
obj_private->so_info = so;
|
313 |
|
|
|
314 |
|
|
if (!bfd_check_format (so->abfd, bfd_object))
|
315 |
|
|
{
|
316 |
|
|
error ("\"%s\": not in executable format: %s.",
|
317 |
|
|
name, bfd_errmsg (bfd_get_error ()));
|
318 |
|
|
}
|
319 |
|
|
}
|
320 |
|
|
|
321 |
|
|
|
322 |
|
|
static void
|
323 |
|
|
som_solib_load_symbols (so, name, from_tty, text_addr, target)
|
324 |
|
|
struct so_list *so;
|
325 |
|
|
char *name;
|
326 |
|
|
int from_tty;
|
327 |
|
|
CORE_ADDR text_addr;
|
328 |
|
|
struct target_ops *target;
|
329 |
|
|
{
|
330 |
|
|
struct section_table *p;
|
331 |
|
|
int status;
|
332 |
|
|
char buf[4];
|
333 |
|
|
CORE_ADDR presumed_data_start;
|
334 |
|
|
|
335 |
|
|
#ifdef SOLIB_DEBUG
|
336 |
|
|
printf ("--Adding symbols for shared library \"%s\"\n", name);
|
337 |
|
|
#endif
|
338 |
|
|
|
339 |
|
|
som_solib_add_solib_objfile (so, name, from_tty, text_addr);
|
340 |
|
|
|
341 |
|
|
/* Now we need to build a section table for this library since
|
342 |
|
|
we might be debugging a core file from a dynamically linked
|
343 |
|
|
executable in which the libraries were not privately mapped. */
|
344 |
|
|
if (build_section_table (so->abfd,
|
345 |
|
|
&so->sections,
|
346 |
|
|
&so->sections_end))
|
347 |
|
|
{
|
348 |
|
|
error ("Unable to build section table for shared library\n.");
|
349 |
|
|
return;
|
350 |
|
|
}
|
351 |
|
|
|
352 |
|
|
/* Relocate all the sections based on where they got loaded. */
|
353 |
|
|
for (p = so->sections; p < so->sections_end; p++)
|
354 |
|
|
{
|
355 |
|
|
if (p->the_bfd_section->flags & SEC_CODE)
|
356 |
|
|
{
|
357 |
|
|
p->addr += ANOFFSET (so->objfile->section_offsets, SECT_OFF_TEXT);
|
358 |
|
|
p->endaddr += ANOFFSET (so->objfile->section_offsets, SECT_OFF_TEXT);
|
359 |
|
|
}
|
360 |
|
|
else if (p->the_bfd_section->flags & SEC_DATA)
|
361 |
|
|
{
|
362 |
|
|
p->addr += ANOFFSET (so->objfile->section_offsets, SECT_OFF_DATA);
|
363 |
|
|
p->endaddr += ANOFFSET (so->objfile->section_offsets, SECT_OFF_DATA);
|
364 |
|
|
}
|
365 |
|
|
}
|
366 |
|
|
|
367 |
|
|
/* Now see if we need to map in the text and data for this shared
|
368 |
|
|
library (for example debugging a core file which does not use
|
369 |
|
|
private shared libraries.).
|
370 |
|
|
|
371 |
|
|
Carefully peek at the first text address in the library. If the
|
372 |
|
|
read succeeds, then the libraries were privately mapped and were
|
373 |
|
|
included in the core dump file.
|
374 |
|
|
|
375 |
|
|
If the peek failed, then the libraries were not privately mapped
|
376 |
|
|
and are not in the core file, we'll have to read them in ourselves. */
|
377 |
|
|
status = target_read_memory (text_addr, buf, 4);
|
378 |
|
|
if (status != 0)
|
379 |
|
|
{
|
380 |
|
|
int old, new;
|
381 |
|
|
|
382 |
|
|
new = so->sections_end - so->sections;
|
383 |
|
|
|
384 |
|
|
old = target_resize_to_sections (target, new);
|
385 |
|
|
|
386 |
|
|
/* Copy over the old data before it gets clobbered. */
|
387 |
|
|
memcpy ((char *) (target->to_sections + old),
|
388 |
|
|
so->sections,
|
389 |
|
|
((sizeof (struct section_table)) * new));
|
390 |
|
|
}
|
391 |
|
|
}
|
392 |
|
|
|
393 |
|
|
|
394 |
|
|
/* Add symbols from shared libraries into the symtab list, unless the
|
395 |
|
|
size threshold (specified by auto_solib_add, in megabytes) would
|
396 |
|
|
be exceeded. */
|
397 |
|
|
|
398 |
|
|
void
|
399 |
|
|
som_solib_add (arg_string, from_tty, target)
|
400 |
|
|
char *arg_string;
|
401 |
|
|
int from_tty;
|
402 |
|
|
struct target_ops *target;
|
403 |
|
|
{
|
404 |
|
|
struct minimal_symbol *msymbol;
|
405 |
|
|
struct so_list *so_list_tail;
|
406 |
|
|
CORE_ADDR addr;
|
407 |
|
|
asection *shlib_info;
|
408 |
|
|
int status;
|
409 |
|
|
unsigned int dld_flags;
|
410 |
|
|
char buf[4], *re_err;
|
411 |
|
|
int threshold_warning_given = 0;
|
412 |
|
|
|
413 |
|
|
/* First validate our arguments. */
|
414 |
|
|
if ((re_err = re_comp (arg_string ? arg_string : ".")) != NULL)
|
415 |
|
|
{
|
416 |
|
|
error ("Invalid regexp: %s", re_err);
|
417 |
|
|
}
|
418 |
|
|
|
419 |
|
|
/* If we're debugging a core file, or have attached to a running
|
420 |
|
|
process, then som_solib_create_inferior_hook will not have been
|
421 |
|
|
called.
|
422 |
|
|
|
423 |
|
|
We need to first determine if we're dealing with a dynamically
|
424 |
|
|
linked executable. If not, then return without an error or warning.
|
425 |
|
|
|
426 |
|
|
We also need to examine __dld_flags to determine if the shared library
|
427 |
|
|
list is valid and to determine if the libraries have been privately
|
428 |
|
|
mapped. */
|
429 |
|
|
if (symfile_objfile == NULL)
|
430 |
|
|
return;
|
431 |
|
|
|
432 |
|
|
/* First see if the objfile was dynamically linked. */
|
433 |
|
|
shlib_info = bfd_get_section_by_name (symfile_objfile->obfd, "$SHLIB_INFO$");
|
434 |
|
|
if (!shlib_info)
|
435 |
|
|
return;
|
436 |
|
|
|
437 |
|
|
/* It's got a $SHLIB_INFO$ section, make sure it's not empty. */
|
438 |
|
|
if (bfd_section_size (symfile_objfile->obfd, shlib_info) == 0)
|
439 |
|
|
return;
|
440 |
|
|
|
441 |
|
|
msymbol = lookup_minimal_symbol ("__dld_flags", NULL, NULL);
|
442 |
|
|
if (msymbol == NULL)
|
443 |
|
|
{
|
444 |
|
|
error ("Unable to find __dld_flags symbol in object file.\n");
|
445 |
|
|
return;
|
446 |
|
|
}
|
447 |
|
|
|
448 |
|
|
addr = SYMBOL_VALUE_ADDRESS (msymbol);
|
449 |
|
|
/* Read the current contents. */
|
450 |
|
|
status = target_read_memory (addr, buf, 4);
|
451 |
|
|
if (status != 0)
|
452 |
|
|
{
|
453 |
|
|
error ("Unable to read __dld_flags\n");
|
454 |
|
|
return;
|
455 |
|
|
}
|
456 |
|
|
dld_flags = extract_unsigned_integer (buf, 4);
|
457 |
|
|
|
458 |
|
|
/* __dld_list may not be valid. If not, then we punt, warning the user if
|
459 |
|
|
we were called as a result of the add-symfile command.
|
460 |
|
|
*/
|
461 |
|
|
if ((dld_flags & DLD_FLAGS_LISTVALID) == 0)
|
462 |
|
|
{
|
463 |
|
|
if (from_tty)
|
464 |
|
|
error ("__dld_list is not valid according to __dld_flags.\n");
|
465 |
|
|
return;
|
466 |
|
|
}
|
467 |
|
|
|
468 |
|
|
/* If the libraries were not mapped private, warn the user. */
|
469 |
|
|
if ((dld_flags & DLD_FLAGS_MAPPRIVATE) == 0)
|
470 |
|
|
warning ("The shared libraries were not privately mapped; setting a\nbreakpoint in a shared library will not work until you rerun the program.\n");
|
471 |
|
|
|
472 |
|
|
msymbol = lookup_minimal_symbol ("__dld_list", NULL, NULL);
|
473 |
|
|
if (!msymbol)
|
474 |
|
|
{
|
475 |
|
|
/* Older crt0.o files (hpux8) don't have __dld_list as a symbol,
|
476 |
|
|
but the data is still available if you know where to look. */
|
477 |
|
|
msymbol = lookup_minimal_symbol ("__dld_flags", NULL, NULL);
|
478 |
|
|
if (!msymbol)
|
479 |
|
|
{
|
480 |
|
|
error ("Unable to find dynamic library list.\n");
|
481 |
|
|
return;
|
482 |
|
|
}
|
483 |
|
|
addr = SYMBOL_VALUE_ADDRESS (msymbol) - 8;
|
484 |
|
|
}
|
485 |
|
|
else
|
486 |
|
|
addr = SYMBOL_VALUE_ADDRESS (msymbol);
|
487 |
|
|
|
488 |
|
|
status = target_read_memory (addr, buf, 4);
|
489 |
|
|
if (status != 0)
|
490 |
|
|
{
|
491 |
|
|
error ("Unable to find dynamic library list.\n");
|
492 |
|
|
return;
|
493 |
|
|
}
|
494 |
|
|
|
495 |
|
|
addr = extract_unsigned_integer (buf, 4);
|
496 |
|
|
|
497 |
|
|
/* If addr is zero, then we're using an old dynamic loader which
|
498 |
|
|
doesn't maintain __dld_list. We'll have to use a completely
|
499 |
|
|
different approach to get shared library information. */
|
500 |
|
|
if (addr == 0)
|
501 |
|
|
goto old_dld;
|
502 |
|
|
|
503 |
|
|
/* Using the information in __dld_list is the preferred method
|
504 |
|
|
to get at shared library information. It doesn't depend on
|
505 |
|
|
any functions in /opt/langtools/lib/end.o and has a chance of working
|
506 |
|
|
with hpux10 when it is released. */
|
507 |
|
|
status = target_read_memory (addr, buf, 4);
|
508 |
|
|
if (status != 0)
|
509 |
|
|
{
|
510 |
|
|
error ("Unable to find dynamic library list.\n");
|
511 |
|
|
return;
|
512 |
|
|
}
|
513 |
|
|
|
514 |
|
|
/* addr now holds the address of the first entry in the dynamic
|
515 |
|
|
library list. */
|
516 |
|
|
addr = extract_unsigned_integer (buf, 4);
|
517 |
|
|
|
518 |
|
|
/* Now that we have a pointer to the dynamic library list, walk
|
519 |
|
|
through it and add the symbols for each library. */
|
520 |
|
|
|
521 |
|
|
so_list_tail = so_list_head;
|
522 |
|
|
/* Find the end of the list of shared objects. */
|
523 |
|
|
while (so_list_tail && so_list_tail->next)
|
524 |
|
|
so_list_tail = so_list_tail->next;
|
525 |
|
|
|
526 |
|
|
#ifdef SOLIB_DEBUG
|
527 |
|
|
printf ("--About to read shared library list data\n");
|
528 |
|
|
#endif
|
529 |
|
|
|
530 |
|
|
/* "addr" will always point to the base of the
|
531 |
|
|
* current data entry describing the current
|
532 |
|
|
* shared library.
|
533 |
|
|
*/
|
534 |
|
|
while (1)
|
535 |
|
|
{
|
536 |
|
|
CORE_ADDR name_addr, text_addr;
|
537 |
|
|
unsigned int name_len;
|
538 |
|
|
char *name;
|
539 |
|
|
struct so_list *new_so;
|
540 |
|
|
struct so_list *so_list = so_list_head;
|
541 |
|
|
struct stat statbuf;
|
542 |
|
|
LONGEST st_size;
|
543 |
|
|
int is_main_program;
|
544 |
|
|
|
545 |
|
|
if (addr == 0)
|
546 |
|
|
break;
|
547 |
|
|
|
548 |
|
|
/* Get a pointer to the name of this library. */
|
549 |
|
|
status = target_read_memory (addr, buf, 4);
|
550 |
|
|
if (status != 0)
|
551 |
|
|
goto err;
|
552 |
|
|
|
553 |
|
|
name_addr = extract_unsigned_integer (buf, 4);
|
554 |
|
|
name_len = 0;
|
555 |
|
|
while (1)
|
556 |
|
|
{
|
557 |
|
|
target_read_memory (name_addr + name_len, buf, 1);
|
558 |
|
|
if (status != 0)
|
559 |
|
|
goto err;
|
560 |
|
|
|
561 |
|
|
name_len++;
|
562 |
|
|
if (*buf == '\0')
|
563 |
|
|
break;
|
564 |
|
|
}
|
565 |
|
|
name = alloca (name_len);
|
566 |
|
|
status = target_read_memory (name_addr, name, name_len);
|
567 |
|
|
if (status != 0)
|
568 |
|
|
goto err;
|
569 |
|
|
|
570 |
|
|
/* See if we've already loaded something with this name. */
|
571 |
|
|
while (so_list)
|
572 |
|
|
{
|
573 |
|
|
if (!strcmp (so_list->som_solib.name, name))
|
574 |
|
|
break;
|
575 |
|
|
so_list = so_list->next;
|
576 |
|
|
}
|
577 |
|
|
|
578 |
|
|
/* See if the file exists. If not, give a warning, but don't
|
579 |
|
|
die. */
|
580 |
|
|
status = stat (name, &statbuf);
|
581 |
|
|
if (status == -1)
|
582 |
|
|
{
|
583 |
|
|
warning ("Can't find file %s referenced in dld_list.", name);
|
584 |
|
|
|
585 |
|
|
status = target_read_memory (addr + 36, buf, 4);
|
586 |
|
|
if (status != 0)
|
587 |
|
|
goto err;
|
588 |
|
|
|
589 |
|
|
addr = (CORE_ADDR) extract_unsigned_integer (buf, 4);
|
590 |
|
|
continue;
|
591 |
|
|
}
|
592 |
|
|
|
593 |
|
|
/* If we've already loaded this one or it's the main program, skip it. */
|
594 |
|
|
is_main_program = (strcmp (name, symfile_objfile->name) == 0);
|
595 |
|
|
if (so_list || is_main_program)
|
596 |
|
|
{
|
597 |
|
|
/* This is the "next" pointer in the strcuture.
|
598 |
|
|
*/
|
599 |
|
|
status = target_read_memory (addr + 36, buf, 4);
|
600 |
|
|
if (status != 0)
|
601 |
|
|
goto err;
|
602 |
|
|
|
603 |
|
|
addr = (CORE_ADDR) extract_unsigned_integer (buf, 4);
|
604 |
|
|
|
605 |
|
|
/* Record the main program's symbol table size. */
|
606 |
|
|
if (is_main_program && !so_list)
|
607 |
|
|
{
|
608 |
|
|
st_size = som_solib_sizeof_symbol_table (name);
|
609 |
|
|
som_solib_total_st_size += st_size;
|
610 |
|
|
}
|
611 |
|
|
|
612 |
|
|
/* Was this a shlib that we noted but didn't load the symbols for?
|
613 |
|
|
If so, were we invoked this time from the command-line, via
|
614 |
|
|
a 'sharedlibrary' or 'add-symbol-file' command? If yes to
|
615 |
|
|
both, we'd better load the symbols this time.
|
616 |
|
|
*/
|
617 |
|
|
if (from_tty && so_list && !is_main_program && (so_list->objfile == NULL))
|
618 |
|
|
som_solib_load_symbols (so_list,
|
619 |
|
|
name,
|
620 |
|
|
from_tty,
|
621 |
|
|
so_list->som_solib.text_addr,
|
622 |
|
|
target);
|
623 |
|
|
|
624 |
|
|
continue;
|
625 |
|
|
}
|
626 |
|
|
|
627 |
|
|
name = obsavestring (name, name_len - 1,
|
628 |
|
|
&symfile_objfile->symbol_obstack);
|
629 |
|
|
|
630 |
|
|
status = target_read_memory (addr + 8, buf, 4);
|
631 |
|
|
if (status != 0)
|
632 |
|
|
goto err;
|
633 |
|
|
|
634 |
|
|
text_addr = extract_unsigned_integer (buf, 4);
|
635 |
|
|
|
636 |
|
|
new_so = (struct so_list *) xmalloc (sizeof (struct so_list));
|
637 |
|
|
memset ((char *) new_so, 0, sizeof (struct so_list));
|
638 |
|
|
if (so_list_head == NULL)
|
639 |
|
|
{
|
640 |
|
|
so_list_head = new_so;
|
641 |
|
|
so_list_tail = new_so;
|
642 |
|
|
}
|
643 |
|
|
else
|
644 |
|
|
{
|
645 |
|
|
so_list_tail->next = new_so;
|
646 |
|
|
so_list_tail = new_so;
|
647 |
|
|
}
|
648 |
|
|
|
649 |
|
|
/* Fill in all the entries in GDB's shared library list.
|
650 |
|
|
*/
|
651 |
|
|
|
652 |
|
|
new_so->solib_addr = addr;
|
653 |
|
|
new_so->som_solib.name = name;
|
654 |
|
|
status = target_read_memory (addr + 4, buf, 4);
|
655 |
|
|
if (status != 0)
|
656 |
|
|
goto err;
|
657 |
|
|
|
658 |
|
|
new_so->som_solib.struct_version = extract_unsigned_integer (buf + 3, 1);
|
659 |
|
|
new_so->som_solib.bind_mode = extract_unsigned_integer (buf + 2, 1);
|
660 |
|
|
/* Following is "high water mark", highest version number
|
661 |
|
|
* seen, rather than plain version number.
|
662 |
|
|
*/
|
663 |
|
|
new_so->som_solib.library_version = extract_unsigned_integer (buf, 2);
|
664 |
|
|
new_so->som_solib.text_addr = text_addr;
|
665 |
|
|
|
666 |
|
|
/* Q: What about longword at "addr + 8"?
|
667 |
|
|
* A: It's read above, out of order, into "text_addr".
|
668 |
|
|
*/
|
669 |
|
|
|
670 |
|
|
status = target_read_memory (addr + 12, buf, 4);
|
671 |
|
|
if (status != 0)
|
672 |
|
|
goto err;
|
673 |
|
|
|
674 |
|
|
new_so->som_solib.text_link_addr = extract_unsigned_integer (buf, 4);
|
675 |
|
|
|
676 |
|
|
status = target_read_memory (addr + 16, buf, 4);
|
677 |
|
|
if (status != 0)
|
678 |
|
|
goto err;
|
679 |
|
|
|
680 |
|
|
new_so->som_solib.text_end = extract_unsigned_integer (buf, 4);
|
681 |
|
|
|
682 |
|
|
status = target_read_memory (addr + 20, buf, 4);
|
683 |
|
|
if (status != 0)
|
684 |
|
|
goto err;
|
685 |
|
|
|
686 |
|
|
new_so->som_solib.data_start = extract_unsigned_integer (buf, 4);
|
687 |
|
|
|
688 |
|
|
status = target_read_memory (addr + 24, buf, 4);
|
689 |
|
|
if (status != 0)
|
690 |
|
|
goto err;
|
691 |
|
|
|
692 |
|
|
new_so->som_solib.bss_start = extract_unsigned_integer (buf, 4);
|
693 |
|
|
|
694 |
|
|
status = target_read_memory (addr + 28, buf, 4);
|
695 |
|
|
if (status != 0)
|
696 |
|
|
goto err;
|
697 |
|
|
|
698 |
|
|
new_so->som_solib.data_end = extract_unsigned_integer (buf, 4);
|
699 |
|
|
|
700 |
|
|
status = target_read_memory (addr + 32, buf, 4);
|
701 |
|
|
if (status != 0)
|
702 |
|
|
goto err;
|
703 |
|
|
|
704 |
|
|
new_so->som_solib.got_value = extract_unsigned_integer (buf, 4);
|
705 |
|
|
|
706 |
|
|
status = target_read_memory (addr + 36, buf, 4);
|
707 |
|
|
if (status != 0)
|
708 |
|
|
goto err;
|
709 |
|
|
|
710 |
|
|
new_so->som_solib.next = (void *) extract_unsigned_integer (buf, 4);
|
711 |
|
|
|
712 |
|
|
/* Note that we don't re-set "addr" to the next pointer
|
713 |
|
|
* until after we've read the trailing data.
|
714 |
|
|
*/
|
715 |
|
|
|
716 |
|
|
status = target_read_memory (addr + 40, buf, 4);
|
717 |
|
|
new_so->som_solib.tsd_start_addr = extract_unsigned_integer (buf, 4);
|
718 |
|
|
if (status != 0)
|
719 |
|
|
goto err;
|
720 |
|
|
|
721 |
|
|
/* Now indirect via that value!
|
722 |
|
|
*/
|
723 |
|
|
status = target_read_memory (new_so->som_solib.tsd_start_addr, buf, 4);
|
724 |
|
|
new_so->som_solib.tsd_start_addr = extract_unsigned_integer (buf, 4);
|
725 |
|
|
if (status != 0)
|
726 |
|
|
goto err;
|
727 |
|
|
#ifdef SOLIB_DEBUG
|
728 |
|
|
printf ("\n+ library \"%s\" is described at 0x%x\n", name, addr);
|
729 |
|
|
printf (" 'version' is %d\n", new_so->som_solib.struct_version);
|
730 |
|
|
printf (" 'bind_mode' is %d\n", new_so->som_solib.bind_mode);
|
731 |
|
|
printf (" 'library_version' is %d\n", new_so->som_solib.library_version);
|
732 |
|
|
printf (" 'text_addr' is 0x%x\n", new_so->som_solib.text_addr);
|
733 |
|
|
printf (" 'text_link_addr' is 0x%x\n", new_so->som_solib.text_link_addr);
|
734 |
|
|
printf (" 'text_end' is 0x%x\n", new_so->som_solib.text_end);
|
735 |
|
|
printf (" 'data_start' is 0x%x\n", new_so->som_solib.data_start);
|
736 |
|
|
printf (" 'bss_start' is 0x%x\n", new_so->som_solib.bss_start);
|
737 |
|
|
printf (" 'data_end' is 0x%x\n", new_so->som_solib.data_end);
|
738 |
|
|
printf (" 'got_value' is %x\n", new_so->som_solib.got_value);
|
739 |
|
|
printf (" 'next' is 0x%x\n", new_so->som_solib.next);
|
740 |
|
|
printf (" 'tsd_start_addr' is 0x%x\n", new_so->som_solib.tsd_start_addr);
|
741 |
|
|
#endif
|
742 |
|
|
|
743 |
|
|
/* Go on to the next shared library descriptor.
|
744 |
|
|
*/
|
745 |
|
|
addr = (CORE_ADDR) new_so->som_solib.next;
|
746 |
|
|
|
747 |
|
|
|
748 |
|
|
|
749 |
|
|
/* At this point, we have essentially hooked the shlib into the
|
750 |
|
|
"info share" command. However, we haven't yet loaded its
|
751 |
|
|
symbol table. We must now decide whether we ought to, i.e.,
|
752 |
|
|
whether doing so would exceed the symbol table size threshold.
|
753 |
|
|
|
754 |
|
|
If the threshold has just now been exceeded, then we'll issue
|
755 |
|
|
a warning message (which explains how to load symbols manually,
|
756 |
|
|
if the user so desires).
|
757 |
|
|
|
758 |
|
|
If the threshold has just now or previously been exceeded,
|
759 |
|
|
we'll just add the shlib to the list of object files, but won't
|
760 |
|
|
actually load its symbols. (This is more useful than it might
|
761 |
|
|
sound, for it allows us to e.g., still load and use the shlibs'
|
762 |
|
|
unwind information for stack tracebacks.)
|
763 |
|
|
*/
|
764 |
|
|
|
765 |
|
|
/* Note that we DON'T want to preclude the user from using the
|
766 |
|
|
add-symbol-file command! Thus, we only worry about the threshold
|
767 |
|
|
when we're invoked for other reasons.
|
768 |
|
|
*/
|
769 |
|
|
st_size = som_solib_sizeof_symbol_table (name);
|
770 |
|
|
som_solib_st_size_threshold_exceeded =
|
771 |
|
|
!from_tty &&
|
772 |
|
|
((st_size + som_solib_total_st_size) > (auto_solib_add * (LONGEST) 1000000));
|
773 |
|
|
|
774 |
|
|
if (som_solib_st_size_threshold_exceeded)
|
775 |
|
|
{
|
776 |
|
|
if (!threshold_warning_given)
|
777 |
|
|
warning ("Symbols for some libraries have not been loaded, because\ndoing so would exceed the size threshold specified by auto-solib-add.\nTo manually load symbols, use the 'sharedlibrary' command.\nTo raise the threshold, set auto-solib-add to a larger value and rerun\nthe program.\n");
|
778 |
|
|
threshold_warning_given = 1;
|
779 |
|
|
|
780 |
|
|
/* We'll still make note of this shlib, even if we don't
|
781 |
|
|
read its symbols. This allows us to use its unwind
|
782 |
|
|
information well enough to know how to e.g., correctly
|
783 |
|
|
do a traceback from a PC within the shlib, even if we
|
784 |
|
|
can't symbolize those PCs...
|
785 |
|
|
*/
|
786 |
|
|
som_solib_add_solib_objfile (new_so, name, from_tty, text_addr);
|
787 |
|
|
continue;
|
788 |
|
|
}
|
789 |
|
|
|
790 |
|
|
som_solib_total_st_size += st_size;
|
791 |
|
|
|
792 |
|
|
/* This fills in new_so->objfile, among others. */
|
793 |
|
|
som_solib_load_symbols (new_so, name, from_tty, text_addr, target);
|
794 |
|
|
}
|
795 |
|
|
|
796 |
|
|
#ifdef SOLIB_DEBUG
|
797 |
|
|
printf ("--Done reading shared library data\n");
|
798 |
|
|
#endif
|
799 |
|
|
|
800 |
|
|
/* Getting new symbols may change our opinion about what is
|
801 |
|
|
frameless. */
|
802 |
|
|
reinit_frame_cache ();
|
803 |
|
|
return;
|
804 |
|
|
|
805 |
|
|
old_dld:
|
806 |
|
|
error ("Debugging dynamic executables loaded via the hpux8 dld.sl is not supported.\n");
|
807 |
|
|
return;
|
808 |
|
|
|
809 |
|
|
err:
|
810 |
|
|
error ("Error while reading dynamic library list.\n");
|
811 |
|
|
return;
|
812 |
|
|
}
|
813 |
|
|
|
814 |
|
|
|
815 |
|
|
/* This hook gets called just before the first instruction in the
|
816 |
|
|
inferior process is executed.
|
817 |
|
|
|
818 |
|
|
This is our opportunity to set magic flags in the inferior so
|
819 |
|
|
that GDB can be notified when a shared library is mapped in and
|
820 |
|
|
to tell the dynamic linker that a private copy of the library is
|
821 |
|
|
needed (so GDB can set breakpoints in the library).
|
822 |
|
|
|
823 |
|
|
__dld_flags is the location of the magic flags; as of this implementation
|
824 |
|
|
there are 3 flags of interest:
|
825 |
|
|
|
826 |
|
|
bit 0 when set indicates that private copies of the libraries are needed
|
827 |
|
|
bit 1 when set indicates that the callback hook routine is valid
|
828 |
|
|
bit 2 when set indicates that the dynamic linker should maintain the
|
829 |
|
|
__dld_list structure when loading/unloading libraries.
|
830 |
|
|
|
831 |
|
|
Note that shared libraries are not mapped in at this time, so we have
|
832 |
|
|
run the inferior until the libraries are mapped in. Typically this
|
833 |
|
|
means running until the "_start" is called. */
|
834 |
|
|
|
835 |
|
|
void
|
836 |
|
|
som_solib_create_inferior_hook ()
|
837 |
|
|
{
|
838 |
|
|
struct minimal_symbol *msymbol;
|
839 |
|
|
unsigned int dld_flags, status, have_endo;
|
840 |
|
|
asection *shlib_info;
|
841 |
|
|
char buf[4];
|
842 |
|
|
struct objfile *objfile;
|
843 |
|
|
CORE_ADDR anaddr;
|
844 |
|
|
|
845 |
|
|
/* First, remove all the solib event breakpoints. Their addresses
|
846 |
|
|
may have changed since the last time we ran the program. */
|
847 |
|
|
remove_solib_event_breakpoints ();
|
848 |
|
|
|
849 |
|
|
if (symfile_objfile == NULL)
|
850 |
|
|
return;
|
851 |
|
|
|
852 |
|
|
/* First see if the objfile was dynamically linked. */
|
853 |
|
|
shlib_info = bfd_get_section_by_name (symfile_objfile->obfd, "$SHLIB_INFO$");
|
854 |
|
|
if (!shlib_info)
|
855 |
|
|
return;
|
856 |
|
|
|
857 |
|
|
/* It's got a $SHLIB_INFO$ section, make sure it's not empty. */
|
858 |
|
|
if (bfd_section_size (symfile_objfile->obfd, shlib_info) == 0)
|
859 |
|
|
return;
|
860 |
|
|
|
861 |
|
|
have_endo = 0;
|
862 |
|
|
/* Slam the pid of the process into __d_pid; failing is only a warning! */
|
863 |
|
|
msymbol = lookup_minimal_symbol ("__d_pid", NULL, symfile_objfile);
|
864 |
|
|
if (msymbol == NULL)
|
865 |
|
|
{
|
866 |
|
|
warning ("Unable to find __d_pid symbol in object file.");
|
867 |
|
|
warning ("Suggest linking with /opt/langtools/lib/end.o.");
|
868 |
|
|
warning ("GDB will be unable to track shl_load/shl_unload calls");
|
869 |
|
|
goto keep_going;
|
870 |
|
|
}
|
871 |
|
|
|
872 |
|
|
anaddr = SYMBOL_VALUE_ADDRESS (msymbol);
|
873 |
|
|
store_unsigned_integer (buf, 4, inferior_pid);
|
874 |
|
|
status = target_write_memory (anaddr, buf, 4);
|
875 |
|
|
if (status != 0)
|
876 |
|
|
{
|
877 |
|
|
warning ("Unable to write __d_pid");
|
878 |
|
|
warning ("Suggest linking with /opt/langtools/lib/end.o.");
|
879 |
|
|
warning ("GDB will be unable to track shl_load/shl_unload calls");
|
880 |
|
|
goto keep_going;
|
881 |
|
|
}
|
882 |
|
|
|
883 |
|
|
/* Get the value of _DLD_HOOK (an export stub) and put it in __dld_hook;
|
884 |
|
|
This will force the dynamic linker to call __d_trap when significant
|
885 |
|
|
events occur.
|
886 |
|
|
|
887 |
|
|
Note that the above is the pre-HP-UX 9.0 behaviour. At 9.0 and above,
|
888 |
|
|
the dld provides an export stub named "__d_trap" as well as the
|
889 |
|
|
function named "__d_trap" itself, but doesn't provide "_DLD_HOOK".
|
890 |
|
|
We'll look first for the old flavor and then the new.
|
891 |
|
|
*/
|
892 |
|
|
msymbol = lookup_minimal_symbol ("_DLD_HOOK", NULL, symfile_objfile);
|
893 |
|
|
if (msymbol == NULL)
|
894 |
|
|
msymbol = lookup_minimal_symbol ("__d_trap", NULL, symfile_objfile);
|
895 |
|
|
if (msymbol == NULL)
|
896 |
|
|
{
|
897 |
|
|
warning ("Unable to find _DLD_HOOK symbol in object file.");
|
898 |
|
|
warning ("Suggest linking with /opt/langtools/lib/end.o.");
|
899 |
|
|
warning ("GDB will be unable to track shl_load/shl_unload calls");
|
900 |
|
|
goto keep_going;
|
901 |
|
|
}
|
902 |
|
|
anaddr = SYMBOL_VALUE_ADDRESS (msymbol);
|
903 |
|
|
dld_cache.hook.address = anaddr;
|
904 |
|
|
|
905 |
|
|
/* Grrr, this might not be an export symbol! We have to find the
|
906 |
|
|
export stub. */
|
907 |
|
|
ALL_OBJFILES (objfile)
|
908 |
|
|
{
|
909 |
|
|
struct unwind_table_entry *u;
|
910 |
|
|
struct minimal_symbol *msymbol2;
|
911 |
|
|
|
912 |
|
|
/* What a crock. */
|
913 |
|
|
msymbol2 = lookup_minimal_symbol_solib_trampoline (SYMBOL_NAME (msymbol),
|
914 |
|
|
NULL, objfile);
|
915 |
|
|
/* Found a symbol with the right name. */
|
916 |
|
|
if (msymbol2)
|
917 |
|
|
{
|
918 |
|
|
struct unwind_table_entry *u;
|
919 |
|
|
/* It must be a shared library trampoline. */
|
920 |
|
|
if (SYMBOL_TYPE (msymbol2) != mst_solib_trampoline)
|
921 |
|
|
continue;
|
922 |
|
|
|
923 |
|
|
/* It must also be an export stub. */
|
924 |
|
|
u = find_unwind_entry (SYMBOL_VALUE (msymbol2));
|
925 |
|
|
if (!u || u->stub_unwind.stub_type != EXPORT)
|
926 |
|
|
continue;
|
927 |
|
|
|
928 |
|
|
/* OK. Looks like the correct import stub. */
|
929 |
|
|
anaddr = SYMBOL_VALUE (msymbol2);
|
930 |
|
|
dld_cache.hook_stub.address = anaddr;
|
931 |
|
|
}
|
932 |
|
|
}
|
933 |
|
|
store_unsigned_integer (buf, 4, anaddr);
|
934 |
|
|
|
935 |
|
|
msymbol = lookup_minimal_symbol ("__dld_hook", NULL, symfile_objfile);
|
936 |
|
|
if (msymbol == NULL)
|
937 |
|
|
{
|
938 |
|
|
warning ("Unable to find __dld_hook symbol in object file.");
|
939 |
|
|
warning ("Suggest linking with /opt/langtools/lib/end.o.");
|
940 |
|
|
warning ("GDB will be unable to track shl_load/shl_unload calls");
|
941 |
|
|
goto keep_going;
|
942 |
|
|
}
|
943 |
|
|
anaddr = SYMBOL_VALUE_ADDRESS (msymbol);
|
944 |
|
|
status = target_write_memory (anaddr, buf, 4);
|
945 |
|
|
|
946 |
|
|
/* Now set a shlib_event breakpoint at __d_trap so we can track
|
947 |
|
|
significant shared library events. */
|
948 |
|
|
msymbol = lookup_minimal_symbol ("__d_trap", NULL, symfile_objfile);
|
949 |
|
|
if (msymbol == NULL)
|
950 |
|
|
{
|
951 |
|
|
warning ("Unable to find __dld_d_trap symbol in object file.");
|
952 |
|
|
warning ("Suggest linking with /opt/langtools/lib/end.o.");
|
953 |
|
|
warning ("GDB will be unable to track shl_load/shl_unload calls");
|
954 |
|
|
goto keep_going;
|
955 |
|
|
}
|
956 |
|
|
create_solib_event_breakpoint (SYMBOL_VALUE_ADDRESS (msymbol));
|
957 |
|
|
|
958 |
|
|
/* We have all the support usually found in end.o, so we can track
|
959 |
|
|
shl_load and shl_unload calls. */
|
960 |
|
|
have_endo = 1;
|
961 |
|
|
|
962 |
|
|
keep_going:
|
963 |
|
|
|
964 |
|
|
/* Get the address of __dld_flags, if no such symbol exists, then we can
|
965 |
|
|
not debug the shared code. */
|
966 |
|
|
msymbol = lookup_minimal_symbol ("__dld_flags", NULL, NULL);
|
967 |
|
|
if (msymbol == NULL)
|
968 |
|
|
{
|
969 |
|
|
error ("Unable to find __dld_flags symbol in object file.\n");
|
970 |
|
|
}
|
971 |
|
|
|
972 |
|
|
anaddr = SYMBOL_VALUE_ADDRESS (msymbol);
|
973 |
|
|
|
974 |
|
|
/* Read the current contents. */
|
975 |
|
|
status = target_read_memory (anaddr, buf, 4);
|
976 |
|
|
if (status != 0)
|
977 |
|
|
{
|
978 |
|
|
error ("Unable to read __dld_flags\n");
|
979 |
|
|
}
|
980 |
|
|
dld_flags = extract_unsigned_integer (buf, 4);
|
981 |
|
|
|
982 |
|
|
/* Turn on the flags we care about. */
|
983 |
|
|
dld_flags |= DLD_FLAGS_MAPPRIVATE;
|
984 |
|
|
if (have_endo)
|
985 |
|
|
dld_flags |= DLD_FLAGS_HOOKVALID;
|
986 |
|
|
store_unsigned_integer (buf, 4, dld_flags);
|
987 |
|
|
status = target_write_memory (anaddr, buf, 4);
|
988 |
|
|
if (status != 0)
|
989 |
|
|
{
|
990 |
|
|
error ("Unable to write __dld_flags\n");
|
991 |
|
|
}
|
992 |
|
|
|
993 |
|
|
/* Now find the address of _start and set a breakpoint there.
|
994 |
|
|
We still need this code for two reasons:
|
995 |
|
|
|
996 |
|
|
* Not all sites have /opt/langtools/lib/end.o, so it's not always
|
997 |
|
|
possible to track the dynamic linker's events.
|
998 |
|
|
|
999 |
|
|
* At this time no events are triggered for shared libraries
|
1000 |
|
|
loaded at startup time (what a crock). */
|
1001 |
|
|
|
1002 |
|
|
msymbol = lookup_minimal_symbol ("_start", NULL, symfile_objfile);
|
1003 |
|
|
if (msymbol == NULL)
|
1004 |
|
|
{
|
1005 |
|
|
error ("Unable to find _start symbol in object file.\n");
|
1006 |
|
|
}
|
1007 |
|
|
|
1008 |
|
|
anaddr = SYMBOL_VALUE_ADDRESS (msymbol);
|
1009 |
|
|
|
1010 |
|
|
/* Make the breakpoint at "_start" a shared library event breakpoint. */
|
1011 |
|
|
create_solib_event_breakpoint (anaddr);
|
1012 |
|
|
|
1013 |
|
|
/* Wipe out all knowledge of old shared libraries since their
|
1014 |
|
|
mapping can change from one exec to another! */
|
1015 |
|
|
while (so_list_head)
|
1016 |
|
|
{
|
1017 |
|
|
struct so_list *temp;
|
1018 |
|
|
|
1019 |
|
|
temp = so_list_head;
|
1020 |
|
|
free (so_list_head);
|
1021 |
|
|
so_list_head = temp->next;
|
1022 |
|
|
}
|
1023 |
|
|
clear_symtab_users ();
|
1024 |
|
|
}
|
1025 |
|
|
|
1026 |
|
|
|
1027 |
|
|
static void
|
1028 |
|
|
reset_inferior_pid (saved_inferior_pid)
|
1029 |
|
|
int saved_inferior_pid;
|
1030 |
|
|
{
|
1031 |
|
|
inferior_pid = saved_inferior_pid;
|
1032 |
|
|
}
|
1033 |
|
|
|
1034 |
|
|
|
1035 |
|
|
/* This operation removes the "hook" between GDB and the dynamic linker,
|
1036 |
|
|
which causes the dld to notify GDB of shared library events.
|
1037 |
|
|
|
1038 |
|
|
After this operation completes, the dld will no longer notify GDB of
|
1039 |
|
|
shared library events. To resume notifications, GDB must call
|
1040 |
|
|
som_solib_create_inferior_hook.
|
1041 |
|
|
|
1042 |
|
|
This operation does not remove any knowledge of shared libraries which
|
1043 |
|
|
GDB may already have been notified of.
|
1044 |
|
|
*/
|
1045 |
|
|
void
|
1046 |
|
|
som_solib_remove_inferior_hook (pid)
|
1047 |
|
|
int pid;
|
1048 |
|
|
{
|
1049 |
|
|
CORE_ADDR addr;
|
1050 |
|
|
struct minimal_symbol *msymbol;
|
1051 |
|
|
int status;
|
1052 |
|
|
char dld_flags_buffer[TARGET_INT_BIT / TARGET_CHAR_BIT];
|
1053 |
|
|
unsigned int dld_flags_value;
|
1054 |
|
|
int saved_inferior_pid = inferior_pid;
|
1055 |
|
|
struct cleanup *old_cleanups = make_cleanup (reset_inferior_pid, saved_inferior_pid);
|
1056 |
|
|
|
1057 |
|
|
/* Ensure that we're really operating on the specified process. */
|
1058 |
|
|
inferior_pid = pid;
|
1059 |
|
|
|
1060 |
|
|
/* We won't bother to remove the solib breakpoints from this process.
|
1061 |
|
|
|
1062 |
|
|
In fact, on PA64 the breakpoint is hard-coded into the dld callback,
|
1063 |
|
|
and thus we're not supposed to remove it.
|
1064 |
|
|
|
1065 |
|
|
Rather, we'll merely clear the dld_flags bit that enables callbacks.
|
1066 |
|
|
*/
|
1067 |
|
|
msymbol = lookup_minimal_symbol ("__dld_flags", NULL, NULL);
|
1068 |
|
|
|
1069 |
|
|
addr = SYMBOL_VALUE_ADDRESS (msymbol);
|
1070 |
|
|
status = target_read_memory (addr, dld_flags_buffer, TARGET_INT_BIT / TARGET_CHAR_BIT);
|
1071 |
|
|
|
1072 |
|
|
dld_flags_value = extract_unsigned_integer (dld_flags_buffer,
|
1073 |
|
|
sizeof (dld_flags_value));
|
1074 |
|
|
|
1075 |
|
|
dld_flags_value &= ~DLD_FLAGS_HOOKVALID;
|
1076 |
|
|
store_unsigned_integer (dld_flags_buffer,
|
1077 |
|
|
sizeof (dld_flags_value),
|
1078 |
|
|
dld_flags_value);
|
1079 |
|
|
status = target_write_memory (addr, dld_flags_buffer, TARGET_INT_BIT / TARGET_CHAR_BIT);
|
1080 |
|
|
|
1081 |
|
|
do_cleanups (old_cleanups);
|
1082 |
|
|
}
|
1083 |
|
|
|
1084 |
|
|
|
1085 |
|
|
/* This function creates a breakpoint on the dynamic linker hook, which
|
1086 |
|
|
is called when e.g., a shl_load or shl_unload call is made. This
|
1087 |
|
|
breakpoint will only trigger when a shl_load call is made.
|
1088 |
|
|
|
1089 |
|
|
If filename is NULL, then loads of any dll will be caught. Else,
|
1090 |
|
|
only loads of the file whose pathname is the string contained by
|
1091 |
|
|
filename will be caught.
|
1092 |
|
|
|
1093 |
|
|
Undefined behaviour is guaranteed if this function is called before
|
1094 |
|
|
som_solib_create_inferior_hook.
|
1095 |
|
|
*/
|
1096 |
|
|
void
|
1097 |
|
|
som_solib_create_catch_load_hook (pid, tempflag, filename, cond_string)
|
1098 |
|
|
int pid;
|
1099 |
|
|
int tempflag;
|
1100 |
|
|
char *filename;
|
1101 |
|
|
char *cond_string;
|
1102 |
|
|
{
|
1103 |
|
|
create_solib_load_event_breakpoint ("__d_trap", tempflag, filename, cond_string);
|
1104 |
|
|
}
|
1105 |
|
|
|
1106 |
|
|
/* This function creates a breakpoint on the dynamic linker hook, which
|
1107 |
|
|
is called when e.g., a shl_load or shl_unload call is made. This
|
1108 |
|
|
breakpoint will only trigger when a shl_unload call is made.
|
1109 |
|
|
|
1110 |
|
|
If filename is NULL, then unloads of any dll will be caught. Else,
|
1111 |
|
|
only unloads of the file whose pathname is the string contained by
|
1112 |
|
|
filename will be caught.
|
1113 |
|
|
|
1114 |
|
|
Undefined behaviour is guaranteed if this function is called before
|
1115 |
|
|
som_solib_create_inferior_hook.
|
1116 |
|
|
*/
|
1117 |
|
|
void
|
1118 |
|
|
som_solib_create_catch_unload_hook (pid, tempflag, filename, cond_string)
|
1119 |
|
|
int pid;
|
1120 |
|
|
int tempflag;
|
1121 |
|
|
char *filename;
|
1122 |
|
|
char *cond_string;
|
1123 |
|
|
{
|
1124 |
|
|
create_solib_unload_event_breakpoint ("__d_trap", tempflag, filename, cond_string);
|
1125 |
|
|
}
|
1126 |
|
|
|
1127 |
|
|
int
|
1128 |
|
|
som_solib_have_load_event (pid)
|
1129 |
|
|
int pid;
|
1130 |
|
|
{
|
1131 |
|
|
CORE_ADDR event_kind;
|
1132 |
|
|
|
1133 |
|
|
event_kind = read_register (ARG0_REGNUM);
|
1134 |
|
|
return (event_kind == SHL_LOAD);
|
1135 |
|
|
}
|
1136 |
|
|
|
1137 |
|
|
int
|
1138 |
|
|
som_solib_have_unload_event (pid)
|
1139 |
|
|
int pid;
|
1140 |
|
|
{
|
1141 |
|
|
CORE_ADDR event_kind;
|
1142 |
|
|
|
1143 |
|
|
event_kind = read_register (ARG0_REGNUM);
|
1144 |
|
|
return (event_kind == SHL_UNLOAD);
|
1145 |
|
|
}
|
1146 |
|
|
|
1147 |
|
|
static char *
|
1148 |
|
|
som_solib_library_pathname (pid)
|
1149 |
|
|
int pid;
|
1150 |
|
|
{
|
1151 |
|
|
CORE_ADDR dll_handle_address;
|
1152 |
|
|
CORE_ADDR dll_pathname_address;
|
1153 |
|
|
struct som_solib_mapped_entry dll_descriptor;
|
1154 |
|
|
char *p;
|
1155 |
|
|
static char dll_pathname[1024];
|
1156 |
|
|
|
1157 |
|
|
/* Read the descriptor of this newly-loaded library. */
|
1158 |
|
|
dll_handle_address = read_register (ARG1_REGNUM);
|
1159 |
|
|
read_memory (dll_handle_address, (char *) &dll_descriptor, sizeof (dll_descriptor));
|
1160 |
|
|
|
1161 |
|
|
/* We can find a pointer to the dll's pathname within the descriptor. */
|
1162 |
|
|
dll_pathname_address = (CORE_ADDR) dll_descriptor.name;
|
1163 |
|
|
|
1164 |
|
|
/* Read the pathname, one byte at a time. */
|
1165 |
|
|
p = dll_pathname;
|
1166 |
|
|
for (;;)
|
1167 |
|
|
{
|
1168 |
|
|
char b;
|
1169 |
|
|
read_memory (dll_pathname_address++, (char *) &b, 1);
|
1170 |
|
|
*p++ = b;
|
1171 |
|
|
if (b == '\0')
|
1172 |
|
|
break;
|
1173 |
|
|
}
|
1174 |
|
|
|
1175 |
|
|
return dll_pathname;
|
1176 |
|
|
}
|
1177 |
|
|
|
1178 |
|
|
char *
|
1179 |
|
|
som_solib_loaded_library_pathname (pid)
|
1180 |
|
|
int pid;
|
1181 |
|
|
{
|
1182 |
|
|
if (!som_solib_have_load_event (pid))
|
1183 |
|
|
error ("Must have a load event to use this query");
|
1184 |
|
|
|
1185 |
|
|
return som_solib_library_pathname (pid);
|
1186 |
|
|
}
|
1187 |
|
|
|
1188 |
|
|
char *
|
1189 |
|
|
som_solib_unloaded_library_pathname (pid)
|
1190 |
|
|
int pid;
|
1191 |
|
|
{
|
1192 |
|
|
if (!som_solib_have_unload_event (pid))
|
1193 |
|
|
error ("Must have an unload event to use this query");
|
1194 |
|
|
|
1195 |
|
|
return som_solib_library_pathname (pid);
|
1196 |
|
|
}
|
1197 |
|
|
|
1198 |
|
|
static void
|
1199 |
|
|
som_solib_desire_dynamic_linker_symbols ()
|
1200 |
|
|
{
|
1201 |
|
|
struct objfile *objfile;
|
1202 |
|
|
struct unwind_table_entry *u;
|
1203 |
|
|
struct minimal_symbol *dld_msymbol;
|
1204 |
|
|
|
1205 |
|
|
/* Do we already know the value of these symbols? If so, then
|
1206 |
|
|
we've no work to do.
|
1207 |
|
|
|
1208 |
|
|
(If you add clauses to this test, be sure to likewise update the
|
1209 |
|
|
test within the loop.)
|
1210 |
|
|
*/
|
1211 |
|
|
if (dld_cache.is_valid)
|
1212 |
|
|
return;
|
1213 |
|
|
|
1214 |
|
|
ALL_OBJFILES (objfile)
|
1215 |
|
|
{
|
1216 |
|
|
dld_msymbol = lookup_minimal_symbol ("shl_load", NULL, objfile);
|
1217 |
|
|
if (dld_msymbol != NULL)
|
1218 |
|
|
{
|
1219 |
|
|
dld_cache.load.address = SYMBOL_VALUE (dld_msymbol);
|
1220 |
|
|
dld_cache.load.unwind = find_unwind_entry (dld_cache.load.address);
|
1221 |
|
|
}
|
1222 |
|
|
|
1223 |
|
|
dld_msymbol = lookup_minimal_symbol_solib_trampoline ("shl_load",
|
1224 |
|
|
NULL,
|
1225 |
|
|
objfile);
|
1226 |
|
|
if (dld_msymbol != NULL)
|
1227 |
|
|
{
|
1228 |
|
|
if (SYMBOL_TYPE (dld_msymbol) == mst_solib_trampoline)
|
1229 |
|
|
{
|
1230 |
|
|
u = find_unwind_entry (SYMBOL_VALUE (dld_msymbol));
|
1231 |
|
|
if ((u != NULL) && (u->stub_unwind.stub_type == EXPORT))
|
1232 |
|
|
{
|
1233 |
|
|
dld_cache.load_stub.address = SYMBOL_VALUE (dld_msymbol);
|
1234 |
|
|
dld_cache.load_stub.unwind = u;
|
1235 |
|
|
}
|
1236 |
|
|
}
|
1237 |
|
|
}
|
1238 |
|
|
|
1239 |
|
|
dld_msymbol = lookup_minimal_symbol ("shl_unload", NULL, objfile);
|
1240 |
|
|
if (dld_msymbol != NULL)
|
1241 |
|
|
{
|
1242 |
|
|
dld_cache.unload.address = SYMBOL_VALUE (dld_msymbol);
|
1243 |
|
|
dld_cache.unload.unwind = find_unwind_entry (dld_cache.unload.address);
|
1244 |
|
|
|
1245 |
|
|
/* ??rehrauer: I'm not sure exactly what this is, but it appears
|
1246 |
|
|
that on some HPUX 10.x versions, there's two unwind regions to
|
1247 |
|
|
cover the body of "shl_unload", the second being 4 bytes past
|
1248 |
|
|
the end of the first. This is a large hack to handle that
|
1249 |
|
|
case, but since I don't seem to have any legitimate way to
|
1250 |
|
|
look for this thing via the symbol table...
|
1251 |
|
|
*/
|
1252 |
|
|
if (dld_cache.unload.unwind != NULL)
|
1253 |
|
|
{
|
1254 |
|
|
u = find_unwind_entry (dld_cache.unload.unwind->region_end + 4);
|
1255 |
|
|
if (u != NULL)
|
1256 |
|
|
{
|
1257 |
|
|
dld_cache.unload2.address = u->region_start;
|
1258 |
|
|
dld_cache.unload2.unwind = u;
|
1259 |
|
|
}
|
1260 |
|
|
}
|
1261 |
|
|
}
|
1262 |
|
|
|
1263 |
|
|
dld_msymbol = lookup_minimal_symbol_solib_trampoline ("shl_unload",
|
1264 |
|
|
NULL,
|
1265 |
|
|
objfile);
|
1266 |
|
|
if (dld_msymbol != NULL)
|
1267 |
|
|
{
|
1268 |
|
|
if (SYMBOL_TYPE (dld_msymbol) == mst_solib_trampoline)
|
1269 |
|
|
{
|
1270 |
|
|
u = find_unwind_entry (SYMBOL_VALUE (dld_msymbol));
|
1271 |
|
|
if ((u != NULL) && (u->stub_unwind.stub_type == EXPORT))
|
1272 |
|
|
{
|
1273 |
|
|
dld_cache.unload_stub.address = SYMBOL_VALUE (dld_msymbol);
|
1274 |
|
|
dld_cache.unload_stub.unwind = u;
|
1275 |
|
|
}
|
1276 |
|
|
}
|
1277 |
|
|
}
|
1278 |
|
|
|
1279 |
|
|
/* Did we find everything we were looking for? If so, stop. */
|
1280 |
|
|
if ((dld_cache.load.address != NULL) && (dld_cache.load_stub.address != NULL)
|
1281 |
|
|
&& (dld_cache.unload.address != NULL) && (dld_cache.unload_stub.address != NULL))
|
1282 |
|
|
{
|
1283 |
|
|
dld_cache.is_valid = 1;
|
1284 |
|
|
break;
|
1285 |
|
|
}
|
1286 |
|
|
}
|
1287 |
|
|
|
1288 |
|
|
dld_cache.hook.unwind = find_unwind_entry (dld_cache.hook.address);
|
1289 |
|
|
dld_cache.hook_stub.unwind = find_unwind_entry (dld_cache.hook_stub.address);
|
1290 |
|
|
|
1291 |
|
|
/* We're prepared not to find some of these symbols, which is why
|
1292 |
|
|
this function is a "desire" operation, and not a "require".
|
1293 |
|
|
*/
|
1294 |
|
|
}
|
1295 |
|
|
|
1296 |
|
|
int
|
1297 |
|
|
som_solib_in_dynamic_linker (pid, pc)
|
1298 |
|
|
int pid;
|
1299 |
|
|
CORE_ADDR pc;
|
1300 |
|
|
{
|
1301 |
|
|
struct unwind_table_entry *u_pc;
|
1302 |
|
|
|
1303 |
|
|
/* Are we in the dld itself?
|
1304 |
|
|
|
1305 |
|
|
??rehrauer: Large hack -- We'll assume that any address in a
|
1306 |
|
|
shared text region is the dld's text. This would obviously
|
1307 |
|
|
fall down if the user attached to a process, whose shlibs
|
1308 |
|
|
weren't mapped to a (writeable) private region. However, in
|
1309 |
|
|
that case the debugger probably isn't able to set the fundamental
|
1310 |
|
|
breakpoint in the dld callback anyways, so this hack should be
|
1311 |
|
|
safe.
|
1312 |
|
|
*/
|
1313 |
|
|
if ((pc & (CORE_ADDR) 0xc0000000) == (CORE_ADDR) 0xc0000000)
|
1314 |
|
|
return 1;
|
1315 |
|
|
|
1316 |
|
|
/* Cache the address of some symbols that are part of the dynamic
|
1317 |
|
|
linker, if not already known.
|
1318 |
|
|
*/
|
1319 |
|
|
som_solib_desire_dynamic_linker_symbols ();
|
1320 |
|
|
|
1321 |
|
|
/* Are we in the dld callback? Or its export stub? */
|
1322 |
|
|
u_pc = find_unwind_entry (pc);
|
1323 |
|
|
if (u_pc == NULL)
|
1324 |
|
|
return 0;
|
1325 |
|
|
|
1326 |
|
|
if ((u_pc == dld_cache.hook.unwind) || (u_pc == dld_cache.hook_stub.unwind))
|
1327 |
|
|
return 1;
|
1328 |
|
|
|
1329 |
|
|
/* Or the interface of the dld (i.e., "shl_load" or friends)? */
|
1330 |
|
|
if ((u_pc == dld_cache.load.unwind)
|
1331 |
|
|
|| (u_pc == dld_cache.unload.unwind)
|
1332 |
|
|
|| (u_pc == dld_cache.unload2.unwind)
|
1333 |
|
|
|| (u_pc == dld_cache.load_stub.unwind)
|
1334 |
|
|
|| (u_pc == dld_cache.unload_stub.unwind))
|
1335 |
|
|
return 1;
|
1336 |
|
|
|
1337 |
|
|
/* Apparently this address isn't part of the dld's text. */
|
1338 |
|
|
return 0;
|
1339 |
|
|
}
|
1340 |
|
|
|
1341 |
|
|
|
1342 |
|
|
/* Return the GOT value for the shared library in which ADDR belongs. If
|
1343 |
|
|
ADDR isn't in any known shared library, return zero. */
|
1344 |
|
|
|
1345 |
|
|
CORE_ADDR
|
1346 |
|
|
som_solib_get_got_by_pc (addr)
|
1347 |
|
|
CORE_ADDR addr;
|
1348 |
|
|
{
|
1349 |
|
|
struct so_list *so_list = so_list_head;
|
1350 |
|
|
CORE_ADDR got_value = 0;
|
1351 |
|
|
|
1352 |
|
|
while (so_list)
|
1353 |
|
|
{
|
1354 |
|
|
if (so_list->som_solib.text_addr <= addr
|
1355 |
|
|
&& so_list->som_solib.text_end > addr)
|
1356 |
|
|
{
|
1357 |
|
|
got_value = so_list->som_solib.got_value;
|
1358 |
|
|
break;
|
1359 |
|
|
}
|
1360 |
|
|
so_list = so_list->next;
|
1361 |
|
|
}
|
1362 |
|
|
return got_value;
|
1363 |
|
|
}
|
1364 |
|
|
|
1365 |
|
|
/* elz:
|
1366 |
|
|
Return the address of the handle of the shared library
|
1367 |
|
|
in which ADDR belongs. If
|
1368 |
|
|
ADDR isn't in any known shared library, return zero. */
|
1369 |
|
|
/* this function is used in hppa_fix_call_dummy in hppa-tdep.c */
|
1370 |
|
|
|
1371 |
|
|
CORE_ADDR
|
1372 |
|
|
som_solib_get_solib_by_pc (addr)
|
1373 |
|
|
CORE_ADDR addr;
|
1374 |
|
|
{
|
1375 |
|
|
struct so_list *so_list = so_list_head;
|
1376 |
|
|
|
1377 |
|
|
while (so_list)
|
1378 |
|
|
{
|
1379 |
|
|
if (so_list->som_solib.text_addr <= addr
|
1380 |
|
|
&& so_list->som_solib.text_end > addr)
|
1381 |
|
|
{
|
1382 |
|
|
break;
|
1383 |
|
|
}
|
1384 |
|
|
so_list = so_list->next;
|
1385 |
|
|
}
|
1386 |
|
|
if (so_list)
|
1387 |
|
|
return so_list->solib_addr;
|
1388 |
|
|
else
|
1389 |
|
|
return 0;
|
1390 |
|
|
}
|
1391 |
|
|
|
1392 |
|
|
|
1393 |
|
|
int
|
1394 |
|
|
som_solib_section_offsets (objfile, offsets)
|
1395 |
|
|
struct objfile *objfile;
|
1396 |
|
|
struct section_offsets *offsets;
|
1397 |
|
|
{
|
1398 |
|
|
struct so_list *so_list = so_list_head;
|
1399 |
|
|
|
1400 |
|
|
while (so_list)
|
1401 |
|
|
{
|
1402 |
|
|
/* Oh what a pain! We need the offsets before so_list->objfile
|
1403 |
|
|
is valid. The BFDs will never match. Make a best guess. */
|
1404 |
|
|
if (strstr (objfile->name, so_list->som_solib.name))
|
1405 |
|
|
{
|
1406 |
|
|
asection *private_section;
|
1407 |
|
|
|
1408 |
|
|
/* The text offset is easy. */
|
1409 |
|
|
ANOFFSET (offsets, SECT_OFF_TEXT)
|
1410 |
|
|
= (so_list->som_solib.text_addr
|
1411 |
|
|
- so_list->som_solib.text_link_addr);
|
1412 |
|
|
ANOFFSET (offsets, SECT_OFF_RODATA)
|
1413 |
|
|
= ANOFFSET (offsets, SECT_OFF_TEXT);
|
1414 |
|
|
|
1415 |
|
|
/* We should look at presumed_dp in the SOM header, but
|
1416 |
|
|
that's not easily available. This should be OK though. */
|
1417 |
|
|
private_section = bfd_get_section_by_name (objfile->obfd,
|
1418 |
|
|
"$PRIVATE$");
|
1419 |
|
|
if (!private_section)
|
1420 |
|
|
{
|
1421 |
|
|
warning ("Unable to find $PRIVATE$ in shared library!");
|
1422 |
|
|
ANOFFSET (offsets, SECT_OFF_DATA) = 0;
|
1423 |
|
|
ANOFFSET (offsets, SECT_OFF_BSS) = 0;
|
1424 |
|
|
return 1;
|
1425 |
|
|
}
|
1426 |
|
|
ANOFFSET (offsets, SECT_OFF_DATA)
|
1427 |
|
|
= (so_list->som_solib.data_start - private_section->vma);
|
1428 |
|
|
ANOFFSET (offsets, SECT_OFF_BSS)
|
1429 |
|
|
= ANOFFSET (offsets, SECT_OFF_DATA);
|
1430 |
|
|
return 1;
|
1431 |
|
|
}
|
1432 |
|
|
so_list = so_list->next;
|
1433 |
|
|
}
|
1434 |
|
|
return 0;
|
1435 |
|
|
}
|
1436 |
|
|
|
1437 |
|
|
/* Dump information about all the currently loaded shared libraries. */
|
1438 |
|
|
|
1439 |
|
|
static void
|
1440 |
|
|
som_sharedlibrary_info_command (ignore, from_tty)
|
1441 |
|
|
char *ignore;
|
1442 |
|
|
int from_tty;
|
1443 |
|
|
{
|
1444 |
|
|
struct so_list *so_list = so_list_head;
|
1445 |
|
|
|
1446 |
|
|
if (exec_bfd == NULL)
|
1447 |
|
|
{
|
1448 |
|
|
printf_unfiltered ("No executable file.\n");
|
1449 |
|
|
return;
|
1450 |
|
|
}
|
1451 |
|
|
|
1452 |
|
|
if (so_list == NULL)
|
1453 |
|
|
{
|
1454 |
|
|
printf_unfiltered ("No shared libraries loaded at this time.\n");
|
1455 |
|
|
return;
|
1456 |
|
|
}
|
1457 |
|
|
|
1458 |
|
|
printf_unfiltered ("Shared Object Libraries\n");
|
1459 |
|
|
printf_unfiltered (" %-12s%-12s%-12s%-12s%-12s%-12s\n",
|
1460 |
|
|
" flags", " tstart", " tend", " dstart", " dend", " dlt");
|
1461 |
|
|
while (so_list)
|
1462 |
|
|
{
|
1463 |
|
|
unsigned int flags;
|
1464 |
|
|
|
1465 |
|
|
flags = so_list->som_solib.struct_version << 24;
|
1466 |
|
|
flags |= so_list->som_solib.bind_mode << 16;
|
1467 |
|
|
flags |= so_list->som_solib.library_version;
|
1468 |
|
|
printf_unfiltered ("%s", so_list->som_solib.name);
|
1469 |
|
|
if (so_list->objfile == NULL)
|
1470 |
|
|
printf_unfiltered (" (symbols not loaded)");
|
1471 |
|
|
printf_unfiltered ("\n");
|
1472 |
|
|
printf_unfiltered (" %-12s", local_hex_string_custom (flags, "08l"));
|
1473 |
|
|
printf_unfiltered ("%-12s",
|
1474 |
|
|
local_hex_string_custom (so_list->som_solib.text_addr, "08l"));
|
1475 |
|
|
printf_unfiltered ("%-12s",
|
1476 |
|
|
local_hex_string_custom (so_list->som_solib.text_end, "08l"));
|
1477 |
|
|
printf_unfiltered ("%-12s",
|
1478 |
|
|
local_hex_string_custom (so_list->som_solib.data_start, "08l"));
|
1479 |
|
|
printf_unfiltered ("%-12s",
|
1480 |
|
|
local_hex_string_custom (so_list->som_solib.data_end, "08l"));
|
1481 |
|
|
printf_unfiltered ("%-12s\n",
|
1482 |
|
|
local_hex_string_custom (so_list->som_solib.got_value, "08l"));
|
1483 |
|
|
so_list = so_list->next;
|
1484 |
|
|
}
|
1485 |
|
|
}
|
1486 |
|
|
|
1487 |
|
|
static void
|
1488 |
|
|
som_solib_sharedlibrary_command (args, from_tty)
|
1489 |
|
|
char *args;
|
1490 |
|
|
int from_tty;
|
1491 |
|
|
{
|
1492 |
|
|
dont_repeat ();
|
1493 |
|
|
som_solib_add (args, from_tty, (struct target_ops *) 0);
|
1494 |
|
|
}
|
1495 |
|
|
|
1496 |
|
|
|
1497 |
|
|
|
1498 |
|
|
char *
|
1499 |
|
|
som_solib_address (addr)
|
1500 |
|
|
CORE_ADDR addr;
|
1501 |
|
|
{
|
1502 |
|
|
struct so_list *so = so_list_head;
|
1503 |
|
|
|
1504 |
|
|
while (so)
|
1505 |
|
|
{
|
1506 |
|
|
/* Is this address within this shlib's text range? If so,
|
1507 |
|
|
return the shlib's name.
|
1508 |
|
|
*/
|
1509 |
|
|
if ((addr >= so->som_solib.text_addr) && (addr <= so->som_solib.text_end))
|
1510 |
|
|
return so->som_solib.name;
|
1511 |
|
|
|
1512 |
|
|
/* Nope, keep looking... */
|
1513 |
|
|
so = so->next;
|
1514 |
|
|
}
|
1515 |
|
|
|
1516 |
|
|
/* No, we couldn't prove that the address is within a shlib. */
|
1517 |
|
|
return NULL;
|
1518 |
|
|
}
|
1519 |
|
|
|
1520 |
|
|
|
1521 |
|
|
void
|
1522 |
|
|
som_solib_restart ()
|
1523 |
|
|
{
|
1524 |
|
|
struct so_list *sl = so_list_head;
|
1525 |
|
|
|
1526 |
|
|
/* Before the shlib info vanishes, use it to disable any breakpoints
|
1527 |
|
|
that may still be active in those shlibs.
|
1528 |
|
|
*/
|
1529 |
|
|
disable_breakpoints_in_shlibs (0);
|
1530 |
|
|
|
1531 |
|
|
/* Discard all the shlib descriptors.
|
1532 |
|
|
*/
|
1533 |
|
|
while (sl)
|
1534 |
|
|
{
|
1535 |
|
|
struct so_list *next_sl = sl->next;
|
1536 |
|
|
free (sl);
|
1537 |
|
|
sl = next_sl;
|
1538 |
|
|
}
|
1539 |
|
|
so_list_head = NULL;
|
1540 |
|
|
|
1541 |
|
|
som_solib_total_st_size = (LONGEST) 0;
|
1542 |
|
|
som_solib_st_size_threshold_exceeded = 0;
|
1543 |
|
|
|
1544 |
|
|
dld_cache.is_valid = 0;
|
1545 |
|
|
|
1546 |
|
|
dld_cache.hook.address = 0;
|
1547 |
|
|
dld_cache.hook.unwind = NULL;
|
1548 |
|
|
|
1549 |
|
|
dld_cache.hook_stub.address = 0;
|
1550 |
|
|
dld_cache.hook_stub.unwind = NULL;
|
1551 |
|
|
|
1552 |
|
|
dld_cache.load.address = 0;
|
1553 |
|
|
dld_cache.load.unwind = NULL;
|
1554 |
|
|
|
1555 |
|
|
dld_cache.load_stub.address = 0;
|
1556 |
|
|
dld_cache.load_stub.unwind = NULL;
|
1557 |
|
|
|
1558 |
|
|
dld_cache.unload.address = 0;
|
1559 |
|
|
dld_cache.unload.unwind = NULL;
|
1560 |
|
|
|
1561 |
|
|
dld_cache.unload2.address = 0;
|
1562 |
|
|
dld_cache.unload2.unwind = NULL;
|
1563 |
|
|
|
1564 |
|
|
dld_cache.unload_stub.address = 0;
|
1565 |
|
|
dld_cache.unload_stub.unwind = NULL;
|
1566 |
|
|
}
|
1567 |
|
|
|
1568 |
|
|
|
1569 |
|
|
|
1570 |
|
|
void
|
1571 |
|
|
_initialize_som_solib ()
|
1572 |
|
|
{
|
1573 |
|
|
add_com ("sharedlibrary", class_files, som_solib_sharedlibrary_command,
|
1574 |
|
|
"Load shared object library symbols for files matching REGEXP.");
|
1575 |
|
|
add_info ("sharedlibrary", som_sharedlibrary_info_command,
|
1576 |
|
|
"Status of loaded shared object libraries.");
|
1577 |
|
|
add_show_from_set
|
1578 |
|
|
(add_set_cmd ("auto-solib-add", class_support, var_zinteger,
|
1579 |
|
|
(char *) &auto_solib_add,
|
1580 |
|
|
"Set autoloading size threshold (in megabytes) of shared library symbols.\n\
|
1581 |
|
|
If nonzero, symbols from all shared object libraries will be loaded\n\
|
1582 |
|
|
automatically when the inferior begins execution or when the dynamic linker\n\
|
1583 |
|
|
informs gdb that a new library has been loaded, until the symbol table\n\
|
1584 |
|
|
of the program and libraries exceeds this threshold.\n\
|
1585 |
|
|
Otherwise, symbols must be loaded manually, using `sharedlibrary'.",
|
1586 |
|
|
&setlist),
|
1587 |
|
|
&showlist);
|
1588 |
|
|
|
1589 |
|
|
/* ??rehrauer: On HP-UX, the kernel parameter MAXDSIZ limits how much
|
1590 |
|
|
data space a process can use. We ought to be reading MAXDSIZ and
|
1591 |
|
|
setting auto_solib_add to some large fraction of that value. If
|
1592 |
|
|
not that, we maybe ought to be setting it smaller than the default
|
1593 |
|
|
for MAXDSIZ (that being 64Mb, I believe). However, [1] this threshold
|
1594 |
|
|
is only crudely approximated rather than actually measured, and [2]
|
1595 |
|
|
50 Mbytes is too small for debugging gdb itself. Thus, the arbitrary
|
1596 |
|
|
100 figure.
|
1597 |
|
|
*/
|
1598 |
|
|
auto_solib_add = 100; /* Megabytes */
|
1599 |
|
|
|
1600 |
|
|
som_solib_restart ();
|
1601 |
|
|
}
|
1602 |
|
|
|
1603 |
|
|
/* Get some HPUX-specific data from a shared lib.
|
1604 |
|
|
*/
|
1605 |
|
|
CORE_ADDR
|
1606 |
|
|
so_lib_thread_start_addr (so)
|
1607 |
|
|
struct so_list *so;
|
1608 |
|
|
{
|
1609 |
|
|
return so->som_solib.tsd_start_addr;
|
1610 |
|
|
}
|