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