1 /* Handle SunOS and SVR4 shared libraries for GDB, the GNU Debugger.
2 Copyright 1990, 91, 92, 93, 94, 95, 96, 98, 1999
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 /* $FreeBSD: src/contrib/gdb/gdb/solib.c,v 1.7 1999/11/22 18:04:53 peter Exp $ */
22 /* $DragonFly: src/contrib/gdb/gdb/Attic/solib.c,v 1.2 2003/06/17 04:24:02 dillon Exp $ */
26 /* This file is only compilable if link.h is available. */
30 #include <sys/types.h>
32 #include "gdb_string.h"
33 #include <sys/param.h>
37 #ifndef SVR4_SHARED_LIBS
38 /* SunOS shared libs need the nlist structure. */
41 #include "elf/external.h"
42 #include "elf/common.h"
55 #include "gnu-regex.h"
61 #define MAX_PATH_SIZE 512 /* FIXME: Should be dynamic */
63 /* On SVR4 systems, a list of symbols in the dynamic linker where
64 GDB can try to place a breakpoint to monitor shared library
67 If none of these symbols are found, or other errors occur, then
68 SVR4 systems will fall back to using a symbol as the "startup
69 mapping complete" breakpoint address. */
71 #ifdef SVR4_SHARED_LIBS
72 static char *solib_break_names[] = {
81 #define BKPT_AT_SYMBOL 1
83 #if defined (BKPT_AT_SYMBOL) && defined (SVR4_SHARED_LIBS)
84 static char *bkpt_names[] = {
85 #ifdef SOLIB_BKPT_NAME
86 SOLIB_BKPT_NAME, /* Prefer configured name if it exists. */
94 /* Symbols which are used to locate the base of the link map structures. */
96 #ifndef SVR4_SHARED_LIBS
97 static char *debug_base_symbols[] = {
104 static char *main_name_list[] = {
109 /* local data declarations */
111 #ifndef SVR4_SHARED_LIBS
113 #define LM_ADDR(so) ((so) -> lm.lm_addr)
114 #define LM_NEXT(so) ((so) -> lm.lm_next)
115 #define LM_NAME(so) ((so) -> lm.lm_name)
116 /* Test for first link map entry; first entry is a shared library. */
117 #define IGNORE_FIRST_LINK_MAP_ENTRY(x) (0)
118 static struct link_dynamic dynamic_copy;
119 static struct link_dynamic_2 ld_2_copy;
120 static struct ld_debug debug_copy;
121 static CORE_ADDR debug_addr;
122 static CORE_ADDR flag_addr;
124 #else /* SVR4_SHARED_LIBS */
126 #define LM_ADDR(so) ((so) -> lm.l_addr)
127 #define LM_NEXT(so) ((so) -> lm.l_next)
128 #define LM_NAME(so) ((so) -> lm.l_name)
129 /* Test for first link map entry; first entry is the exec-file. */
130 #define IGNORE_FIRST_LINK_MAP_ENTRY(x) ((x).l_prev == NULL)
131 static struct r_debug debug_copy;
132 char shadow_contents[BREAKPOINT_MAX]; /* Stash old bkpt addr contents */
134 #endif /* !SVR4_SHARED_LIBS */
137 struct so_list *next; /* next structure in linked list */
138 struct link_map lm; /* copy of link map from inferior */
139 struct link_map *lmaddr; /* addr in inferior lm was read from */
140 CORE_ADDR lmend; /* upper addr bound of mapped object */
141 char so_name[MAX_PATH_SIZE]; /* shared object lib name (FIXME) */
142 char symbols_loaded; /* flag: symbols read in yet? */
143 char from_tty; /* flag: print msgs? */
144 struct objfile *objfile; /* objfile for loaded lib */
145 struct section_table *sections;
146 struct section_table *sections_end;
147 struct section_table *textsection;
151 static struct so_list *so_list_head; /* List of known shared objects */
152 static CORE_ADDR debug_base; /* Base of dynamic linker structures */
153 static CORE_ADDR breakpoint_addr; /* Address where end bkpt is set */
155 static int solib_cleanup_queued = 0; /* make_run_cleanup called */
158 fdmatch PARAMS ((int, int)); /* In libiberty */
160 /* Local function prototypes */
163 do_clear_solib PARAMS ((PTR));
166 match_main PARAMS ((char *));
169 special_symbol_handling PARAMS ((struct so_list *));
172 sharedlibrary_command PARAMS ((char *, int));
175 enable_break PARAMS ((void));
178 info_sharedlibrary_command PARAMS ((char *, int));
180 static int symbol_add_stub PARAMS ((PTR));
182 static struct so_list *
183 alloc_solib PARAMS ((struct link_map *));
186 free_solib PARAMS ((struct so_list *));
188 static struct so_list *
189 find_solib PARAMS ((struct so_list *, int maybe_changed));
191 static struct link_map *
192 first_link_map_member PARAMS ((void));
195 locate_base PARAMS ((void));
197 static int solib_map_sections PARAMS ((PTR));
199 #ifdef SVR4_SHARED_LIBS
202 elf_locate_base PARAMS ((void));
207 disable_break PARAMS ((void));
210 allocate_rt_common_objfile PARAMS ((void));
213 solib_add_common_symbols PARAMS ((struct rtc_symb *));
217 void _initialize_solib PARAMS ((void));
219 /* If non-zero, this is a prefix that will be added to the front of the name
220 shared libraries with an absolute filename for loading. */
221 static char *solib_absolute_prefix = NULL;
223 /* If non-empty, this is a search path for loading non-absolute shared library
224 symbol files. This takes precedence over the environment variables PATH
225 and LD_LIBRARY_PATH. */
226 static char *solib_search_path = NULL;
232 solib_map_sections -- open bfd and build sections for shared lib
236 static int solib_map_sections (struct so_list *so)
240 Given a pointer to one of the shared objects in our list
241 of mapped objects, use the recorded name to open a bfd
242 descriptor for the object, build a section table, and then
243 relocate all the section addresses by the base address at
244 which the shared object was mapped.
248 In most (all?) cases the shared object file name recorded in the
249 dynamic linkage tables will be a fully qualified pathname. For
250 cases where it isn't, do we really mimic the systems search
251 mechanism correctly in the below code (particularly the tilde
256 solib_map_sections (arg)
259 struct so_list *so = (struct so_list *) arg; /* catch_errors bogon */
261 char *scratch_pathname;
263 struct section_table *p;
264 struct cleanup *old_chain;
267 filename = tilde_expand (so -> so_name);
269 if (solib_absolute_prefix && ROOTED_P (filename))
270 /* Prefix shared libraries with absolute filenames with
271 SOLIB_ABSOLUTE_PREFIX. */
276 pfx_len = strlen (solib_absolute_prefix);
278 /* Remove trailing slashes. */
279 while (pfx_len > 0 && SLASH_P (solib_absolute_prefix[pfx_len - 1]))
282 pfxed_fn = xmalloc (pfx_len + strlen (filename) + 1);
283 strcpy (pfxed_fn, solib_absolute_prefix);
284 strcat (pfxed_fn, filename);
290 old_chain = make_cleanup (free, filename);
294 if (solib_search_path)
295 scratch_chan = openp (solib_search_path,
296 1, filename, O_RDONLY, 0, &scratch_pathname);
297 if (scratch_chan < 0)
298 scratch_chan = openp (get_in_environ (inferior_environ, "PATH"),
299 1, filename, O_RDONLY, 0, &scratch_pathname);
300 if (scratch_chan < 0)
302 scratch_chan = openp (get_in_environ
303 (inferior_environ, "LD_LIBRARY_PATH"),
304 1, filename, O_RDONLY, 0, &scratch_pathname);
306 if (scratch_chan < 0)
308 perror_with_name (filename);
310 /* Leave scratch_pathname allocated. abfd->name will point to it. */
312 abfd = bfd_fdopenr (scratch_pathname, gnutarget, scratch_chan);
315 close (scratch_chan);
316 error ("Could not open `%s' as an executable file: %s",
317 scratch_pathname, bfd_errmsg (bfd_get_error ()));
319 /* Leave bfd open, core_xfer_memory and "info files" need it. */
321 abfd -> cacheable = true;
323 /* copy full path name into so_name, so that later symbol_file_add can find
325 if (strlen (scratch_pathname) >= MAX_PATH_SIZE)
326 error ("Full path name length of shared library exceeds MAX_PATH_SIZE in so_list structure.");
327 strcpy (so->so_name, scratch_pathname);
329 if (!bfd_check_format (abfd, bfd_object))
331 error ("\"%s\": not in executable format: %s.",
332 scratch_pathname, bfd_errmsg (bfd_get_error ()));
334 if (build_section_table (abfd, &so -> sections, &so -> sections_end))
336 error ("Can't find the file sections in `%s': %s",
337 bfd_get_filename (abfd), bfd_errmsg (bfd_get_error ()));
340 for (p = so -> sections; p < so -> sections_end; p++)
342 /* Relocate the section binding addresses as recorded in the shared
343 object's file by the base address to which the object was actually
345 p -> addr += (CORE_ADDR) LM_ADDR (so);
346 p -> endaddr += (CORE_ADDR) LM_ADDR (so);
347 so -> lmend = (CORE_ADDR) max (p -> endaddr, so -> lmend);
348 if (STREQ (p -> the_bfd_section -> name, ".text"))
350 so -> textsection = p;
354 /* Free the file names, close the file now. */
355 do_cleanups (old_chain);
360 #ifndef SVR4_SHARED_LIBS
362 /* Allocate the runtime common object file. */
365 allocate_rt_common_objfile ()
367 struct objfile *objfile;
368 struct objfile *last_one;
370 objfile = (struct objfile *) xmalloc (sizeof (struct objfile));
371 memset (objfile, 0, sizeof (struct objfile));
372 objfile -> md = NULL;
373 obstack_specify_allocation (&objfile -> psymbol_cache.cache, 0, 0,
375 obstack_specify_allocation (&objfile -> psymbol_obstack, 0, 0, xmalloc,
377 obstack_specify_allocation (&objfile -> symbol_obstack, 0, 0, xmalloc,
379 obstack_specify_allocation (&objfile -> type_obstack, 0, 0, xmalloc,
381 objfile -> name = mstrsave (objfile -> md, "rt_common");
383 /* Add this file onto the tail of the linked list of other such files. */
385 objfile -> next = NULL;
386 if (object_files == NULL)
387 object_files = objfile;
390 for (last_one = object_files;
392 last_one = last_one -> next);
393 last_one -> next = objfile;
396 rt_common_objfile = objfile;
399 /* Read all dynamically loaded common symbol definitions from the inferior
400 and put them into the minimal symbol table for the runtime common
404 solib_add_common_symbols (rtc_symp)
405 struct rtc_symb *rtc_symp;
407 struct rtc_symb inferior_rtc_symb;
408 struct nlist inferior_rtc_nlist;
412 /* Remove any runtime common symbols from previous runs. */
414 if (rt_common_objfile != NULL && rt_common_objfile -> minimal_symbol_count)
416 obstack_free (&rt_common_objfile -> symbol_obstack, 0);
417 obstack_specify_allocation (&rt_common_objfile -> symbol_obstack, 0, 0,
419 rt_common_objfile -> minimal_symbol_count = 0;
420 rt_common_objfile -> msymbols = NULL;
423 init_minimal_symbol_collection ();
424 make_cleanup ((make_cleanup_func) discard_minimal_symbols, 0);
428 read_memory ((CORE_ADDR) rtc_symp,
429 (char *) &inferior_rtc_symb,
430 sizeof (inferior_rtc_symb));
431 read_memory ((CORE_ADDR) inferior_rtc_symb.rtc_sp,
432 (char *) &inferior_rtc_nlist,
433 sizeof(inferior_rtc_nlist));
434 if (inferior_rtc_nlist.n_type == N_COMM)
436 /* FIXME: The length of the symbol name is not available, but in the
437 current implementation the common symbol is allocated immediately
438 behind the name of the symbol. */
439 len = inferior_rtc_nlist.n_value - inferior_rtc_nlist.n_un.n_strx;
441 name = xmalloc (len);
442 read_memory ((CORE_ADDR) inferior_rtc_nlist.n_un.n_name, name, len);
444 /* Allocate the runtime common objfile if necessary. */
445 if (rt_common_objfile == NULL)
446 allocate_rt_common_objfile ();
448 prim_record_minimal_symbol (name, inferior_rtc_nlist.n_value,
449 mst_bss, rt_common_objfile);
452 rtc_symp = inferior_rtc_symb.rtc_next;
455 /* Install any minimal symbols that have been collected as the current
456 minimal symbols for the runtime common objfile. */
458 install_minimal_symbols (rt_common_objfile);
461 #endif /* SVR4_SHARED_LIBS */
464 #ifdef SVR4_SHARED_LIBS
467 bfd_lookup_symbol PARAMS ((bfd *, char *));
473 bfd_lookup_symbol -- lookup the value for a specific symbol
477 CORE_ADDR bfd_lookup_symbol (bfd *abfd, char *symname)
481 An expensive way to lookup the value of a single symbol for
482 bfd's that are only temporary anyway. This is used by the
483 shared library support to find the address of the debugger
484 interface structures in the shared library.
486 Note that 0 is specifically allowed as an error return (no
491 bfd_lookup_symbol (abfd, symname)
497 asymbol **symbol_table;
498 unsigned int number_of_symbols;
500 struct cleanup *back_to;
501 CORE_ADDR symaddr = 0;
503 storage_needed = bfd_get_symtab_upper_bound (abfd);
505 if (storage_needed > 0)
507 symbol_table = (asymbol **) xmalloc (storage_needed);
508 back_to = make_cleanup (free, (PTR)symbol_table);
509 number_of_symbols = bfd_canonicalize_symtab (abfd, symbol_table);
511 for (i = 0; i < number_of_symbols; i++)
513 sym = *symbol_table++;
514 if (STREQ (sym -> name, symname))
516 /* Bfd symbols are section relative. */
517 symaddr = sym -> value + sym -> section -> vma;
521 do_cleanups (back_to);
524 if (symaddr) return (symaddr);
526 storage_needed = bfd_get_dynamic_symtab_upper_bound (abfd);
528 if (storage_needed > 0)
530 symbol_table = (asymbol **) xmalloc (storage_needed);
531 back_to = make_cleanup (free, (PTR)symbol_table);
532 number_of_symbols = bfd_canonicalize_dynamic_symtab (abfd, symbol_table);
534 for (i = 0; i < number_of_symbols; i++)
536 sym = *symbol_table++;
537 if (STREQ (sym -> name, symname))
539 /* Bfd symbols are section relative. */
540 symaddr = sym -> value + sym -> section -> vma;
544 do_cleanups (back_to);
549 #ifdef HANDLE_SVR4_EXEC_EMULATORS
552 Solaris BCP (the part of Solaris which allows it to run SunOS4
553 a.out files) throws in another wrinkle. Solaris does not fill
554 in the usual a.out link map structures when running BCP programs,
555 the only way to get at them is via groping around in the dynamic
557 The dynamic linker and it's structures are located in the shared
558 C library, which gets run as the executable's "interpreter" by
561 Note that we can assume nothing about the process state at the time
562 we need to find these structures. We may be stopped on the first
563 instruction of the interpreter (C shared library), the first
564 instruction of the executable itself, or somewhere else entirely
565 (if we attached to the process for example).
568 static char *debug_base_symbols[] = {
569 "r_debug", /* Solaris 2.3 */
570 "_r_debug", /* Solaris 2.1, 2.2 */
575 look_for_base PARAMS ((int, CORE_ADDR));
581 look_for_base -- examine file for each mapped address segment
585 static int look_for_base (int fd, CORE_ADDR baseaddr)
589 This function is passed to proc_iterate_over_mappings, which
590 causes it to get called once for each mapped address space, with
591 an open file descriptor for the file mapped to that space, and the
592 base address of that mapped space.
594 Our job is to find the debug base symbol in the file that this
595 fd is open on, if it exists, and if so, initialize the dynamic
596 linker structure base address debug_base.
598 Note that this is a computationally expensive proposition, since
599 we basically have to open a bfd on every call, so we specifically
600 avoid opening the exec file.
604 look_for_base (fd, baseaddr)
609 CORE_ADDR address = 0;
612 /* If the fd is -1, then there is no file that corresponds to this
613 mapped memory segment, so skip it. Also, if the fd corresponds
614 to the exec file, skip it as well. */
618 && fdmatch (fileno ((FILE *)(exec_bfd -> iostream)), fd)))
623 /* Try to open whatever random file this fd corresponds to. Note that
624 we have no way currently to find the filename. Don't gripe about
625 any problems we might have, just fail. */
627 if ((interp_bfd = bfd_fdopenr ("unnamed", gnutarget, fd)) == NULL)
631 if (!bfd_check_format (interp_bfd, bfd_object))
633 /* FIXME-leak: on failure, might not free all memory associated with
635 bfd_close (interp_bfd);
639 /* Now try to find our debug base symbol in this file, which we at
640 least know to be a valid ELF executable or shared library. */
642 for (symbolp = debug_base_symbols; *symbolp != NULL; symbolp++)
644 address = bfd_lookup_symbol (interp_bfd, *symbolp);
652 /* FIXME-leak: on failure, might not free all memory associated with
654 bfd_close (interp_bfd);
658 /* Eureka! We found the symbol. But now we may need to relocate it
659 by the base address. If the symbol's value is less than the base
660 address of the shared library, then it hasn't yet been relocated
661 by the dynamic linker, and we have to do it ourself. FIXME: Note
662 that we make the assumption that the first segment that corresponds
663 to the shared library has the base address to which the library
666 if (address < baseaddr)
670 debug_base = address;
671 /* FIXME-leak: on failure, might not free all memory associated with
673 bfd_close (interp_bfd);
676 #endif /* HANDLE_SVR4_EXEC_EMULATORS */
682 elf_locate_base -- locate the base address of dynamic linker structs
683 for SVR4 elf targets.
687 CORE_ADDR elf_locate_base (void)
691 For SVR4 elf targets the address of the dynamic linker's runtime
692 structure is contained within the dynamic info section in the
693 executable file. The dynamic section is also mapped into the
694 inferior address space. Because the runtime loader fills in the
695 real address before starting the inferior, we have to read in the
696 dynamic info section from the inferior address space.
697 If there are any errors while trying to find the address, we
698 silently return 0, otherwise the found address is returned.
705 sec_ptr dyninfo_sect;
706 int dyninfo_sect_size;
707 CORE_ADDR dyninfo_addr;
711 /* Find the start address of the .dynamic section. */
712 dyninfo_sect = bfd_get_section_by_name (exec_bfd, ".dynamic");
713 if (dyninfo_sect == NULL)
715 dyninfo_addr = bfd_section_vma (exec_bfd, dyninfo_sect);
717 /* Read in .dynamic section, silently ignore errors. */
718 dyninfo_sect_size = bfd_section_size (exec_bfd, dyninfo_sect);
719 buf = alloca (dyninfo_sect_size);
720 if (target_read_memory (dyninfo_addr, buf, dyninfo_sect_size))
723 /* Find the DT_DEBUG entry in the the .dynamic section.
724 For mips elf we look for DT_MIPS_RLD_MAP, mips elf apparently has
725 no DT_DEBUG entries. */
727 for (bufend = buf + dyninfo_sect_size;
729 buf += sizeof (Elf32_External_Dyn))
731 Elf32_External_Dyn *x_dynp = (Elf32_External_Dyn *)buf;
735 dyn_tag = bfd_h_get_32 (exec_bfd, (bfd_byte *) x_dynp->d_tag);
736 if (dyn_tag == DT_NULL)
738 else if (dyn_tag == DT_DEBUG)
740 dyn_ptr = bfd_h_get_32 (exec_bfd, (bfd_byte *) x_dynp->d_un.d_ptr);
743 #ifdef DT_MIPS_RLD_MAP
744 else if (dyn_tag == DT_MIPS_RLD_MAP)
746 char pbuf[TARGET_PTR_BIT / HOST_CHAR_BIT];
748 /* DT_MIPS_RLD_MAP contains a pointer to the address
749 of the dynamic link structure. */
750 dyn_ptr = bfd_h_get_32 (exec_bfd, (bfd_byte *) x_dynp->d_un.d_ptr);
751 if (target_read_memory (dyn_ptr, pbuf, sizeof (pbuf)))
753 return extract_unsigned_integer (pbuf, sizeof (pbuf));
758 for (bufend = buf + dyninfo_sect_size;
760 buf += sizeof (Elf64_External_Dyn))
762 Elf64_External_Dyn *x_dynp = (Elf64_External_Dyn *)buf;
766 dyn_tag = bfd_h_get_64 (exec_bfd, (bfd_byte *) x_dynp->d_tag);
767 if (dyn_tag == DT_NULL)
769 else if (dyn_tag == DT_DEBUG)
771 dyn_ptr = bfd_h_get_64 (exec_bfd, (bfd_byte *) x_dynp->d_un.d_ptr);
777 /* DT_DEBUG entry not found. */
781 #endif /* SVR4_SHARED_LIBS */
787 locate_base -- locate the base address of dynamic linker structs
791 CORE_ADDR locate_base (void)
795 For both the SunOS and SVR4 shared library implementations, if the
796 inferior executable has been linked dynamically, there is a single
797 address somewhere in the inferior's data space which is the key to
798 locating all of the dynamic linker's runtime structures. This
799 address is the value of the debug base symbol. The job of this
800 function is to find and return that address, or to return 0 if there
801 is no such address (the executable is statically linked for example).
803 For SunOS, the job is almost trivial, since the dynamic linker and
804 all of it's structures are statically linked to the executable at
805 link time. Thus the symbol for the address we are looking for has
806 already been added to the minimal symbol table for the executable's
807 objfile at the time the symbol file's symbols were read, and all we
808 have to do is look it up there. Note that we explicitly do NOT want
809 to find the copies in the shared library.
811 The SVR4 version is a bit more complicated because the address
812 is contained somewhere in the dynamic info section. We have to go
813 to a lot more work to discover the address of the debug base symbol.
814 Because of this complexity, we cache the value we find and return that
815 value on subsequent invocations. Note there is no copy in the
816 executable symbol tables.
824 #ifndef SVR4_SHARED_LIBS
826 struct minimal_symbol *msymbol;
827 CORE_ADDR address = 0;
830 /* For SunOS, we want to limit the search for the debug base symbol to the
831 executable being debugged, since there is a duplicate named symbol in the
832 shared library. We don't want the shared library versions. */
834 for (symbolp = debug_base_symbols; *symbolp != NULL; symbolp++)
836 msymbol = lookup_minimal_symbol (*symbolp, NULL, symfile_objfile);
837 if ((msymbol != NULL) && (SYMBOL_VALUE_ADDRESS (msymbol) != 0))
839 address = SYMBOL_VALUE_ADDRESS (msymbol);
845 #else /* SVR4_SHARED_LIBS */
847 /* Check to see if we have a currently valid address, and if so, avoid
848 doing all this work again and just return the cached address. If
849 we have no cached address, try to locate it in the dynamic info
850 section for ELF executables. */
855 && bfd_get_flavour (exec_bfd) == bfd_target_elf_flavour)
856 debug_base = elf_locate_base ();
857 #ifdef HANDLE_SVR4_EXEC_EMULATORS
858 /* Try it the hard way for emulated executables. */
859 else if (inferior_pid != 0 && target_has_execution)
860 proc_iterate_over_mappings (look_for_base);
865 #endif /* !SVR4_SHARED_LIBS */
873 first_link_map_member -- locate first member in dynamic linker's map
877 static struct link_map *first_link_map_member (void)
881 Read in a copy of the first member in the inferior's dynamic
882 link map from the inferior's dynamic linker structures, and return
883 a pointer to the copy in our address space.
886 static struct link_map *
887 first_link_map_member ()
889 struct link_map *lm = NULL;
891 #ifndef SVR4_SHARED_LIBS
893 read_memory (debug_base, (char *) &dynamic_copy, sizeof (dynamic_copy));
894 if (dynamic_copy.ld_version >= 2)
896 /* It is a version that we can deal with, so read in the secondary
897 structure and find the address of the link map list from it. */
898 read_memory ((CORE_ADDR) dynamic_copy.ld_un.ld_2, (char *) &ld_2_copy,
899 sizeof (struct link_dynamic_2));
900 lm = ld_2_copy.ld_loaded;
903 #else /* SVR4_SHARED_LIBS */
905 read_memory (debug_base, (char *) &debug_copy, sizeof (struct r_debug));
906 /* FIXME: Perhaps we should validate the info somehow, perhaps by
907 checking r_version for a known version number, or r_state for
909 lm = debug_copy.r_map;
911 #endif /* !SVR4_SHARED_LIBS */
920 free_solib -- free a so_list structure
924 void free_solib (struct so_list *so_list_ptr)
928 Free the memory used by a struct so_list.
939 free ((PTR)so -> sections);
943 bfd_filename = bfd_get_filename (so -> abfd);
944 if (!bfd_close (so -> abfd))
945 warning ("cannot close \"%s\": %s",
946 bfd_filename, bfd_errmsg (bfd_get_error ()));
949 /* This happens for the executable on SVR4. */
953 free ((PTR)bfd_filename);
961 alloc_solib -- free a so_list structure
965 struct so_list *alloc_solib (struct link_map *lm)
969 Allocate the struct so_list to cache debugging information
970 for a struct link_map entry in the target.
980 /* Get next link map structure from inferior image and build a local
981 abbreviated load_map structure */
982 new = (struct so_list *) xmalloc (sizeof (struct so_list));
983 memset ((char *) new, 0, sizeof (struct so_list));
986 read_memory ((CORE_ADDR) lm, (char *) &(new -> lm),
987 sizeof (struct link_map));
988 /* For SVR4 versions, the first entry in the link map is for the
989 inferior executable, so we must ignore it. For some versions of
990 SVR4, it has no name. For others (Solaris 2.3 for example), it
991 does have a name, so we can no longer use a missing name to
992 decide when to ignore it. */
993 if (!IGNORE_FIRST_LINK_MAP_ENTRY (new -> lm))
997 target_read_string ((CORE_ADDR) LM_NAME (new), &buffer,
998 MAX_PATH_SIZE - 1, &errcode);
1000 error ("find_solib: Can't read pathname for load map: %s\n",
1001 safe_strerror (errcode));
1002 strncpy (new -> so_name, buffer, MAX_PATH_SIZE - 1);
1003 new -> so_name[MAX_PATH_SIZE - 1] = '\0';
1005 solib_map_sections (new);
1015 find_solib -- step through list of shared objects
1019 struct so_list *find_solib (struct so_list *so_list_ptr, int maybe_changed)
1023 This module contains the routine which finds the names of any
1024 loaded "images" in the current process. The argument in must be
1025 NULL on the first call, and then the returned value must be passed
1026 in on subsequent calls. This provides the capability to "step" down
1027 the list of loaded objects. On the last object, a NULL value is
1030 The arg and return value are "struct link_map" pointers, as defined
1033 If it is expected that the contents of the shared library list has changed
1034 (e.g. when the special shared library breakpoint is hit) then pass non-zero
1035 for maybe_changed, otherwise zero.
1038 static struct so_list *
1039 find_solib (so_list_ptr, maybe_changed)
1040 struct so_list *so_list_ptr; /* Last lm or NULL for first one */
1041 int maybe_changed; /* non-zero if shlib list might have changed */
1043 struct link_map *lm = NULL;
1044 struct so_list *new;
1045 struct so_list *so_list_next;
1046 struct so_list *p, **prev;
1048 if (so_list_ptr == NULL)
1050 struct so_list **map;
1052 /* If we have not already read in the dynamic linking structures
1053 from the inferior, lookup the address of the base structure. */
1054 if (debug_base == 0)
1055 debug_base = locate_base ();
1056 if (debug_base != 0)
1058 /* Read the base structure in and find the address of the first
1059 link map list member. */
1060 lm = first_link_map_member ();
1065 prev = &so_list_head;
1066 so_list_ptr = so_list_head;
1070 /* We have been called before, and are in the process of walking
1071 the shared library list. Advance to the next shared object.
1073 Always read from the target to check to see if any were
1074 added, but be quiet if we can't read from the target any more. */
1075 int status = target_read_memory ((CORE_ADDR) so_list_ptr -> lmaddr,
1076 (char *) &(so_list_ptr -> lm),
1077 sizeof (struct link_map));
1081 lm = LM_NEXT (so_list_ptr);
1088 prev = &so_list_ptr -> next;
1089 so_list_ptr = so_list_ptr -> next;
1092 /* If we don't believe that the list has changed, just return the cached copy. */
1094 return (so_list_ptr);
1096 /* At this point, lm is the address of the next list element in the target and
1097 so_list_ptr is our cached entry for it. */
1101 if (so_list_ptr == NULL || so_list_ptr -> lmaddr != lm)
1103 /* We have detected a change in the list. Check for a deletion by searching
1104 forward in the cached list */
1107 for (p = so_list_ptr -> next; p; p = p -> next)
1108 if (p -> lmaddr == lm)
1116 /* This lib has been deleted */
1117 while (so_list_ptr != p)
1119 *prev = so_list_ptr -> next;
1120 free_solib (so_list_ptr);
1121 so_list_ptr = *prev;
1126 /* A new lib has been inserted into the list */
1127 new = alloc_solib (lm);
1128 new -> next = so_list_ptr;
1136 if (so_list_ptr != NULL)
1140 if (! solib_cleanup_queued)
1142 make_run_cleanup (do_clear_solib, NULL);
1143 solib_cleanup_queued = 1;
1149 target_read_memory ((CORE_ADDR) lm, (char *) &(new -> lm),
1150 sizeof (struct link_map));
1151 /* For SVR4 versions, the first entry in the link map is for the
1152 inferior executable, so we must ignore it. For some versions of
1153 SVR4, it has no name. For others (Solaris 2.3 for example), it
1154 does have a name, so we can no longer use a missing name to
1155 decide when to ignore it. */
1156 if (lm && new && !IGNORE_FIRST_LINK_MAP_ENTRY (new -> lm))
1160 target_read_string ((CORE_ADDR) LM_NAME (new), &buffer,
1161 MAX_PATH_SIZE - 1, &errcode);
1164 warning ("find_solib: Can't read pathname for load map: %s\n",
1165 safe_strerror (errcode));
1166 return (so_list_next);
1168 strncpy (new -> so_name, buffer, MAX_PATH_SIZE - 1);
1169 new -> so_name[MAX_PATH_SIZE - 1] = '\0';
1171 catch_errors (solib_map_sections, new,
1172 "Error while mapping shared library sections:\n",
1177 return (so_list_ptr);
1180 /* A small stub to get us past the arg-passing pinhole of catch_errors. */
1183 symbol_add_stub (arg)
1186 register struct so_list *so = (struct so_list *) arg; /* catch_errs bogon */
1187 CORE_ADDR text_addr = 0;
1189 if (so -> textsection)
1190 text_addr = so -> textsection -> addr;
1191 else if (so -> abfd != NULL)
1193 asection *lowest_sect;
1195 /* If we didn't find a mapped non zero sized .text section, set up
1196 text_addr so that the relocation in symbol_file_add does no harm. */
1198 lowest_sect = bfd_get_section_by_name (so -> abfd, ".text");
1199 if (lowest_sect == NULL)
1200 bfd_map_over_sections (so -> abfd, find_lowest_section,
1201 (PTR) &lowest_sect);
1203 text_addr = bfd_section_vma (so -> abfd, lowest_sect)
1204 + (CORE_ADDR) LM_ADDR (so);
1207 ALL_OBJFILES (so -> objfile)
1209 if (strcmp (so -> objfile -> name, so -> so_name) == 0)
1213 symbol_file_add (so -> so_name, so -> from_tty,
1219 /* This function will check the so name to see if matches the main list.
1220 In some system the main object is in the list, which we want to exclude */
1222 static int match_main (soname)
1227 for (mainp = main_name_list; *mainp != NULL; mainp++)
1229 if (strcmp (soname, *mainp) == 0)
1240 solib_add -- add a shared library file to the symtab and section list
1244 void solib_add (char *arg_string, int from_tty,
1245 struct target_ops *target)
1252 solib_add (arg_string, from_tty, target)
1255 struct target_ops *target;
1257 register struct so_list *so = NULL; /* link map state variable */
1259 /* Last shared library that we read. */
1260 struct so_list *so_last = NULL;
1266 if ((re_err = re_comp (arg_string ? arg_string : ".")) != NULL)
1268 error ("Invalid regexp: %s", re_err);
1271 /* Add the shared library sections to the section table of the
1272 specified target, if any. */
1275 /* Count how many new section_table entries there are. */
1278 while ((so = find_solib (so, 1)) != NULL)
1280 if (so -> so_name[0] && !match_main (so -> so_name))
1282 count += so -> sections_end - so -> sections;
1290 /* We must update the to_sections field in the core_ops structure
1291 here, otherwise we dereference a potential dangling pointer
1292 for each call to target_read/write_memory within this routine. */
1293 update_coreops = core_ops.to_sections == target->to_sections;
1295 /* Reallocate the target's section table including the new size. */
1296 if (target -> to_sections)
1298 old = target -> to_sections_end - target -> to_sections;
1299 target -> to_sections = (struct section_table *)
1300 xrealloc ((char *)target -> to_sections,
1301 (sizeof (struct section_table)) * (count + old));
1306 target -> to_sections = (struct section_table *)
1307 xmalloc ((sizeof (struct section_table)) * count);
1309 target -> to_sections_end = target -> to_sections + (count + old);
1311 /* Update the to_sections field in the core_ops structure
1315 core_ops.to_sections = target->to_sections;
1316 core_ops.to_sections_end = target->to_sections_end;
1319 /* Add these section table entries to the target's table. */
1320 while ((so = find_solib (so, 1)) != NULL)
1322 if (so -> so_name[0])
1324 count = so -> sections_end - so -> sections;
1325 memcpy ((char *) (target -> to_sections + old),
1327 (sizeof (struct section_table)) * count);
1334 /* Now add the symbol files. */
1335 while ((so = find_solib (so, 1)) != NULL)
1337 if (so -> so_name[0] && re_exec (so -> so_name) &&
1338 !match_main (so -> so_name))
1340 so -> from_tty = from_tty;
1341 if (so -> symbols_loaded)
1345 printf_unfiltered ("Symbols already loaded for %s\n", so -> so_name);
1348 else if (catch_errors
1349 (symbol_add_stub, so,
1350 "Error while reading shared library symbols:\n",
1354 so -> symbols_loaded = 1;
1359 /* Getting new symbols may change our opinion about what is
1362 reinit_frame_cache ();
1365 special_symbol_handling (so_last);
1372 info_sharedlibrary_command -- code for "info sharedlibrary"
1376 static void info_sharedlibrary_command ()
1380 Walk through the shared library list and print information
1381 about each attached library.
1385 info_sharedlibrary_command (ignore, from_tty)
1389 register struct so_list *so = NULL; /* link map state variable */
1390 int header_done = 0;
1394 if (exec_bfd == NULL)
1396 printf_unfiltered ("No exec file.\n");
1400 #ifndef TARGET_ELF64
1408 while ((so = find_solib (so, 0)) != NULL)
1410 if (so -> so_name[0])
1414 printf_unfiltered("%-*s%-*s%-12s%s\n", addr_width, "From",
1415 addr_width, "To", "Syms Read",
1416 "Shared Object Library");
1420 printf_unfiltered ("%-*s", addr_width,
1421 local_hex_string_custom ((unsigned long) LM_ADDR (so),
1423 printf_unfiltered ("%-*s", addr_width,
1424 local_hex_string_custom ((unsigned long) so -> lmend,
1426 printf_unfiltered ("%-12s", so -> symbols_loaded ? "Yes" : "No");
1427 printf_unfiltered ("%s\n", so -> so_name);
1430 if (so_list_head == NULL)
1432 printf_unfiltered ("No shared libraries loaded at this time.\n");
1440 solib_address -- check to see if an address is in a shared lib
1444 char * solib_address (CORE_ADDR address)
1448 Provides a hook for other gdb routines to discover whether or
1449 not a particular address is within the mapped address space of
1450 a shared library. Any address between the base mapping address
1451 and the first address beyond the end of the last mapping, is
1452 considered to be within the shared library address space, for
1455 For example, this routine is called at one point to disable
1456 breakpoints which are in shared libraries that are not currently
1461 solib_address (address)
1464 register struct so_list *so = 0; /* link map state variable */
1466 while ((so = find_solib (so, 0)) != NULL)
1468 if (so -> so_name[0])
1470 if ((address >= (CORE_ADDR) LM_ADDR (so)) &&
1471 (address < (CORE_ADDR) so -> lmend))
1472 return (so->so_name);
1478 /* Called by free_all_symtabs */
1483 struct so_list *next;
1486 while (so_list_head)
1488 next = so_list_head -> next;
1489 free_solib (so_list_head);
1490 so_list_head = next;
1496 do_clear_solib (dummy)
1499 solib_cleanup_queued = 0;
1503 #ifdef SVR4_SHARED_LIBS
1505 /* Return 1 if PC lies in the dynamic symbol resolution code of the
1506 SVR4 run time loader. */
1508 static CORE_ADDR interp_text_sect_low;
1509 static CORE_ADDR interp_text_sect_high;
1510 static CORE_ADDR interp_plt_sect_low;
1511 static CORE_ADDR interp_plt_sect_high;
1514 in_svr4_dynsym_resolve_code (pc)
1517 return ((pc >= interp_text_sect_low && pc < interp_text_sect_high)
1518 || (pc >= interp_plt_sect_low && pc < interp_plt_sect_high)
1519 || in_plt_section (pc, NULL));
1527 disable_break -- remove the "mapping changed" breakpoint
1531 static int disable_break ()
1535 Removes the breakpoint that gets hit when the dynamic linker
1536 completes a mapping change.
1540 #ifndef SVR4_SHARED_LIBS
1547 #ifndef SVR4_SHARED_LIBS
1549 int in_debugger = 0;
1551 /* Read the debugger structure from the inferior to retrieve the
1552 address of the breakpoint and the original contents of the
1553 breakpoint address. Remove the breakpoint by writing the original
1556 read_memory (debug_addr, (char *) &debug_copy, sizeof (debug_copy));
1558 /* Set `in_debugger' to zero now. */
1560 write_memory (flag_addr, (char *) &in_debugger, sizeof (in_debugger));
1562 breakpoint_addr = (CORE_ADDR) debug_copy.ldd_bp_addr;
1563 write_memory (breakpoint_addr, (char *) &debug_copy.ldd_bp_inst,
1564 sizeof (debug_copy.ldd_bp_inst));
1566 #else /* SVR4_SHARED_LIBS */
1568 /* Note that breakpoint address and original contents are in our address
1569 space, so we just need to write the original contents back. */
1571 if (memory_remove_breakpoint (breakpoint_addr, shadow_contents) != 0)
1576 #endif /* !SVR4_SHARED_LIBS */
1578 /* For the SVR4 version, we always know the breakpoint address. For the
1579 SunOS version we don't know it until the above code is executed.
1580 Grumble if we are stopped anywhere besides the breakpoint address. */
1582 if (stop_pc != breakpoint_addr)
1584 warning ("stopped at unknown breakpoint while handling shared libraries");
1590 #endif /* #ifdef SVR4_SHARED_LIBS */
1596 enable_break -- arrange for dynamic linker to hit breakpoint
1600 int enable_break (void)
1604 Both the SunOS and the SVR4 dynamic linkers have, as part of their
1605 debugger interface, support for arranging for the inferior to hit
1606 a breakpoint after mapping in the shared libraries. This function
1607 enables that breakpoint.
1609 For SunOS, there is a special flag location (in_debugger) which we
1610 set to 1. When the dynamic linker sees this flag set, it will set
1611 a breakpoint at a location known only to itself, after saving the
1612 original contents of that place and the breakpoint address itself,
1613 in it's own internal structures. When we resume the inferior, it
1614 will eventually take a SIGTRAP when it runs into the breakpoint.
1615 We handle this (in a different place) by restoring the contents of
1616 the breakpointed location (which is only known after it stops),
1617 chasing around to locate the shared libraries that have been
1618 loaded, then resuming.
1620 For SVR4, the debugger interface structure contains a member (r_brk)
1621 which is statically initialized at the time the shared library is
1622 built, to the offset of a function (_r_debug_state) which is guaran-
1623 teed to be called once before mapping in a library, and again when
1624 the mapping is complete. At the time we are examining this member,
1625 it contains only the unrelocated offset of the function, so we have
1626 to do our own relocation. Later, when the dynamic linker actually
1627 runs, it relocates r_brk to be the actual address of _r_debug_state().
1629 The debugger interface structure also contains an enumeration which
1630 is set to either RT_ADD or RT_DELETE prior to changing the mapping,
1631 depending upon whether or not the library is being mapped or unmapped,
1632 and then set to RT_CONSISTENT after the library is mapped/unmapped.
1640 #ifndef SVR4_SHARED_LIBS
1645 /* Get link_dynamic structure */
1647 j = target_read_memory (debug_base, (char *) &dynamic_copy,
1648 sizeof (dynamic_copy));
1655 /* Calc address of debugger interface structure */
1657 debug_addr = (CORE_ADDR) dynamic_copy.ldd;
1659 /* Calc address of `in_debugger' member of debugger interface structure */
1661 flag_addr = debug_addr + (CORE_ADDR) ((char *) &debug_copy.ldd_in_debugger -
1662 (char *) &debug_copy);
1664 /* Write a value of 1 to this member. */
1667 write_memory (flag_addr, (char *) &in_debugger, sizeof (in_debugger));
1670 #else /* SVR4_SHARED_LIBS */
1672 #ifdef BKPT_AT_SYMBOL
1674 struct minimal_symbol *msymbol;
1676 asection *interp_sect;
1678 /* First, remove all the solib event breakpoints. Their addresses
1679 may have changed since the last time we ran the program. */
1680 remove_solib_event_breakpoints ();
1682 #ifdef SVR4_SHARED_LIBS
1683 interp_text_sect_low = interp_text_sect_high = 0;
1684 interp_plt_sect_low = interp_plt_sect_high = 0;
1686 /* Find the .interp section; if not found, warn the user and drop
1687 into the old breakpoint at symbol code. */
1688 interp_sect = bfd_get_section_by_name (exec_bfd, ".interp");
1691 unsigned int interp_sect_size;
1693 CORE_ADDR load_addr;
1695 CORE_ADDR sym_addr = 0;
1697 /* Read the contents of the .interp section into a local buffer;
1698 the contents specify the dynamic linker this program uses. */
1699 interp_sect_size = bfd_section_size (exec_bfd, interp_sect);
1700 buf = alloca (interp_sect_size);
1701 bfd_get_section_contents (exec_bfd, interp_sect,
1702 buf, 0, interp_sect_size);
1704 /* Now we need to figure out where the dynamic linker was
1705 loaded so that we can load its symbols and place a breakpoint
1706 in the dynamic linker itself.
1708 This address is stored on the stack. However, I've been unable
1709 to find any magic formula to find it for Solaris (appears to
1710 be trivial on GNU/Linux). Therefore, we have to try an alternate
1711 mechanism to find the dynamic linker's base address. */
1712 tmp_bfd = bfd_openr (buf, gnutarget);
1713 if (tmp_bfd == NULL)
1714 goto bkpt_at_symbol;
1716 /* Make sure the dynamic linker's really a useful object. */
1717 if (!bfd_check_format (tmp_bfd, bfd_object))
1719 warning ("Unable to grok dynamic linker %s as an object file", buf);
1720 bfd_close (tmp_bfd);
1721 goto bkpt_at_symbol;
1724 /* We find the dynamic linker's base address by examining the
1725 current pc (which point at the entry point for the dynamic
1726 linker) and subtracting the offset of the entry point. */
1727 load_addr = read_pc () - tmp_bfd->start_address;
1729 /* Record the relocated start and end address of the dynamic linker
1730 text and plt section for in_svr4_dynsym_resolve_code. */
1731 interp_sect = bfd_get_section_by_name (tmp_bfd, ".text");
1734 interp_text_sect_low =
1735 bfd_section_vma (tmp_bfd, interp_sect) + load_addr;
1736 interp_text_sect_high =
1737 interp_text_sect_low + bfd_section_size (tmp_bfd, interp_sect);
1739 interp_sect = bfd_get_section_by_name (tmp_bfd, ".plt");
1742 interp_plt_sect_low =
1743 bfd_section_vma (tmp_bfd, interp_sect) + load_addr;
1744 interp_plt_sect_high =
1745 interp_plt_sect_low + bfd_section_size (tmp_bfd, interp_sect);
1748 /* Now try to set a breakpoint in the dynamic linker. */
1749 for (bkpt_namep = solib_break_names; *bkpt_namep != NULL; bkpt_namep++)
1751 sym_addr = bfd_lookup_symbol (tmp_bfd, *bkpt_namep);
1756 /* We're done with the temporary bfd. */
1757 bfd_close (tmp_bfd);
1761 create_solib_event_breakpoint (load_addr + sym_addr);
1765 /* For whatever reason we couldn't set a breakpoint in the dynamic
1766 linker. Warn and drop into the old code. */
1768 warning ("Unable to find dynamic linker breakpoint function.\nGDB will be unable to debug shared library initializers\nand track explicitly loaded dynamic code.");
1772 /* Scan through the list of symbols, trying to look up the symbol and
1773 set a breakpoint there. Terminate loop when we/if we succeed. */
1775 breakpoint_addr = 0;
1776 for (bkpt_namep = bkpt_names; *bkpt_namep != NULL; bkpt_namep++)
1778 msymbol = lookup_minimal_symbol (*bkpt_namep, NULL, symfile_objfile);
1779 if ((msymbol != NULL) && (SYMBOL_VALUE_ADDRESS (msymbol) != 0))
1781 create_solib_event_breakpoint (SYMBOL_VALUE_ADDRESS (msymbol));
1786 /* Nothing good happened. */
1789 #endif /* BKPT_AT_SYMBOL */
1791 #endif /* !SVR4_SHARED_LIBS */
1800 solib_create_inferior_hook -- shared library startup support
1804 void solib_create_inferior_hook()
1808 When gdb starts up the inferior, it nurses it along (through the
1809 shell) until it is ready to execute it's first instruction. At this
1810 point, this function gets called via expansion of the macro
1811 SOLIB_CREATE_INFERIOR_HOOK.
1813 For SunOS executables, this first instruction is typically the
1814 one at "_start", or a similar text label, regardless of whether
1815 the executable is statically or dynamically linked. The runtime
1816 startup code takes care of dynamically linking in any shared
1817 libraries, once gdb allows the inferior to continue.
1819 For SVR4 executables, this first instruction is either the first
1820 instruction in the dynamic linker (for dynamically linked
1821 executables) or the instruction at "start" for statically linked
1822 executables. For dynamically linked executables, the system
1823 first exec's /lib/libc.so.N, which contains the dynamic linker,
1824 and starts it running. The dynamic linker maps in any needed
1825 shared libraries, maps in the actual user executable, and then
1826 jumps to "start" in the user executable.
1828 For both SunOS shared libraries, and SVR4 shared libraries, we
1829 can arrange to cooperate with the dynamic linker to discover the
1830 names of shared libraries that are dynamically linked, and the
1831 base addresses to which they are linked.
1833 This function is responsible for discovering those names and
1834 addresses, and saving sufficient information about them to allow
1835 their symbols to be read at a later time.
1839 Between enable_break() and disable_break(), this code does not
1840 properly handle hitting breakpoints which the user might have
1841 set in the startup code or in the dynamic linker itself. Proper
1842 handling will probably have to wait until the implementation is
1843 changed to use the "breakpoint handler function" method.
1845 Also, what if child has exit()ed? Must exit loop somehow.
1849 solib_create_inferior_hook()
1851 /* If we are using the BKPT_AT_SYMBOL code, then we don't need the base
1852 yet. In fact, in the case of a SunOS4 executable being run on
1853 Solaris, we can't get it yet. find_solib will get it when it needs
1855 #if !(defined (SVR4_SHARED_LIBS) && defined (BKPT_AT_SYMBOL))
1856 if ((debug_base = locate_base ()) == 0)
1858 /* Can't find the symbol or the executable is statically linked. */
1863 if (!enable_break ())
1865 warning ("shared library handler failed to enable breakpoint");
1869 #if !defined(SVR4_SHARED_LIBS) || defined(_SCO_DS)
1870 /* SCO and SunOS need the loop below, other systems should be using the
1871 special shared library breakpoints and the shared library breakpoint
1874 Now run the target. It will eventually hit the breakpoint, at
1875 which point all of the libraries will have been mapped in and we
1876 can go groveling around in the dynamic linker structures to find
1877 out what we need to know about them. */
1879 clear_proceed_status ();
1880 stop_soon_quietly = 1;
1881 stop_signal = TARGET_SIGNAL_0;
1884 target_resume (-1, 0, stop_signal);
1885 wait_for_inferior ();
1887 while (stop_signal != TARGET_SIGNAL_TRAP);
1888 stop_soon_quietly = 0;
1890 #if !defined(_SCO_DS)
1891 /* We are now either at the "mapping complete" breakpoint (or somewhere
1892 else, a condition we aren't prepared to deal with anyway), so adjust
1893 the PC as necessary after a breakpoint, disable the breakpoint, and
1894 add any shared libraries that were mapped in. */
1896 if (DECR_PC_AFTER_BREAK)
1898 stop_pc -= DECR_PC_AFTER_BREAK;
1899 write_register (PC_REGNUM, stop_pc);
1902 if (!disable_break ())
1904 warning ("shared library handler failed to disable breakpoint");
1908 solib_add ((char *) 0, 0, (struct target_ops *) 0);
1909 #endif /* ! _SCO_DS */
1917 special_symbol_handling -- additional shared library symbol handling
1921 void special_symbol_handling (struct so_list *so)
1925 Once the symbols from a shared object have been loaded in the usual
1926 way, we are called to do any system specific symbol handling that
1929 For SunOS4, this consists of grunging around in the dynamic
1930 linkers structures to find symbol definitions for "common" symbols
1931 and adding them to the minimal symbol table for the runtime common
1937 special_symbol_handling (so)
1940 #ifndef SVR4_SHARED_LIBS
1943 if (debug_addr == 0)
1945 /* Get link_dynamic structure */
1947 j = target_read_memory (debug_base, (char *) &dynamic_copy,
1948 sizeof (dynamic_copy));
1955 /* Calc address of debugger interface structure */
1956 /* FIXME, this needs work for cross-debugging of core files
1957 (byteorder, size, alignment, etc). */
1959 debug_addr = (CORE_ADDR) dynamic_copy.ldd;
1962 /* Read the debugger structure from the inferior, just to make sure
1963 we have a current copy. */
1965 j = target_read_memory (debug_addr, (char *) &debug_copy,
1966 sizeof (debug_copy));
1968 return; /* unreadable */
1970 /* Get common symbol definitions for the loaded object. */
1972 if (debug_copy.ldd_cp)
1974 solib_add_common_symbols (debug_copy.ldd_cp);
1977 #endif /* !SVR4_SHARED_LIBS */
1985 sharedlibrary_command -- handle command to explicitly add library
1989 static void sharedlibrary_command (char *args, int from_tty)
1996 sharedlibrary_command (args, from_tty)
2001 solib_add (args, from_tty, (struct target_ops *) 0);
2004 #endif /* HAVE_LINK_H */
2011 add_com ("sharedlibrary", class_files, sharedlibrary_command,
2012 "Load shared object library symbols for files matching REGEXP.");
2013 add_info ("sharedlibrary", info_sharedlibrary_command,
2014 "Status of loaded shared object libraries.");
2017 (add_set_cmd ("auto-solib-add", class_support, var_zinteger,
2018 (char *) &auto_solib_add,
2019 "Set autoloading of shared library symbols.\n\
2020 If nonzero, symbols from all shared object libraries will be loaded\n\
2021 automatically when the inferior begins execution or when the dynamic linker\n\
2022 informs gdb that a new library has been loaded. Otherwise, symbols\n\
2023 must be loaded manually, using `sharedlibrary'.",
2028 (add_set_cmd ("solib-absolute-prefix", class_support, var_filename,
2029 (char *) &solib_absolute_prefix,
2030 "Set prefix for loading absolute shared library symbol files.\n\
2031 For other (relative) files, you can add values using `set solib-search-path'.",
2035 (add_set_cmd ("solib-search-path", class_support, var_string,
2036 (char *) &solib_search_path,
2037 "Set the search path for loading non-absolute shared library symbol files.\n\
2038 This takes precedence over the environment variables PATH and LD_LIBRARY_PATH.",
2042 #endif /* HAVE_LINK_H */