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