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