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 $ */
25 /* This file is only compilable if link.h is available. */
29 #include <sys/types.h>
31 #include "gdb_string.h"
32 #include <sys/param.h>
36 #ifndef SVR4_SHARED_LIBS
37 /* SunOS shared libs need the nlist structure. */
40 #include "elf/external.h"
41 #include "elf/common.h"
54 #include "gnu-regex.h"
60 #define MAX_PATH_SIZE 512 /* FIXME: Should be dynamic */
62 /* On SVR4 systems, a list of symbols in the dynamic linker where
63 GDB can try to place a breakpoint to monitor shared library
66 If none of these symbols are found, or other errors occur, then
67 SVR4 systems will fall back to using a symbol as the "startup
68 mapping complete" breakpoint address. */
70 #ifdef SVR4_SHARED_LIBS
71 static char *solib_break_names[] = {
80 #define BKPT_AT_SYMBOL 1
82 #if defined (BKPT_AT_SYMBOL) && defined (SVR4_SHARED_LIBS)
83 static char *bkpt_names[] = {
84 #ifdef SOLIB_BKPT_NAME
85 SOLIB_BKPT_NAME, /* Prefer configured name if it exists. */
93 /* Symbols which are used to locate the base of the link map structures. */
95 #ifndef SVR4_SHARED_LIBS
96 static char *debug_base_symbols[] = {
103 static char *main_name_list[] = {
108 /* local data declarations */
110 #ifndef SVR4_SHARED_LIBS
112 #define LM_ADDR(so) ((so) -> lm.lm_addr)
113 #define LM_NEXT(so) ((so) -> lm.lm_next)
114 #define LM_NAME(so) ((so) -> lm.lm_name)
115 /* Test for first link map entry; first entry is a shared library. */
116 #define IGNORE_FIRST_LINK_MAP_ENTRY(x) (0)
117 static struct link_dynamic dynamic_copy;
118 static struct link_dynamic_2 ld_2_copy;
119 static struct ld_debug debug_copy;
120 static CORE_ADDR debug_addr;
121 static CORE_ADDR flag_addr;
123 #else /* SVR4_SHARED_LIBS */
125 #define LM_ADDR(so) ((so) -> lm.l_addr)
126 #define LM_NEXT(so) ((so) -> lm.l_next)
127 #define LM_NAME(so) ((so) -> lm.l_name)
128 /* Test for first link map entry; first entry is the exec-file. */
129 #define IGNORE_FIRST_LINK_MAP_ENTRY(x) ((x).l_prev == NULL)
130 static struct r_debug debug_copy;
131 char shadow_contents[BREAKPOINT_MAX]; /* Stash old bkpt addr contents */
133 #endif /* !SVR4_SHARED_LIBS */
136 struct so_list *next; /* next structure in linked list */
137 struct link_map lm; /* copy of link map from inferior */
138 struct link_map *lmaddr; /* addr in inferior lm was read from */
139 CORE_ADDR lmend; /* upper addr bound of mapped object */
140 char so_name[MAX_PATH_SIZE]; /* shared object lib name (FIXME) */
141 char symbols_loaded; /* flag: symbols read in yet? */
142 char from_tty; /* flag: print msgs? */
143 struct objfile *objfile; /* objfile for loaded lib */
144 struct section_table *sections;
145 struct section_table *sections_end;
146 struct section_table *textsection;
150 static struct so_list *so_list_head; /* List of known shared objects */
151 static CORE_ADDR debug_base; /* Base of dynamic linker structures */
152 static CORE_ADDR breakpoint_addr; /* Address where end bkpt is set */
154 static int solib_cleanup_queued = 0; /* make_run_cleanup called */
157 fdmatch PARAMS ((int, int)); /* In libiberty */
159 /* Local function prototypes */
162 do_clear_solib PARAMS ((PTR));
165 match_main PARAMS ((char *));
168 special_symbol_handling PARAMS ((struct so_list *));
171 sharedlibrary_command PARAMS ((char *, int));
174 enable_break PARAMS ((void));
177 info_sharedlibrary_command PARAMS ((char *, int));
179 static int symbol_add_stub PARAMS ((PTR));
181 static struct so_list *
182 alloc_solib PARAMS ((struct link_map *));
185 free_solib PARAMS ((struct so_list *));
187 static struct so_list *
188 find_solib PARAMS ((struct so_list *, int maybe_changed));
190 static struct link_map *
191 first_link_map_member PARAMS ((void));
194 locate_base PARAMS ((void));
196 static int solib_map_sections PARAMS ((PTR));
198 #ifdef SVR4_SHARED_LIBS
201 elf_locate_base PARAMS ((void));
206 disable_break PARAMS ((void));
209 allocate_rt_common_objfile PARAMS ((void));
212 solib_add_common_symbols PARAMS ((struct rtc_symb *));
216 void _initialize_solib PARAMS ((void));
218 /* If non-zero, this is a prefix that will be added to the front of the name
219 shared libraries with an absolute filename for loading. */
220 static char *solib_absolute_prefix = NULL;
222 /* If non-empty, this is a search path for loading non-absolute shared library
223 symbol files. This takes precedence over the environment variables PATH
224 and LD_LIBRARY_PATH. */
225 static char *solib_search_path = NULL;
231 solib_map_sections -- open bfd and build sections for shared lib
235 static int solib_map_sections (struct so_list *so)
239 Given a pointer to one of the shared objects in our list
240 of mapped objects, use the recorded name to open a bfd
241 descriptor for the object, build a section table, and then
242 relocate all the section addresses by the base address at
243 which the shared object was mapped.
247 In most (all?) cases the shared object file name recorded in the
248 dynamic linkage tables will be a fully qualified pathname. For
249 cases where it isn't, do we really mimic the systems search
250 mechanism correctly in the below code (particularly the tilde
255 solib_map_sections (arg)
258 struct so_list *so = (struct so_list *) arg; /* catch_errors bogon */
260 char *scratch_pathname;
262 struct section_table *p;
263 struct cleanup *old_chain;
266 filename = tilde_expand (so -> so_name);
268 if (solib_absolute_prefix && ROOTED_P (filename))
269 /* Prefix shared libraries with absolute filenames with
270 SOLIB_ABSOLUTE_PREFIX. */
275 pfx_len = strlen (solib_absolute_prefix);
277 /* Remove trailing slashes. */
278 while (pfx_len > 0 && SLASH_P (solib_absolute_prefix[pfx_len - 1]))
281 pfxed_fn = xmalloc (pfx_len + strlen (filename) + 1);
282 strcpy (pfxed_fn, solib_absolute_prefix);
283 strcat (pfxed_fn, filename);
289 old_chain = make_cleanup (free, filename);
293 if (solib_search_path)
294 scratch_chan = openp (solib_search_path,
295 1, filename, O_RDONLY, 0, &scratch_pathname);
296 if (scratch_chan < 0)
297 scratch_chan = openp (get_in_environ (inferior_environ, "PATH"),
298 1, filename, O_RDONLY, 0, &scratch_pathname);
299 if (scratch_chan < 0)
301 scratch_chan = openp (get_in_environ
302 (inferior_environ, "LD_LIBRARY_PATH"),
303 1, filename, O_RDONLY, 0, &scratch_pathname);
305 if (scratch_chan < 0)
307 perror_with_name (filename);
309 /* Leave scratch_pathname allocated. abfd->name will point to it. */
311 abfd = bfd_fdopenr (scratch_pathname, gnutarget, scratch_chan);
314 close (scratch_chan);
315 error ("Could not open `%s' as an executable file: %s",
316 scratch_pathname, bfd_errmsg (bfd_get_error ()));
318 /* Leave bfd open, core_xfer_memory and "info files" need it. */
320 abfd -> cacheable = true;
322 /* copy full path name into so_name, so that later symbol_file_add can find
324 if (strlen (scratch_pathname) >= MAX_PATH_SIZE)
325 error ("Full path name length of shared library exceeds MAX_PATH_SIZE in so_list structure.");
326 strcpy (so->so_name, scratch_pathname);
328 if (!bfd_check_format (abfd, bfd_object))
330 error ("\"%s\": not in executable format: %s.",
331 scratch_pathname, bfd_errmsg (bfd_get_error ()));
333 if (build_section_table (abfd, &so -> sections, &so -> sections_end))
335 error ("Can't find the file sections in `%s': %s",
336 bfd_get_filename (abfd), bfd_errmsg (bfd_get_error ()));
339 for (p = so -> sections; p < so -> sections_end; p++)
341 /* Relocate the section binding addresses as recorded in the shared
342 object's file by the base address to which the object was actually
344 p -> addr += (CORE_ADDR) LM_ADDR (so);
345 p -> endaddr += (CORE_ADDR) LM_ADDR (so);
346 so -> lmend = (CORE_ADDR) max (p -> endaddr, so -> lmend);
347 if (STREQ (p -> the_bfd_section -> name, ".text"))
349 so -> textsection = p;
353 /* Free the file names, close the file now. */
354 do_cleanups (old_chain);
359 #ifndef SVR4_SHARED_LIBS
361 /* Allocate the runtime common object file. */
364 allocate_rt_common_objfile ()
366 struct objfile *objfile;
367 struct objfile *last_one;
369 objfile = (struct objfile *) xmalloc (sizeof (struct objfile));
370 memset (objfile, 0, sizeof (struct objfile));
371 objfile -> md = NULL;
372 obstack_specify_allocation (&objfile -> psymbol_cache.cache, 0, 0,
374 obstack_specify_allocation (&objfile -> psymbol_obstack, 0, 0, xmalloc,
376 obstack_specify_allocation (&objfile -> symbol_obstack, 0, 0, xmalloc,
378 obstack_specify_allocation (&objfile -> type_obstack, 0, 0, xmalloc,
380 objfile -> name = mstrsave (objfile -> md, "rt_common");
382 /* Add this file onto the tail of the linked list of other such files. */
384 objfile -> next = NULL;
385 if (object_files == NULL)
386 object_files = objfile;
389 for (last_one = object_files;
391 last_one = last_one -> next);
392 last_one -> next = objfile;
395 rt_common_objfile = objfile;
398 /* Read all dynamically loaded common symbol definitions from the inferior
399 and put them into the minimal symbol table for the runtime common
403 solib_add_common_symbols (rtc_symp)
404 struct rtc_symb *rtc_symp;
406 struct rtc_symb inferior_rtc_symb;
407 struct nlist inferior_rtc_nlist;
411 /* Remove any runtime common symbols from previous runs. */
413 if (rt_common_objfile != NULL && rt_common_objfile -> minimal_symbol_count)
415 obstack_free (&rt_common_objfile -> symbol_obstack, 0);
416 obstack_specify_allocation (&rt_common_objfile -> symbol_obstack, 0, 0,
418 rt_common_objfile -> minimal_symbol_count = 0;
419 rt_common_objfile -> msymbols = NULL;
422 init_minimal_symbol_collection ();
423 make_cleanup ((make_cleanup_func) discard_minimal_symbols, 0);
427 read_memory ((CORE_ADDR) rtc_symp,
428 (char *) &inferior_rtc_symb,
429 sizeof (inferior_rtc_symb));
430 read_memory ((CORE_ADDR) inferior_rtc_symb.rtc_sp,
431 (char *) &inferior_rtc_nlist,
432 sizeof(inferior_rtc_nlist));
433 if (inferior_rtc_nlist.n_type == N_COMM)
435 /* FIXME: The length of the symbol name is not available, but in the
436 current implementation the common symbol is allocated immediately
437 behind the name of the symbol. */
438 len = inferior_rtc_nlist.n_value - inferior_rtc_nlist.n_un.n_strx;
440 name = xmalloc (len);
441 read_memory ((CORE_ADDR) inferior_rtc_nlist.n_un.n_name, name, len);
443 /* Allocate the runtime common objfile if necessary. */
444 if (rt_common_objfile == NULL)
445 allocate_rt_common_objfile ();
447 prim_record_minimal_symbol (name, inferior_rtc_nlist.n_value,
448 mst_bss, rt_common_objfile);
451 rtc_symp = inferior_rtc_symb.rtc_next;
454 /* Install any minimal symbols that have been collected as the current
455 minimal symbols for the runtime common objfile. */
457 install_minimal_symbols (rt_common_objfile);
460 #endif /* SVR4_SHARED_LIBS */
463 #ifdef SVR4_SHARED_LIBS
466 bfd_lookup_symbol PARAMS ((bfd *, char *));
472 bfd_lookup_symbol -- lookup the value for a specific symbol
476 CORE_ADDR bfd_lookup_symbol (bfd *abfd, char *symname)
480 An expensive way to lookup the value of a single symbol for
481 bfd's that are only temporary anyway. This is used by the
482 shared library support to find the address of the debugger
483 interface structures in the shared library.
485 Note that 0 is specifically allowed as an error return (no
490 bfd_lookup_symbol (abfd, symname)
496 asymbol **symbol_table;
497 unsigned int number_of_symbols;
499 struct cleanup *back_to;
500 CORE_ADDR symaddr = 0;
502 storage_needed = bfd_get_symtab_upper_bound (abfd);
504 if (storage_needed > 0)
506 symbol_table = (asymbol **) xmalloc (storage_needed);
507 back_to = make_cleanup (free, (PTR)symbol_table);
508 number_of_symbols = bfd_canonicalize_symtab (abfd, symbol_table);
510 for (i = 0; i < number_of_symbols; i++)
512 sym = *symbol_table++;
513 if (STREQ (sym -> name, symname))
515 /* Bfd symbols are section relative. */
516 symaddr = sym -> value + sym -> section -> vma;
520 do_cleanups (back_to);
523 if (symaddr) return (symaddr);
525 storage_needed = bfd_get_dynamic_symtab_upper_bound (abfd);
527 if (storage_needed > 0)
529 symbol_table = (asymbol **) xmalloc (storage_needed);
530 back_to = make_cleanup (free, (PTR)symbol_table);
531 number_of_symbols = bfd_canonicalize_dynamic_symtab (abfd, symbol_table);
533 for (i = 0; i < number_of_symbols; i++)
535 sym = *symbol_table++;
536 if (STREQ (sym -> name, symname))
538 /* Bfd symbols are section relative. */
539 symaddr = sym -> value + sym -> section -> vma;
543 do_cleanups (back_to);
548 #ifdef HANDLE_SVR4_EXEC_EMULATORS
551 Solaris BCP (the part of Solaris which allows it to run SunOS4
552 a.out files) throws in another wrinkle. Solaris does not fill
553 in the usual a.out link map structures when running BCP programs,
554 the only way to get at them is via groping around in the dynamic
556 The dynamic linker and it's structures are located in the shared
557 C library, which gets run as the executable's "interpreter" by
560 Note that we can assume nothing about the process state at the time
561 we need to find these structures. We may be stopped on the first
562 instruction of the interpreter (C shared library), the first
563 instruction of the executable itself, or somewhere else entirely
564 (if we attached to the process for example).
567 static char *debug_base_symbols[] = {
568 "r_debug", /* Solaris 2.3 */
569 "_r_debug", /* Solaris 2.1, 2.2 */
574 look_for_base PARAMS ((int, CORE_ADDR));
580 look_for_base -- examine file for each mapped address segment
584 static int look_for_base (int fd, CORE_ADDR baseaddr)
588 This function is passed to proc_iterate_over_mappings, which
589 causes it to get called once for each mapped address space, with
590 an open file descriptor for the file mapped to that space, and the
591 base address of that mapped space.
593 Our job is to find the debug base symbol in the file that this
594 fd is open on, if it exists, and if so, initialize the dynamic
595 linker structure base address debug_base.
597 Note that this is a computationally expensive proposition, since
598 we basically have to open a bfd on every call, so we specifically
599 avoid opening the exec file.
603 look_for_base (fd, baseaddr)
608 CORE_ADDR address = 0;
611 /* If the fd is -1, then there is no file that corresponds to this
612 mapped memory segment, so skip it. Also, if the fd corresponds
613 to the exec file, skip it as well. */
617 && fdmatch (fileno ((FILE *)(exec_bfd -> iostream)), fd)))
622 /* Try to open whatever random file this fd corresponds to. Note that
623 we have no way currently to find the filename. Don't gripe about
624 any problems we might have, just fail. */
626 if ((interp_bfd = bfd_fdopenr ("unnamed", gnutarget, fd)) == NULL)
630 if (!bfd_check_format (interp_bfd, bfd_object))
632 /* FIXME-leak: on failure, might not free all memory associated with
634 bfd_close (interp_bfd);
638 /* Now try to find our debug base symbol in this file, which we at
639 least know to be a valid ELF executable or shared library. */
641 for (symbolp = debug_base_symbols; *symbolp != NULL; symbolp++)
643 address = bfd_lookup_symbol (interp_bfd, *symbolp);
651 /* FIXME-leak: on failure, might not free all memory associated with
653 bfd_close (interp_bfd);
657 /* Eureka! We found the symbol. But now we may need to relocate it
658 by the base address. If the symbol's value is less than the base
659 address of the shared library, then it hasn't yet been relocated
660 by the dynamic linker, and we have to do it ourself. FIXME: Note
661 that we make the assumption that the first segment that corresponds
662 to the shared library has the base address to which the library
665 if (address < baseaddr)
669 debug_base = address;
670 /* FIXME-leak: on failure, might not free all memory associated with
672 bfd_close (interp_bfd);
675 #endif /* HANDLE_SVR4_EXEC_EMULATORS */
681 elf_locate_base -- locate the base address of dynamic linker structs
682 for SVR4 elf targets.
686 CORE_ADDR elf_locate_base (void)
690 For SVR4 elf targets the address of the dynamic linker's runtime
691 structure is contained within the dynamic info section in the
692 executable file. The dynamic section is also mapped into the
693 inferior address space. Because the runtime loader fills in the
694 real address before starting the inferior, we have to read in the
695 dynamic info section from the inferior address space.
696 If there are any errors while trying to find the address, we
697 silently return 0, otherwise the found address is returned.
704 sec_ptr dyninfo_sect;
705 int dyninfo_sect_size;
706 CORE_ADDR dyninfo_addr;
710 /* Find the start address of the .dynamic section. */
711 dyninfo_sect = bfd_get_section_by_name (exec_bfd, ".dynamic");
712 if (dyninfo_sect == NULL)
714 dyninfo_addr = bfd_section_vma (exec_bfd, dyninfo_sect);
716 /* Read in .dynamic section, silently ignore errors. */
717 dyninfo_sect_size = bfd_section_size (exec_bfd, dyninfo_sect);
718 buf = alloca (dyninfo_sect_size);
719 if (target_read_memory (dyninfo_addr, buf, dyninfo_sect_size))
722 /* Find the DT_DEBUG entry in the the .dynamic section.
723 For mips elf we look for DT_MIPS_RLD_MAP, mips elf apparently has
724 no DT_DEBUG entries. */
726 for (bufend = buf + dyninfo_sect_size;
728 buf += sizeof (Elf32_External_Dyn))
730 Elf32_External_Dyn *x_dynp = (Elf32_External_Dyn *)buf;
734 dyn_tag = bfd_h_get_32 (exec_bfd, (bfd_byte *) x_dynp->d_tag);
735 if (dyn_tag == DT_NULL)
737 else if (dyn_tag == DT_DEBUG)
739 dyn_ptr = bfd_h_get_32 (exec_bfd, (bfd_byte *) x_dynp->d_un.d_ptr);
742 #ifdef DT_MIPS_RLD_MAP
743 else if (dyn_tag == DT_MIPS_RLD_MAP)
745 char pbuf[TARGET_PTR_BIT / HOST_CHAR_BIT];
747 /* DT_MIPS_RLD_MAP contains a pointer to the address
748 of the dynamic link structure. */
749 dyn_ptr = bfd_h_get_32 (exec_bfd, (bfd_byte *) x_dynp->d_un.d_ptr);
750 if (target_read_memory (dyn_ptr, pbuf, sizeof (pbuf)))
752 return extract_unsigned_integer (pbuf, sizeof (pbuf));
757 for (bufend = buf + dyninfo_sect_size;
759 buf += sizeof (Elf64_External_Dyn))
761 Elf64_External_Dyn *x_dynp = (Elf64_External_Dyn *)buf;
765 dyn_tag = bfd_h_get_64 (exec_bfd, (bfd_byte *) x_dynp->d_tag);
766 if (dyn_tag == DT_NULL)
768 else if (dyn_tag == DT_DEBUG)
770 dyn_ptr = bfd_h_get_64 (exec_bfd, (bfd_byte *) x_dynp->d_un.d_ptr);
776 /* DT_DEBUG entry not found. */
780 #endif /* SVR4_SHARED_LIBS */
786 locate_base -- locate the base address of dynamic linker structs
790 CORE_ADDR locate_base (void)
794 For both the SunOS and SVR4 shared library implementations, if the
795 inferior executable has been linked dynamically, there is a single
796 address somewhere in the inferior's data space which is the key to
797 locating all of the dynamic linker's runtime structures. This
798 address is the value of the debug base symbol. The job of this
799 function is to find and return that address, or to return 0 if there
800 is no such address (the executable is statically linked for example).
802 For SunOS, the job is almost trivial, since the dynamic linker and
803 all of it's structures are statically linked to the executable at
804 link time. Thus the symbol for the address we are looking for has
805 already been added to the minimal symbol table for the executable's
806 objfile at the time the symbol file's symbols were read, and all we
807 have to do is look it up there. Note that we explicitly do NOT want
808 to find the copies in the shared library.
810 The SVR4 version is a bit more complicated because the address
811 is contained somewhere in the dynamic info section. We have to go
812 to a lot more work to discover the address of the debug base symbol.
813 Because of this complexity, we cache the value we find and return that
814 value on subsequent invocations. Note there is no copy in the
815 executable symbol tables.
823 #ifndef SVR4_SHARED_LIBS
825 struct minimal_symbol *msymbol;
826 CORE_ADDR address = 0;
829 /* For SunOS, we want to limit the search for the debug base symbol to the
830 executable being debugged, since there is a duplicate named symbol in the
831 shared library. We don't want the shared library versions. */
833 for (symbolp = debug_base_symbols; *symbolp != NULL; symbolp++)
835 msymbol = lookup_minimal_symbol (*symbolp, NULL, symfile_objfile);
836 if ((msymbol != NULL) && (SYMBOL_VALUE_ADDRESS (msymbol) != 0))
838 address = SYMBOL_VALUE_ADDRESS (msymbol);
844 #else /* SVR4_SHARED_LIBS */
846 /* Check to see if we have a currently valid address, and if so, avoid
847 doing all this work again and just return the cached address. If
848 we have no cached address, try to locate it in the dynamic info
849 section for ELF executables. */
854 && bfd_get_flavour (exec_bfd) == bfd_target_elf_flavour)
855 debug_base = elf_locate_base ();
856 #ifdef HANDLE_SVR4_EXEC_EMULATORS
857 /* Try it the hard way for emulated executables. */
858 else if (inferior_pid != 0 && target_has_execution)
859 proc_iterate_over_mappings (look_for_base);
864 #endif /* !SVR4_SHARED_LIBS */
872 first_link_map_member -- locate first member in dynamic linker's map
876 static struct link_map *first_link_map_member (void)
880 Read in a copy of the first member in the inferior's dynamic
881 link map from the inferior's dynamic linker structures, and return
882 a pointer to the copy in our address space.
885 static struct link_map *
886 first_link_map_member ()
888 struct link_map *lm = NULL;
890 #ifndef SVR4_SHARED_LIBS
892 read_memory (debug_base, (char *) &dynamic_copy, sizeof (dynamic_copy));
893 if (dynamic_copy.ld_version >= 2)
895 /* It is a version that we can deal with, so read in the secondary
896 structure and find the address of the link map list from it. */
897 read_memory ((CORE_ADDR) dynamic_copy.ld_un.ld_2, (char *) &ld_2_copy,
898 sizeof (struct link_dynamic_2));
899 lm = ld_2_copy.ld_loaded;
902 #else /* SVR4_SHARED_LIBS */
904 read_memory (debug_base, (char *) &debug_copy, sizeof (struct r_debug));
905 /* FIXME: Perhaps we should validate the info somehow, perhaps by
906 checking r_version for a known version number, or r_state for
908 lm = debug_copy.r_map;
910 #endif /* !SVR4_SHARED_LIBS */
919 free_solib -- free a so_list structure
923 void free_solib (struct so_list *so_list_ptr)
927 Free the memory used by a struct so_list.
938 free ((PTR)so -> sections);
942 bfd_filename = bfd_get_filename (so -> abfd);
943 if (!bfd_close (so -> abfd))
944 warning ("cannot close \"%s\": %s",
945 bfd_filename, bfd_errmsg (bfd_get_error ()));
948 /* This happens for the executable on SVR4. */
952 free ((PTR)bfd_filename);
960 alloc_solib -- free a so_list structure
964 struct so_list *alloc_solib (struct link_map *lm)
968 Allocate the struct so_list to cache debugging information
969 for a struct link_map entry in the target.
979 /* Get next link map structure from inferior image and build a local
980 abbreviated load_map structure */
981 new = (struct so_list *) xmalloc (sizeof (struct so_list));
982 memset ((char *) new, 0, sizeof (struct so_list));
985 read_memory ((CORE_ADDR) lm, (char *) &(new -> lm),
986 sizeof (struct link_map));
987 /* For SVR4 versions, the first entry in the link map is for the
988 inferior executable, so we must ignore it. For some versions of
989 SVR4, it has no name. For others (Solaris 2.3 for example), it
990 does have a name, so we can no longer use a missing name to
991 decide when to ignore it. */
992 if (!IGNORE_FIRST_LINK_MAP_ENTRY (new -> lm))
996 target_read_string ((CORE_ADDR) LM_NAME (new), &buffer,
997 MAX_PATH_SIZE - 1, &errcode);
999 error ("find_solib: Can't read pathname for load map: %s\n",
1000 safe_strerror (errcode));
1001 strncpy (new -> so_name, buffer, MAX_PATH_SIZE - 1);
1002 new -> so_name[MAX_PATH_SIZE - 1] = '\0';
1004 solib_map_sections (new);
1014 find_solib -- step through list of shared objects
1018 struct so_list *find_solib (struct so_list *so_list_ptr, int maybe_changed)
1022 This module contains the routine which finds the names of any
1023 loaded "images" in the current process. The argument in must be
1024 NULL on the first call, and then the returned value must be passed
1025 in on subsequent calls. This provides the capability to "step" down
1026 the list of loaded objects. On the last object, a NULL value is
1029 The arg and return value are "struct link_map" pointers, as defined
1032 If it is expected that the contents of the shared library list has changed
1033 (e.g. when the special shared library breakpoint is hit) then pass non-zero
1034 for maybe_changed, otherwise zero.
1037 static struct so_list *
1038 find_solib (so_list_ptr, maybe_changed)
1039 struct so_list *so_list_ptr; /* Last lm or NULL for first one */
1040 int maybe_changed; /* non-zero if shlib list might have changed */
1042 struct link_map *lm = NULL;
1043 struct so_list *new;
1044 struct so_list *so_list_next;
1045 struct so_list *p, **prev;
1047 if (so_list_ptr == NULL)
1049 struct so_list **map;
1051 /* If we have not already read in the dynamic linking structures
1052 from the inferior, lookup the address of the base structure. */
1053 if (debug_base == 0)
1054 debug_base = locate_base ();
1055 if (debug_base != 0)
1057 /* Read the base structure in and find the address of the first
1058 link map list member. */
1059 lm = first_link_map_member ();
1064 prev = &so_list_head;
1065 so_list_ptr = so_list_head;
1069 /* We have been called before, and are in the process of walking
1070 the shared library list. Advance to the next shared object.
1072 Always read from the target to check to see if any were
1073 added, but be quiet if we can't read from the target any more. */
1074 int status = target_read_memory ((CORE_ADDR) so_list_ptr -> lmaddr,
1075 (char *) &(so_list_ptr -> lm),
1076 sizeof (struct link_map));
1080 lm = LM_NEXT (so_list_ptr);
1087 prev = &so_list_ptr -> next;
1088 so_list_ptr = so_list_ptr -> next;
1091 /* If we don't believe that the list has changed, just return the cached copy. */
1093 return (so_list_ptr);
1095 /* At this point, lm is the address of the next list element in the target and
1096 so_list_ptr is our cached entry for it. */
1100 if (so_list_ptr == NULL || so_list_ptr -> lmaddr != lm)
1102 /* We have detected a change in the list. Check for a deletion by searching
1103 forward in the cached list */
1106 for (p = so_list_ptr -> next; p; p = p -> next)
1107 if (p -> lmaddr == lm)
1115 /* This lib has been deleted */
1116 while (so_list_ptr != p)
1118 *prev = so_list_ptr -> next;
1119 free_solib (so_list_ptr);
1120 so_list_ptr = *prev;
1125 /* A new lib has been inserted into the list */
1126 new = alloc_solib (lm);
1127 new -> next = so_list_ptr;
1135 if (so_list_ptr != NULL)
1139 if (! solib_cleanup_queued)
1141 make_run_cleanup (do_clear_solib, NULL);
1142 solib_cleanup_queued = 1;
1148 target_read_memory ((CORE_ADDR) lm, (char *) &(new -> lm),
1149 sizeof (struct link_map));
1150 /* For SVR4 versions, the first entry in the link map is for the
1151 inferior executable, so we must ignore it. For some versions of
1152 SVR4, it has no name. For others (Solaris 2.3 for example), it
1153 does have a name, so we can no longer use a missing name to
1154 decide when to ignore it. */
1155 if (lm && new && !IGNORE_FIRST_LINK_MAP_ENTRY (new -> lm))
1159 target_read_string ((CORE_ADDR) LM_NAME (new), &buffer,
1160 MAX_PATH_SIZE - 1, &errcode);
1163 warning ("find_solib: Can't read pathname for load map: %s\n",
1164 safe_strerror (errcode));
1165 return (so_list_next);
1167 strncpy (new -> so_name, buffer, MAX_PATH_SIZE - 1);
1168 new -> so_name[MAX_PATH_SIZE - 1] = '\0';
1170 catch_errors (solib_map_sections, new,
1171 "Error while mapping shared library sections:\n",
1176 return (so_list_ptr);
1179 /* A small stub to get us past the arg-passing pinhole of catch_errors. */
1182 symbol_add_stub (arg)
1185 register struct so_list *so = (struct so_list *) arg; /* catch_errs bogon */
1186 CORE_ADDR text_addr = 0;
1188 if (so -> textsection)
1189 text_addr = so -> textsection -> addr;
1190 else if (so -> abfd != NULL)
1192 asection *lowest_sect;
1194 /* If we didn't find a mapped non zero sized .text section, set up
1195 text_addr so that the relocation in symbol_file_add does no harm. */
1197 lowest_sect = bfd_get_section_by_name (so -> abfd, ".text");
1198 if (lowest_sect == NULL)
1199 bfd_map_over_sections (so -> abfd, find_lowest_section,
1200 (PTR) &lowest_sect);
1202 text_addr = bfd_section_vma (so -> abfd, lowest_sect)
1203 + (CORE_ADDR) LM_ADDR (so);
1206 ALL_OBJFILES (so -> objfile)
1208 if (strcmp (so -> objfile -> name, so -> so_name) == 0)
1212 symbol_file_add (so -> so_name, so -> from_tty,
1218 /* This function will check the so name to see if matches the main list.
1219 In some system the main object is in the list, which we want to exclude */
1221 static int match_main (soname)
1226 for (mainp = main_name_list; *mainp != NULL; mainp++)
1228 if (strcmp (soname, *mainp) == 0)
1239 solib_add -- add a shared library file to the symtab and section list
1243 void solib_add (char *arg_string, int from_tty,
1244 struct target_ops *target)
1251 solib_add (arg_string, from_tty, target)
1254 struct target_ops *target;
1256 register struct so_list *so = NULL; /* link map state variable */
1258 /* Last shared library that we read. */
1259 struct so_list *so_last = NULL;
1265 if ((re_err = re_comp (arg_string ? arg_string : ".")) != NULL)
1267 error ("Invalid regexp: %s", re_err);
1270 /* Add the shared library sections to the section table of the
1271 specified target, if any. */
1274 /* Count how many new section_table entries there are. */
1277 while ((so = find_solib (so, 1)) != NULL)
1279 if (so -> so_name[0] && !match_main (so -> so_name))
1281 count += so -> sections_end - so -> sections;
1289 /* We must update the to_sections field in the core_ops structure
1290 here, otherwise we dereference a potential dangling pointer
1291 for each call to target_read/write_memory within this routine. */
1292 update_coreops = core_ops.to_sections == target->to_sections;
1294 /* Reallocate the target's section table including the new size. */
1295 if (target -> to_sections)
1297 old = target -> to_sections_end - target -> to_sections;
1298 target -> to_sections = (struct section_table *)
1299 xrealloc ((char *)target -> to_sections,
1300 (sizeof (struct section_table)) * (count + old));
1305 target -> to_sections = (struct section_table *)
1306 xmalloc ((sizeof (struct section_table)) * count);
1308 target -> to_sections_end = target -> to_sections + (count + old);
1310 /* Update the to_sections field in the core_ops structure
1314 core_ops.to_sections = target->to_sections;
1315 core_ops.to_sections_end = target->to_sections_end;
1318 /* Add these section table entries to the target's table. */
1319 while ((so = find_solib (so, 1)) != NULL)
1321 if (so -> so_name[0])
1323 count = so -> sections_end - so -> sections;
1324 memcpy ((char *) (target -> to_sections + old),
1326 (sizeof (struct section_table)) * count);
1333 /* Now add the symbol files. */
1334 while ((so = find_solib (so, 1)) != NULL)
1336 if (so -> so_name[0] && re_exec (so -> so_name) &&
1337 !match_main (so -> so_name))
1339 so -> from_tty = from_tty;
1340 if (so -> symbols_loaded)
1344 printf_unfiltered ("Symbols already loaded for %s\n", so -> so_name);
1347 else if (catch_errors
1348 (symbol_add_stub, so,
1349 "Error while reading shared library symbols:\n",
1353 so -> symbols_loaded = 1;
1358 /* Getting new symbols may change our opinion about what is
1361 reinit_frame_cache ();
1364 special_symbol_handling (so_last);
1371 info_sharedlibrary_command -- code for "info sharedlibrary"
1375 static void info_sharedlibrary_command ()
1379 Walk through the shared library list and print information
1380 about each attached library.
1384 info_sharedlibrary_command (ignore, from_tty)
1388 register struct so_list *so = NULL; /* link map state variable */
1389 int header_done = 0;
1393 if (exec_bfd == NULL)
1395 printf_unfiltered ("No exec file.\n");
1399 #ifndef TARGET_ELF64
1407 while ((so = find_solib (so, 0)) != NULL)
1409 if (so -> so_name[0])
1413 printf_unfiltered("%-*s%-*s%-12s%s\n", addr_width, "From",
1414 addr_width, "To", "Syms Read",
1415 "Shared Object Library");
1419 printf_unfiltered ("%-*s", addr_width,
1420 local_hex_string_custom ((unsigned long) LM_ADDR (so),
1422 printf_unfiltered ("%-*s", addr_width,
1423 local_hex_string_custom ((unsigned long) so -> lmend,
1425 printf_unfiltered ("%-12s", so -> symbols_loaded ? "Yes" : "No");
1426 printf_unfiltered ("%s\n", so -> so_name);
1429 if (so_list_head == NULL)
1431 printf_unfiltered ("No shared libraries loaded at this time.\n");
1439 solib_address -- check to see if an address is in a shared lib
1443 char * solib_address (CORE_ADDR address)
1447 Provides a hook for other gdb routines to discover whether or
1448 not a particular address is within the mapped address space of
1449 a shared library. Any address between the base mapping address
1450 and the first address beyond the end of the last mapping, is
1451 considered to be within the shared library address space, for
1454 For example, this routine is called at one point to disable
1455 breakpoints which are in shared libraries that are not currently
1460 solib_address (address)
1463 register struct so_list *so = 0; /* link map state variable */
1465 while ((so = find_solib (so, 0)) != NULL)
1467 if (so -> so_name[0])
1469 if ((address >= (CORE_ADDR) LM_ADDR (so)) &&
1470 (address < (CORE_ADDR) so -> lmend))
1471 return (so->so_name);
1477 /* Called by free_all_symtabs */
1482 struct so_list *next;
1485 while (so_list_head)
1487 next = so_list_head -> next;
1488 free_solib (so_list_head);
1489 so_list_head = next;
1495 do_clear_solib (dummy)
1498 solib_cleanup_queued = 0;
1502 #ifdef SVR4_SHARED_LIBS
1504 /* Return 1 if PC lies in the dynamic symbol resolution code of the
1505 SVR4 run time loader. */
1507 static CORE_ADDR interp_text_sect_low;
1508 static CORE_ADDR interp_text_sect_high;
1509 static CORE_ADDR interp_plt_sect_low;
1510 static CORE_ADDR interp_plt_sect_high;
1513 in_svr4_dynsym_resolve_code (pc)
1516 return ((pc >= interp_text_sect_low && pc < interp_text_sect_high)
1517 || (pc >= interp_plt_sect_low && pc < interp_plt_sect_high)
1518 || in_plt_section (pc, NULL));
1526 disable_break -- remove the "mapping changed" breakpoint
1530 static int disable_break ()
1534 Removes the breakpoint that gets hit when the dynamic linker
1535 completes a mapping change.
1539 #ifndef SVR4_SHARED_LIBS
1546 #ifndef SVR4_SHARED_LIBS
1548 int in_debugger = 0;
1550 /* Read the debugger structure from the inferior to retrieve the
1551 address of the breakpoint and the original contents of the
1552 breakpoint address. Remove the breakpoint by writing the original
1555 read_memory (debug_addr, (char *) &debug_copy, sizeof (debug_copy));
1557 /* Set `in_debugger' to zero now. */
1559 write_memory (flag_addr, (char *) &in_debugger, sizeof (in_debugger));
1561 breakpoint_addr = (CORE_ADDR) debug_copy.ldd_bp_addr;
1562 write_memory (breakpoint_addr, (char *) &debug_copy.ldd_bp_inst,
1563 sizeof (debug_copy.ldd_bp_inst));
1565 #else /* SVR4_SHARED_LIBS */
1567 /* Note that breakpoint address and original contents are in our address
1568 space, so we just need to write the original contents back. */
1570 if (memory_remove_breakpoint (breakpoint_addr, shadow_contents) != 0)
1575 #endif /* !SVR4_SHARED_LIBS */
1577 /* For the SVR4 version, we always know the breakpoint address. For the
1578 SunOS version we don't know it until the above code is executed.
1579 Grumble if we are stopped anywhere besides the breakpoint address. */
1581 if (stop_pc != breakpoint_addr)
1583 warning ("stopped at unknown breakpoint while handling shared libraries");
1589 #endif /* #ifdef SVR4_SHARED_LIBS */
1595 enable_break -- arrange for dynamic linker to hit breakpoint
1599 int enable_break (void)
1603 Both the SunOS and the SVR4 dynamic linkers have, as part of their
1604 debugger interface, support for arranging for the inferior to hit
1605 a breakpoint after mapping in the shared libraries. This function
1606 enables that breakpoint.
1608 For SunOS, there is a special flag location (in_debugger) which we
1609 set to 1. When the dynamic linker sees this flag set, it will set
1610 a breakpoint at a location known only to itself, after saving the
1611 original contents of that place and the breakpoint address itself,
1612 in it's own internal structures. When we resume the inferior, it
1613 will eventually take a SIGTRAP when it runs into the breakpoint.
1614 We handle this (in a different place) by restoring the contents of
1615 the breakpointed location (which is only known after it stops),
1616 chasing around to locate the shared libraries that have been
1617 loaded, then resuming.
1619 For SVR4, the debugger interface structure contains a member (r_brk)
1620 which is statically initialized at the time the shared library is
1621 built, to the offset of a function (_r_debug_state) which is guaran-
1622 teed to be called once before mapping in a library, and again when
1623 the mapping is complete. At the time we are examining this member,
1624 it contains only the unrelocated offset of the function, so we have
1625 to do our own relocation. Later, when the dynamic linker actually
1626 runs, it relocates r_brk to be the actual address of _r_debug_state().
1628 The debugger interface structure also contains an enumeration which
1629 is set to either RT_ADD or RT_DELETE prior to changing the mapping,
1630 depending upon whether or not the library is being mapped or unmapped,
1631 and then set to RT_CONSISTENT after the library is mapped/unmapped.
1639 #ifndef SVR4_SHARED_LIBS
1644 /* Get link_dynamic structure */
1646 j = target_read_memory (debug_base, (char *) &dynamic_copy,
1647 sizeof (dynamic_copy));
1654 /* Calc address of debugger interface structure */
1656 debug_addr = (CORE_ADDR) dynamic_copy.ldd;
1658 /* Calc address of `in_debugger' member of debugger interface structure */
1660 flag_addr = debug_addr + (CORE_ADDR) ((char *) &debug_copy.ldd_in_debugger -
1661 (char *) &debug_copy);
1663 /* Write a value of 1 to this member. */
1666 write_memory (flag_addr, (char *) &in_debugger, sizeof (in_debugger));
1669 #else /* SVR4_SHARED_LIBS */
1671 #ifdef BKPT_AT_SYMBOL
1673 struct minimal_symbol *msymbol;
1675 asection *interp_sect;
1677 /* First, remove all the solib event breakpoints. Their addresses
1678 may have changed since the last time we ran the program. */
1679 remove_solib_event_breakpoints ();
1681 #ifdef SVR4_SHARED_LIBS
1682 interp_text_sect_low = interp_text_sect_high = 0;
1683 interp_plt_sect_low = interp_plt_sect_high = 0;
1685 /* Find the .interp section; if not found, warn the user and drop
1686 into the old breakpoint at symbol code. */
1687 interp_sect = bfd_get_section_by_name (exec_bfd, ".interp");
1690 unsigned int interp_sect_size;
1692 CORE_ADDR load_addr;
1694 CORE_ADDR sym_addr = 0;
1696 /* Read the contents of the .interp section into a local buffer;
1697 the contents specify the dynamic linker this program uses. */
1698 interp_sect_size = bfd_section_size (exec_bfd, interp_sect);
1699 buf = alloca (interp_sect_size);
1700 bfd_get_section_contents (exec_bfd, interp_sect,
1701 buf, 0, interp_sect_size);
1703 /* Now we need to figure out where the dynamic linker was
1704 loaded so that we can load its symbols and place a breakpoint
1705 in the dynamic linker itself.
1707 This address is stored on the stack. However, I've been unable
1708 to find any magic formula to find it for Solaris (appears to
1709 be trivial on GNU/Linux). Therefore, we have to try an alternate
1710 mechanism to find the dynamic linker's base address. */
1711 tmp_bfd = bfd_openr (buf, gnutarget);
1712 if (tmp_bfd == NULL)
1713 goto bkpt_at_symbol;
1715 /* Make sure the dynamic linker's really a useful object. */
1716 if (!bfd_check_format (tmp_bfd, bfd_object))
1718 warning ("Unable to grok dynamic linker %s as an object file", buf);
1719 bfd_close (tmp_bfd);
1720 goto bkpt_at_symbol;
1723 /* We find the dynamic linker's base address by examining the
1724 current pc (which point at the entry point for the dynamic
1725 linker) and subtracting the offset of the entry point. */
1726 load_addr = read_pc () - tmp_bfd->start_address;
1728 /* Record the relocated start and end address of the dynamic linker
1729 text and plt section for in_svr4_dynsym_resolve_code. */
1730 interp_sect = bfd_get_section_by_name (tmp_bfd, ".text");
1733 interp_text_sect_low =
1734 bfd_section_vma (tmp_bfd, interp_sect) + load_addr;
1735 interp_text_sect_high =
1736 interp_text_sect_low + bfd_section_size (tmp_bfd, interp_sect);
1738 interp_sect = bfd_get_section_by_name (tmp_bfd, ".plt");
1741 interp_plt_sect_low =
1742 bfd_section_vma (tmp_bfd, interp_sect) + load_addr;
1743 interp_plt_sect_high =
1744 interp_plt_sect_low + bfd_section_size (tmp_bfd, interp_sect);
1747 /* Now try to set a breakpoint in the dynamic linker. */
1748 for (bkpt_namep = solib_break_names; *bkpt_namep != NULL; bkpt_namep++)
1750 sym_addr = bfd_lookup_symbol (tmp_bfd, *bkpt_namep);
1755 /* We're done with the temporary bfd. */
1756 bfd_close (tmp_bfd);
1760 create_solib_event_breakpoint (load_addr + sym_addr);
1764 /* For whatever reason we couldn't set a breakpoint in the dynamic
1765 linker. Warn and drop into the old code. */
1767 warning ("Unable to find dynamic linker breakpoint function.\nGDB will be unable to debug shared library initializers\nand track explicitly loaded dynamic code.");
1771 /* Scan through the list of symbols, trying to look up the symbol and
1772 set a breakpoint there. Terminate loop when we/if we succeed. */
1774 breakpoint_addr = 0;
1775 for (bkpt_namep = bkpt_names; *bkpt_namep != NULL; bkpt_namep++)
1777 msymbol = lookup_minimal_symbol (*bkpt_namep, NULL, symfile_objfile);
1778 if ((msymbol != NULL) && (SYMBOL_VALUE_ADDRESS (msymbol) != 0))
1780 create_solib_event_breakpoint (SYMBOL_VALUE_ADDRESS (msymbol));
1785 /* Nothing good happened. */
1788 #endif /* BKPT_AT_SYMBOL */
1790 #endif /* !SVR4_SHARED_LIBS */
1799 solib_create_inferior_hook -- shared library startup support
1803 void solib_create_inferior_hook()
1807 When gdb starts up the inferior, it nurses it along (through the
1808 shell) until it is ready to execute it's first instruction. At this
1809 point, this function gets called via expansion of the macro
1810 SOLIB_CREATE_INFERIOR_HOOK.
1812 For SunOS executables, this first instruction is typically the
1813 one at "_start", or a similar text label, regardless of whether
1814 the executable is statically or dynamically linked. The runtime
1815 startup code takes care of dynamically linking in any shared
1816 libraries, once gdb allows the inferior to continue.
1818 For SVR4 executables, this first instruction is either the first
1819 instruction in the dynamic linker (for dynamically linked
1820 executables) or the instruction at "start" for statically linked
1821 executables. For dynamically linked executables, the system
1822 first exec's /lib/libc.so.N, which contains the dynamic linker,
1823 and starts it running. The dynamic linker maps in any needed
1824 shared libraries, maps in the actual user executable, and then
1825 jumps to "start" in the user executable.
1827 For both SunOS shared libraries, and SVR4 shared libraries, we
1828 can arrange to cooperate with the dynamic linker to discover the
1829 names of shared libraries that are dynamically linked, and the
1830 base addresses to which they are linked.
1832 This function is responsible for discovering those names and
1833 addresses, and saving sufficient information about them to allow
1834 their symbols to be read at a later time.
1838 Between enable_break() and disable_break(), this code does not
1839 properly handle hitting breakpoints which the user might have
1840 set in the startup code or in the dynamic linker itself. Proper
1841 handling will probably have to wait until the implementation is
1842 changed to use the "breakpoint handler function" method.
1844 Also, what if child has exit()ed? Must exit loop somehow.
1848 solib_create_inferior_hook()
1850 /* If we are using the BKPT_AT_SYMBOL code, then we don't need the base
1851 yet. In fact, in the case of a SunOS4 executable being run on
1852 Solaris, we can't get it yet. find_solib will get it when it needs
1854 #if !(defined (SVR4_SHARED_LIBS) && defined (BKPT_AT_SYMBOL))
1855 if ((debug_base = locate_base ()) == 0)
1857 /* Can't find the symbol or the executable is statically linked. */
1862 if (!enable_break ())
1864 warning ("shared library handler failed to enable breakpoint");
1868 #if !defined(SVR4_SHARED_LIBS) || defined(_SCO_DS)
1869 /* SCO and SunOS need the loop below, other systems should be using the
1870 special shared library breakpoints and the shared library breakpoint
1873 Now run the target. It will eventually hit the breakpoint, at
1874 which point all of the libraries will have been mapped in and we
1875 can go groveling around in the dynamic linker structures to find
1876 out what we need to know about them. */
1878 clear_proceed_status ();
1879 stop_soon_quietly = 1;
1880 stop_signal = TARGET_SIGNAL_0;
1883 target_resume (-1, 0, stop_signal);
1884 wait_for_inferior ();
1886 while (stop_signal != TARGET_SIGNAL_TRAP);
1887 stop_soon_quietly = 0;
1889 #if !defined(_SCO_DS)
1890 /* We are now either at the "mapping complete" breakpoint (or somewhere
1891 else, a condition we aren't prepared to deal with anyway), so adjust
1892 the PC as necessary after a breakpoint, disable the breakpoint, and
1893 add any shared libraries that were mapped in. */
1895 if (DECR_PC_AFTER_BREAK)
1897 stop_pc -= DECR_PC_AFTER_BREAK;
1898 write_register (PC_REGNUM, stop_pc);
1901 if (!disable_break ())
1903 warning ("shared library handler failed to disable breakpoint");
1907 solib_add ((char *) 0, 0, (struct target_ops *) 0);
1908 #endif /* ! _SCO_DS */
1916 special_symbol_handling -- additional shared library symbol handling
1920 void special_symbol_handling (struct so_list *so)
1924 Once the symbols from a shared object have been loaded in the usual
1925 way, we are called to do any system specific symbol handling that
1928 For SunOS4, this consists of grunging around in the dynamic
1929 linkers structures to find symbol definitions for "common" symbols
1930 and adding them to the minimal symbol table for the runtime common
1936 special_symbol_handling (so)
1939 #ifndef SVR4_SHARED_LIBS
1942 if (debug_addr == 0)
1944 /* Get link_dynamic structure */
1946 j = target_read_memory (debug_base, (char *) &dynamic_copy,
1947 sizeof (dynamic_copy));
1954 /* Calc address of debugger interface structure */
1955 /* FIXME, this needs work for cross-debugging of core files
1956 (byteorder, size, alignment, etc). */
1958 debug_addr = (CORE_ADDR) dynamic_copy.ldd;
1961 /* Read the debugger structure from the inferior, just to make sure
1962 we have a current copy. */
1964 j = target_read_memory (debug_addr, (char *) &debug_copy,
1965 sizeof (debug_copy));
1967 return; /* unreadable */
1969 /* Get common symbol definitions for the loaded object. */
1971 if (debug_copy.ldd_cp)
1973 solib_add_common_symbols (debug_copy.ldd_cp);
1976 #endif /* !SVR4_SHARED_LIBS */
1984 sharedlibrary_command -- handle command to explicitly add library
1988 static void sharedlibrary_command (char *args, int from_tty)
1995 sharedlibrary_command (args, from_tty)
2000 solib_add (args, from_tty, (struct target_ops *) 0);
2003 #endif /* HAVE_LINK_H */
2010 add_com ("sharedlibrary", class_files, sharedlibrary_command,
2011 "Load shared object library symbols for files matching REGEXP.");
2012 add_info ("sharedlibrary", info_sharedlibrary_command,
2013 "Status of loaded shared object libraries.");
2016 (add_set_cmd ("auto-solib-add", class_support, var_zinteger,
2017 (char *) &auto_solib_add,
2018 "Set autoloading of shared library symbols.\n\
2019 If nonzero, symbols from all shared object libraries will be loaded\n\
2020 automatically when the inferior begins execution or when the dynamic linker\n\
2021 informs gdb that a new library has been loaded. Otherwise, symbols\n\
2022 must be loaded manually, using `sharedlibrary'.",
2027 (add_set_cmd ("solib-absolute-prefix", class_support, var_filename,
2028 (char *) &solib_absolute_prefix,
2029 "Set prefix for loading absolute shared library symbol files.\n\
2030 For other (relative) files, you can add values using `set solib-search-path'.",
2034 (add_set_cmd ("solib-search-path", class_support, var_string,
2035 (char *) &solib_search_path,
2036 "Set the search path for loading non-absolute shared library symbol files.\n\
2037 This takes precedence over the environment variables PATH and LD_LIBRARY_PATH.",
2041 #endif /* HAVE_LINK_H */