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