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