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