1 /* Handle HP ELF shared libraries for GDB, the GNU Debugger.
2 Copyright 1999 Free Software Foundation, Inc.
4 This file is part of GDB.
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.
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.
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.
21 HP in their infinite stupidity choose not to use standard ELF dynamic
22 linker interfaces. They also choose not to make their ELF dymamic
23 linker interfaces compatible with the SOM dynamic linker. The
24 net result is we can not use either of the existing somsolib.c or
25 solib.c. What a crock.
27 Even more disgusting. This file depends on functions provided only
28 in certain PA64 libraries. Thus this file is supposed to only be
29 used native. When will HP ever learn that they need to provide the
30 same functionality in all their libraries! */
43 #include "breakpoint.h"
47 #include "gdb-stabs.h"
59 /* Defined in exec.c; used to prevent dangling pointer bug. */
60 extern struct target_ops exec_ops
;
63 bfd_lookup_symbol
PARAMS ((bfd
*, char *));
64 /* This lives in hppa-tdep.c. */
65 extern struct unwind_table_entry
*find_unwind_entry
PARAMS ((CORE_ADDR pc
));
67 /* These ought to be defined in some public interface, but aren't. They
68 identify dynamic linker events. */
70 #define DLD_CB_UNLOAD 0
72 /* A structure to keep track of all the known shared objects. */
78 struct objfile
*objfile
;
79 CORE_ADDR pa64_solib_desc_addr
;
80 struct load_module_desc pa64_solib_desc
;
81 struct section_table
*sections
;
82 struct section_table
*sections_end
;
86 static struct so_list
*so_list_head
;
88 /* This is the cumulative size in bytes of the symbol tables of all
89 shared objects on the so_list_head list. (When we say size, here
90 we mean of the information before it is brought into memory and
91 potentially expanded by GDB.) When adding a new shlib, this value
92 is compared against the threshold size, held by auto_solib_add
93 (in megabytes). If adding symbols for the new shlib would cause
94 the total size to exceed the threshold, then the new shlib's symbols
96 static LONGEST pa64_solib_total_st_size
;
98 /* When the threshold is reached for any shlib, we refuse to add
99 symbols for subsequent shlibs, even if those shlibs' symbols would
100 be small enough to fit under the threshold. (Although this may
101 result in one, early large shlib preventing the loading of later,
102 smalller shlibs' symbols, it allows us to issue one informational
103 message. The alternative, to issue a message for each shlib whose
104 symbols aren't loaded, could be a big annoyance where the threshold
105 is exceeded due to a very large number of shlibs.) */
106 static int pa64_solib_st_size_threshold_exceeded
;
108 /* When adding fields, be sure to clear them in _initialize_pa64_solib. */
111 CORE_ADDR dld_flags_addr
;
113 sec_ptr dyninfo_sect
;
114 boolean have_read_dld_descriptor
;
117 CORE_ADDR load_map_addr
;
118 struct load_module_desc dld_desc
;
122 static dld_cache_t dld_cache
;
124 static void pa64_sharedlibrary_info_command
PARAMS ((char *, int));
126 static void pa64_solib_sharedlibrary_command
PARAMS ((char *, int));
128 static void * pa64_target_read_memory
PARAMS ((void *, CORE_ADDR
, size_t, int));
130 static boolean read_dld_descriptor
PARAMS ((struct target_ops
*));
132 static boolean read_dynamic_info
PARAMS ((asection
*, dld_cache_t
*));
134 static void add_to_solist
PARAMS ((boolean
, char *, struct load_module_desc
*,
135 CORE_ADDR
, struct target_ops
*));
137 /* When examining the shared library for debugging information we have to
138 look for HP debug symbols, stabs and dwarf2 debug symbols. */
139 static char *pa64_debug_section_names
[] = {
140 ".debug_header", ".debug_gntt", ".debug_lntt", ".debug_slt", ".debug_vt",
141 ".stabs", ".stabstr", ".debug_info", ".debug_abbrev", ".debug_aranges",
142 ".debug_macinfo", ".debug_line", ".debug_loc", ".debug_pubnames",
146 /* Return a ballbark figure for the amount of memory GDB will need to
147 allocate to read in the debug symbols from FILENAME. */
149 pa64_solib_sizeof_symbol_table (filename
)
156 LONGEST st_size
= (LONGEST
) 0;
159 /* We believe that filename was handed to us by the dynamic linker, and
160 is therefore always an absolute path. */
161 desc
= openp (getenv ("PATH"), 1, filename
, O_RDONLY
| O_BINARY
,
165 perror_with_name (filename
);
167 filename
= absolute_name
;
169 abfd
= bfd_fdopenr (filename
, gnutarget
, desc
);
173 make_cleanup (free
, filename
);
174 error ("\"%s\": can't open to read symbols: %s.", filename
,
175 bfd_errmsg (bfd_get_error ()));
178 if (!bfd_check_format (abfd
, bfd_object
))
181 make_cleanup (free
, filename
);
182 error ("\"%s\": can't read symbols: %s.", filename
,
183 bfd_errmsg (bfd_get_error ()));
186 /* Sum the sizes of the various sections that compose debug info. */
187 for (i
= 0; pa64_debug_section_names
[i
] != NULL
; i
++)
191 sect
= bfd_get_section_by_name (abfd
, pa64_debug_section_names
[i
]);
193 st_size
+= (LONGEST
)bfd_section_size (abfd
, sect
);
199 /* Unfortunately, just summing the sizes of various debug info
200 sections isn't a very accurate measurement of how much heap
201 space the debugger will need to hold them. It also doesn't
202 account for space needed by linker (aka "minimal") symbols.
204 Anecdotal evidence suggests that just summing the sizes of
205 debug-info-related sections understates the heap space needed
206 to represent it internally by about an order of magnitude.
208 Since it's not exactly brain surgery we're doing here, rather
209 than attempt to more accurately measure the size of a shlib's
210 symbol table in GDB's heap, we'll just apply a 10x fudge-
211 factor to the debug info sections' size-sum. No, this doesn't
212 account for minimal symbols in non-debuggable shlibs. But it
213 all roughly washes out in the end. */
214 return st_size
* (LONGEST
) 10;
217 /* Add a shared library to the objfile list and load its symbols into
218 GDB's symbol table. */
220 pa64_solib_add_solib_objfile (so
, name
, from_tty
, text_addr
)
228 obj_private_data_t
*obj_private
;
230 /* We need the BFD so that we can look at its sections. We open up the
231 file temporarily, then close it when we are done. */
232 tmp_bfd
= bfd_openr (name
, gnutarget
);
235 perror_with_name (name
);
239 if (!bfd_check_format (tmp_bfd
, bfd_object
))
242 error ("\"%s\" is not an object file: %s", name
,
243 bfd_errmsg (bfd_get_error ()));
247 /* Undo some braindamage from symfile.c.
249 First, symfile.c will subtract the VMA of the first .text section
250 in the shared library that it finds. Undo that. */
251 sec
= bfd_get_section_by_name (tmp_bfd
, ".text");
252 text_addr
+= bfd_section_vma (tmp_bfd
, sec
);
254 /* Now find the true lowest section in the shared library. */
256 bfd_map_over_sections (tmp_bfd
, find_lowest_section
, (PTR
) &sec
);
260 /* Subtract out the VMA of the lowest section. */
261 text_addr
-= bfd_section_vma (tmp_bfd
, sec
);
263 /* ??? Add back in the filepos of that lowest section. */
264 text_addr
+= sec
->filepos
;
267 /* We are done with the temporary bfd. Get rid of it and make sure
268 nobody else can us it. */
272 /* Now let the generic code load up symbols for this library. */
273 so
->objfile
= symbol_file_add (name
, from_tty
, text_addr
, 0, 0, 0, 0, 1);
274 so
->abfd
= so
->objfile
->obfd
;
276 /* Mark this as a shared library and save private data. */
277 so
->objfile
->flags
|= OBJF_SHARED
;
279 if (so
->objfile
->obj_private
== NULL
)
281 obj_private
= (obj_private_data_t
*)
282 obstack_alloc (&so
->objfile
->psymbol_obstack
,
283 sizeof (obj_private_data_t
));
284 obj_private
->unwind_info
= NULL
;
285 obj_private
->so_info
= NULL
;
286 so
->objfile
->obj_private
= (PTR
) obj_private
;
289 obj_private
= (obj_private_data_t
*) so
->objfile
->obj_private
;
290 obj_private
->so_info
= so
;
291 obj_private
->dp
= so
->pa64_solib_desc
.linkage_ptr
;
294 /* Load debugging information for a shared library. TARGET may be
295 NULL if we are not attaching to a process or reading a core file. */
298 pa64_solib_load_symbols (so
, name
, from_tty
, text_addr
, target
)
303 struct target_ops
*target
;
305 struct section_table
*p
;
309 CORE_ADDR presumed_data_start
;
312 text_addr
= so
->pa64_solib_desc
.text_base
;
314 pa64_solib_add_solib_objfile (so
, name
, from_tty
, text_addr
);
316 /* Now we need to build a section table for this library since
317 we might be debugging a core file from a dynamically linked
318 executable in which the libraries were not privately mapped. */
319 if (build_section_table (so
->abfd
,
323 error ("Unable to build section table for shared library\n.");
327 ANOFFSET (so
->objfile
->section_offsets
, SECT_OFF_TEXT
)
328 = so
->pa64_solib_desc
.text_base
;
329 ANOFFSET (so
->objfile
->section_offsets
, SECT_OFF_DATA
)
330 = so
->pa64_solib_desc
.data_base
;
332 /* Relocate all the sections based on where they got loaded. */
333 for (p
= so
->sections
; p
< so
->sections_end
; p
++)
335 if (p
->the_bfd_section
->flags
& SEC_CODE
)
337 p
->addr
+= ANOFFSET (so
->objfile
->section_offsets
, SECT_OFF_TEXT
);
338 p
->endaddr
+= ANOFFSET (so
->objfile
->section_offsets
, SECT_OFF_TEXT
);
340 else if (p
->the_bfd_section
->flags
& SEC_DATA
)
342 p
->addr
+= ANOFFSET (so
->objfile
->section_offsets
, SECT_OFF_DATA
);
343 p
->endaddr
+= ANOFFSET (so
->objfile
->section_offsets
, SECT_OFF_DATA
);
347 /* Now see if we need to map in the text and data for this shared
348 library (for example debugging a core file which does not use
349 private shared libraries.).
351 Carefully peek at the first text address in the library. If the
352 read succeeds, then the libraries were privately mapped and were
353 included in the core dump file.
355 If the peek failed, then the libraries were not privately mapped
356 and are not in the core file, we'll have to read them in ourselves. */
357 status
= target_read_memory (text_addr
, buf
, 4);
364 /* We must update the to_sections field in the core_ops structure
365 here, otherwise we dereference a potential dangling pointer
366 for each call to target_read/write_memory within this routine. */
367 update_coreops
= core_ops
.to_sections
== target
->to_sections
;
369 /* Ditto exec_ops (this was a bug). */
370 update_execops
= exec_ops
.to_sections
== target
->to_sections
;
372 new = so
->sections_end
- so
->sections
;
373 /* Add sections from the shared library to the core target. */
374 if (target
->to_sections
)
376 old
= target
->to_sections_end
- target
->to_sections
;
377 target
->to_sections
= (struct section_table
*)
378 xrealloc ((char *) target
->to_sections
,
379 ((sizeof (struct section_table
)) * (old
+ new)));
384 target
->to_sections
= (struct section_table
*)
385 xmalloc ((sizeof (struct section_table
)) * new);
387 target
->to_sections_end
= (target
->to_sections
+ old
+ new);
389 /* Update the to_sections field in the core_ops structure
390 if needed, ditto exec_ops. */
393 core_ops
.to_sections
= target
->to_sections
;
394 core_ops
.to_sections_end
= target
->to_sections_end
;
399 exec_ops
.to_sections
= target
->to_sections
;
400 exec_ops
.to_sections_end
= target
->to_sections_end
;
403 /* Copy over the old data before it gets clobbered. */
404 memcpy ((char *) (target
->to_sections
+ old
),
406 ((sizeof (struct section_table
)) * new));
411 /* Add symbols from shared libraries into the symtab list, unless the
412 size threshold (specified by auto_solib_add, in megabytes) would
416 pa64_solib_add (arg_string
, from_tty
, target
)
419 struct target_ops
*target
;
421 struct minimal_symbol
*msymbol
;
423 asection
*shlib_info
;
425 unsigned int dld_flags
;
426 char buf
[4], *re_err
;
427 int threshold_warning_given
= 0;
429 struct load_module_desc dll_desc
;
432 /* First validate our arguments. */
433 if ((re_err
= re_comp (arg_string
? arg_string
: ".")) != NULL
)
435 error ("Invalid regexp: %s", re_err
);
438 /* If we're debugging a core file, or have attached to a running
439 process, then pa64_solib_create_inferior_hook will not have been
442 We need to first determine if we're dealing with a dynamically
443 linked executable. If not, then return without an error or warning.
445 We also need to examine __dld_flags to determine if the shared library
446 list is valid and to determine if the libraries have been privately
448 if (symfile_objfile
== NULL
)
451 /* First see if the objfile was dynamically linked. */
452 shlib_info
= bfd_get_section_by_name (symfile_objfile
->obfd
, ".dynamic");
456 /* It's got a .dynamic section, make sure it's not empty. */
457 if (bfd_section_size (symfile_objfile
->obfd
, shlib_info
) == 0)
460 /* Read in the load map pointer if we have not done so already. */
461 if (! dld_cache
.have_read_dld_descriptor
)
462 if (! read_dld_descriptor (target
))
465 /* If the libraries were not mapped private, warn the user. */
466 if ((dld_cache
.dld_flags
& DT_HP_DEBUG_PRIVATE
) == 0)
467 warning ("The shared libraries were not privately mapped; setting a\nbreakpoint in a shared library will not work until you rerun the program.\n");
469 /* For each shaerd library, add it to the shared library list. */
470 for (dll_index
= 1; ; dll_index
++)
472 /* Read in the load module descriptor. */
473 if (dlgetmodinfo (dll_index
, &dll_desc
, sizeof (dll_desc
),
474 pa64_target_read_memory
, 0, dld_cache
.load_map
)
478 /* Get the name of the shared library. */
479 dll_path
= (char *)dlgetname (&dll_desc
, sizeof (dll_desc
),
480 pa64_target_read_memory
,
481 0, dld_cache
.load_map
);
484 error ("pa64_solib_add, unable to read shared library path.");
486 add_to_solist (from_tty
, dll_path
, &dll_desc
, 0, target
);
491 /* This hook gets called just before the first instruction in the
492 inferior process is executed.
494 This is our opportunity to set magic flags in the inferior so
495 that GDB can be notified when a shared library is mapped in and
496 to tell the dynamic linker that a private copy of the library is
497 needed (so GDB can set breakpoints in the library).
499 We need to set two flag bits in this routine.
501 DT_HP_DEBUG_PRIVATE to indicate that shared libraries should be
504 DT_HP_DEBUG_CALLBACK to indicate that we want the dynamic linker to
505 call the breakpoint routine for significant events. */
508 pa64_solib_create_inferior_hook ()
510 struct minimal_symbol
*msymbol
;
511 unsigned int dld_flags
, status
;
512 asection
*shlib_info
, *interp_sect
;
514 struct objfile
*objfile
;
517 /* First, remove all the solib event breakpoints. Their addresses
518 may have changed since the last time we ran the program. */
519 remove_solib_event_breakpoints ();
521 if (symfile_objfile
== NULL
)
524 /* First see if the objfile was dynamically linked. */
525 shlib_info
= bfd_get_section_by_name (symfile_objfile
->obfd
, ".dynamic");
529 /* It's got a .dynamic section, make sure it's not empty. */
530 if (bfd_section_size (symfile_objfile
->obfd
, shlib_info
) == 0)
533 /* Read in the .dynamic section. */
534 if (! read_dynamic_info (shlib_info
, &dld_cache
))
535 error ("Unable to read the .dynamic section.");
537 /* Turn on the flags we care about. */
538 dld_cache
.dld_flags
|= DT_HP_DEBUG_PRIVATE
;
539 dld_cache
.dld_flags
|= DT_HP_DEBUG_CALLBACK
;
540 status
= target_write_memory (dld_cache
.dld_flags_addr
,
541 (char *) &dld_cache
.dld_flags
,
542 sizeof (dld_cache
.dld_flags
));
544 error ("Unable to modify dynamic linker flags.");
546 /* Now we have to create a shared library breakpoint in the dynamic
547 linker. This can be somewhat tricky since the symbol is inside
548 the dynamic linker (for which we do not have symbols or a base
549 load address! Luckily I wrote this code for solib.c years ago. */
550 interp_sect
= bfd_get_section_by_name (exec_bfd
, ".interp");
553 unsigned int interp_sect_size
;
557 CORE_ADDR sym_addr
= 0;
559 /* Read the contents of the .interp section into a local buffer;
560 the contents specify the dynamic linker this program uses. */
561 interp_sect_size
= bfd_section_size (exec_bfd
, interp_sect
);
562 buf
= alloca (interp_sect_size
);
563 bfd_get_section_contents (exec_bfd
, interp_sect
,
564 buf
, 0, interp_sect_size
);
566 /* Now we need to figure out where the dynamic linker was
567 loaded so that we can load its symbols and place a breakpoint
568 in the dynamic linker itself.
570 This address is stored on the stack. However, I've been unable
571 to find any magic formula to find it for Solaris (appears to
572 be trivial on GNU/Linux). Therefore, we have to try an alternate
573 mechanism to find the dynamic linker's base address. */
574 tmp_bfd
= bfd_openr (buf
, gnutarget
);
578 /* Make sure the dynamic linker's really a useful object. */
579 if (!bfd_check_format (tmp_bfd
, bfd_object
))
581 warning ("Unable to grok dynamic linker %s as an object file", buf
);
586 /* We find the dynamic linker's base address by examining the
587 current pc (which point at the entry point for the dynamic
588 linker) and subtracting the offset of the entry point.
590 Also note the breakpoint is the second instruction in the
592 load_addr
= read_pc () - tmp_bfd
->start_address
;
593 sym_addr
= bfd_lookup_symbol (tmp_bfd
, "__dld_break");
594 sym_addr
= load_addr
+ sym_addr
+ 4;
596 /* Create the shared library breakpoint. */
599 = create_solib_event_breakpoint (sym_addr
);
601 /* The breakpoint is actually hard-coded into the dynamic linker,
602 so we don't need to actually insert a breakpoint instruction
603 there. In fact, the dynamic linker's code is immutable, even to
604 ttrace, so we shouldn't even try to do that. For cases like
605 this, we have "permanent" breakpoints. */
606 make_breakpoint_permanent (b
);
609 /* We're done with the temporary bfd. */
614 /* Wipe out all knowledge of old shared libraries since their
615 mapping can change from one exec to another! */
618 struct so_list
*temp
;
622 so_list_head
= temp
->next
;
624 clear_symtab_users ();
627 /* This operation removes the "hook" between GDB and the dynamic linker,
628 which causes the dld to notify GDB of shared library events.
630 After this operation completes, the dld will no longer notify GDB of
631 shared library events. To resume notifications, GDB must call
632 pa64_solib_create_inferior_hook.
634 This operation does not remove any knowledge of shared libraries which
635 GDB may already have been notified of. */
638 pa64_solib_remove_inferior_hook (pid
)
641 /* Turn off the DT_HP_DEBUG_CALLBACK bit in the dynamic linker flags. */
642 dld_cache
.dld_flags
&= ~DT_HP_DEBUG_CALLBACK
;
643 target_write_memory (dld_cache
.dld_flags_addr
,
644 (char *)&dld_cache
.dld_flags
,
645 sizeof (dld_cache
.dld_flags
));
648 /* This function creates a breakpoint on the dynamic linker hook, which
649 is called when e.g., a shl_load or shl_unload call is made. This
650 breakpoint will only trigger when a shl_load call is made.
652 If filename is NULL, then loads of any dll will be caught. Else,
653 only loads of the file whose pathname is the string contained by
654 filename will be caught.
656 Undefined behaviour is guaranteed if this function is called before
657 pa64_solib_create_inferior_hook. */
660 pa64_solib_create_catch_load_hook (pid
, tempflag
, filename
, cond_string
)
666 create_solib_load_event_breakpoint ("", tempflag
, filename
, cond_string
);
669 /* This function creates a breakpoint on the dynamic linker hook, which
670 is called when e.g., a shl_load or shl_unload call is made. This
671 breakpoint will only trigger when a shl_unload call is made.
673 If filename is NULL, then unloads of any dll will be caught. Else,
674 only unloads of the file whose pathname is the string contained by
675 filename will be caught.
677 Undefined behaviour is guaranteed if this function is called before
678 pa64_solib_create_inferior_hook. */
681 pa64_solib_create_catch_unload_hook (pid
, tempflag
, filename
, cond_string
)
687 create_solib_unload_event_breakpoint ("", tempflag
, filename
, cond_string
);
690 /* Return nonzero if the dynamic linker has reproted that a library
694 pa64_solib_have_load_event (pid
)
697 CORE_ADDR event_kind
;
699 event_kind
= read_register (ARG0_REGNUM
);
700 return (event_kind
== DLD_CB_LOAD
);
703 /* Return nonzero if the dynamic linker has reproted that a library
704 has been unloaded. */
706 pa64_solib_have_unload_event (pid
)
709 CORE_ADDR event_kind
;
711 event_kind
= read_register (ARG0_REGNUM
);
712 return (event_kind
== DLD_CB_UNLOAD
);
715 /* Return a pointer to a string indicating the pathname of the most
716 recently loaded library.
718 The caller is reposible for copying the string before the inferior is
722 pa64_solib_loaded_library_pathname (pid
)
725 static char dll_path
[MAXPATHLEN
];
726 CORE_ADDR dll_path_addr
= read_register (ARG3_REGNUM
);
727 read_memory_string (dll_path_addr
, dll_path
, MAXPATHLEN
);
731 /* Return a pointer to a string indicating the pathname of the most
732 recently unloaded library.
734 The caller is reposible for copying the string before the inferior is
738 pa64_solib_unloaded_library_pathname (pid
)
741 static char dll_path
[MAXPATHLEN
];
742 CORE_ADDR dll_path_addr
= read_register (ARG3_REGNUM
);
743 read_memory_string (dll_path_addr
, dll_path
, MAXPATHLEN
);
747 /* Return nonzero if PC is an address inside the dynamic linker. */
750 pa64_solib_in_dynamic_linker (pid
, pc
)
754 asection
*shlib_info
;
756 if (symfile_objfile
== NULL
)
759 if (!dld_cache
.have_read_dld_descriptor
)
760 if (!read_dld_descriptor (¤t_target
))
763 return (pc
>= dld_cache
.dld_desc
.text_base
764 && pc
< dld_cache
.dld_desc
.text_base
+ dld_cache
.dld_desc
.text_size
);
768 /* Return the GOT value for the shared library in which ADDR belongs. If
769 ADDR isn't in any known shared library, return zero. */
772 pa64_solib_get_got_by_pc (addr
)
775 struct so_list
*so_list
= so_list_head
;
776 CORE_ADDR got_value
= 0;
780 if (so_list
->pa64_solib_desc
.text_base
<= addr
781 && ((so_list
->pa64_solib_desc
.text_base
782 + so_list
->pa64_solib_desc
.text_size
)
785 got_value
= so_list
->pa64_solib_desc
.linkage_ptr
;
788 so_list
= so_list
->next
;
793 /* Return the address of the handle of the shared library in which ADDR
794 belongs. If ADDR isn't in any known shared library, return zero.
796 This function is used in hppa_fix_call_dummy in hppa-tdep.c. */
799 pa64_solib_get_solib_by_pc (addr
)
802 struct so_list
*so_list
= so_list_head
;
803 CORE_ADDR retval
= 0;
807 if (so_list
->pa64_solib_desc
.text_base
<= addr
808 && ((so_list
->pa64_solib_desc
.text_base
809 + so_list
->pa64_solib_desc
.text_size
)
812 retval
= so_list
->pa64_solib_desc_addr
;
815 so_list
= so_list
->next
;
820 /* Dump information about all the currently loaded shared libraries. */
823 pa64_sharedlibrary_info_command (ignore
, from_tty
)
827 struct so_list
*so_list
= so_list_head
;
829 if (exec_bfd
== NULL
)
831 printf_unfiltered ("no exec file.\n");
837 printf_unfiltered ("No shared libraries loaded at this time.\n");
841 printf_unfiltered ("Shared Object Libraries\n");
842 printf_unfiltered (" %-19s%-19s%-19s%-19s\n",
843 " text start", " text end",
844 " data start", " data end");
849 printf_unfiltered ("%s", so_list
->name
);
850 if (so_list
->objfile
== NULL
)
851 printf_unfiltered (" (symbols not loaded)");
852 if (so_list
->loaded
== 0)
853 printf_unfiltered (" (shared library unloaded)");
854 printf_unfiltered (" %-18s",
855 local_hex_string_custom (so_list
->pa64_solib_desc
.linkage_ptr
,
857 printf_unfiltered ("\n");
858 printf_unfiltered ("%-18s",
859 local_hex_string_custom (so_list
->pa64_solib_desc
.text_base
,
861 printf_unfiltered (" %-18s",
862 local_hex_string_custom ((so_list
->pa64_solib_desc
.text_base
863 + so_list
->pa64_solib_desc
.text_size
),
865 printf_unfiltered (" %-18s",
866 local_hex_string_custom (so_list
->pa64_solib_desc
.data_base
,
868 printf_unfiltered (" %-18s\n",
869 local_hex_string_custom ((so_list
->pa64_solib_desc
.data_base
870 + so_list
->pa64_solib_desc
.data_size
),
872 so_list
= so_list
->next
;
876 /* Load up one or more shared libraries as directed by the user. */
879 pa64_solib_sharedlibrary_command (args
, from_tty
)
884 pa64_solib_add (args
, from_tty
, (struct target_ops
*) 0);
887 /* Return the name of the shared library containing ADDR or NULL if ADDR
888 is not contained in any known shared library. */
891 pa64_solib_address (addr
)
894 struct so_list
*so
= so_list_head
;
898 /* Is this address within this shlib's text range? If so,
899 return the shlib's name. */
900 if (addr
>= so
->pa64_solib_desc
.text_base
901 && addr
< (so
->pa64_solib_desc
.text_base
902 | so
->pa64_solib_desc
.text_size
))
905 /* Nope, keep looking... */
909 /* No, we couldn't prove that the address is within a shlib. */
913 /* We are killing the inferior and restarting the program. */
916 pa64_solib_restart ()
918 struct so_list
*sl
= so_list_head
;
920 /* Before the shlib info vanishes, use it to disable any breakpoints
921 that may still be active in those shlibs. */
922 disable_breakpoints_in_shlibs (0);
924 /* Discard all the shlib descriptors. */
927 struct so_list
*next_sl
= sl
->next
;
933 pa64_solib_total_st_size
= (LONGEST
) 0;
934 pa64_solib_st_size_threshold_exceeded
= 0;
936 dld_cache
.is_valid
= 0;
937 dld_cache
.have_read_dld_descriptor
= 0;
938 dld_cache
.dld_flags_addr
= 0;
939 dld_cache
.load_map
= 0;
940 dld_cache
.load_map_addr
= 0;
941 dld_cache
.dld_desc
.data_base
= 0;
942 dld_cache
.dld_flags
= 0;
943 dld_cache
.dyninfo_sect
= 0;
947 _initialize_pa64_solib ()
949 add_com ("sharedlibrary", class_files
, pa64_solib_sharedlibrary_command
,
950 "Load shared object library symbols for files matching REGEXP.");
951 add_info ("sharedlibrary", pa64_sharedlibrary_info_command
,
952 "Status of loaded shared object libraries.");
954 (add_set_cmd ("auto-solib-add", class_support
, var_zinteger
,
955 (char *) &auto_solib_add
,
956 "Set autoloading size threshold (in megabytes) of shared library symbols.\n\
957 If nonzero, symbols from all shared object libraries will be loaded\n\
958 automatically when the inferior begins execution or when the dynamic linker\n\
959 informs gdb that a new library has been loaded, until the symbol table\n\
960 of the program and libraries exceeds this threshold.\n\
961 Otherwise, symbols must be loaded manually, using `sharedlibrary'.",
965 /* ??rehrauer: On HP-UX, the kernel parameter MAXDSIZ limits how much
966 data space a process can use. We ought to be reading MAXDSIZ and
967 setting auto_solib_add to some large fraction of that value. If
968 not that, we maybe ought to be setting it smaller than the default
969 for MAXDSIZ (that being 64Mb, I believe). However, [1] this threshold
970 is only crudely approximated rather than actually measured, and [2]
971 50 Mbytes is too small for debugging gdb itself. Thus, the arbitrary
974 auto_solib_add
= 100; /* Megabytes */
976 pa64_solib_restart ();
979 /* Get some HPUX-specific data from a shared lib. */
981 so_lib_thread_start_addr (so
)
984 return so
->pa64_solib_desc
.tls_start_addr
;
987 /* Read the dynamic linker's internal shared library descriptor.
989 This must happen after dld starts running, so we can't do it in
990 read_dynamic_info. Record the fact that we have loaded the
991 descriptor. If the library is archive bound, then return zero, else
995 read_dld_descriptor (target
)
996 struct target_ops
*target
;
999 asection
*dyninfo_sect
;
1001 /* If necessary call read_dynamic_info to extract the contents of the
1002 .dynamic section from the shared library. */
1003 if (!dld_cache
.is_valid
)
1005 if (symfile_objfile
== NULL
)
1006 error ("No object file symbols.");
1008 dyninfo_sect
= bfd_get_section_by_name (symfile_objfile
->obfd
,
1015 if (!read_dynamic_info (dyninfo_sect
, &dld_cache
))
1016 error ("Unable to read in .dynamic section information.");
1019 /* Read the load map pointer. */
1020 if (target_read_memory (dld_cache
.load_map_addr
,
1021 (char*) &dld_cache
.load_map
,
1022 sizeof(dld_cache
.load_map
))
1025 error ("Error while reading in load map pointer.");
1028 /* Read in the dld load module descriptor */
1029 if (dlgetmodinfo (-1,
1030 &dld_cache
.dld_desc
,
1031 sizeof(dld_cache
.dld_desc
),
1032 pa64_target_read_memory
,
1037 error ("Error trying to get information about dynamic linker.");
1040 /* Indicate that we have loaded the dld descriptor. */
1041 dld_cache
.have_read_dld_descriptor
= 1;
1043 /* Add dld.sl to the list of known shared libraries so that we can
1046 ?!? This may not be correct. Consider of dld.sl contains symbols
1047 which are also referenced/defined by the user program or some user
1048 shared library. We need to make absolutely sure that we do not
1049 pollute the namespace from GDB's point of view. */
1050 dll_path
= dlgetname (&dld_cache
.dld_desc
,
1051 sizeof(dld_cache
.dld_desc
),
1052 pa64_target_read_memory
,
1054 dld_cache
.load_map
);
1055 add_to_solist(0, dll_path
, &dld_cache
.dld_desc
, 0, target
);
1060 /* Read the .dynamic section and extract the information of interest,
1061 which is stored in dld_cache. The routine elf_locate_base in solib.c
1062 was used as a model for this. */
1065 read_dynamic_info (dyninfo_sect
, dld_cache_p
)
1066 asection
*dyninfo_sect
;
1067 dld_cache_t
*dld_cache_p
;
1071 CORE_ADDR dyninfo_addr
;
1072 int dyninfo_sect_size
;
1073 CORE_ADDR entry_addr
;
1075 /* Read in .dynamic section, silently ignore errors. */
1076 dyninfo_addr
= bfd_section_vma (symfile_objfile
->obfd
, dyninfo_sect
);
1077 dyninfo_sect_size
= bfd_section_size (exec_bfd
, dyninfo_sect
);
1078 buf
= alloca (dyninfo_sect_size
);
1079 if (target_read_memory (dyninfo_addr
, buf
, dyninfo_sect_size
))
1082 /* Scan the .dynamic section and record the items of interest.
1083 In particular, DT_HP_DLD_FLAGS */
1084 for (bufend
= buf
+ dyninfo_sect_size
, entry_addr
= dyninfo_addr
;
1086 buf
+= sizeof (Elf64_Dyn
), entry_addr
+= sizeof (Elf64_Dyn
))
1088 Elf64_Dyn
*x_dynp
= (Elf64_Dyn
*)buf
;
1089 Elf64_Sxword dyn_tag
;
1091 char pbuf
[TARGET_PTR_BIT
/ HOST_CHAR_BIT
];
1093 dyn_tag
= bfd_h_get_64 (symfile_objfile
->obfd
,
1094 (bfd_byte
*) &x_dynp
->d_tag
);
1096 /* We can't use a switch here because dyn_tag is 64 bits and HP's
1097 lame comiler does not handle 64bit items in switch statements. */
1098 if (dyn_tag
== DT_NULL
)
1100 else if (dyn_tag
== DT_HP_DLD_FLAGS
)
1102 /* Set dld_flags_addr and dld_flags in *dld_cache_p */
1103 dld_cache_p
->dld_flags_addr
= entry_addr
+ offsetof(Elf64_Dyn
, d_un
);
1104 if (target_read_memory (dld_cache_p
->dld_flags_addr
,
1105 (char*) &dld_cache_p
->dld_flags
,
1106 sizeof(dld_cache_p
->dld_flags
))
1109 error ("Error while reading in .dynamic section of the program.");
1112 else if (dyn_tag
== DT_HP_LOAD_MAP
)
1114 /* Dld will place the address of the load map at load_map_addr
1115 after it starts running. */
1116 if (target_read_memory (entry_addr
+ offsetof(Elf64_Dyn
,
1118 (char*) &dld_cache_p
->load_map_addr
,
1119 sizeof(dld_cache_p
->load_map_addr
))
1122 error ("Error while reading in .dynamic section of the program.");
1127 /* tag is not of interest */
1131 /* Record other information and set is_valid to 1. */
1132 dld_cache_p
->dyninfo_sect
= dyninfo_sect
;
1134 /* Verify that we read in required info. These fields are re-set to zero
1135 in pa64_solib_restart. */
1137 if (dld_cache_p
->dld_flags_addr
!= 0 && dld_cache_p
->load_map_addr
!= 0)
1138 dld_cache_p
->is_valid
= 1;
1145 /* Wrapper for target_read_memory to make dlgetmodinfo happy. */
1148 pa64_target_read_memory (buffer
, ptr
, bufsiz
, ident
)
1154 if (target_read_memory (ptr
, buffer
, bufsiz
) != 0)
1159 /* Called from handle_dynlink_load_event and pa64_solib_add to add
1160 a shared library to so_list_head list and possibly to read in the
1161 debug information for the library.
1163 If load_module_desc_p is NULL, then the load module descriptor must
1164 be read from the inferior process at the address load_module_desc_addr. */
1167 add_to_solist (from_tty
, dll_path
, load_module_desc_p
,
1168 load_module_desc_addr
, target
)
1171 struct load_module_desc
*load_module_desc_p
;
1172 CORE_ADDR load_module_desc_addr
;
1173 struct target_ops
*target
;
1175 struct so_list
*new_so
, *so_list_tail
;
1176 int pa64_solib_st_size_threshhold_exceeded
;
1179 if (symfile_objfile
== NULL
)
1182 so_list_tail
= so_list_head
;
1183 /* Find the end of the list of shared objects. */
1184 while (so_list_tail
&& so_list_tail
->next
)
1186 if (strcmp (so_list_tail
->name
, dll_path
) == 0)
1188 so_list_tail
= so_list_tail
->next
;
1191 if (so_list_tail
&& strcmp (so_list_tail
->name
, dll_path
) == 0)
1194 /* Add the shared library to the so_list_head list */
1195 new_so
= (struct so_list
*) xmalloc (sizeof (struct so_list
));
1196 memset ((char *)new_so
, 0, sizeof (struct so_list
));
1197 if (so_list_head
== NULL
)
1199 so_list_head
= new_so
;
1200 so_list_tail
= new_so
;
1204 so_list_tail
->next
= new_so
;
1205 so_list_tail
= new_so
;
1208 /* Initialize the new_so */
1209 if (load_module_desc_p
)
1211 new_so
->pa64_solib_desc
= *load_module_desc_p
;
1215 if (target_read_memory (load_module_desc_addr
,
1216 (char*) &new_so
->pa64_solib_desc
,
1217 sizeof(struct load_module_desc
))
1220 error ("Error while reading in dynamic library %s", dll_path
);
1224 new_so
->pa64_solib_desc_addr
= load_module_desc_addr
;
1226 new_so
->name
= obsavestring (dll_path
, strlen(dll_path
),
1227 &symfile_objfile
->symbol_obstack
);
1229 /* If we are not going to load the library, tell the user if we
1230 haven't already and return. */
1232 st_size
= pa64_solib_sizeof_symbol_table (dll_path
);
1233 pa64_solib_st_size_threshhold_exceeded
=
1235 && ( (st_size
+ pa64_solib_total_st_size
)
1236 > (auto_solib_add
* (LONGEST
)1000000));
1237 if (pa64_solib_st_size_threshhold_exceeded
)
1239 pa64_solib_add_solib_objfile (new_so
, dll_path
, from_tty
, 1);
1243 /* Now read in debug info. */
1244 pa64_solib_total_st_size
+= st_size
;
1246 /* This fills in new_so->objfile, among others. */
1247 pa64_solib_load_symbols (new_so
,
1258 bfd_lookup_symbol -- lookup the value for a specific symbol
1262 CORE_ADDR bfd_lookup_symbol (bfd *abfd, char *symname)
1266 An expensive way to lookup the value of a single symbol for
1267 bfd's that are only temporary anyway. This is used by the
1268 shared library support to find the address of the debugger
1269 interface structures in the shared library.
1271 Note that 0 is specifically allowed as an error return (no
1276 bfd_lookup_symbol (abfd
, symname
)
1280 unsigned int storage_needed
;
1282 asymbol
**symbol_table
;
1283 unsigned int number_of_symbols
;
1285 struct cleanup
*back_to
;
1286 CORE_ADDR symaddr
= 0;
1288 storage_needed
= bfd_get_symtab_upper_bound (abfd
);
1290 if (storage_needed
> 0)
1292 symbol_table
= (asymbol
**) xmalloc (storage_needed
);
1293 back_to
= make_cleanup (free
, (PTR
) symbol_table
);
1294 number_of_symbols
= bfd_canonicalize_symtab (abfd
, symbol_table
);
1296 for (i
= 0; i
< number_of_symbols
; i
++)
1298 sym
= *symbol_table
++;
1299 if (STREQ (sym
->name
, symname
))
1301 /* Bfd symbols are section relative. */
1302 symaddr
= sym
->value
+ sym
->section
->vma
;
1306 do_cleanups (back_to
);