1 /* Handle SunOS and SVR4 shared libraries for GDB, the GNU Debugger.
2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000,
4 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
27 #include <sys/types.h>
29 #include "gdb_string.h"
30 #include <sys/param.h>
33 #ifndef SVR4_SHARED_LIBS
34 /* SunOS shared libs need the nlist structure. */
38 #include "elf/external.h"
39 #include "elf/common.h"
51 #include "gdb_regex.h"
58 #include "solib-svr4.h"
60 #ifndef SVR4_FETCH_LINK_MAP_OFFSETS
61 #define SVR4_FETCH_LINK_MAP_OFFSETS() svr4_fetch_link_map_offsets ()
64 static struct link_map_offsets
*svr4_fetch_link_map_offsets (void);
65 static struct link_map_offsets
*legacy_fetch_link_map_offsets (void);
67 /* fetch_link_map_offsets_gdbarch_data is a handle used to obtain the
68 architecture specific link map offsets fetching function. */
70 static struct gdbarch_data
*fetch_link_map_offsets_gdbarch_data
;
72 /* legacy_svr4_fetch_link_map_offsets_hook is a pointer to a function
73 which is used to fetch link map offsets. It will only be set
74 by solib-legacy.c, if at all. */
76 struct link_map_offsets
*(*legacy_svr4_fetch_link_map_offsets_hook
)(void) = 0;
78 /* Link map info to include in an allocated so_list entry */
82 /* Pointer to copy of link map from inferior. The type is char *
83 rather than void *, so that we may use byte offsets to find the
84 various fields without the need for a cast. */
88 /* On SVR4 systems, a list of symbols in the dynamic linker where
89 GDB can try to place a breakpoint to monitor shared library
92 If none of these symbols are found, or other errors occur, then
93 SVR4 systems will fall back to using a symbol as the "startup
94 mapping complete" breakpoint address. */
96 #ifdef SVR4_SHARED_LIBS
97 static char *solib_break_names
[] =
102 "rtld_db_dlactivity",
108 #define BKPT_AT_SYMBOL 1
110 #if defined (BKPT_AT_SYMBOL) && defined (SVR4_SHARED_LIBS)
111 static char *bkpt_names
[] =
113 #ifdef SOLIB_BKPT_NAME
114 SOLIB_BKPT_NAME
, /* Prefer configured name if it exists. */
122 /* Symbols which are used to locate the base of the link map structures. */
124 #ifndef SVR4_SHARED_LIBS
125 static char *debug_base_symbols
[] =
133 static char *main_name_list
[] =
140 /* Macro to extract an address from a solib structure.
141 When GDB is configured for some 32-bit targets (e.g. Solaris 2.7
142 sparc), BFD is configured to handle 64-bit targets, so CORE_ADDR is
143 64 bits. We have to extract only the significant bits of addresses
144 to get the right address when accessing the core file BFD. */
146 #define SOLIB_EXTRACT_ADDRESS(MEMBER) \
147 extract_address (&(MEMBER), sizeof (MEMBER))
149 /* local data declarations */
151 #ifndef SVR4_SHARED_LIBS
153 /* NOTE: converted the macros LM_ADDR, LM_NEXT, LM_NAME and
154 IGNORE_FIRST_LINK_MAP_ENTRY into functions (see below).
157 static struct link_dynamic dynamic_copy
;
158 static struct link_dynamic_2 ld_2_copy
;
159 static struct ld_debug debug_copy
;
160 static CORE_ADDR debug_addr
;
161 static CORE_ADDR flag_addr
;
163 #endif /* !SVR4_SHARED_LIBS */
165 /* link map access functions */
168 LM_ADDR (struct so_list
*so
)
170 struct link_map_offsets
*lmo
= SVR4_FETCH_LINK_MAP_OFFSETS ();
172 return (CORE_ADDR
) extract_signed_integer (so
->lm_info
->lm
+ lmo
->l_addr_offset
,
177 LM_NEXT (struct so_list
*so
)
179 struct link_map_offsets
*lmo
= SVR4_FETCH_LINK_MAP_OFFSETS ();
181 return extract_address (so
->lm_info
->lm
+ lmo
->l_next_offset
, lmo
->l_next_size
);
185 LM_NAME (struct so_list
*so
)
187 struct link_map_offsets
*lmo
= SVR4_FETCH_LINK_MAP_OFFSETS ();
189 return extract_address (so
->lm_info
->lm
+ lmo
->l_name_offset
, lmo
->l_name_size
);
192 #ifndef SVR4_SHARED_LIBS
195 IGNORE_FIRST_LINK_MAP_ENTRY (struct so_list
*so
)
200 #else /* SVR4_SHARED_LIBS */
203 IGNORE_FIRST_LINK_MAP_ENTRY (struct so_list
*so
)
205 struct link_map_offsets
*lmo
= SVR4_FETCH_LINK_MAP_OFFSETS ();
207 return extract_address (so
->lm_info
->lm
+ lmo
->l_prev_offset
,
208 lmo
->l_prev_size
) == 0;
211 #endif /* !SVR4_SHARED_LIBS */
213 static CORE_ADDR debug_base
; /* Base of dynamic linker structures */
214 static CORE_ADDR breakpoint_addr
; /* Address where end bkpt is set */
216 /* Local function prototypes */
218 static int match_main (char *);
220 #ifndef SVR4_SHARED_LIBS
222 /* Allocate the runtime common object file. */
225 allocate_rt_common_objfile (void)
227 struct objfile
*objfile
;
228 struct objfile
*last_one
;
230 objfile
= (struct objfile
*) xmalloc (sizeof (struct objfile
));
231 memset (objfile
, 0, sizeof (struct objfile
));
233 obstack_specify_allocation (&objfile
->psymbol_cache
.cache
, 0, 0,
235 obstack_specify_allocation (&objfile
->psymbol_obstack
, 0, 0, xmalloc
,
237 obstack_specify_allocation (&objfile
->symbol_obstack
, 0, 0, xmalloc
,
239 obstack_specify_allocation (&objfile
->type_obstack
, 0, 0, xmalloc
,
241 objfile
->name
= mstrsave (objfile
->md
, "rt_common");
243 /* Add this file onto the tail of the linked list of other such files. */
245 objfile
->next
= NULL
;
246 if (object_files
== NULL
)
247 object_files
= objfile
;
250 for (last_one
= object_files
;
252 last_one
= last_one
->next
);
253 last_one
->next
= objfile
;
256 rt_common_objfile
= objfile
;
259 /* Read all dynamically loaded common symbol definitions from the inferior
260 and put them into the minimal symbol table for the runtime common
264 solib_add_common_symbols (CORE_ADDR rtc_symp
)
266 struct rtc_symb inferior_rtc_symb
;
267 struct nlist inferior_rtc_nlist
;
271 /* Remove any runtime common symbols from previous runs. */
273 if (rt_common_objfile
!= NULL
&& rt_common_objfile
->minimal_symbol_count
)
275 obstack_free (&rt_common_objfile
->symbol_obstack
, 0);
276 obstack_specify_allocation (&rt_common_objfile
->symbol_obstack
, 0, 0,
278 rt_common_objfile
->minimal_symbol_count
= 0;
279 rt_common_objfile
->msymbols
= NULL
;
282 init_minimal_symbol_collection ();
283 make_cleanup_discard_minimal_symbols ();
287 read_memory (rtc_symp
,
288 (char *) &inferior_rtc_symb
,
289 sizeof (inferior_rtc_symb
));
290 read_memory (SOLIB_EXTRACT_ADDRESS (inferior_rtc_symb
.rtc_sp
),
291 (char *) &inferior_rtc_nlist
,
292 sizeof (inferior_rtc_nlist
));
293 if (inferior_rtc_nlist
.n_type
== N_COMM
)
295 /* FIXME: The length of the symbol name is not available, but in the
296 current implementation the common symbol is allocated immediately
297 behind the name of the symbol. */
298 len
= inferior_rtc_nlist
.n_value
- inferior_rtc_nlist
.n_un
.n_strx
;
300 name
= xmalloc (len
);
301 read_memory (SOLIB_EXTRACT_ADDRESS (inferior_rtc_nlist
.n_un
.n_name
),
304 /* Allocate the runtime common objfile if necessary. */
305 if (rt_common_objfile
== NULL
)
306 allocate_rt_common_objfile ();
308 prim_record_minimal_symbol (name
, inferior_rtc_nlist
.n_value
,
309 mst_bss
, rt_common_objfile
);
312 rtc_symp
= SOLIB_EXTRACT_ADDRESS (inferior_rtc_symb
.rtc_next
);
315 /* Install any minimal symbols that have been collected as the current
316 minimal symbols for the runtime common objfile. */
318 install_minimal_symbols (rt_common_objfile
);
321 #endif /* SVR4_SHARED_LIBS */
324 #ifdef SVR4_SHARED_LIBS
326 static CORE_ADDR
bfd_lookup_symbol (bfd
*, char *);
332 bfd_lookup_symbol -- lookup the value for a specific symbol
336 CORE_ADDR bfd_lookup_symbol (bfd *abfd, char *symname)
340 An expensive way to lookup the value of a single symbol for
341 bfd's that are only temporary anyway. This is used by the
342 shared library support to find the address of the debugger
343 interface structures in the shared library.
345 Note that 0 is specifically allowed as an error return (no
350 bfd_lookup_symbol (bfd
*abfd
, char *symname
)
354 asymbol
**symbol_table
;
355 unsigned int number_of_symbols
;
357 struct cleanup
*back_to
;
358 CORE_ADDR symaddr
= 0;
360 storage_needed
= bfd_get_symtab_upper_bound (abfd
);
362 if (storage_needed
> 0)
364 symbol_table
= (asymbol
**) xmalloc (storage_needed
);
365 back_to
= make_cleanup (xfree
, (PTR
) symbol_table
);
366 number_of_symbols
= bfd_canonicalize_symtab (abfd
, symbol_table
);
368 for (i
= 0; i
< number_of_symbols
; i
++)
370 sym
= *symbol_table
++;
371 if (STREQ (sym
->name
, symname
))
373 /* Bfd symbols are section relative. */
374 symaddr
= sym
->value
+ sym
->section
->vma
;
378 do_cleanups (back_to
);
384 /* On FreeBSD, the dynamic linker is stripped by default. So we'll
385 have to check the dynamic string table too. */
387 storage_needed
= bfd_get_dynamic_symtab_upper_bound (abfd
);
389 if (storage_needed
> 0)
391 symbol_table
= (asymbol
**) xmalloc (storage_needed
);
392 back_to
= make_cleanup (xfree
, (PTR
) symbol_table
);
393 number_of_symbols
= bfd_canonicalize_dynamic_symtab (abfd
, symbol_table
);
395 for (i
= 0; i
< number_of_symbols
; i
++)
397 sym
= *symbol_table
++;
398 if (STREQ (sym
->name
, symname
))
400 /* Bfd symbols are section relative. */
401 symaddr
= sym
->value
+ sym
->section
->vma
;
405 do_cleanups (back_to
);
411 #ifdef HANDLE_SVR4_EXEC_EMULATORS
414 Solaris BCP (the part of Solaris which allows it to run SunOS4
415 a.out files) throws in another wrinkle. Solaris does not fill
416 in the usual a.out link map structures when running BCP programs,
417 the only way to get at them is via groping around in the dynamic
419 The dynamic linker and it's structures are located in the shared
420 C library, which gets run as the executable's "interpreter" by
423 Note that we can assume nothing about the process state at the time
424 we need to find these structures. We may be stopped on the first
425 instruction of the interpreter (C shared library), the first
426 instruction of the executable itself, or somewhere else entirely
427 (if we attached to the process for example).
430 static char *debug_base_symbols
[] =
432 "r_debug", /* Solaris 2.3 */
433 "_r_debug", /* Solaris 2.1, 2.2 */
437 static int look_for_base (int, CORE_ADDR
);
443 look_for_base -- examine file for each mapped address segment
447 static int look_for_base (int fd, CORE_ADDR baseaddr)
451 This function is passed to proc_iterate_over_mappings, which
452 causes it to get called once for each mapped address space, with
453 an open file descriptor for the file mapped to that space, and the
454 base address of that mapped space.
456 Our job is to find the debug base symbol in the file that this
457 fd is open on, if it exists, and if so, initialize the dynamic
458 linker structure base address debug_base.
460 Note that this is a computationally expensive proposition, since
461 we basically have to open a bfd on every call, so we specifically
462 avoid opening the exec file.
466 look_for_base (int fd
, CORE_ADDR baseaddr
)
469 CORE_ADDR address
= 0;
472 /* If the fd is -1, then there is no file that corresponds to this
473 mapped memory segment, so skip it. Also, if the fd corresponds
474 to the exec file, skip it as well. */
478 && fdmatch (fileno ((FILE *) (exec_bfd
->iostream
)), fd
)))
483 /* Try to open whatever random file this fd corresponds to. Note that
484 we have no way currently to find the filename. Don't gripe about
485 any problems we might have, just fail. */
487 if ((interp_bfd
= bfd_fdopenr ("unnamed", gnutarget
, fd
)) == NULL
)
491 if (!bfd_check_format (interp_bfd
, bfd_object
))
493 /* FIXME-leak: on failure, might not free all memory associated with
495 bfd_close (interp_bfd
);
499 /* Now try to find our debug base symbol in this file, which we at
500 least know to be a valid ELF executable or shared library. */
502 for (symbolp
= debug_base_symbols
; *symbolp
!= NULL
; symbolp
++)
504 address
= bfd_lookup_symbol (interp_bfd
, *symbolp
);
512 /* FIXME-leak: on failure, might not free all memory associated with
514 bfd_close (interp_bfd
);
518 /* Eureka! We found the symbol. But now we may need to relocate it
519 by the base address. If the symbol's value is less than the base
520 address of the shared library, then it hasn't yet been relocated
521 by the dynamic linker, and we have to do it ourself. FIXME: Note
522 that we make the assumption that the first segment that corresponds
523 to the shared library has the base address to which the library
526 if (address
< baseaddr
)
530 debug_base
= address
;
531 /* FIXME-leak: on failure, might not free all memory associated with
533 bfd_close (interp_bfd
);
536 #endif /* HANDLE_SVR4_EXEC_EMULATORS */
542 elf_locate_base -- locate the base address of dynamic linker structs
543 for SVR4 elf targets.
547 CORE_ADDR elf_locate_base (void)
551 For SVR4 elf targets the address of the dynamic linker's runtime
552 structure is contained within the dynamic info section in the
553 executable file. The dynamic section is also mapped into the
554 inferior address space. Because the runtime loader fills in the
555 real address before starting the inferior, we have to read in the
556 dynamic info section from the inferior address space.
557 If there are any errors while trying to find the address, we
558 silently return 0, otherwise the found address is returned.
563 elf_locate_base (void)
565 sec_ptr dyninfo_sect
;
566 int dyninfo_sect_size
;
567 CORE_ADDR dyninfo_addr
;
572 /* Find the start address of the .dynamic section. */
573 dyninfo_sect
= bfd_get_section_by_name (exec_bfd
, ".dynamic");
574 if (dyninfo_sect
== NULL
)
576 dyninfo_addr
= bfd_section_vma (exec_bfd
, dyninfo_sect
);
578 /* Read in .dynamic section, silently ignore errors. */
579 dyninfo_sect_size
= bfd_section_size (exec_bfd
, dyninfo_sect
);
580 buf
= alloca (dyninfo_sect_size
);
581 if (target_read_memory (dyninfo_addr
, buf
, dyninfo_sect_size
))
584 /* Find the DT_DEBUG entry in the the .dynamic section.
585 For mips elf we look for DT_MIPS_RLD_MAP, mips elf apparently has
586 no DT_DEBUG entries. */
588 arch_size
= bfd_get_arch_size (exec_bfd
);
589 if (arch_size
== -1) /* failure */
594 for (bufend
= buf
+ dyninfo_sect_size
;
596 buf
+= sizeof (Elf32_External_Dyn
))
598 Elf32_External_Dyn
*x_dynp
= (Elf32_External_Dyn
*) buf
;
602 dyn_tag
= bfd_h_get_32 (exec_bfd
, (bfd_byte
*) x_dynp
->d_tag
);
603 if (dyn_tag
== DT_NULL
)
605 else if (dyn_tag
== DT_DEBUG
)
607 dyn_ptr
= bfd_h_get_32 (exec_bfd
,
608 (bfd_byte
*) x_dynp
->d_un
.d_ptr
);
611 else if (dyn_tag
== DT_MIPS_RLD_MAP
)
615 pbuf
= alloca (TARGET_PTR_BIT
/ HOST_CHAR_BIT
);
616 /* DT_MIPS_RLD_MAP contains a pointer to the address
617 of the dynamic link structure. */
618 dyn_ptr
= bfd_h_get_32 (exec_bfd
,
619 (bfd_byte
*) x_dynp
->d_un
.d_ptr
);
620 if (target_read_memory (dyn_ptr
, pbuf
, sizeof (pbuf
)))
622 return extract_unsigned_integer (pbuf
, sizeof (pbuf
));
626 else /* 64-bit elf */
628 for (bufend
= buf
+ dyninfo_sect_size
;
630 buf
+= sizeof (Elf64_External_Dyn
))
632 Elf64_External_Dyn
*x_dynp
= (Elf64_External_Dyn
*) buf
;
636 dyn_tag
= bfd_h_get_64 (exec_bfd
, (bfd_byte
*) x_dynp
->d_tag
);
637 if (dyn_tag
== DT_NULL
)
639 else if (dyn_tag
== DT_DEBUG
)
641 dyn_ptr
= bfd_h_get_64 (exec_bfd
,
642 (bfd_byte
*) x_dynp
->d_un
.d_ptr
);
648 /* DT_DEBUG entry not found. */
652 #endif /* SVR4_SHARED_LIBS */
658 locate_base -- locate the base address of dynamic linker structs
662 CORE_ADDR locate_base (void)
666 For both the SunOS and SVR4 shared library implementations, if the
667 inferior executable has been linked dynamically, there is a single
668 address somewhere in the inferior's data space which is the key to
669 locating all of the dynamic linker's runtime structures. This
670 address is the value of the debug base symbol. The job of this
671 function is to find and return that address, or to return 0 if there
672 is no such address (the executable is statically linked for example).
674 For SunOS, the job is almost trivial, since the dynamic linker and
675 all of it's structures are statically linked to the executable at
676 link time. Thus the symbol for the address we are looking for has
677 already been added to the minimal symbol table for the executable's
678 objfile at the time the symbol file's symbols were read, and all we
679 have to do is look it up there. Note that we explicitly do NOT want
680 to find the copies in the shared library.
682 The SVR4 version is a bit more complicated because the address
683 is contained somewhere in the dynamic info section. We have to go
684 to a lot more work to discover the address of the debug base symbol.
685 Because of this complexity, we cache the value we find and return that
686 value on subsequent invocations. Note there is no copy in the
687 executable symbol tables.
695 #ifndef SVR4_SHARED_LIBS
697 struct minimal_symbol
*msymbol
;
698 CORE_ADDR address
= 0;
701 /* For SunOS, we want to limit the search for the debug base symbol to the
702 executable being debugged, since there is a duplicate named symbol in the
703 shared library. We don't want the shared library versions. */
705 for (symbolp
= debug_base_symbols
; *symbolp
!= NULL
; symbolp
++)
707 msymbol
= lookup_minimal_symbol (*symbolp
, NULL
, symfile_objfile
);
708 if ((msymbol
!= NULL
) && (SYMBOL_VALUE_ADDRESS (msymbol
) != 0))
710 address
= SYMBOL_VALUE_ADDRESS (msymbol
);
716 #else /* SVR4_SHARED_LIBS */
718 /* Check to see if we have a currently valid address, and if so, avoid
719 doing all this work again and just return the cached address. If
720 we have no cached address, try to locate it in the dynamic info
721 section for ELF executables. */
726 && bfd_get_flavour (exec_bfd
) == bfd_target_elf_flavour
)
727 debug_base
= elf_locate_base ();
728 #ifdef HANDLE_SVR4_EXEC_EMULATORS
729 /* Try it the hard way for emulated executables. */
730 else if (!ptid_equal (inferior_ptid
, null_ptid
) && target_has_execution
)
731 proc_iterate_over_mappings (look_for_base
);
736 #endif /* !SVR4_SHARED_LIBS */
744 first_link_map_member -- locate first member in dynamic linker's map
748 static CORE_ADDR first_link_map_member (void)
752 Find the first element in the inferior's dynamic link map, and
753 return its address in the inferior. This function doesn't copy the
754 link map entry itself into our address space; current_sos actually
758 first_link_map_member (void)
762 #ifndef SVR4_SHARED_LIBS
764 read_memory (debug_base
, (char *) &dynamic_copy
, sizeof (dynamic_copy
));
765 if (dynamic_copy
.ld_version
>= 2)
767 /* It is a version that we can deal with, so read in the secondary
768 structure and find the address of the link map list from it. */
769 read_memory (SOLIB_EXTRACT_ADDRESS (dynamic_copy
.ld_un
.ld_2
),
770 (char *) &ld_2_copy
, sizeof (struct link_dynamic_2
));
771 lm
= SOLIB_EXTRACT_ADDRESS (ld_2_copy
.ld_loaded
);
774 #else /* SVR4_SHARED_LIBS */
775 struct link_map_offsets
*lmo
= SVR4_FETCH_LINK_MAP_OFFSETS ();
776 char *r_map_buf
= xmalloc (lmo
->r_map_size
);
777 struct cleanup
*cleanups
= make_cleanup (xfree
, r_map_buf
);
779 read_memory (debug_base
+ lmo
->r_map_offset
, r_map_buf
, lmo
->r_map_size
);
781 lm
= extract_address (r_map_buf
, lmo
->r_map_size
);
783 /* FIXME: Perhaps we should validate the info somehow, perhaps by
784 checking r_version for a known version number, or r_state for
787 do_cleanups (cleanups
);
789 #endif /* !SVR4_SHARED_LIBS */
794 #ifdef SVR4_SHARED_LIBS
799 open_symbol_file_object
803 void open_symbol_file_object (void *from_tty)
807 If no open symbol file, attempt to locate and open the main symbol
808 file. On SVR4 systems, this is the first link map entry. If its
809 name is here, we can open it. Useful when attaching to a process
810 without first loading its symbol file.
812 If FROM_TTYP dereferences to a non-zero integer, allow messages to
813 be printed. This parameter is a pointer rather than an int because
814 open_symbol_file_object() is called via catch_errors() and
815 catch_errors() requires a pointer argument. */
818 open_symbol_file_object (void *from_ttyp
)
820 CORE_ADDR lm
, l_name
;
823 int from_tty
= *(int *)from_ttyp
;
824 struct link_map_offsets
*lmo
= SVR4_FETCH_LINK_MAP_OFFSETS ();
825 char *l_name_buf
= xmalloc (lmo
->l_name_size
);
826 struct cleanup
*cleanups
= make_cleanup (xfree
, l_name_buf
);
829 if (!query ("Attempt to reload symbols from process? "))
832 if ((debug_base
= locate_base ()) == 0)
833 return 0; /* failed somehow... */
835 /* First link map member should be the executable. */
836 if ((lm
= first_link_map_member ()) == 0)
837 return 0; /* failed somehow... */
839 /* Read address of name from target memory to GDB. */
840 read_memory (lm
+ lmo
->l_name_offset
, l_name_buf
, lmo
->l_name_size
);
842 /* Convert the address to host format. */
843 l_name
= extract_address (l_name_buf
, lmo
->l_name_size
);
845 /* Free l_name_buf. */
846 do_cleanups (cleanups
);
849 return 0; /* No filename. */
851 /* Now fetch the filename from target memory. */
852 target_read_string (l_name
, &filename
, SO_NAME_MAX_PATH_SIZE
- 1, &errcode
);
856 warning ("failed to read exec filename from attached file: %s",
857 safe_strerror (errcode
));
861 make_cleanup (xfree
, filename
);
862 /* Have a pathname: read the symbol file. */
863 symbol_file_add_main (filename
, from_tty
);
870 open_symbol_file_object (void *from_ttyp
)
875 #endif /* SVR4_SHARED_LIBS */
880 current_sos -- build a list of currently loaded shared objects
884 struct so_list *current_sos ()
888 Build a list of `struct so_list' objects describing the shared
889 objects currently loaded in the inferior. This list does not
890 include an entry for the main executable file.
892 Note that we only gather information directly available from the
893 inferior --- we don't examine any of the shared library files
894 themselves. The declaration of `struct so_list' says which fields
895 we provide values for. */
897 static struct so_list
*
898 svr4_current_sos (void)
901 struct so_list
*head
= 0;
902 struct so_list
**link_ptr
= &head
;
904 /* Make sure we've looked up the inferior's dynamic linker's base
908 debug_base
= locate_base ();
910 /* If we can't find the dynamic linker's base structure, this
911 must not be a dynamically linked executable. Hmm. */
916 /* Walk the inferior's link map list, and build our list of
917 `struct so_list' nodes. */
918 lm
= first_link_map_member ();
921 struct link_map_offsets
*lmo
= SVR4_FETCH_LINK_MAP_OFFSETS ();
923 = (struct so_list
*) xmalloc (sizeof (struct so_list
));
924 struct cleanup
*old_chain
= make_cleanup (xfree
, new);
926 memset (new, 0, sizeof (*new));
928 new->lm_info
= xmalloc (sizeof (struct lm_info
));
929 make_cleanup (xfree
, new->lm_info
);
931 new->lm_info
->lm
= xmalloc (lmo
->link_map_size
);
932 make_cleanup (xfree
, new->lm_info
->lm
);
933 memset (new->lm_info
->lm
, 0, lmo
->link_map_size
);
935 read_memory (lm
, new->lm_info
->lm
, lmo
->link_map_size
);
939 /* For SVR4 versions, the first entry in the link map is for the
940 inferior executable, so we must ignore it. For some versions of
941 SVR4, it has no name. For others (Solaris 2.3 for example), it
942 does have a name, so we can no longer use a missing name to
943 decide when to ignore it. */
944 if (IGNORE_FIRST_LINK_MAP_ENTRY (new))
951 /* Extract this shared object's name. */
952 target_read_string (LM_NAME (new), &buffer
,
953 SO_NAME_MAX_PATH_SIZE
- 1, &errcode
);
956 warning ("current_sos: Can't read pathname for load map: %s\n",
957 safe_strerror (errcode
));
961 strncpy (new->so_name
, buffer
, SO_NAME_MAX_PATH_SIZE
- 1);
962 new->so_name
[SO_NAME_MAX_PATH_SIZE
- 1] = '\0';
964 strcpy (new->so_original_name
, new->so_name
);
967 /* If this entry has no name, or its name matches the name
968 for the main executable, don't include it in the list. */
969 if (! new->so_name
[0]
970 || match_main (new->so_name
))
976 link_ptr
= &new->next
;
980 discard_cleanups (old_chain
);
987 /* On some systems, the only way to recognize the link map entry for
988 the main executable file is by looking at its name. Return
989 non-zero iff SONAME matches one of the known main executable names. */
992 match_main (char *soname
)
996 for (mainp
= main_name_list
; *mainp
!= NULL
; mainp
++)
998 if (strcmp (soname
, *mainp
) == 0)
1006 /* Return 1 if PC lies in the dynamic symbol resolution code of the
1007 SVR4 run time loader. */
1008 #ifdef SVR4_SHARED_LIBS
1009 static CORE_ADDR interp_text_sect_low
;
1010 static CORE_ADDR interp_text_sect_high
;
1011 static CORE_ADDR interp_plt_sect_low
;
1012 static CORE_ADDR interp_plt_sect_high
;
1015 svr4_in_dynsym_resolve_code (CORE_ADDR pc
)
1017 return ((pc
>= interp_text_sect_low
&& pc
< interp_text_sect_high
)
1018 || (pc
>= interp_plt_sect_low
&& pc
< interp_plt_sect_high
)
1019 || in_plt_section (pc
, NULL
));
1021 #else /* !SVR4_SHARED_LIBS */
1023 svr4_in_dynsym_resolve_code (CORE_ADDR pc
)
1027 #endif /* SVR4_SHARED_LIBS */
1033 disable_break -- remove the "mapping changed" breakpoint
1037 static int disable_break ()
1041 Removes the breakpoint that gets hit when the dynamic linker
1042 completes a mapping change.
1046 #ifndef SVR4_SHARED_LIBS
1049 disable_break (void)
1053 int in_debugger
= 0;
1055 /* Read the debugger structure from the inferior to retrieve the
1056 address of the breakpoint and the original contents of the
1057 breakpoint address. Remove the breakpoint by writing the original
1060 read_memory (debug_addr
, (char *) &debug_copy
, sizeof (debug_copy
));
1062 /* Set `in_debugger' to zero now. */
1064 write_memory (flag_addr
, (char *) &in_debugger
, sizeof (in_debugger
));
1066 breakpoint_addr
= SOLIB_EXTRACT_ADDRESS (debug_copy
.ldd_bp_addr
);
1067 write_memory (breakpoint_addr
, (char *) &debug_copy
.ldd_bp_inst
,
1068 sizeof (debug_copy
.ldd_bp_inst
));
1070 /* For the SVR4 version, we always know the breakpoint address. For the
1071 SunOS version we don't know it until the above code is executed.
1072 Grumble if we are stopped anywhere besides the breakpoint address. */
1074 if (stop_pc
!= breakpoint_addr
)
1076 warning ("stopped at unknown breakpoint while handling shared libraries");
1082 #endif /* #ifdef SVR4_SHARED_LIBS */
1088 enable_break -- arrange for dynamic linker to hit breakpoint
1092 int enable_break (void)
1096 Both the SunOS and the SVR4 dynamic linkers have, as part of their
1097 debugger interface, support for arranging for the inferior to hit
1098 a breakpoint after mapping in the shared libraries. This function
1099 enables that breakpoint.
1101 For SunOS, there is a special flag location (in_debugger) which we
1102 set to 1. When the dynamic linker sees this flag set, it will set
1103 a breakpoint at a location known only to itself, after saving the
1104 original contents of that place and the breakpoint address itself,
1105 in it's own internal structures. When we resume the inferior, it
1106 will eventually take a SIGTRAP when it runs into the breakpoint.
1107 We handle this (in a different place) by restoring the contents of
1108 the breakpointed location (which is only known after it stops),
1109 chasing around to locate the shared libraries that have been
1110 loaded, then resuming.
1112 For SVR4, the debugger interface structure contains a member (r_brk)
1113 which is statically initialized at the time the shared library is
1114 built, to the offset of a function (_r_debug_state) which is guaran-
1115 teed to be called once before mapping in a library, and again when
1116 the mapping is complete. At the time we are examining this member,
1117 it contains only the unrelocated offset of the function, so we have
1118 to do our own relocation. Later, when the dynamic linker actually
1119 runs, it relocates r_brk to be the actual address of _r_debug_state().
1121 The debugger interface structure also contains an enumeration which
1122 is set to either RT_ADD or RT_DELETE prior to changing the mapping,
1123 depending upon whether or not the library is being mapped or unmapped,
1124 and then set to RT_CONSISTENT after the library is mapped/unmapped.
1132 #ifndef SVR4_SHARED_LIBS
1137 /* Get link_dynamic structure */
1139 j
= target_read_memory (debug_base
, (char *) &dynamic_copy
,
1140 sizeof (dynamic_copy
));
1147 /* Calc address of debugger interface structure */
1149 debug_addr
= SOLIB_EXTRACT_ADDRESS (dynamic_copy
.ldd
);
1151 /* Calc address of `in_debugger' member of debugger interface structure */
1153 flag_addr
= debug_addr
+ (CORE_ADDR
) ((char *) &debug_copy
.ldd_in_debugger
-
1154 (char *) &debug_copy
);
1156 /* Write a value of 1 to this member. */
1159 write_memory (flag_addr
, (char *) &in_debugger
, sizeof (in_debugger
));
1162 #else /* SVR4_SHARED_LIBS */
1164 #ifdef BKPT_AT_SYMBOL
1166 struct minimal_symbol
*msymbol
;
1168 asection
*interp_sect
;
1170 /* First, remove all the solib event breakpoints. Their addresses
1171 may have changed since the last time we ran the program. */
1172 remove_solib_event_breakpoints ();
1174 #ifdef SVR4_SHARED_LIBS
1175 interp_text_sect_low
= interp_text_sect_high
= 0;
1176 interp_plt_sect_low
= interp_plt_sect_high
= 0;
1178 /* Find the .interp section; if not found, warn the user and drop
1179 into the old breakpoint at symbol code. */
1180 interp_sect
= bfd_get_section_by_name (exec_bfd
, ".interp");
1183 unsigned int interp_sect_size
;
1185 CORE_ADDR load_addr
= 0;
1186 int load_addr_found
= 0;
1187 struct so_list
*inferior_sos
;
1188 bfd
*tmp_bfd
= NULL
;
1190 char *tmp_pathname
= NULL
;
1191 CORE_ADDR sym_addr
= 0;
1193 /* Read the contents of the .interp section into a local buffer;
1194 the contents specify the dynamic linker this program uses. */
1195 interp_sect_size
= bfd_section_size (exec_bfd
, interp_sect
);
1196 buf
= alloca (interp_sect_size
);
1197 bfd_get_section_contents (exec_bfd
, interp_sect
,
1198 buf
, 0, interp_sect_size
);
1200 /* Now we need to figure out where the dynamic linker was
1201 loaded so that we can load its symbols and place a breakpoint
1202 in the dynamic linker itself.
1204 This address is stored on the stack. However, I've been unable
1205 to find any magic formula to find it for Solaris (appears to
1206 be trivial on GNU/Linux). Therefore, we have to try an alternate
1207 mechanism to find the dynamic linker's base address. */
1209 tmp_fd
= solib_open (buf
, &tmp_pathname
);
1211 tmp_bfd
= bfd_fdopenr (tmp_pathname
, gnutarget
, tmp_fd
);
1213 if (tmp_bfd
== NULL
)
1214 goto bkpt_at_symbol
;
1216 /* Make sure the dynamic linker's really a useful object. */
1217 if (!bfd_check_format (tmp_bfd
, bfd_object
))
1219 warning ("Unable to grok dynamic linker %s as an object file", buf
);
1220 bfd_close (tmp_bfd
);
1221 goto bkpt_at_symbol
;
1224 /* If the entry in _DYNAMIC for the dynamic linker has already
1225 been filled in, we can read its base address from there. */
1226 inferior_sos
= svr4_current_sos ();
1229 /* Connected to a running target. Update our shared library table. */
1230 solib_add (NULL
, 0, NULL
);
1232 while (inferior_sos
)
1234 if (strcmp (buf
, inferior_sos
->so_original_name
) == 0)
1236 load_addr_found
= 1;
1237 load_addr
= LM_ADDR (inferior_sos
);
1240 inferior_sos
= inferior_sos
->next
;
1243 /* Otherwise we find the dynamic linker's base address by examining
1244 the current pc (which should point at the entry point for the
1245 dynamic linker) and subtracting the offset of the entry point. */
1246 if (!load_addr_found
)
1247 load_addr
= read_pc () - tmp_bfd
->start_address
;
1249 /* Record the relocated start and end address of the dynamic linker
1250 text and plt section for svr4_in_dynsym_resolve_code. */
1251 interp_sect
= bfd_get_section_by_name (tmp_bfd
, ".text");
1254 interp_text_sect_low
=
1255 bfd_section_vma (tmp_bfd
, interp_sect
) + load_addr
;
1256 interp_text_sect_high
=
1257 interp_text_sect_low
+ bfd_section_size (tmp_bfd
, interp_sect
);
1259 interp_sect
= bfd_get_section_by_name (tmp_bfd
, ".plt");
1262 interp_plt_sect_low
=
1263 bfd_section_vma (tmp_bfd
, interp_sect
) + load_addr
;
1264 interp_plt_sect_high
=
1265 interp_plt_sect_low
+ bfd_section_size (tmp_bfd
, interp_sect
);
1268 /* Now try to set a breakpoint in the dynamic linker. */
1269 for (bkpt_namep
= solib_break_names
; *bkpt_namep
!= NULL
; bkpt_namep
++)
1271 sym_addr
= bfd_lookup_symbol (tmp_bfd
, *bkpt_namep
);
1276 /* We're done with the temporary bfd. */
1277 bfd_close (tmp_bfd
);
1281 create_solib_event_breakpoint (load_addr
+ sym_addr
);
1285 /* For whatever reason we couldn't set a breakpoint in the dynamic
1286 linker. Warn and drop into the old code. */
1288 warning ("Unable to find dynamic linker breakpoint function.\nGDB will be unable to debug shared library initializers\nand track explicitly loaded dynamic code.");
1292 /* Scan through the list of symbols, trying to look up the symbol and
1293 set a breakpoint there. Terminate loop when we/if we succeed. */
1295 breakpoint_addr
= 0;
1296 for (bkpt_namep
= bkpt_names
; *bkpt_namep
!= NULL
; bkpt_namep
++)
1298 msymbol
= lookup_minimal_symbol (*bkpt_namep
, NULL
, symfile_objfile
);
1299 if ((msymbol
!= NULL
) && (SYMBOL_VALUE_ADDRESS (msymbol
) != 0))
1301 create_solib_event_breakpoint (SYMBOL_VALUE_ADDRESS (msymbol
));
1306 /* Nothing good happened. */
1309 #endif /* BKPT_AT_SYMBOL */
1311 #endif /* !SVR4_SHARED_LIBS */
1320 special_symbol_handling -- additional shared library symbol handling
1324 void special_symbol_handling ()
1328 Once the symbols from a shared object have been loaded in the usual
1329 way, we are called to do any system specific symbol handling that
1332 For SunOS4, this consists of grunging around in the dynamic
1333 linkers structures to find symbol definitions for "common" symbols
1334 and adding them to the minimal symbol table for the runtime common
1340 svr4_special_symbol_handling (void)
1342 #ifndef SVR4_SHARED_LIBS
1345 if (debug_addr
== 0)
1347 /* Get link_dynamic structure */
1349 j
= target_read_memory (debug_base
, (char *) &dynamic_copy
,
1350 sizeof (dynamic_copy
));
1357 /* Calc address of debugger interface structure */
1358 /* FIXME, this needs work for cross-debugging of core files
1359 (byteorder, size, alignment, etc). */
1361 debug_addr
= SOLIB_EXTRACT_ADDRESS (dynamic_copy
.ldd
);
1364 /* Read the debugger structure from the inferior, just to make sure
1365 we have a current copy. */
1367 j
= target_read_memory (debug_addr
, (char *) &debug_copy
,
1368 sizeof (debug_copy
));
1370 return; /* unreadable */
1372 /* Get common symbol definitions for the loaded object. */
1374 if (debug_copy
.ldd_cp
)
1376 solib_add_common_symbols (SOLIB_EXTRACT_ADDRESS (debug_copy
.ldd_cp
));
1379 #endif /* !SVR4_SHARED_LIBS */
1382 /* Relocate the main executable. This function should be called upon
1383 stopping the inferior process at the entry point to the program.
1384 The entry point from BFD is compared to the PC and if they are
1385 different, the main executable is relocated by the proper amount.
1387 As written it will only attempt to relocate executables which
1388 lack interpreter sections. It seems likely that only dynamic
1389 linker executables will get relocated, though it should work
1390 properly for a position-independent static executable as well. */
1393 svr4_relocate_main_executable (void)
1395 asection
*interp_sect
;
1396 CORE_ADDR pc
= read_pc ();
1398 /* Decide if the objfile needs to be relocated. As indicated above,
1399 we will only be here when execution is stopped at the beginning
1400 of the program. Relocation is necessary if the address at which
1401 we are presently stopped differs from the start address stored in
1402 the executable AND there's no interpreter section. The condition
1403 regarding the interpreter section is very important because if
1404 there *is* an interpreter section, execution will begin there
1405 instead. When there is an interpreter section, the start address
1406 is (presumably) used by the interpreter at some point to start
1407 execution of the program.
1409 If there is an interpreter, it is normal for it to be set to an
1410 arbitrary address at the outset. The job of finding it is
1411 handled in enable_break().
1413 So, to summarize, relocations are necessary when there is no
1414 interpreter section and the start address obtained from the
1415 executable is different from the address at which GDB is
1418 [ The astute reader will note that we also test to make sure that
1419 the executable in question has the DYNAMIC flag set. It is my
1420 opinion that this test is unnecessary (undesirable even). It
1421 was added to avoid inadvertent relocation of an executable
1422 whose e_type member in the ELF header is not ET_DYN. There may
1423 be a time in the future when it is desirable to do relocations
1424 on other types of files as well in which case this condition
1425 should either be removed or modified to accomodate the new file
1426 type. (E.g, an ET_EXEC executable which has been built to be
1427 position-independent could safely be relocated by the OS if
1428 desired. It is true that this violates the ABI, but the ABI
1429 has been known to be bent from time to time.) - Kevin, Nov 2000. ]
1432 interp_sect
= bfd_get_section_by_name (exec_bfd
, ".interp");
1433 if (interp_sect
== NULL
1434 && (bfd_get_file_flags (exec_bfd
) & DYNAMIC
) != 0
1435 && bfd_get_start_address (exec_bfd
) != pc
)
1437 struct cleanup
*old_chain
;
1438 struct section_offsets
*new_offsets
;
1440 CORE_ADDR displacement
;
1442 /* It is necessary to relocate the objfile. The amount to
1443 relocate by is simply the address at which we are stopped
1444 minus the starting address from the executable.
1446 We relocate all of the sections by the same amount. This
1447 behavior is mandated by recent editions of the System V ABI.
1448 According to the System V Application Binary Interface,
1449 Edition 4.1, page 5-5:
1451 ... Though the system chooses virtual addresses for
1452 individual processes, it maintains the segments' relative
1453 positions. Because position-independent code uses relative
1454 addressesing between segments, the difference between
1455 virtual addresses in memory must match the difference
1456 between virtual addresses in the file. The difference
1457 between the virtual address of any segment in memory and
1458 the corresponding virtual address in the file is thus a
1459 single constant value for any one executable or shared
1460 object in a given process. This difference is the base
1461 address. One use of the base address is to relocate the
1462 memory image of the program during dynamic linking.
1464 The same language also appears in Edition 4.0 of the System V
1465 ABI and is left unspecified in some of the earlier editions. */
1467 displacement
= pc
- bfd_get_start_address (exec_bfd
);
1470 new_offsets
= xcalloc (sizeof (struct section_offsets
),
1471 symfile_objfile
->num_sections
);
1472 old_chain
= make_cleanup (xfree
, new_offsets
);
1474 for (i
= 0; i
< symfile_objfile
->num_sections
; i
++)
1476 if (displacement
!= ANOFFSET (symfile_objfile
->section_offsets
, i
))
1478 new_offsets
->offsets
[i
] = displacement
;
1482 objfile_relocate (symfile_objfile
, new_offsets
);
1484 do_cleanups (old_chain
);
1492 svr4_solib_create_inferior_hook -- shared library startup support
1496 void svr4_solib_create_inferior_hook()
1500 When gdb starts up the inferior, it nurses it along (through the
1501 shell) until it is ready to execute it's first instruction. At this
1502 point, this function gets called via expansion of the macro
1503 SOLIB_CREATE_INFERIOR_HOOK.
1505 For SunOS executables, this first instruction is typically the
1506 one at "_start", or a similar text label, regardless of whether
1507 the executable is statically or dynamically linked. The runtime
1508 startup code takes care of dynamically linking in any shared
1509 libraries, once gdb allows the inferior to continue.
1511 For SVR4 executables, this first instruction is either the first
1512 instruction in the dynamic linker (for dynamically linked
1513 executables) or the instruction at "start" for statically linked
1514 executables. For dynamically linked executables, the system
1515 first exec's /lib/libc.so.N, which contains the dynamic linker,
1516 and starts it running. The dynamic linker maps in any needed
1517 shared libraries, maps in the actual user executable, and then
1518 jumps to "start" in the user executable.
1520 For both SunOS shared libraries, and SVR4 shared libraries, we
1521 can arrange to cooperate with the dynamic linker to discover the
1522 names of shared libraries that are dynamically linked, and the
1523 base addresses to which they are linked.
1525 This function is responsible for discovering those names and
1526 addresses, and saving sufficient information about them to allow
1527 their symbols to be read at a later time.
1531 Between enable_break() and disable_break(), this code does not
1532 properly handle hitting breakpoints which the user might have
1533 set in the startup code or in the dynamic linker itself. Proper
1534 handling will probably have to wait until the implementation is
1535 changed to use the "breakpoint handler function" method.
1537 Also, what if child has exit()ed? Must exit loop somehow.
1541 svr4_solib_create_inferior_hook (void)
1543 /* Relocate the main executable if necessary. */
1544 svr4_relocate_main_executable ();
1546 /* If we are using the BKPT_AT_SYMBOL code, then we don't need the base
1547 yet. In fact, in the case of a SunOS4 executable being run on
1548 Solaris, we can't get it yet. current_sos will get it when it needs
1550 #if !(defined (SVR4_SHARED_LIBS) && defined (BKPT_AT_SYMBOL))
1551 if ((debug_base
= locate_base ()) == 0)
1553 /* Can't find the symbol or the executable is statically linked. */
1558 if (!enable_break ())
1560 warning ("shared library handler failed to enable breakpoint");
1564 #if !defined(SVR4_SHARED_LIBS) || defined(_SCO_DS)
1565 /* SCO and SunOS need the loop below, other systems should be using the
1566 special shared library breakpoints and the shared library breakpoint
1569 Now run the target. It will eventually hit the breakpoint, at
1570 which point all of the libraries will have been mapped in and we
1571 can go groveling around in the dynamic linker structures to find
1572 out what we need to know about them. */
1574 clear_proceed_status ();
1575 stop_soon_quietly
= 1;
1576 stop_signal
= TARGET_SIGNAL_0
;
1579 target_resume (pid_to_ptid (-1), 0, stop_signal
);
1580 wait_for_inferior ();
1582 while (stop_signal
!= TARGET_SIGNAL_TRAP
);
1583 stop_soon_quietly
= 0;
1585 #if !defined(_SCO_DS)
1586 /* We are now either at the "mapping complete" breakpoint (or somewhere
1587 else, a condition we aren't prepared to deal with anyway), so adjust
1588 the PC as necessary after a breakpoint, disable the breakpoint, and
1589 add any shared libraries that were mapped in. */
1591 if (DECR_PC_AFTER_BREAK
)
1593 stop_pc
-= DECR_PC_AFTER_BREAK
;
1594 write_register (PC_REGNUM
, stop_pc
);
1597 if (!disable_break ())
1599 warning ("shared library handler failed to disable breakpoint");
1603 solib_add ((char *) 0, 0, (struct target_ops
*) 0);
1604 #endif /* ! _SCO_DS */
1609 svr4_clear_solib (void)
1615 svr4_free_so (struct so_list
*so
)
1617 xfree (so
->lm_info
->lm
);
1618 xfree (so
->lm_info
);
1622 svr4_relocate_section_addresses (struct so_list
*so
,
1623 struct section_table
*sec
)
1625 sec
->addr
+= LM_ADDR (so
);
1626 sec
->endaddr
+= LM_ADDR (so
);
1629 /* Fetch a link_map_offsets structure for native targets using struct
1630 definitions from link.h. See solib-legacy.c for the function
1631 which does the actual work.
1633 Note: For non-native targets (i.e. cross-debugging situations),
1634 a target specific fetch_link_map_offsets() function should be
1635 defined and registered via set_solib_svr4_fetch_link_map_offsets(). */
1637 static struct link_map_offsets
*
1638 legacy_fetch_link_map_offsets (void)
1640 if (legacy_svr4_fetch_link_map_offsets_hook
)
1641 return legacy_svr4_fetch_link_map_offsets_hook ();
1644 internal_error (__FILE__
, __LINE__
,
1645 "legacy_fetch_link_map_offsets called without legacy "
1646 "link_map support enabled.");
1651 /* Fetch a link_map_offsets structure using the method registered in the
1652 architecture vector. */
1654 static struct link_map_offsets
*
1655 svr4_fetch_link_map_offsets (void)
1657 struct link_map_offsets
*(*flmo
)(void) =
1658 gdbarch_data (fetch_link_map_offsets_gdbarch_data
);
1662 internal_error (__FILE__
, __LINE__
,
1663 "svr4_fetch_link_map_offsets: fetch_link_map_offsets "
1664 "method not defined for this architecture.");
1671 /* set_solib_svr4_fetch_link_map_offsets() is intended to be called by
1672 a <arch>_gdbarch_init() function. It is used to establish an
1673 architecture specific link_map_offsets fetcher for the architecture
1677 set_solib_svr4_fetch_link_map_offsets (struct gdbarch
*gdbarch
,
1678 struct link_map_offsets
*(*flmo
) (void))
1680 set_gdbarch_data (gdbarch
, fetch_link_map_offsets_gdbarch_data
, flmo
);
1683 /* Initialize the architecture specific link_map_offsets fetcher.
1684 This is called after <arch>_gdbarch_init() has set up its struct
1685 gdbarch for the new architecture, so care must be taken to use the
1686 value set by set_solib_svr4_fetch_link_map_offsets(), above. We
1687 do, however, attempt to provide a reasonable alternative (for
1688 native targets anyway) if the <arch>_gdbarch_init() fails to call
1689 set_solib_svr4_fetch_link_map_offsets(). */
1692 init_fetch_link_map_offsets (struct gdbarch
*gdbarch
)
1694 struct link_map_offsets
*(*flmo
) =
1695 gdbarch_data (fetch_link_map_offsets_gdbarch_data
);
1698 return legacy_fetch_link_map_offsets
;
1703 static struct target_so_ops svr4_so_ops
;
1706 _initialize_svr4_solib (void)
1708 fetch_link_map_offsets_gdbarch_data
=
1709 register_gdbarch_data (init_fetch_link_map_offsets
, 0);
1711 svr4_so_ops
.relocate_section_addresses
= svr4_relocate_section_addresses
;
1712 svr4_so_ops
.free_so
= svr4_free_so
;
1713 svr4_so_ops
.clear_solib
= svr4_clear_solib
;
1714 svr4_so_ops
.solib_create_inferior_hook
= svr4_solib_create_inferior_hook
;
1715 svr4_so_ops
.special_symbol_handling
= svr4_special_symbol_handling
;
1716 svr4_so_ops
.current_sos
= svr4_current_sos
;
1717 svr4_so_ops
.open_symbol_file_object
= open_symbol_file_object
;
1718 svr4_so_ops
.in_dynsym_resolve_code
= svr4_in_dynsym_resolve_code
;
1720 /* FIXME: Don't do this here. *_gdbarch_init() should set so_ops. */
1721 current_target_so_ops
= &svr4_so_ops
;