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,
20 Boston, MA 02111-1307, USA. */
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>
35 #ifndef SVR4_SHARED_LIBS
36 /* SunOS shared libs need the nlist structure. */
39 #include "elf/external.h"
52 #include "gnu-regex.h"
58 #define MAX_PATH_SIZE 512 /* FIXME: Should be dynamic */
60 /* On SVR4 systems, a list of symbols in the dynamic linker where
61 GDB can try to place a breakpoint to monitor shared library
64 If none of these symbols are found, or other errors occur, then
65 SVR4 systems will fall back to using a symbol as the "startup
66 mapping complete" breakpoint address. */
68 #ifdef SVR4_SHARED_LIBS
69 static char *solib_break_names
[] =
79 #define BKPT_AT_SYMBOL 1
81 #if defined (BKPT_AT_SYMBOL) && defined (SVR4_SHARED_LIBS)
82 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
[] =
104 static char *main_name_list
[] =
110 /* local data declarations */
112 #ifndef SVR4_SHARED_LIBS
114 #define LM_ADDR(so) ((so) -> lm.lm_addr)
115 #define LM_NEXT(so) ((so) -> lm.lm_next)
116 #define LM_NAME(so) ((so) -> lm.lm_name)
117 /* Test for first link map entry; first entry is a shared library. */
118 #define IGNORE_FIRST_LINK_MAP_ENTRY(x) (0)
119 static struct link_dynamic dynamic_copy
;
120 static struct link_dynamic_2 ld_2_copy
;
121 static struct ld_debug debug_copy
;
122 static CORE_ADDR debug_addr
;
123 static CORE_ADDR flag_addr
;
125 #else /* SVR4_SHARED_LIBS */
127 #define LM_ADDR(so) ((so) -> lm.l_addr)
128 #define LM_NEXT(so) ((so) -> lm.l_next)
129 #define LM_NAME(so) ((so) -> lm.l_name)
130 /* Test for first link map entry; first entry is the exec-file. */
131 #define IGNORE_FIRST_LINK_MAP_ENTRY(x) ((x).l_prev == NULL)
132 static struct r_debug debug_copy
;
133 char shadow_contents
[BREAKPOINT_MAX
]; /* Stash old bkpt addr contents */
135 #endif /* !SVR4_SHARED_LIBS */
139 struct so_list
*next
; /* next structure in linked list */
140 struct link_map lm
; /* copy of link map from inferior */
141 struct link_map
*lmaddr
; /* addr in inferior lm was read from */
142 CORE_ADDR lmend
; /* upper addr bound of mapped object */
143 char so_name
[MAX_PATH_SIZE
]; /* shared object lib name (FIXME) */
144 char symbols_loaded
; /* flag: symbols read in yet? */
145 char from_tty
; /* flag: print msgs? */
146 struct objfile
*objfile
; /* objfile for loaded lib */
147 struct section_table
*sections
;
148 struct section_table
*sections_end
;
149 struct section_table
*textsection
;
153 static struct so_list
*so_list_head
; /* List of known shared objects */
154 static CORE_ADDR debug_base
; /* Base of dynamic linker structures */
155 static CORE_ADDR breakpoint_addr
; /* Address where end bkpt is set */
157 static int solib_cleanup_queued
= 0; /* make_run_cleanup called */
160 fdmatch
PARAMS ((int, int)); /* In libiberty */
162 /* Local function prototypes */
165 do_clear_solib
PARAMS ((PTR
));
168 match_main
PARAMS ((char *));
171 special_symbol_handling
PARAMS ((struct so_list
*));
174 sharedlibrary_command
PARAMS ((char *, int));
177 enable_break
PARAMS ((void));
180 info_sharedlibrary_command
PARAMS ((char *, int));
182 static int symbol_add_stub
PARAMS ((PTR
));
184 static struct so_list
*
185 find_solib
PARAMS ((struct so_list
*));
187 static struct link_map
*
188 first_link_map_member
PARAMS ((void));
191 locate_base
PARAMS ((void));
193 static int solib_map_sections
PARAMS ((PTR
));
195 #ifdef SVR4_SHARED_LIBS
198 elf_locate_base
PARAMS ((void));
203 disable_break
PARAMS ((void));
206 allocate_rt_common_objfile
PARAMS ((void));
209 solib_add_common_symbols
PARAMS ((struct rtc_symb
*));
213 void _initialize_solib
PARAMS ((void));
215 /* If non-zero, this is a prefix that will be added to the front of the name
216 shared libraries with an absolute filename for loading. */
217 static char *solib_absolute_prefix
= NULL
;
219 /* If non-empty, this is a search path for loading non-absolute shared library
220 symbol files. This takes precedence over the environment variables PATH
221 and LD_LIBRARY_PATH. */
222 static char *solib_search_path
= NULL
;
228 solib_map_sections -- open bfd and build sections for shared lib
232 static int solib_map_sections (struct so_list *so)
236 Given a pointer to one of the shared objects in our list
237 of mapped objects, use the recorded name to open a bfd
238 descriptor for the object, build a section table, and then
239 relocate all the section addresses by the base address at
240 which the shared object was mapped.
244 In most (all?) cases the shared object file name recorded in the
245 dynamic linkage tables will be a fully qualified pathname. For
246 cases where it isn't, do we really mimic the systems search
247 mechanism correctly in the below code (particularly the tilde
252 solib_map_sections (arg
)
255 struct so_list
*so
= (struct so_list
*) arg
; /* catch_errors bogon */
257 char *scratch_pathname
;
259 struct section_table
*p
;
260 struct cleanup
*old_chain
;
263 filename
= tilde_expand (so
->so_name
);
265 if (solib_absolute_prefix
&& ROOTED_P (filename
))
266 /* Prefix shared libraries with absolute filenames with
267 SOLIB_ABSOLUTE_PREFIX. */
272 pfx_len
= strlen (solib_absolute_prefix
);
274 /* Remove trailing slashes. */
275 while (pfx_len
> 0 && SLASH_P (solib_absolute_prefix
[pfx_len
- 1]))
278 pfxed_fn
= xmalloc (pfx_len
+ strlen (filename
) + 1);
279 strcpy (pfxed_fn
, solib_absolute_prefix
);
280 strcat (pfxed_fn
, filename
);
286 old_chain
= make_cleanup (free
, filename
);
290 if (solib_search_path
)
291 scratch_chan
= openp (solib_search_path
,
292 1, filename
, O_RDONLY
, 0, &scratch_pathname
);
293 if (scratch_chan
< 0)
294 scratch_chan
= openp (get_in_environ (inferior_environ
, "PATH"),
295 1, filename
, O_RDONLY
, 0, &scratch_pathname
);
296 if (scratch_chan
< 0)
298 scratch_chan
= openp (get_in_environ
299 (inferior_environ
, "LD_LIBRARY_PATH"),
300 1, filename
, O_RDONLY
, 0, &scratch_pathname
);
302 if (scratch_chan
< 0)
304 perror_with_name (filename
);
306 /* Leave scratch_pathname allocated. abfd->name will point to it. */
308 abfd
= bfd_fdopenr (scratch_pathname
, gnutarget
, scratch_chan
);
311 close (scratch_chan
);
312 error ("Could not open `%s' as an executable file: %s",
313 scratch_pathname
, bfd_errmsg (bfd_get_error ()));
315 /* Leave bfd open, core_xfer_memory and "info files" need it. */
317 abfd
->cacheable
= true;
319 /* copy full path name into so_name, so that later symbol_file_add can find
321 if (strlen (scratch_pathname
) >= MAX_PATH_SIZE
)
322 error ("Full path name length of shared library exceeds MAX_PATH_SIZE in so_list structure.");
323 strcpy (so
->so_name
, scratch_pathname
);
325 if (!bfd_check_format (abfd
, bfd_object
))
327 error ("\"%s\": not in executable format: %s.",
328 scratch_pathname
, bfd_errmsg (bfd_get_error ()));
330 if (build_section_table (abfd
, &so
->sections
, &so
->sections_end
))
332 error ("Can't find the file sections in `%s': %s",
333 bfd_get_filename (abfd
), bfd_errmsg (bfd_get_error ()));
336 for (p
= so
->sections
; p
< so
->sections_end
; p
++)
338 /* Relocate the section binding addresses as recorded in the shared
339 object's file by the base address to which the object was actually
341 p
->addr
+= (CORE_ADDR
) LM_ADDR (so
);
342 p
->endaddr
+= (CORE_ADDR
) LM_ADDR (so
);
343 so
->lmend
= (CORE_ADDR
) max (p
->endaddr
, so
->lmend
);
344 if (STREQ (p
->the_bfd_section
->name
, ".text"))
350 /* Free the file names, close the file now. */
351 do_cleanups (old_chain
);
356 #ifndef SVR4_SHARED_LIBS
358 /* Allocate the runtime common object file. */
361 allocate_rt_common_objfile ()
363 struct objfile
*objfile
;
364 struct objfile
*last_one
;
366 objfile
= (struct objfile
*) xmalloc (sizeof (struct objfile
));
367 memset (objfile
, 0, sizeof (struct objfile
));
369 obstack_specify_allocation (&objfile
->psymbol_cache
.cache
, 0, 0,
371 obstack_specify_allocation (&objfile
->psymbol_obstack
, 0, 0, xmalloc
,
373 obstack_specify_allocation (&objfile
->symbol_obstack
, 0, 0, xmalloc
,
375 obstack_specify_allocation (&objfile
->type_obstack
, 0, 0, xmalloc
,
377 objfile
->name
= mstrsave (objfile
->md
, "rt_common");
379 /* Add this file onto the tail of the linked list of other such files. */
381 objfile
->next
= NULL
;
382 if (object_files
== NULL
)
383 object_files
= objfile
;
386 for (last_one
= object_files
;
388 last_one
= last_one
->next
);
389 last_one
->next
= objfile
;
392 rt_common_objfile
= objfile
;
395 /* Read all dynamically loaded common symbol definitions from the inferior
396 and put them into the minimal symbol table for the runtime common
400 solib_add_common_symbols (rtc_symp
)
401 struct rtc_symb
*rtc_symp
;
403 struct rtc_symb inferior_rtc_symb
;
404 struct nlist inferior_rtc_nlist
;
408 /* Remove any runtime common symbols from previous runs. */
410 if (rt_common_objfile
!= NULL
&& rt_common_objfile
->minimal_symbol_count
)
412 obstack_free (&rt_common_objfile
->symbol_obstack
, 0);
413 obstack_specify_allocation (&rt_common_objfile
->symbol_obstack
, 0, 0,
415 rt_common_objfile
->minimal_symbol_count
= 0;
416 rt_common_objfile
->msymbols
= NULL
;
419 init_minimal_symbol_collection ();
420 make_cleanup ((make_cleanup_func
) discard_minimal_symbols
, 0);
424 read_memory ((CORE_ADDR
) rtc_symp
,
425 (char *) &inferior_rtc_symb
,
426 sizeof (inferior_rtc_symb
));
427 read_memory ((CORE_ADDR
) inferior_rtc_symb
.rtc_sp
,
428 (char *) &inferior_rtc_nlist
,
429 sizeof (inferior_rtc_nlist
));
430 if (inferior_rtc_nlist
.n_type
== N_COMM
)
432 /* FIXME: The length of the symbol name is not available, but in the
433 current implementation the common symbol is allocated immediately
434 behind the name of the symbol. */
435 len
= inferior_rtc_nlist
.n_value
- inferior_rtc_nlist
.n_un
.n_strx
;
437 name
= xmalloc (len
);
438 read_memory ((CORE_ADDR
) inferior_rtc_nlist
.n_un
.n_name
, name
, len
);
440 /* Allocate the runtime common objfile if necessary. */
441 if (rt_common_objfile
== NULL
)
442 allocate_rt_common_objfile ();
444 prim_record_minimal_symbol (name
, inferior_rtc_nlist
.n_value
,
445 mst_bss
, rt_common_objfile
);
448 rtc_symp
= inferior_rtc_symb
.rtc_next
;
451 /* Install any minimal symbols that have been collected as the current
452 minimal symbols for the runtime common objfile. */
454 install_minimal_symbols (rt_common_objfile
);
457 #endif /* SVR4_SHARED_LIBS */
460 #ifdef SVR4_SHARED_LIBS
463 bfd_lookup_symbol
PARAMS ((bfd
*, char *));
469 bfd_lookup_symbol -- lookup the value for a specific symbol
473 CORE_ADDR bfd_lookup_symbol (bfd *abfd, char *symname)
477 An expensive way to lookup the value of a single symbol for
478 bfd's that are only temporary anyway. This is used by the
479 shared library support to find the address of the debugger
480 interface structures in the shared library.
482 Note that 0 is specifically allowed as an error return (no
487 bfd_lookup_symbol (abfd
, symname
)
491 unsigned int storage_needed
;
493 asymbol
**symbol_table
;
494 unsigned int number_of_symbols
;
496 struct cleanup
*back_to
;
497 CORE_ADDR symaddr
= 0;
499 storage_needed
= bfd_get_symtab_upper_bound (abfd
);
501 if (storage_needed
> 0)
503 symbol_table
= (asymbol
**) xmalloc (storage_needed
);
504 back_to
= make_cleanup (free
, (PTR
) symbol_table
);
505 number_of_symbols
= bfd_canonicalize_symtab (abfd
, symbol_table
);
507 for (i
= 0; i
< number_of_symbols
; i
++)
509 sym
= *symbol_table
++;
510 if (STREQ (sym
->name
, symname
))
512 /* Bfd symbols are section relative. */
513 symaddr
= sym
->value
+ sym
->section
->vma
;
517 do_cleanups (back_to
);
522 #ifdef HANDLE_SVR4_EXEC_EMULATORS
525 Solaris BCP (the part of Solaris which allows it to run SunOS4
526 a.out files) throws in another wrinkle. Solaris does not fill
527 in the usual a.out link map structures when running BCP programs,
528 the only way to get at them is via groping around in the dynamic
530 The dynamic linker and it's structures are located in the shared
531 C library, which gets run as the executable's "interpreter" by
534 Note that we can assume nothing about the process state at the time
535 we need to find these structures. We may be stopped on the first
536 instruction of the interpreter (C shared library), the first
537 instruction of the executable itself, or somewhere else entirely
538 (if we attached to the process for example).
541 static char *debug_base_symbols
[] =
543 "r_debug", /* Solaris 2.3 */
544 "_r_debug", /* Solaris 2.1, 2.2 */
549 look_for_base
PARAMS ((int, CORE_ADDR
));
555 look_for_base -- examine file for each mapped address segment
559 static int look_for_base (int fd, CORE_ADDR baseaddr)
563 This function is passed to proc_iterate_over_mappings, which
564 causes it to get called once for each mapped address space, with
565 an open file descriptor for the file mapped to that space, and the
566 base address of that mapped space.
568 Our job is to find the debug base symbol in the file that this
569 fd is open on, if it exists, and if so, initialize the dynamic
570 linker structure base address debug_base.
572 Note that this is a computationally expensive proposition, since
573 we basically have to open a bfd on every call, so we specifically
574 avoid opening the exec file.
578 look_for_base (fd
, baseaddr
)
583 CORE_ADDR address
= 0;
586 /* If the fd is -1, then there is no file that corresponds to this
587 mapped memory segment, so skip it. Also, if the fd corresponds
588 to the exec file, skip it as well. */
592 && fdmatch (fileno ((FILE *) (exec_bfd
->iostream
)), fd
)))
597 /* Try to open whatever random file this fd corresponds to. Note that
598 we have no way currently to find the filename. Don't gripe about
599 any problems we might have, just fail. */
601 if ((interp_bfd
= bfd_fdopenr ("unnamed", gnutarget
, fd
)) == NULL
)
605 if (!bfd_check_format (interp_bfd
, bfd_object
))
607 /* FIXME-leak: on failure, might not free all memory associated with
609 bfd_close (interp_bfd
);
613 /* Now try to find our debug base symbol in this file, which we at
614 least know to be a valid ELF executable or shared library. */
616 for (symbolp
= debug_base_symbols
; *symbolp
!= NULL
; symbolp
++)
618 address
= bfd_lookup_symbol (interp_bfd
, *symbolp
);
626 /* FIXME-leak: on failure, might not free all memory associated with
628 bfd_close (interp_bfd
);
632 /* Eureka! We found the symbol. But now we may need to relocate it
633 by the base address. If the symbol's value is less than the base
634 address of the shared library, then it hasn't yet been relocated
635 by the dynamic linker, and we have to do it ourself. FIXME: Note
636 that we make the assumption that the first segment that corresponds
637 to the shared library has the base address to which the library
640 if (address
< baseaddr
)
644 debug_base
= address
;
645 /* FIXME-leak: on failure, might not free all memory associated with
647 bfd_close (interp_bfd
);
650 #endif /* HANDLE_SVR4_EXEC_EMULATORS */
656 elf_locate_base -- locate the base address of dynamic linker structs
657 for SVR4 elf targets.
661 CORE_ADDR elf_locate_base (void)
665 For SVR4 elf targets the address of the dynamic linker's runtime
666 structure is contained within the dynamic info section in the
667 executable file. The dynamic section is also mapped into the
668 inferior address space. Because the runtime loader fills in the
669 real address before starting the inferior, we have to read in the
670 dynamic info section from the inferior address space.
671 If there are any errors while trying to find the address, we
672 silently return 0, otherwise the found address is returned.
679 sec_ptr dyninfo_sect
;
680 int dyninfo_sect_size
;
681 CORE_ADDR dyninfo_addr
;
685 /* Find the start address of the .dynamic section. */
686 dyninfo_sect
= bfd_get_section_by_name (exec_bfd
, ".dynamic");
687 if (dyninfo_sect
== NULL
)
689 dyninfo_addr
= bfd_section_vma (exec_bfd
, dyninfo_sect
);
691 /* Read in .dynamic section, silently ignore errors. */
692 dyninfo_sect_size
= bfd_section_size (exec_bfd
, dyninfo_sect
);
693 buf
= alloca (dyninfo_sect_size
);
694 if (target_read_memory (dyninfo_addr
, buf
, dyninfo_sect_size
))
697 /* Find the DT_DEBUG entry in the the .dynamic section.
698 For mips elf we look for DT_MIPS_RLD_MAP, mips elf apparently has
699 no DT_DEBUG entries. */
701 for (bufend
= buf
+ dyninfo_sect_size
;
703 buf
+= sizeof (Elf32_External_Dyn
))
705 Elf32_External_Dyn
*x_dynp
= (Elf32_External_Dyn
*) buf
;
709 dyn_tag
= bfd_h_get_32 (exec_bfd
, (bfd_byte
*) x_dynp
->d_tag
);
710 if (dyn_tag
== DT_NULL
)
712 else if (dyn_tag
== DT_DEBUG
)
714 dyn_ptr
= bfd_h_get_32 (exec_bfd
, (bfd_byte
*) x_dynp
->d_un
.d_ptr
);
717 #ifdef DT_MIPS_RLD_MAP
718 else if (dyn_tag
== DT_MIPS_RLD_MAP
)
720 char pbuf
[TARGET_PTR_BIT
/ HOST_CHAR_BIT
];
722 /* DT_MIPS_RLD_MAP contains a pointer to the address
723 of the dynamic link structure. */
724 dyn_ptr
= bfd_h_get_32 (exec_bfd
, (bfd_byte
*) x_dynp
->d_un
.d_ptr
);
725 if (target_read_memory (dyn_ptr
, pbuf
, sizeof (pbuf
)))
727 return extract_unsigned_integer (pbuf
, sizeof (pbuf
));
732 for (bufend
= buf
+ dyninfo_sect_size
;
734 buf
+= sizeof (Elf64_External_Dyn
))
736 Elf64_External_Dyn
*x_dynp
= (Elf64_External_Dyn
*) buf
;
740 dyn_tag
= bfd_h_get_64 (exec_bfd
, (bfd_byte
*) x_dynp
->d_tag
);
741 if (dyn_tag
== DT_NULL
)
743 else if (dyn_tag
== DT_DEBUG
)
745 dyn_ptr
= bfd_h_get_64 (exec_bfd
, (bfd_byte
*) x_dynp
->d_un
.d_ptr
);
751 /* DT_DEBUG entry not found. */
755 #endif /* SVR4_SHARED_LIBS */
761 locate_base -- locate the base address of dynamic linker structs
765 CORE_ADDR locate_base (void)
769 For both the SunOS and SVR4 shared library implementations, if the
770 inferior executable has been linked dynamically, there is a single
771 address somewhere in the inferior's data space which is the key to
772 locating all of the dynamic linker's runtime structures. This
773 address is the value of the debug base symbol. The job of this
774 function is to find and return that address, or to return 0 if there
775 is no such address (the executable is statically linked for example).
777 For SunOS, the job is almost trivial, since the dynamic linker and
778 all of it's structures are statically linked to the executable at
779 link time. Thus the symbol for the address we are looking for has
780 already been added to the minimal symbol table for the executable's
781 objfile at the time the symbol file's symbols were read, and all we
782 have to do is look it up there. Note that we explicitly do NOT want
783 to find the copies in the shared library.
785 The SVR4 version is a bit more complicated because the address
786 is contained somewhere in the dynamic info section. We have to go
787 to a lot more work to discover the address of the debug base symbol.
788 Because of this complexity, we cache the value we find and return that
789 value on subsequent invocations. Note there is no copy in the
790 executable symbol tables.
798 #ifndef SVR4_SHARED_LIBS
800 struct minimal_symbol
*msymbol
;
801 CORE_ADDR address
= 0;
804 /* For SunOS, we want to limit the search for the debug base symbol to the
805 executable being debugged, since there is a duplicate named symbol in the
806 shared library. We don't want the shared library versions. */
808 for (symbolp
= debug_base_symbols
; *symbolp
!= NULL
; symbolp
++)
810 msymbol
= lookup_minimal_symbol (*symbolp
, NULL
, symfile_objfile
);
811 if ((msymbol
!= NULL
) && (SYMBOL_VALUE_ADDRESS (msymbol
) != 0))
813 address
= SYMBOL_VALUE_ADDRESS (msymbol
);
819 #else /* SVR4_SHARED_LIBS */
821 /* Check to see if we have a currently valid address, and if so, avoid
822 doing all this work again and just return the cached address. If
823 we have no cached address, try to locate it in the dynamic info
824 section for ELF executables. */
829 && bfd_get_flavour (exec_bfd
) == bfd_target_elf_flavour
)
830 debug_base
= elf_locate_base ();
831 #ifdef HANDLE_SVR4_EXEC_EMULATORS
832 /* Try it the hard way for emulated executables. */
833 else if (inferior_pid
!= 0 && target_has_execution
)
834 proc_iterate_over_mappings (look_for_base
);
839 #endif /* !SVR4_SHARED_LIBS */
847 first_link_map_member -- locate first member in dynamic linker's map
851 static struct link_map *first_link_map_member (void)
855 Read in a copy of the first member in the inferior's dynamic
856 link map from the inferior's dynamic linker structures, and return
857 a pointer to the copy in our address space.
860 static struct link_map
*
861 first_link_map_member ()
863 struct link_map
*lm
= NULL
;
865 #ifndef SVR4_SHARED_LIBS
867 read_memory (debug_base
, (char *) &dynamic_copy
, sizeof (dynamic_copy
));
868 if (dynamic_copy
.ld_version
>= 2)
870 /* It is a version that we can deal with, so read in the secondary
871 structure and find the address of the link map list from it. */
872 read_memory ((CORE_ADDR
) dynamic_copy
.ld_un
.ld_2
, (char *) &ld_2_copy
,
873 sizeof (struct link_dynamic_2
));
874 lm
= ld_2_copy
.ld_loaded
;
877 #else /* SVR4_SHARED_LIBS */
879 read_memory (debug_base
, (char *) &debug_copy
, sizeof (struct r_debug
));
880 /* FIXME: Perhaps we should validate the info somehow, perhaps by
881 checking r_version for a known version number, or r_state for
883 lm
= debug_copy
.r_map
;
885 #endif /* !SVR4_SHARED_LIBS */
890 #ifdef SVR4_SHARED_LIBS
895 open_exec_file_object
899 void open_symbol_file_object (int from_tty)
903 If no open symbol file, attempt to locate and open the main symbol
904 file. On SVR4 systems, this is the first link map entry. If its
905 name is here, we can open it. Useful when attaching to a process
906 without first loading its symbol file.
911 open_symbol_file_object (arg
)
914 int from_tty
= (int) arg
; /* sneak past catch_errors */
915 struct link_map
*lm
, lmcopy
;
920 if (!query ("Attempt to reload symbols from process? "))
923 if ((debug_base
= locate_base ()) == 0)
924 return 0; /* failed somehow... */
926 /* First link map member should be the executable. */
927 if ((lm
= first_link_map_member ()) == NULL
)
928 return 0; /* failed somehow... */
930 /* Read from target memory to GDB. */
931 read_memory ((CORE_ADDR
) lm
, (void *) &lmcopy
, sizeof (lmcopy
));
933 if (lmcopy
.l_name
== 0)
934 return 0; /* no filename. */
936 /* Now fetch the filename from target memory. */
937 target_read_string ((CORE_ADDR
) lmcopy
.l_name
, &filename
,
938 MAX_PATH_SIZE
- 1, &errcode
);
941 warning ("failed to read exec filename from attached file: %s",
942 safe_strerror (errcode
));
946 make_cleanup ((make_cleanup_func
) free
, (void *) filename
);
947 /* Have a pathname: read the symbol file. */
948 symbol_file_command (filename
, from_tty
);
952 #endif /* SVR4_SHARED_LIBS */
958 find_solib -- step through list of shared objects
962 struct so_list *find_solib (struct so_list *so_list_ptr)
966 This module contains the routine which finds the names of any
967 loaded "images" in the current process. The argument in must be
968 NULL on the first call, and then the returned value must be passed
969 in on subsequent calls. This provides the capability to "step" down
970 the list of loaded objects. On the last object, a NULL value is
973 The arg and return value are "struct link_map" pointers, as defined
977 static struct so_list
*
978 find_solib (so_list_ptr
)
979 struct so_list
*so_list_ptr
; /* Last lm or NULL for first one */
981 struct so_list
*so_list_next
= NULL
;
982 struct link_map
*lm
= NULL
;
985 if (so_list_ptr
== NULL
)
987 /* We are setting up for a new scan through the loaded images. */
988 if ((so_list_next
= so_list_head
) == NULL
)
990 /* We have not already read in the dynamic linking structures
991 from the inferior, lookup the address of the base structure. */
992 debug_base
= locate_base ();
995 /* Read the base structure in and find the address of the first
996 link map list member. */
997 lm
= first_link_map_member ();
1003 /* We have been called before, and are in the process of walking
1004 the shared library list. Advance to the next shared object. */
1005 if ((lm
= LM_NEXT (so_list_ptr
)) == NULL
)
1007 /* We have hit the end of the list, so check to see if any were
1008 added, but be quiet if we can't read from the target any more. */
1009 int status
= target_read_memory ((CORE_ADDR
) so_list_ptr
->lmaddr
,
1010 (char *) &(so_list_ptr
->lm
),
1011 sizeof (struct link_map
));
1014 lm
= LM_NEXT (so_list_ptr
);
1021 so_list_next
= so_list_ptr
->next
;
1023 if ((so_list_next
== NULL
) && (lm
!= NULL
))
1025 /* Get next link map structure from inferior image and build a local
1026 abbreviated load_map structure */
1027 new = (struct so_list
*) xmalloc (sizeof (struct so_list
));
1028 memset ((char *) new, 0, sizeof (struct so_list
));
1030 /* Add the new node as the next node in the list, or as the root
1031 node if this is the first one. */
1032 if (so_list_ptr
!= NULL
)
1034 so_list_ptr
->next
= new;
1040 if (!solib_cleanup_queued
)
1042 make_run_cleanup (do_clear_solib
, NULL
);
1043 solib_cleanup_queued
= 1;
1048 read_memory ((CORE_ADDR
) lm
, (char *) &(new->lm
),
1049 sizeof (struct link_map
));
1050 /* For SVR4 versions, the first entry in the link map is for the
1051 inferior executable, so we must ignore it. For some versions of
1052 SVR4, it has no name. For others (Solaris 2.3 for example), it
1053 does have a name, so we can no longer use a missing name to
1054 decide when to ignore it. */
1055 if (!IGNORE_FIRST_LINK_MAP_ENTRY (new->lm
))
1059 target_read_string ((CORE_ADDR
) LM_NAME (new), &buffer
,
1060 MAX_PATH_SIZE
- 1, &errcode
);
1063 warning ("find_solib: Can't read pathname for load map: %s\n",
1064 safe_strerror (errcode
));
1065 return (so_list_next
);
1067 strncpy (new->so_name
, buffer
, MAX_PATH_SIZE
- 1);
1068 new->so_name
[MAX_PATH_SIZE
- 1] = '\0';
1070 catch_errors (solib_map_sections
, new,
1071 "Error while mapping shared library sections:\n",
1075 return (so_list_next
);
1078 /* A small stub to get us past the arg-passing pinhole of catch_errors. */
1081 symbol_add_stub (arg
)
1084 register struct so_list
*so
= (struct so_list
*) arg
; /* catch_errs bogon */
1085 CORE_ADDR text_addr
= 0;
1086 struct section_addr_info section_addrs
;
1088 memset (§ion_addrs
, 0, sizeof (section_addrs
));
1089 if (so
->textsection
)
1090 text_addr
= so
->textsection
->addr
;
1091 else if (so
->abfd
!= NULL
)
1093 asection
*lowest_sect
;
1095 /* If we didn't find a mapped non zero sized .text section, set up
1096 text_addr so that the relocation in symbol_file_add does no harm. */
1098 lowest_sect
= bfd_get_section_by_name (so
->abfd
, ".text");
1099 if (lowest_sect
== NULL
)
1100 bfd_map_over_sections (so
->abfd
, find_lowest_section
,
1101 (PTR
) &lowest_sect
);
1103 text_addr
= bfd_section_vma (so
->abfd
, lowest_sect
)
1104 + (CORE_ADDR
) LM_ADDR (so
);
1107 ALL_OBJFILES (so
->objfile
)
1109 if (strcmp (so
->objfile
->name
, so
->so_name
) == 0)
1112 section_addrs
.text_addr
= text_addr
;
1114 symbol_file_add (so
->so_name
, so
->from_tty
,
1115 §ion_addrs
, 0, OBJF_SHARED
);
1119 /* This function will check the so name to see if matches the main list.
1120 In some system the main object is in the list, which we want to exclude */
1128 for (mainp
= main_name_list
; *mainp
!= NULL
; mainp
++)
1130 if (strcmp (soname
, *mainp
) == 0)
1141 solib_add -- add a shared library file to the symtab and section list
1145 void solib_add (char *arg_string, int from_tty,
1146 struct target_ops *target)
1153 solib_add (arg_string
, from_tty
, target
)
1156 struct target_ops
*target
;
1158 register struct so_list
*so
= NULL
; /* link map state variable */
1160 /* Last shared library that we read. */
1161 struct so_list
*so_last
= NULL
;
1167 #ifdef SVR4_SHARED_LIBS
1168 /* If we are attaching to a running process for which we
1169 have not opened a symbol file, we may be able to get its
1172 symfile_objfile
== NULL
)
1173 catch_errors (open_symbol_file_object
, (PTR
) from_tty
,
1174 "Error reading attached process's symbol file.\n",
1177 #endif SVR4_SHARED_LIBS
1179 if ((re_err
= re_comp (arg_string
? arg_string
: ".")) != NULL
)
1181 error ("Invalid regexp: %s", re_err
);
1184 /* Add the shared library sections to the section table of the
1185 specified target, if any. */
1188 /* Count how many new section_table entries there are. */
1191 while ((so
= find_solib (so
)) != NULL
)
1193 if (so
->so_name
[0] && !match_main (so
->so_name
))
1195 count
+= so
->sections_end
- so
->sections
;
1202 /* Add these section table entries to the target's table. */
1203 old
= target_resize_to_sections (target
, count
);
1204 while ((so
= find_solib (so
)) != NULL
)
1208 count
= so
->sections_end
- so
->sections
;
1209 memcpy ((char *) (target
->to_sections
+ old
),
1211 (sizeof (struct section_table
)) * count
);
1218 /* Now add the symbol files. */
1219 while ((so
= find_solib (so
)) != NULL
)
1221 if (so
->so_name
[0] && re_exec (so
->so_name
) &&
1222 !match_main (so
->so_name
))
1224 so
->from_tty
= from_tty
;
1225 if (so
->symbols_loaded
)
1229 printf_unfiltered ("Symbols already loaded for %s\n", so
->so_name
);
1232 else if (catch_errors
1233 (symbol_add_stub
, so
,
1234 "Error while reading shared library symbols:\n",
1238 so
->symbols_loaded
= 1;
1243 /* Getting new symbols may change our opinion about what is
1246 reinit_frame_cache ();
1249 special_symbol_handling (so_last
);
1256 info_sharedlibrary_command -- code for "info sharedlibrary"
1260 static void info_sharedlibrary_command ()
1264 Walk through the shared library list and print information
1265 about each attached library.
1269 info_sharedlibrary_command (ignore
, from_tty
)
1273 register struct so_list
*so
= NULL
; /* link map state variable */
1274 int header_done
= 0;
1278 if (exec_bfd
== NULL
)
1280 printf_unfiltered ("No executable file.\n");
1284 #ifndef TARGET_ELF64
1288 addr_width
= 16 + 4;
1292 while ((so
= find_solib (so
)) != NULL
)
1298 printf_unfiltered ("%-*s%-*s%-12s%s\n", addr_width
, "From",
1299 addr_width
, "To", "Syms Read",
1300 "Shared Object Library");
1304 printf_unfiltered ("%-*s", addr_width
,
1305 local_hex_string_custom ((unsigned long) LM_ADDR (so
),
1307 printf_unfiltered ("%-*s", addr_width
,
1308 local_hex_string_custom ((unsigned long) so
->lmend
,
1310 printf_unfiltered ("%-12s", so
->symbols_loaded
? "Yes" : "No");
1311 printf_unfiltered ("%s\n", so
->so_name
);
1314 if (so_list_head
== NULL
)
1316 printf_unfiltered ("No shared libraries loaded at this time.\n");
1324 solib_address -- check to see if an address is in a shared lib
1328 char * solib_address (CORE_ADDR address)
1332 Provides a hook for other gdb routines to discover whether or
1333 not a particular address is within the mapped address space of
1334 a shared library. Any address between the base mapping address
1335 and the first address beyond the end of the last mapping, is
1336 considered to be within the shared library address space, for
1339 For example, this routine is called at one point to disable
1340 breakpoints which are in shared libraries that are not currently
1345 solib_address (address
)
1348 register struct so_list
*so
= 0; /* link map state variable */
1350 while ((so
= find_solib (so
)) != NULL
)
1354 if ((address
>= (CORE_ADDR
) LM_ADDR (so
)) &&
1355 (address
< (CORE_ADDR
) so
->lmend
))
1356 return (so
->so_name
);
1362 /* Called by free_all_symtabs */
1367 struct so_list
*next
;
1370 /* This function is expected to handle ELF shared libraries. It is
1371 also used on Solaris, which can run either ELF or a.out binaries
1372 (for compatibility with SunOS 4), both of which can use shared
1373 libraries. So we don't know whether we have an ELF executable or
1374 an a.out executable until the user chooses an executable file.
1376 ELF shared libraries don't get mapped into the address space
1377 until after the program starts, so we'd better not try to insert
1378 breakpoints in them immediately. We have to wait until the
1379 dynamic linker has loaded them; we'll hit a bp_shlib_event
1380 breakpoint (look for calls to create_solib_event_breakpoint) when
1383 SunOS shared libraries seem to be different --- they're present
1384 as soon as the process begins execution, so there's no need to
1385 put off inserting breakpoints. There's also nowhere to put a
1386 bp_shlib_event breakpoint, so if we put it off, we'll never get
1389 So: disable breakpoints only if we're using ELF shared libs. */
1390 if (exec_bfd
!= NULL
1391 && bfd_get_flavour (exec_bfd
) != bfd_target_aout_flavour
)
1392 disable_breakpoints_in_shlibs (1);
1394 while (so_list_head
)
1396 if (so_list_head
->sections
)
1398 free ((PTR
) so_list_head
->sections
);
1400 if (so_list_head
->abfd
)
1402 bfd_filename
= bfd_get_filename (so_list_head
->abfd
);
1403 if (!bfd_close (so_list_head
->abfd
))
1404 warning ("cannot close \"%s\": %s",
1405 bfd_filename
, bfd_errmsg (bfd_get_error ()));
1408 /* This happens for the executable on SVR4. */
1409 bfd_filename
= NULL
;
1411 next
= so_list_head
->next
;
1413 free ((PTR
) bfd_filename
);
1414 free ((PTR
) so_list_head
);
1415 so_list_head
= next
;
1421 do_clear_solib (dummy
)
1424 solib_cleanup_queued
= 0;
1428 #ifdef SVR4_SHARED_LIBS
1430 /* Return 1 if PC lies in the dynamic symbol resolution code of the
1431 SVR4 run time loader. */
1433 static CORE_ADDR interp_text_sect_low
;
1434 static CORE_ADDR interp_text_sect_high
;
1435 static CORE_ADDR interp_plt_sect_low
;
1436 static CORE_ADDR interp_plt_sect_high
;
1439 in_svr4_dynsym_resolve_code (pc
)
1442 return ((pc
>= interp_text_sect_low
&& pc
< interp_text_sect_high
)
1443 || (pc
>= interp_plt_sect_low
&& pc
< interp_plt_sect_high
)
1444 || in_plt_section (pc
, NULL
));
1452 disable_break -- remove the "mapping changed" breakpoint
1456 static int disable_break ()
1460 Removes the breakpoint that gets hit when the dynamic linker
1461 completes a mapping change.
1465 #ifndef SVR4_SHARED_LIBS
1472 #ifndef SVR4_SHARED_LIBS
1474 int in_debugger
= 0;
1476 /* Read the debugger structure from the inferior to retrieve the
1477 address of the breakpoint and the original contents of the
1478 breakpoint address. Remove the breakpoint by writing the original
1481 read_memory (debug_addr
, (char *) &debug_copy
, sizeof (debug_copy
));
1483 /* Set `in_debugger' to zero now. */
1485 write_memory (flag_addr
, (char *) &in_debugger
, sizeof (in_debugger
));
1487 breakpoint_addr
= (CORE_ADDR
) debug_copy
.ldd_bp_addr
;
1488 write_memory (breakpoint_addr
, (char *) &debug_copy
.ldd_bp_inst
,
1489 sizeof (debug_copy
.ldd_bp_inst
));
1491 #else /* SVR4_SHARED_LIBS */
1493 /* Note that breakpoint address and original contents are in our address
1494 space, so we just need to write the original contents back. */
1496 if (memory_remove_breakpoint (breakpoint_addr
, shadow_contents
) != 0)
1501 #endif /* !SVR4_SHARED_LIBS */
1503 /* For the SVR4 version, we always know the breakpoint address. For the
1504 SunOS version we don't know it until the above code is executed.
1505 Grumble if we are stopped anywhere besides the breakpoint address. */
1507 if (stop_pc
!= breakpoint_addr
)
1509 warning ("stopped at unknown breakpoint while handling shared libraries");
1515 #endif /* #ifdef SVR4_SHARED_LIBS */
1521 enable_break -- arrange for dynamic linker to hit breakpoint
1525 int enable_break (void)
1529 Both the SunOS and the SVR4 dynamic linkers have, as part of their
1530 debugger interface, support for arranging for the inferior to hit
1531 a breakpoint after mapping in the shared libraries. This function
1532 enables that breakpoint.
1534 For SunOS, there is a special flag location (in_debugger) which we
1535 set to 1. When the dynamic linker sees this flag set, it will set
1536 a breakpoint at a location known only to itself, after saving the
1537 original contents of that place and the breakpoint address itself,
1538 in it's own internal structures. When we resume the inferior, it
1539 will eventually take a SIGTRAP when it runs into the breakpoint.
1540 We handle this (in a different place) by restoring the contents of
1541 the breakpointed location (which is only known after it stops),
1542 chasing around to locate the shared libraries that have been
1543 loaded, then resuming.
1545 For SVR4, the debugger interface structure contains a member (r_brk)
1546 which is statically initialized at the time the shared library is
1547 built, to the offset of a function (_r_debug_state) which is guaran-
1548 teed to be called once before mapping in a library, and again when
1549 the mapping is complete. At the time we are examining this member,
1550 it contains only the unrelocated offset of the function, so we have
1551 to do our own relocation. Later, when the dynamic linker actually
1552 runs, it relocates r_brk to be the actual address of _r_debug_state().
1554 The debugger interface structure also contains an enumeration which
1555 is set to either RT_ADD or RT_DELETE prior to changing the mapping,
1556 depending upon whether or not the library is being mapped or unmapped,
1557 and then set to RT_CONSISTENT after the library is mapped/unmapped.
1565 #ifndef SVR4_SHARED_LIBS
1570 /* Get link_dynamic structure */
1572 j
= target_read_memory (debug_base
, (char *) &dynamic_copy
,
1573 sizeof (dynamic_copy
));
1580 /* Calc address of debugger interface structure */
1582 debug_addr
= (CORE_ADDR
) dynamic_copy
.ldd
;
1584 /* Calc address of `in_debugger' member of debugger interface structure */
1586 flag_addr
= debug_addr
+ (CORE_ADDR
) ((char *) &debug_copy
.ldd_in_debugger
-
1587 (char *) &debug_copy
);
1589 /* Write a value of 1 to this member. */
1592 write_memory (flag_addr
, (char *) &in_debugger
, sizeof (in_debugger
));
1595 #else /* SVR4_SHARED_LIBS */
1597 #ifdef BKPT_AT_SYMBOL
1599 struct minimal_symbol
*msymbol
;
1601 asection
*interp_sect
;
1603 /* First, remove all the solib event breakpoints. Their addresses
1604 may have changed since the last time we ran the program. */
1605 remove_solib_event_breakpoints ();
1607 #ifdef SVR4_SHARED_LIBS
1608 interp_text_sect_low
= interp_text_sect_high
= 0;
1609 interp_plt_sect_low
= interp_plt_sect_high
= 0;
1611 /* Find the .interp section; if not found, warn the user and drop
1612 into the old breakpoint at symbol code. */
1613 interp_sect
= bfd_get_section_by_name (exec_bfd
, ".interp");
1616 unsigned int interp_sect_size
;
1618 CORE_ADDR load_addr
;
1620 CORE_ADDR sym_addr
= 0;
1622 /* Read the contents of the .interp section into a local buffer;
1623 the contents specify the dynamic linker this program uses. */
1624 interp_sect_size
= bfd_section_size (exec_bfd
, interp_sect
);
1625 buf
= alloca (interp_sect_size
);
1626 bfd_get_section_contents (exec_bfd
, interp_sect
,
1627 buf
, 0, interp_sect_size
);
1629 /* Now we need to figure out where the dynamic linker was
1630 loaded so that we can load its symbols and place a breakpoint
1631 in the dynamic linker itself.
1633 This address is stored on the stack. However, I've been unable
1634 to find any magic formula to find it for Solaris (appears to
1635 be trivial on GNU/Linux). Therefore, we have to try an alternate
1636 mechanism to find the dynamic linker's base address. */
1637 tmp_bfd
= bfd_openr (buf
, gnutarget
);
1638 if (tmp_bfd
== NULL
)
1639 goto bkpt_at_symbol
;
1641 /* Make sure the dynamic linker's really a useful object. */
1642 if (!bfd_check_format (tmp_bfd
, bfd_object
))
1644 warning ("Unable to grok dynamic linker %s as an object file", buf
);
1645 bfd_close (tmp_bfd
);
1646 goto bkpt_at_symbol
;
1649 /* We find the dynamic linker's base address by examining the
1650 current pc (which point at the entry point for the dynamic
1651 linker) and subtracting the offset of the entry point. */
1652 load_addr
= read_pc () - tmp_bfd
->start_address
;
1654 /* Record the relocated start and end address of the dynamic linker
1655 text and plt section for in_svr4_dynsym_resolve_code. */
1656 interp_sect
= bfd_get_section_by_name (tmp_bfd
, ".text");
1659 interp_text_sect_low
=
1660 bfd_section_vma (tmp_bfd
, interp_sect
) + load_addr
;
1661 interp_text_sect_high
=
1662 interp_text_sect_low
+ bfd_section_size (tmp_bfd
, interp_sect
);
1664 interp_sect
= bfd_get_section_by_name (tmp_bfd
, ".plt");
1667 interp_plt_sect_low
=
1668 bfd_section_vma (tmp_bfd
, interp_sect
) + load_addr
;
1669 interp_plt_sect_high
=
1670 interp_plt_sect_low
+ bfd_section_size (tmp_bfd
, interp_sect
);
1673 /* Now try to set a breakpoint in the dynamic linker. */
1674 for (bkpt_namep
= solib_break_names
; *bkpt_namep
!= NULL
; bkpt_namep
++)
1676 sym_addr
= bfd_lookup_symbol (tmp_bfd
, *bkpt_namep
);
1681 /* We're done with the temporary bfd. */
1682 bfd_close (tmp_bfd
);
1686 create_solib_event_breakpoint (load_addr
+ sym_addr
);
1690 /* For whatever reason we couldn't set a breakpoint in the dynamic
1691 linker. Warn and drop into the old code. */
1693 warning ("Unable to find dynamic linker breakpoint function.\nGDB will be unable to debug shared library initializers\nand track explicitly loaded dynamic code.");
1697 /* Scan through the list of symbols, trying to look up the symbol and
1698 set a breakpoint there. Terminate loop when we/if we succeed. */
1700 breakpoint_addr
= 0;
1701 for (bkpt_namep
= bkpt_names
; *bkpt_namep
!= NULL
; bkpt_namep
++)
1703 msymbol
= lookup_minimal_symbol (*bkpt_namep
, NULL
, symfile_objfile
);
1704 if ((msymbol
!= NULL
) && (SYMBOL_VALUE_ADDRESS (msymbol
) != 0))
1706 create_solib_event_breakpoint (SYMBOL_VALUE_ADDRESS (msymbol
));
1711 /* Nothing good happened. */
1714 #endif /* BKPT_AT_SYMBOL */
1716 #endif /* !SVR4_SHARED_LIBS */
1725 solib_create_inferior_hook -- shared library startup support
1729 void solib_create_inferior_hook()
1733 When gdb starts up the inferior, it nurses it along (through the
1734 shell) until it is ready to execute it's first instruction. At this
1735 point, this function gets called via expansion of the macro
1736 SOLIB_CREATE_INFERIOR_HOOK.
1738 For SunOS executables, this first instruction is typically the
1739 one at "_start", or a similar text label, regardless of whether
1740 the executable is statically or dynamically linked. The runtime
1741 startup code takes care of dynamically linking in any shared
1742 libraries, once gdb allows the inferior to continue.
1744 For SVR4 executables, this first instruction is either the first
1745 instruction in the dynamic linker (for dynamically linked
1746 executables) or the instruction at "start" for statically linked
1747 executables. For dynamically linked executables, the system
1748 first exec's /lib/libc.so.N, which contains the dynamic linker,
1749 and starts it running. The dynamic linker maps in any needed
1750 shared libraries, maps in the actual user executable, and then
1751 jumps to "start" in the user executable.
1753 For both SunOS shared libraries, and SVR4 shared libraries, we
1754 can arrange to cooperate with the dynamic linker to discover the
1755 names of shared libraries that are dynamically linked, and the
1756 base addresses to which they are linked.
1758 This function is responsible for discovering those names and
1759 addresses, and saving sufficient information about them to allow
1760 their symbols to be read at a later time.
1764 Between enable_break() and disable_break(), this code does not
1765 properly handle hitting breakpoints which the user might have
1766 set in the startup code or in the dynamic linker itself. Proper
1767 handling will probably have to wait until the implementation is
1768 changed to use the "breakpoint handler function" method.
1770 Also, what if child has exit()ed? Must exit loop somehow.
1774 solib_create_inferior_hook ()
1776 /* If we are using the BKPT_AT_SYMBOL code, then we don't need the base
1777 yet. In fact, in the case of a SunOS4 executable being run on
1778 Solaris, we can't get it yet. find_solib will get it when it needs
1780 #if !(defined (SVR4_SHARED_LIBS) && defined (BKPT_AT_SYMBOL))
1781 if ((debug_base
= locate_base ()) == 0)
1783 /* Can't find the symbol or the executable is statically linked. */
1788 if (!enable_break ())
1790 warning ("shared library handler failed to enable breakpoint");
1794 #if !defined(SVR4_SHARED_LIBS) || defined(_SCO_DS)
1795 /* SCO and SunOS need the loop below, other systems should be using the
1796 special shared library breakpoints and the shared library breakpoint
1799 Now run the target. It will eventually hit the breakpoint, at
1800 which point all of the libraries will have been mapped in and we
1801 can go groveling around in the dynamic linker structures to find
1802 out what we need to know about them. */
1804 clear_proceed_status ();
1805 stop_soon_quietly
= 1;
1806 stop_signal
= TARGET_SIGNAL_0
;
1809 target_resume (-1, 0, stop_signal
);
1810 wait_for_inferior ();
1812 while (stop_signal
!= TARGET_SIGNAL_TRAP
);
1813 stop_soon_quietly
= 0;
1815 #if !defined(_SCO_DS)
1816 /* We are now either at the "mapping complete" breakpoint (or somewhere
1817 else, a condition we aren't prepared to deal with anyway), so adjust
1818 the PC as necessary after a breakpoint, disable the breakpoint, and
1819 add any shared libraries that were mapped in. */
1821 if (DECR_PC_AFTER_BREAK
)
1823 stop_pc
-= DECR_PC_AFTER_BREAK
;
1824 write_register (PC_REGNUM
, stop_pc
);
1827 if (!disable_break ())
1829 warning ("shared library handler failed to disable breakpoint");
1833 solib_add ((char *) 0, 0, (struct target_ops
*) 0);
1834 #endif /* ! _SCO_DS */
1842 special_symbol_handling -- additional shared library symbol handling
1846 void special_symbol_handling (struct so_list *so)
1850 Once the symbols from a shared object have been loaded in the usual
1851 way, we are called to do any system specific symbol handling that
1854 For SunOS4, this consists of grunging around in the dynamic
1855 linkers structures to find symbol definitions for "common" symbols
1856 and adding them to the minimal symbol table for the runtime common
1862 special_symbol_handling (so
)
1865 #ifndef SVR4_SHARED_LIBS
1868 if (debug_addr
== 0)
1870 /* Get link_dynamic structure */
1872 j
= target_read_memory (debug_base
, (char *) &dynamic_copy
,
1873 sizeof (dynamic_copy
));
1880 /* Calc address of debugger interface structure */
1881 /* FIXME, this needs work for cross-debugging of core files
1882 (byteorder, size, alignment, etc). */
1884 debug_addr
= (CORE_ADDR
) dynamic_copy
.ldd
;
1887 /* Read the debugger structure from the inferior, just to make sure
1888 we have a current copy. */
1890 j
= target_read_memory (debug_addr
, (char *) &debug_copy
,
1891 sizeof (debug_copy
));
1893 return; /* unreadable */
1895 /* Get common symbol definitions for the loaded object. */
1897 if (debug_copy
.ldd_cp
)
1899 solib_add_common_symbols (debug_copy
.ldd_cp
);
1902 #endif /* !SVR4_SHARED_LIBS */
1910 sharedlibrary_command -- handle command to explicitly add library
1914 static void sharedlibrary_command (char *args, int from_tty)
1921 sharedlibrary_command (args
, from_tty
)
1926 solib_add (args
, from_tty
, (struct target_ops
*) 0);
1929 #endif /* HAVE_LINK_H */
1932 _initialize_solib ()
1936 add_com ("sharedlibrary", class_files
, sharedlibrary_command
,
1937 "Load shared object library symbols for files matching REGEXP.");
1938 add_info ("sharedlibrary", info_sharedlibrary_command
,
1939 "Status of loaded shared object libraries.");
1942 (add_set_cmd ("auto-solib-add", class_support
, var_zinteger
,
1943 (char *) &auto_solib_add
,
1944 "Set autoloading of shared library symbols.\n\
1945 If nonzero, symbols from all shared object libraries will be loaded\n\
1946 automatically when the inferior begins execution or when the dynamic linker\n\
1947 informs gdb that a new library has been loaded. Otherwise, symbols\n\
1948 must be loaded manually, using `sharedlibrary'.",
1953 (add_set_cmd ("solib-absolute-prefix", class_support
, var_filename
,
1954 (char *) &solib_absolute_prefix
,
1955 "Set prefix for loading absolute shared library symbol files.\n\
1956 For other (relative) files, you can add values using `set solib-search-path'.",
1960 (add_set_cmd ("solib-search-path", class_support
, var_string
,
1961 (char *) &solib_search_path
,
1962 "Set the search path for loading non-absolute shared library symbol files.\n\
1963 This takes precedence over the environment variables PATH and LD_LIBRARY_PATH.",
1967 #endif /* HAVE_LINK_H */