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