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() fetch_link_map_offsets ()
64 static struct link_map_offsets
*default_svr4_fetch_link_map_offsets (void);
66 /* fetch_link_map_offsets is the pointer to the architecture specific
67 link map offsets fetching function. It uses the gdbarch_swap
68 mechanism to change its value when the architecture changes. */
69 static struct link_map_offsets
*(*fetch_link_map_offsets
)(void) =
70 default_svr4_fetch_link_map_offsets
;
72 /* fetch_link_map_offsets_init is like the above, but obtains its
73 value from a call to set_solib_svr4_fetch_link_map_offsets().
74 This latter function is intended to be called from a *_gdbarch_init()
75 function. The value of ``fetch_link_map_offsets_init'' is used
76 to actually set ``fetch_link_map_offsets'' when the architecture
78 static struct link_map_offsets
*(*fetch_link_map_offsets_init
)(void) = 0;
80 /* legacy_svr4_fetch_link_map_offsets_hook is a pointer to a function
81 which is used to fetch link map offsets. It will only be set
82 by solib-legacy.c, if at all. */
83 struct link_map_offsets
*(*legacy_svr4_fetch_link_map_offsets_hook
)(void) = 0;
85 /* Link map info to include in an allocated so_list entry */
89 /* Pointer to copy of link map from inferior. The type is char *
90 rather than void *, so that we may use byte offsets to find the
91 various fields without the need for a cast. */
95 /* On SVR4 systems, a list of symbols in the dynamic linker where
96 GDB can try to place a breakpoint to monitor shared library
99 If none of these symbols are found, or other errors occur, then
100 SVR4 systems will fall back to using a symbol as the "startup
101 mapping complete" breakpoint address. */
103 #ifdef SVR4_SHARED_LIBS
104 static char *solib_break_names
[] =
109 "rtld_db_dlactivity",
115 #define BKPT_AT_SYMBOL 1
117 #if defined (BKPT_AT_SYMBOL) && defined (SVR4_SHARED_LIBS)
118 static char *bkpt_names
[] =
120 #ifdef SOLIB_BKPT_NAME
121 SOLIB_BKPT_NAME
, /* Prefer configured name if it exists. */
129 /* Symbols which are used to locate the base of the link map structures. */
131 #ifndef SVR4_SHARED_LIBS
132 static char *debug_base_symbols
[] =
140 static char *main_name_list
[] =
147 /* Fetch (and possibly build) an appropriate link_map_offsets structure
148 for native targets using struct definitions from link.h.
150 Note: For non-native targets (i.e. cross-debugging situations),
151 you need to define a target specific fetch_link_map_offsets()
152 function and call set_solib_svr4_fetch_link_map_offsets () to
153 register this function. */
155 static struct link_map_offsets
*
156 default_svr4_fetch_link_map_offsets (void)
158 if (legacy_svr4_fetch_link_map_offsets_hook
)
159 return legacy_svr4_fetch_link_map_offsets_hook ();
162 internal_error (__FILE__
, __LINE__
,
163 "default_svr4_fetch_link_map_offsets called without legacy link_map support enabled.");
168 /* Macro to extract an address from a solib structure.
169 When GDB is configured for some 32-bit targets (e.g. Solaris 2.7
170 sparc), BFD is configured to handle 64-bit targets, so CORE_ADDR is
171 64 bits. We have to extract only the significant bits of addresses
172 to get the right address when accessing the core file BFD. */
174 #define SOLIB_EXTRACT_ADDRESS(MEMBER) \
175 extract_address (&(MEMBER), sizeof (MEMBER))
177 /* local data declarations */
179 #ifndef SVR4_SHARED_LIBS
181 /* NOTE: converted the macros LM_ADDR, LM_NEXT, LM_NAME and
182 IGNORE_FIRST_LINK_MAP_ENTRY into functions (see below).
185 static struct link_dynamic dynamic_copy
;
186 static struct link_dynamic_2 ld_2_copy
;
187 static struct ld_debug debug_copy
;
188 static CORE_ADDR debug_addr
;
189 static CORE_ADDR flag_addr
;
191 #endif /* !SVR4_SHARED_LIBS */
193 /* link map access functions */
196 LM_ADDR (struct so_list
*so
)
198 struct link_map_offsets
*lmo
= SVR4_FETCH_LINK_MAP_OFFSETS ();
200 return (CORE_ADDR
) extract_signed_integer (so
->lm_info
->lm
+ lmo
->l_addr_offset
,
205 LM_NEXT (struct so_list
*so
)
207 struct link_map_offsets
*lmo
= SVR4_FETCH_LINK_MAP_OFFSETS ();
209 return extract_address (so
->lm_info
->lm
+ lmo
->l_next_offset
, lmo
->l_next_size
);
213 LM_NAME (struct so_list
*so
)
215 struct link_map_offsets
*lmo
= SVR4_FETCH_LINK_MAP_OFFSETS ();
217 return extract_address (so
->lm_info
->lm
+ lmo
->l_name_offset
, lmo
->l_name_size
);
220 #ifndef SVR4_SHARED_LIBS
223 IGNORE_FIRST_LINK_MAP_ENTRY (struct so_list
*so
)
228 #else /* SVR4_SHARED_LIBS */
231 IGNORE_FIRST_LINK_MAP_ENTRY (struct so_list
*so
)
233 struct link_map_offsets
*lmo
= SVR4_FETCH_LINK_MAP_OFFSETS ();
235 return extract_address (so
->lm_info
->lm
+ lmo
->l_prev_offset
,
236 lmo
->l_prev_size
) == 0;
239 #endif /* !SVR4_SHARED_LIBS */
241 static CORE_ADDR debug_base
; /* Base of dynamic linker structures */
242 static CORE_ADDR breakpoint_addr
; /* Address where end bkpt is set */
244 /* Local function prototypes */
246 static int match_main (char *);
248 #ifndef SVR4_SHARED_LIBS
250 /* Allocate the runtime common object file. */
253 allocate_rt_common_objfile (void)
255 struct objfile
*objfile
;
256 struct objfile
*last_one
;
258 objfile
= (struct objfile
*) xmalloc (sizeof (struct objfile
));
259 memset (objfile
, 0, sizeof (struct objfile
));
261 obstack_specify_allocation (&objfile
->psymbol_cache
.cache
, 0, 0,
263 obstack_specify_allocation (&objfile
->psymbol_obstack
, 0, 0, xmalloc
,
265 obstack_specify_allocation (&objfile
->symbol_obstack
, 0, 0, xmalloc
,
267 obstack_specify_allocation (&objfile
->type_obstack
, 0, 0, xmalloc
,
269 objfile
->name
= mstrsave (objfile
->md
, "rt_common");
271 /* Add this file onto the tail of the linked list of other such files. */
273 objfile
->next
= NULL
;
274 if (object_files
== NULL
)
275 object_files
= objfile
;
278 for (last_one
= object_files
;
280 last_one
= last_one
->next
);
281 last_one
->next
= objfile
;
284 rt_common_objfile
= objfile
;
287 /* Read all dynamically loaded common symbol definitions from the inferior
288 and put them into the minimal symbol table for the runtime common
292 solib_add_common_symbols (CORE_ADDR rtc_symp
)
294 struct rtc_symb inferior_rtc_symb
;
295 struct nlist inferior_rtc_nlist
;
299 /* Remove any runtime common symbols from previous runs. */
301 if (rt_common_objfile
!= NULL
&& rt_common_objfile
->minimal_symbol_count
)
303 obstack_free (&rt_common_objfile
->symbol_obstack
, 0);
304 obstack_specify_allocation (&rt_common_objfile
->symbol_obstack
, 0, 0,
306 rt_common_objfile
->minimal_symbol_count
= 0;
307 rt_common_objfile
->msymbols
= NULL
;
310 init_minimal_symbol_collection ();
311 make_cleanup_discard_minimal_symbols ();
315 read_memory (rtc_symp
,
316 (char *) &inferior_rtc_symb
,
317 sizeof (inferior_rtc_symb
));
318 read_memory (SOLIB_EXTRACT_ADDRESS (inferior_rtc_symb
.rtc_sp
),
319 (char *) &inferior_rtc_nlist
,
320 sizeof (inferior_rtc_nlist
));
321 if (inferior_rtc_nlist
.n_type
== N_COMM
)
323 /* FIXME: The length of the symbol name is not available, but in the
324 current implementation the common symbol is allocated immediately
325 behind the name of the symbol. */
326 len
= inferior_rtc_nlist
.n_value
- inferior_rtc_nlist
.n_un
.n_strx
;
328 name
= xmalloc (len
);
329 read_memory (SOLIB_EXTRACT_ADDRESS (inferior_rtc_nlist
.n_un
.n_name
),
332 /* Allocate the runtime common objfile if necessary. */
333 if (rt_common_objfile
== NULL
)
334 allocate_rt_common_objfile ();
336 prim_record_minimal_symbol (name
, inferior_rtc_nlist
.n_value
,
337 mst_bss
, rt_common_objfile
);
340 rtc_symp
= SOLIB_EXTRACT_ADDRESS (inferior_rtc_symb
.rtc_next
);
343 /* Install any minimal symbols that have been collected as the current
344 minimal symbols for the runtime common objfile. */
346 install_minimal_symbols (rt_common_objfile
);
349 #endif /* SVR4_SHARED_LIBS */
352 #ifdef SVR4_SHARED_LIBS
354 static CORE_ADDR
bfd_lookup_symbol (bfd
*, char *);
360 bfd_lookup_symbol -- lookup the value for a specific symbol
364 CORE_ADDR bfd_lookup_symbol (bfd *abfd, char *symname)
368 An expensive way to lookup the value of a single symbol for
369 bfd's that are only temporary anyway. This is used by the
370 shared library support to find the address of the debugger
371 interface structures in the shared library.
373 Note that 0 is specifically allowed as an error return (no
378 bfd_lookup_symbol (bfd
*abfd
, char *symname
)
382 asymbol
**symbol_table
;
383 unsigned int number_of_symbols
;
385 struct cleanup
*back_to
;
386 CORE_ADDR symaddr
= 0;
388 storage_needed
= bfd_get_symtab_upper_bound (abfd
);
390 if (storage_needed
> 0)
392 symbol_table
= (asymbol
**) xmalloc (storage_needed
);
393 back_to
= make_cleanup (xfree
, (PTR
) symbol_table
);
394 number_of_symbols
= bfd_canonicalize_symtab (abfd
, symbol_table
);
396 for (i
= 0; i
< number_of_symbols
; i
++)
398 sym
= *symbol_table
++;
399 if (STREQ (sym
->name
, symname
))
401 /* Bfd symbols are section relative. */
402 symaddr
= sym
->value
+ sym
->section
->vma
;
406 do_cleanups (back_to
);
412 /* On FreeBSD, the dynamic linker is stripped by default. So we'll
413 have to check the dynamic string table too. */
415 storage_needed
= bfd_get_dynamic_symtab_upper_bound (abfd
);
417 if (storage_needed
> 0)
419 symbol_table
= (asymbol
**) xmalloc (storage_needed
);
420 back_to
= make_cleanup (xfree
, (PTR
) symbol_table
);
421 number_of_symbols
= bfd_canonicalize_dynamic_symtab (abfd
, symbol_table
);
423 for (i
= 0; i
< number_of_symbols
; i
++)
425 sym
= *symbol_table
++;
426 if (STREQ (sym
->name
, symname
))
428 /* Bfd symbols are section relative. */
429 symaddr
= sym
->value
+ sym
->section
->vma
;
433 do_cleanups (back_to
);
439 #ifdef HANDLE_SVR4_EXEC_EMULATORS
442 Solaris BCP (the part of Solaris which allows it to run SunOS4
443 a.out files) throws in another wrinkle. Solaris does not fill
444 in the usual a.out link map structures when running BCP programs,
445 the only way to get at them is via groping around in the dynamic
447 The dynamic linker and it's structures are located in the shared
448 C library, which gets run as the executable's "interpreter" by
451 Note that we can assume nothing about the process state at the time
452 we need to find these structures. We may be stopped on the first
453 instruction of the interpreter (C shared library), the first
454 instruction of the executable itself, or somewhere else entirely
455 (if we attached to the process for example).
458 static char *debug_base_symbols
[] =
460 "r_debug", /* Solaris 2.3 */
461 "_r_debug", /* Solaris 2.1, 2.2 */
465 static int look_for_base (int, CORE_ADDR
);
471 look_for_base -- examine file for each mapped address segment
475 static int look_for_base (int fd, CORE_ADDR baseaddr)
479 This function is passed to proc_iterate_over_mappings, which
480 causes it to get called once for each mapped address space, with
481 an open file descriptor for the file mapped to that space, and the
482 base address of that mapped space.
484 Our job is to find the debug base symbol in the file that this
485 fd is open on, if it exists, and if so, initialize the dynamic
486 linker structure base address debug_base.
488 Note that this is a computationally expensive proposition, since
489 we basically have to open a bfd on every call, so we specifically
490 avoid opening the exec file.
494 look_for_base (int fd
, CORE_ADDR baseaddr
)
497 CORE_ADDR address
= 0;
500 /* If the fd is -1, then there is no file that corresponds to this
501 mapped memory segment, so skip it. Also, if the fd corresponds
502 to the exec file, skip it as well. */
506 && fdmatch (fileno ((FILE *) (exec_bfd
->iostream
)), fd
)))
511 /* Try to open whatever random file this fd corresponds to. Note that
512 we have no way currently to find the filename. Don't gripe about
513 any problems we might have, just fail. */
515 if ((interp_bfd
= bfd_fdopenr ("unnamed", gnutarget
, fd
)) == NULL
)
519 if (!bfd_check_format (interp_bfd
, bfd_object
))
521 /* FIXME-leak: on failure, might not free all memory associated with
523 bfd_close (interp_bfd
);
527 /* Now try to find our debug base symbol in this file, which we at
528 least know to be a valid ELF executable or shared library. */
530 for (symbolp
= debug_base_symbols
; *symbolp
!= NULL
; symbolp
++)
532 address
= bfd_lookup_symbol (interp_bfd
, *symbolp
);
540 /* FIXME-leak: on failure, might not free all memory associated with
542 bfd_close (interp_bfd
);
546 /* Eureka! We found the symbol. But now we may need to relocate it
547 by the base address. If the symbol's value is less than the base
548 address of the shared library, then it hasn't yet been relocated
549 by the dynamic linker, and we have to do it ourself. FIXME: Note
550 that we make the assumption that the first segment that corresponds
551 to the shared library has the base address to which the library
554 if (address
< baseaddr
)
558 debug_base
= address
;
559 /* FIXME-leak: on failure, might not free all memory associated with
561 bfd_close (interp_bfd
);
564 #endif /* HANDLE_SVR4_EXEC_EMULATORS */
570 elf_locate_base -- locate the base address of dynamic linker structs
571 for SVR4 elf targets.
575 CORE_ADDR elf_locate_base (void)
579 For SVR4 elf targets the address of the dynamic linker's runtime
580 structure is contained within the dynamic info section in the
581 executable file. The dynamic section is also mapped into the
582 inferior address space. Because the runtime loader fills in the
583 real address before starting the inferior, we have to read in the
584 dynamic info section from the inferior address space.
585 If there are any errors while trying to find the address, we
586 silently return 0, otherwise the found address is returned.
591 elf_locate_base (void)
593 sec_ptr dyninfo_sect
;
594 int dyninfo_sect_size
;
595 CORE_ADDR dyninfo_addr
;
600 /* Find the start address of the .dynamic section. */
601 dyninfo_sect
= bfd_get_section_by_name (exec_bfd
, ".dynamic");
602 if (dyninfo_sect
== NULL
)
604 dyninfo_addr
= bfd_section_vma (exec_bfd
, dyninfo_sect
);
606 /* Read in .dynamic section, silently ignore errors. */
607 dyninfo_sect_size
= bfd_section_size (exec_bfd
, dyninfo_sect
);
608 buf
= alloca (dyninfo_sect_size
);
609 if (target_read_memory (dyninfo_addr
, buf
, dyninfo_sect_size
))
612 /* Find the DT_DEBUG entry in the the .dynamic section.
613 For mips elf we look for DT_MIPS_RLD_MAP, mips elf apparently has
614 no DT_DEBUG entries. */
616 arch_size
= bfd_get_arch_size (exec_bfd
);
617 if (arch_size
== -1) /* failure */
622 for (bufend
= buf
+ dyninfo_sect_size
;
624 buf
+= sizeof (Elf32_External_Dyn
))
626 Elf32_External_Dyn
*x_dynp
= (Elf32_External_Dyn
*) buf
;
630 dyn_tag
= bfd_h_get_32 (exec_bfd
, (bfd_byte
*) x_dynp
->d_tag
);
631 if (dyn_tag
== DT_NULL
)
633 else if (dyn_tag
== DT_DEBUG
)
635 dyn_ptr
= bfd_h_get_32 (exec_bfd
,
636 (bfd_byte
*) x_dynp
->d_un
.d_ptr
);
639 else if (dyn_tag
== DT_MIPS_RLD_MAP
)
643 pbuf
= alloca (TARGET_PTR_BIT
/ HOST_CHAR_BIT
);
644 /* DT_MIPS_RLD_MAP contains a pointer to the address
645 of the dynamic link structure. */
646 dyn_ptr
= bfd_h_get_32 (exec_bfd
,
647 (bfd_byte
*) x_dynp
->d_un
.d_ptr
);
648 if (target_read_memory (dyn_ptr
, pbuf
, sizeof (pbuf
)))
650 return extract_unsigned_integer (pbuf
, sizeof (pbuf
));
654 else /* 64-bit elf */
656 for (bufend
= buf
+ dyninfo_sect_size
;
658 buf
+= sizeof (Elf64_External_Dyn
))
660 Elf64_External_Dyn
*x_dynp
= (Elf64_External_Dyn
*) buf
;
664 dyn_tag
= bfd_h_get_64 (exec_bfd
, (bfd_byte
*) x_dynp
->d_tag
);
665 if (dyn_tag
== DT_NULL
)
667 else if (dyn_tag
== DT_DEBUG
)
669 dyn_ptr
= bfd_h_get_64 (exec_bfd
,
670 (bfd_byte
*) x_dynp
->d_un
.d_ptr
);
676 /* DT_DEBUG entry not found. */
680 #endif /* SVR4_SHARED_LIBS */
686 locate_base -- locate the base address of dynamic linker structs
690 CORE_ADDR locate_base (void)
694 For both the SunOS and SVR4 shared library implementations, if the
695 inferior executable has been linked dynamically, there is a single
696 address somewhere in the inferior's data space which is the key to
697 locating all of the dynamic linker's runtime structures. This
698 address is the value of the debug base symbol. The job of this
699 function is to find and return that address, or to return 0 if there
700 is no such address (the executable is statically linked for example).
702 For SunOS, the job is almost trivial, since the dynamic linker and
703 all of it's structures are statically linked to the executable at
704 link time. Thus the symbol for the address we are looking for has
705 already been added to the minimal symbol table for the executable's
706 objfile at the time the symbol file's symbols were read, and all we
707 have to do is look it up there. Note that we explicitly do NOT want
708 to find the copies in the shared library.
710 The SVR4 version is a bit more complicated because the address
711 is contained somewhere in the dynamic info section. We have to go
712 to a lot more work to discover the address of the debug base symbol.
713 Because of this complexity, we cache the value we find and return that
714 value on subsequent invocations. Note there is no copy in the
715 executable symbol tables.
723 #ifndef SVR4_SHARED_LIBS
725 struct minimal_symbol
*msymbol
;
726 CORE_ADDR address
= 0;
729 /* For SunOS, we want to limit the search for the debug base symbol to the
730 executable being debugged, since there is a duplicate named symbol in the
731 shared library. We don't want the shared library versions. */
733 for (symbolp
= debug_base_symbols
; *symbolp
!= NULL
; symbolp
++)
735 msymbol
= lookup_minimal_symbol (*symbolp
, NULL
, symfile_objfile
);
736 if ((msymbol
!= NULL
) && (SYMBOL_VALUE_ADDRESS (msymbol
) != 0))
738 address
= SYMBOL_VALUE_ADDRESS (msymbol
);
744 #else /* SVR4_SHARED_LIBS */
746 /* Check to see if we have a currently valid address, and if so, avoid
747 doing all this work again and just return the cached address. If
748 we have no cached address, try to locate it in the dynamic info
749 section for ELF executables. */
754 && bfd_get_flavour (exec_bfd
) == bfd_target_elf_flavour
)
755 debug_base
= elf_locate_base ();
756 #ifdef HANDLE_SVR4_EXEC_EMULATORS
757 /* Try it the hard way for emulated executables. */
758 else if (!ptid_equal (inferior_ptid
, null_ptid
) && target_has_execution
)
759 proc_iterate_over_mappings (look_for_base
);
764 #endif /* !SVR4_SHARED_LIBS */
772 first_link_map_member -- locate first member in dynamic linker's map
776 static CORE_ADDR first_link_map_member (void)
780 Find the first element in the inferior's dynamic link map, and
781 return its address in the inferior. This function doesn't copy the
782 link map entry itself into our address space; current_sos actually
786 first_link_map_member (void)
790 #ifndef SVR4_SHARED_LIBS
792 read_memory (debug_base
, (char *) &dynamic_copy
, sizeof (dynamic_copy
));
793 if (dynamic_copy
.ld_version
>= 2)
795 /* It is a version that we can deal with, so read in the secondary
796 structure and find the address of the link map list from it. */
797 read_memory (SOLIB_EXTRACT_ADDRESS (dynamic_copy
.ld_un
.ld_2
),
798 (char *) &ld_2_copy
, sizeof (struct link_dynamic_2
));
799 lm
= SOLIB_EXTRACT_ADDRESS (ld_2_copy
.ld_loaded
);
802 #else /* SVR4_SHARED_LIBS */
803 struct link_map_offsets
*lmo
= SVR4_FETCH_LINK_MAP_OFFSETS ();
804 char *r_map_buf
= xmalloc (lmo
->r_map_size
);
805 struct cleanup
*cleanups
= make_cleanup (xfree
, r_map_buf
);
807 read_memory (debug_base
+ lmo
->r_map_offset
, r_map_buf
, lmo
->r_map_size
);
809 lm
= extract_address (r_map_buf
, lmo
->r_map_size
);
811 /* FIXME: Perhaps we should validate the info somehow, perhaps by
812 checking r_version for a known version number, or r_state for
815 do_cleanups (cleanups
);
817 #endif /* !SVR4_SHARED_LIBS */
822 #ifdef SVR4_SHARED_LIBS
827 open_symbol_file_object
831 void open_symbol_file_object (void *from_tty)
835 If no open symbol file, attempt to locate and open the main symbol
836 file. On SVR4 systems, this is the first link map entry. If its
837 name is here, we can open it. Useful when attaching to a process
838 without first loading its symbol file.
840 If FROM_TTYP dereferences to a non-zero integer, allow messages to
841 be printed. This parameter is a pointer rather than an int because
842 open_symbol_file_object() is called via catch_errors() and
843 catch_errors() requires a pointer argument. */
846 open_symbol_file_object (void *from_ttyp
)
848 CORE_ADDR lm
, l_name
;
851 int from_tty
= *(int *)from_ttyp
;
852 struct link_map_offsets
*lmo
= SVR4_FETCH_LINK_MAP_OFFSETS ();
853 char *l_name_buf
= xmalloc (lmo
->l_name_size
);
854 struct cleanup
*cleanups
= make_cleanup (xfree
, l_name_buf
);
857 if (!query ("Attempt to reload symbols from process? "))
860 if ((debug_base
= locate_base ()) == 0)
861 return 0; /* failed somehow... */
863 /* First link map member should be the executable. */
864 if ((lm
= first_link_map_member ()) == 0)
865 return 0; /* failed somehow... */
867 /* Read address of name from target memory to GDB. */
868 read_memory (lm
+ lmo
->l_name_offset
, l_name_buf
, lmo
->l_name_size
);
870 /* Convert the address to host format. */
871 l_name
= extract_address (l_name_buf
, lmo
->l_name_size
);
873 /* Free l_name_buf. */
874 do_cleanups (cleanups
);
877 return 0; /* No filename. */
879 /* Now fetch the filename from target memory. */
880 target_read_string (l_name
, &filename
, SO_NAME_MAX_PATH_SIZE
- 1, &errcode
);
884 warning ("failed to read exec filename from attached file: %s",
885 safe_strerror (errcode
));
889 make_cleanup (xfree
, filename
);
890 /* Have a pathname: read the symbol file. */
891 symbol_file_add_main (filename
, from_tty
);
898 open_symbol_file_object (void *from_ttyp
)
903 #endif /* SVR4_SHARED_LIBS */
908 current_sos -- build a list of currently loaded shared objects
912 struct so_list *current_sos ()
916 Build a list of `struct so_list' objects describing the shared
917 objects currently loaded in the inferior. This list does not
918 include an entry for the main executable file.
920 Note that we only gather information directly available from the
921 inferior --- we don't examine any of the shared library files
922 themselves. The declaration of `struct so_list' says which fields
923 we provide values for. */
925 static struct so_list
*
926 svr4_current_sos (void)
929 struct so_list
*head
= 0;
930 struct so_list
**link_ptr
= &head
;
932 /* Make sure we've looked up the inferior's dynamic linker's base
936 debug_base
= locate_base ();
938 /* If we can't find the dynamic linker's base structure, this
939 must not be a dynamically linked executable. Hmm. */
944 /* Walk the inferior's link map list, and build our list of
945 `struct so_list' nodes. */
946 lm
= first_link_map_member ();
949 struct link_map_offsets
*lmo
= SVR4_FETCH_LINK_MAP_OFFSETS ();
951 = (struct so_list
*) xmalloc (sizeof (struct so_list
));
952 struct cleanup
*old_chain
= make_cleanup (xfree
, new);
954 memset (new, 0, sizeof (*new));
956 new->lm_info
= xmalloc (sizeof (struct lm_info
));
957 make_cleanup (xfree
, new->lm_info
);
959 new->lm_info
->lm
= xmalloc (lmo
->link_map_size
);
960 make_cleanup (xfree
, new->lm_info
->lm
);
961 memset (new->lm_info
->lm
, 0, lmo
->link_map_size
);
963 read_memory (lm
, new->lm_info
->lm
, lmo
->link_map_size
);
967 /* For SVR4 versions, the first entry in the link map is for the
968 inferior executable, so we must ignore it. For some versions of
969 SVR4, it has no name. For others (Solaris 2.3 for example), it
970 does have a name, so we can no longer use a missing name to
971 decide when to ignore it. */
972 if (IGNORE_FIRST_LINK_MAP_ENTRY (new))
979 /* Extract this shared object's name. */
980 target_read_string (LM_NAME (new), &buffer
,
981 SO_NAME_MAX_PATH_SIZE
- 1, &errcode
);
984 warning ("current_sos: Can't read pathname for load map: %s\n",
985 safe_strerror (errcode
));
989 strncpy (new->so_name
, buffer
, SO_NAME_MAX_PATH_SIZE
- 1);
990 new->so_name
[SO_NAME_MAX_PATH_SIZE
- 1] = '\0';
992 strcpy (new->so_original_name
, new->so_name
);
995 /* If this entry has no name, or its name matches the name
996 for the main executable, don't include it in the list. */
997 if (! new->so_name
[0]
998 || match_main (new->so_name
))
1004 link_ptr
= &new->next
;
1008 discard_cleanups (old_chain
);
1015 /* On some systems, the only way to recognize the link map entry for
1016 the main executable file is by looking at its name. Return
1017 non-zero iff SONAME matches one of the known main executable names. */
1020 match_main (char *soname
)
1024 for (mainp
= main_name_list
; *mainp
!= NULL
; mainp
++)
1026 if (strcmp (soname
, *mainp
) == 0)
1034 /* Return 1 if PC lies in the dynamic symbol resolution code of the
1035 SVR4 run time loader. */
1036 #ifdef SVR4_SHARED_LIBS
1037 static CORE_ADDR interp_text_sect_low
;
1038 static CORE_ADDR interp_text_sect_high
;
1039 static CORE_ADDR interp_plt_sect_low
;
1040 static CORE_ADDR interp_plt_sect_high
;
1043 svr4_in_dynsym_resolve_code (CORE_ADDR pc
)
1045 return ((pc
>= interp_text_sect_low
&& pc
< interp_text_sect_high
)
1046 || (pc
>= interp_plt_sect_low
&& pc
< interp_plt_sect_high
)
1047 || in_plt_section (pc
, NULL
));
1049 #else /* !SVR4_SHARED_LIBS */
1051 svr4_in_dynsym_resolve_code (CORE_ADDR pc
)
1055 #endif /* SVR4_SHARED_LIBS */
1061 disable_break -- remove the "mapping changed" breakpoint
1065 static int disable_break ()
1069 Removes the breakpoint that gets hit when the dynamic linker
1070 completes a mapping change.
1074 #ifndef SVR4_SHARED_LIBS
1077 disable_break (void)
1081 int in_debugger
= 0;
1083 /* Read the debugger structure from the inferior to retrieve the
1084 address of the breakpoint and the original contents of the
1085 breakpoint address. Remove the breakpoint by writing the original
1088 read_memory (debug_addr
, (char *) &debug_copy
, sizeof (debug_copy
));
1090 /* Set `in_debugger' to zero now. */
1092 write_memory (flag_addr
, (char *) &in_debugger
, sizeof (in_debugger
));
1094 breakpoint_addr
= SOLIB_EXTRACT_ADDRESS (debug_copy
.ldd_bp_addr
);
1095 write_memory (breakpoint_addr
, (char *) &debug_copy
.ldd_bp_inst
,
1096 sizeof (debug_copy
.ldd_bp_inst
));
1098 /* For the SVR4 version, we always know the breakpoint address. For the
1099 SunOS version we don't know it until the above code is executed.
1100 Grumble if we are stopped anywhere besides the breakpoint address. */
1102 if (stop_pc
!= breakpoint_addr
)
1104 warning ("stopped at unknown breakpoint while handling shared libraries");
1110 #endif /* #ifdef SVR4_SHARED_LIBS */
1116 enable_break -- arrange for dynamic linker to hit breakpoint
1120 int enable_break (void)
1124 Both the SunOS and the SVR4 dynamic linkers have, as part of their
1125 debugger interface, support for arranging for the inferior to hit
1126 a breakpoint after mapping in the shared libraries. This function
1127 enables that breakpoint.
1129 For SunOS, there is a special flag location (in_debugger) which we
1130 set to 1. When the dynamic linker sees this flag set, it will set
1131 a breakpoint at a location known only to itself, after saving the
1132 original contents of that place and the breakpoint address itself,
1133 in it's own internal structures. When we resume the inferior, it
1134 will eventually take a SIGTRAP when it runs into the breakpoint.
1135 We handle this (in a different place) by restoring the contents of
1136 the breakpointed location (which is only known after it stops),
1137 chasing around to locate the shared libraries that have been
1138 loaded, then resuming.
1140 For SVR4, the debugger interface structure contains a member (r_brk)
1141 which is statically initialized at the time the shared library is
1142 built, to the offset of a function (_r_debug_state) which is guaran-
1143 teed to be called once before mapping in a library, and again when
1144 the mapping is complete. At the time we are examining this member,
1145 it contains only the unrelocated offset of the function, so we have
1146 to do our own relocation. Later, when the dynamic linker actually
1147 runs, it relocates r_brk to be the actual address of _r_debug_state().
1149 The debugger interface structure also contains an enumeration which
1150 is set to either RT_ADD or RT_DELETE prior to changing the mapping,
1151 depending upon whether or not the library is being mapped or unmapped,
1152 and then set to RT_CONSISTENT after the library is mapped/unmapped.
1160 #ifndef SVR4_SHARED_LIBS
1165 /* Get link_dynamic structure */
1167 j
= target_read_memory (debug_base
, (char *) &dynamic_copy
,
1168 sizeof (dynamic_copy
));
1175 /* Calc address of debugger interface structure */
1177 debug_addr
= SOLIB_EXTRACT_ADDRESS (dynamic_copy
.ldd
);
1179 /* Calc address of `in_debugger' member of debugger interface structure */
1181 flag_addr
= debug_addr
+ (CORE_ADDR
) ((char *) &debug_copy
.ldd_in_debugger
-
1182 (char *) &debug_copy
);
1184 /* Write a value of 1 to this member. */
1187 write_memory (flag_addr
, (char *) &in_debugger
, sizeof (in_debugger
));
1190 #else /* SVR4_SHARED_LIBS */
1192 #ifdef BKPT_AT_SYMBOL
1194 struct minimal_symbol
*msymbol
;
1196 asection
*interp_sect
;
1198 /* First, remove all the solib event breakpoints. Their addresses
1199 may have changed since the last time we ran the program. */
1200 remove_solib_event_breakpoints ();
1202 #ifdef SVR4_SHARED_LIBS
1203 interp_text_sect_low
= interp_text_sect_high
= 0;
1204 interp_plt_sect_low
= interp_plt_sect_high
= 0;
1206 /* Find the .interp section; if not found, warn the user and drop
1207 into the old breakpoint at symbol code. */
1208 interp_sect
= bfd_get_section_by_name (exec_bfd
, ".interp");
1211 unsigned int interp_sect_size
;
1213 CORE_ADDR load_addr
= 0;
1214 int load_addr_found
= 0;
1215 struct so_list
*inferior_sos
;
1216 bfd
*tmp_bfd
= NULL
;
1218 char *tmp_pathname
= NULL
;
1219 CORE_ADDR sym_addr
= 0;
1221 /* Read the contents of the .interp section into a local buffer;
1222 the contents specify the dynamic linker this program uses. */
1223 interp_sect_size
= bfd_section_size (exec_bfd
, interp_sect
);
1224 buf
= alloca (interp_sect_size
);
1225 bfd_get_section_contents (exec_bfd
, interp_sect
,
1226 buf
, 0, interp_sect_size
);
1228 /* Now we need to figure out where the dynamic linker was
1229 loaded so that we can load its symbols and place a breakpoint
1230 in the dynamic linker itself.
1232 This address is stored on the stack. However, I've been unable
1233 to find any magic formula to find it for Solaris (appears to
1234 be trivial on GNU/Linux). Therefore, we have to try an alternate
1235 mechanism to find the dynamic linker's base address. */
1237 tmp_fd
= solib_open (buf
, &tmp_pathname
);
1239 tmp_bfd
= bfd_fdopenr (tmp_pathname
, gnutarget
, tmp_fd
);
1241 if (tmp_bfd
== NULL
)
1242 goto bkpt_at_symbol
;
1244 /* Make sure the dynamic linker's really a useful object. */
1245 if (!bfd_check_format (tmp_bfd
, bfd_object
))
1247 warning ("Unable to grok dynamic linker %s as an object file", buf
);
1248 bfd_close (tmp_bfd
);
1249 goto bkpt_at_symbol
;
1252 /* If the entry in _DYNAMIC for the dynamic linker has already
1253 been filled in, we can read its base address from there. */
1254 inferior_sos
= svr4_current_sos ();
1257 /* Connected to a running target. Update our shared library table. */
1258 solib_add (NULL
, 0, NULL
);
1260 while (inferior_sos
)
1262 if (strcmp (buf
, inferior_sos
->so_original_name
) == 0)
1264 load_addr_found
= 1;
1265 load_addr
= LM_ADDR (inferior_sos
);
1268 inferior_sos
= inferior_sos
->next
;
1271 /* Otherwise we find the dynamic linker's base address by examining
1272 the current pc (which should point at the entry point for the
1273 dynamic linker) and subtracting the offset of the entry point. */
1274 if (!load_addr_found
)
1275 load_addr
= read_pc () - tmp_bfd
->start_address
;
1277 /* Record the relocated start and end address of the dynamic linker
1278 text and plt section for svr4_in_dynsym_resolve_code. */
1279 interp_sect
= bfd_get_section_by_name (tmp_bfd
, ".text");
1282 interp_text_sect_low
=
1283 bfd_section_vma (tmp_bfd
, interp_sect
) + load_addr
;
1284 interp_text_sect_high
=
1285 interp_text_sect_low
+ bfd_section_size (tmp_bfd
, interp_sect
);
1287 interp_sect
= bfd_get_section_by_name (tmp_bfd
, ".plt");
1290 interp_plt_sect_low
=
1291 bfd_section_vma (tmp_bfd
, interp_sect
) + load_addr
;
1292 interp_plt_sect_high
=
1293 interp_plt_sect_low
+ bfd_section_size (tmp_bfd
, interp_sect
);
1296 /* Now try to set a breakpoint in the dynamic linker. */
1297 for (bkpt_namep
= solib_break_names
; *bkpt_namep
!= NULL
; bkpt_namep
++)
1299 sym_addr
= bfd_lookup_symbol (tmp_bfd
, *bkpt_namep
);
1304 /* We're done with the temporary bfd. */
1305 bfd_close (tmp_bfd
);
1309 create_solib_event_breakpoint (load_addr
+ sym_addr
);
1313 /* For whatever reason we couldn't set a breakpoint in the dynamic
1314 linker. Warn and drop into the old code. */
1316 warning ("Unable to find dynamic linker breakpoint function.\nGDB will be unable to debug shared library initializers\nand track explicitly loaded dynamic code.");
1320 /* Scan through the list of symbols, trying to look up the symbol and
1321 set a breakpoint there. Terminate loop when we/if we succeed. */
1323 breakpoint_addr
= 0;
1324 for (bkpt_namep
= bkpt_names
; *bkpt_namep
!= NULL
; bkpt_namep
++)
1326 msymbol
= lookup_minimal_symbol (*bkpt_namep
, NULL
, symfile_objfile
);
1327 if ((msymbol
!= NULL
) && (SYMBOL_VALUE_ADDRESS (msymbol
) != 0))
1329 create_solib_event_breakpoint (SYMBOL_VALUE_ADDRESS (msymbol
));
1334 /* Nothing good happened. */
1337 #endif /* BKPT_AT_SYMBOL */
1339 #endif /* !SVR4_SHARED_LIBS */
1348 special_symbol_handling -- additional shared library symbol handling
1352 void special_symbol_handling ()
1356 Once the symbols from a shared object have been loaded in the usual
1357 way, we are called to do any system specific symbol handling that
1360 For SunOS4, this consists of grunging around in the dynamic
1361 linkers structures to find symbol definitions for "common" symbols
1362 and adding them to the minimal symbol table for the runtime common
1368 svr4_special_symbol_handling (void)
1370 #ifndef SVR4_SHARED_LIBS
1373 if (debug_addr
== 0)
1375 /* Get link_dynamic structure */
1377 j
= target_read_memory (debug_base
, (char *) &dynamic_copy
,
1378 sizeof (dynamic_copy
));
1385 /* Calc address of debugger interface structure */
1386 /* FIXME, this needs work for cross-debugging of core files
1387 (byteorder, size, alignment, etc). */
1389 debug_addr
= SOLIB_EXTRACT_ADDRESS (dynamic_copy
.ldd
);
1392 /* Read the debugger structure from the inferior, just to make sure
1393 we have a current copy. */
1395 j
= target_read_memory (debug_addr
, (char *) &debug_copy
,
1396 sizeof (debug_copy
));
1398 return; /* unreadable */
1400 /* Get common symbol definitions for the loaded object. */
1402 if (debug_copy
.ldd_cp
)
1404 solib_add_common_symbols (SOLIB_EXTRACT_ADDRESS (debug_copy
.ldd_cp
));
1407 #endif /* !SVR4_SHARED_LIBS */
1410 /* Relocate the main executable. This function should be called upon
1411 stopping the inferior process at the entry point to the program.
1412 The entry point from BFD is compared to the PC and if they are
1413 different, the main executable is relocated by the proper amount.
1415 As written it will only attempt to relocate executables which
1416 lack interpreter sections. It seems likely that only dynamic
1417 linker executables will get relocated, though it should work
1418 properly for a position-independent static executable as well. */
1421 svr4_relocate_main_executable (void)
1423 asection
*interp_sect
;
1424 CORE_ADDR pc
= read_pc ();
1426 /* Decide if the objfile needs to be relocated. As indicated above,
1427 we will only be here when execution is stopped at the beginning
1428 of the program. Relocation is necessary if the address at which
1429 we are presently stopped differs from the start address stored in
1430 the executable AND there's no interpreter section. The condition
1431 regarding the interpreter section is very important because if
1432 there *is* an interpreter section, execution will begin there
1433 instead. When there is an interpreter section, the start address
1434 is (presumably) used by the interpreter at some point to start
1435 execution of the program.
1437 If there is an interpreter, it is normal for it to be set to an
1438 arbitrary address at the outset. The job of finding it is
1439 handled in enable_break().
1441 So, to summarize, relocations are necessary when there is no
1442 interpreter section and the start address obtained from the
1443 executable is different from the address at which GDB is
1446 [ The astute reader will note that we also test to make sure that
1447 the executable in question has the DYNAMIC flag set. It is my
1448 opinion that this test is unnecessary (undesirable even). It
1449 was added to avoid inadvertent relocation of an executable
1450 whose e_type member in the ELF header is not ET_DYN. There may
1451 be a time in the future when it is desirable to do relocations
1452 on other types of files as well in which case this condition
1453 should either be removed or modified to accomodate the new file
1454 type. (E.g, an ET_EXEC executable which has been built to be
1455 position-independent could safely be relocated by the OS if
1456 desired. It is true that this violates the ABI, but the ABI
1457 has been known to be bent from time to time.) - Kevin, Nov 2000. ]
1460 interp_sect
= bfd_get_section_by_name (exec_bfd
, ".interp");
1461 if (interp_sect
== NULL
1462 && (bfd_get_file_flags (exec_bfd
) & DYNAMIC
) != 0
1463 && bfd_get_start_address (exec_bfd
) != pc
)
1465 struct cleanup
*old_chain
;
1466 struct section_offsets
*new_offsets
;
1468 CORE_ADDR displacement
;
1470 /* It is necessary to relocate the objfile. The amount to
1471 relocate by is simply the address at which we are stopped
1472 minus the starting address from the executable.
1474 We relocate all of the sections by the same amount. This
1475 behavior is mandated by recent editions of the System V ABI.
1476 According to the System V Application Binary Interface,
1477 Edition 4.1, page 5-5:
1479 ... Though the system chooses virtual addresses for
1480 individual processes, it maintains the segments' relative
1481 positions. Because position-independent code uses relative
1482 addressesing between segments, the difference between
1483 virtual addresses in memory must match the difference
1484 between virtual addresses in the file. The difference
1485 between the virtual address of any segment in memory and
1486 the corresponding virtual address in the file is thus a
1487 single constant value for any one executable or shared
1488 object in a given process. This difference is the base
1489 address. One use of the base address is to relocate the
1490 memory image of the program during dynamic linking.
1492 The same language also appears in Edition 4.0 of the System V
1493 ABI and is left unspecified in some of the earlier editions. */
1495 displacement
= pc
- bfd_get_start_address (exec_bfd
);
1498 new_offsets
= xcalloc (sizeof (struct section_offsets
),
1499 symfile_objfile
->num_sections
);
1500 old_chain
= make_cleanup (xfree
, new_offsets
);
1502 for (i
= 0; i
< symfile_objfile
->num_sections
; i
++)
1504 if (displacement
!= ANOFFSET (symfile_objfile
->section_offsets
, i
))
1506 new_offsets
->offsets
[i
] = displacement
;
1510 objfile_relocate (symfile_objfile
, new_offsets
);
1512 do_cleanups (old_chain
);
1520 svr4_solib_create_inferior_hook -- shared library startup support
1524 void svr4_solib_create_inferior_hook()
1528 When gdb starts up the inferior, it nurses it along (through the
1529 shell) until it is ready to execute it's first instruction. At this
1530 point, this function gets called via expansion of the macro
1531 SOLIB_CREATE_INFERIOR_HOOK.
1533 For SunOS executables, this first instruction is typically the
1534 one at "_start", or a similar text label, regardless of whether
1535 the executable is statically or dynamically linked. The runtime
1536 startup code takes care of dynamically linking in any shared
1537 libraries, once gdb allows the inferior to continue.
1539 For SVR4 executables, this first instruction is either the first
1540 instruction in the dynamic linker (for dynamically linked
1541 executables) or the instruction at "start" for statically linked
1542 executables. For dynamically linked executables, the system
1543 first exec's /lib/libc.so.N, which contains the dynamic linker,
1544 and starts it running. The dynamic linker maps in any needed
1545 shared libraries, maps in the actual user executable, and then
1546 jumps to "start" in the user executable.
1548 For both SunOS shared libraries, and SVR4 shared libraries, we
1549 can arrange to cooperate with the dynamic linker to discover the
1550 names of shared libraries that are dynamically linked, and the
1551 base addresses to which they are linked.
1553 This function is responsible for discovering those names and
1554 addresses, and saving sufficient information about them to allow
1555 their symbols to be read at a later time.
1559 Between enable_break() and disable_break(), this code does not
1560 properly handle hitting breakpoints which the user might have
1561 set in the startup code or in the dynamic linker itself. Proper
1562 handling will probably have to wait until the implementation is
1563 changed to use the "breakpoint handler function" method.
1565 Also, what if child has exit()ed? Must exit loop somehow.
1569 svr4_solib_create_inferior_hook (void)
1571 /* Relocate the main executable if necessary. */
1572 svr4_relocate_main_executable ();
1574 /* If we are using the BKPT_AT_SYMBOL code, then we don't need the base
1575 yet. In fact, in the case of a SunOS4 executable being run on
1576 Solaris, we can't get it yet. current_sos will get it when it needs
1578 #if !(defined (SVR4_SHARED_LIBS) && defined (BKPT_AT_SYMBOL))
1579 if ((debug_base
= locate_base ()) == 0)
1581 /* Can't find the symbol or the executable is statically linked. */
1586 if (!enable_break ())
1588 warning ("shared library handler failed to enable breakpoint");
1592 #if !defined(SVR4_SHARED_LIBS) || defined(_SCO_DS)
1593 /* SCO and SunOS need the loop below, other systems should be using the
1594 special shared library breakpoints and the shared library breakpoint
1597 Now run the target. It will eventually hit the breakpoint, at
1598 which point all of the libraries will have been mapped in and we
1599 can go groveling around in the dynamic linker structures to find
1600 out what we need to know about them. */
1602 clear_proceed_status ();
1603 stop_soon_quietly
= 1;
1604 stop_signal
= TARGET_SIGNAL_0
;
1607 target_resume (pid_to_ptid (-1), 0, stop_signal
);
1608 wait_for_inferior ();
1610 while (stop_signal
!= TARGET_SIGNAL_TRAP
);
1611 stop_soon_quietly
= 0;
1613 #if !defined(_SCO_DS)
1614 /* We are now either at the "mapping complete" breakpoint (or somewhere
1615 else, a condition we aren't prepared to deal with anyway), so adjust
1616 the PC as necessary after a breakpoint, disable the breakpoint, and
1617 add any shared libraries that were mapped in. */
1619 if (DECR_PC_AFTER_BREAK
)
1621 stop_pc
-= DECR_PC_AFTER_BREAK
;
1622 write_register (PC_REGNUM
, stop_pc
);
1625 if (!disable_break ())
1627 warning ("shared library handler failed to disable breakpoint");
1631 solib_add ((char *) 0, 0, (struct target_ops
*) 0);
1632 #endif /* ! _SCO_DS */
1637 svr4_clear_solib (void)
1643 svr4_free_so (struct so_list
*so
)
1645 xfree (so
->lm_info
->lm
);
1646 xfree (so
->lm_info
);
1650 svr4_relocate_section_addresses (struct so_list
*so
,
1651 struct section_table
*sec
)
1653 sec
->addr
+= LM_ADDR (so
);
1654 sec
->endaddr
+= LM_ADDR (so
);
1657 /* set_solib_svr4_fetch_link_map_offsets() is intended to be called by
1658 a <arch>_gdbarch_init() function. It uses ``fetch_link_map_offsets_init''
1659 to temporarily hold a pointer to the link map offsets fetcher for
1660 a particular architecture. Once the architecture is actually installed,
1661 init_fetch_link_map_offsets(), below, will be called to install this
1662 value in ``fetch_link_map_offsets''. After that, the gdbarch_swap
1663 machinery will manage the contents of this variable whenever the
1664 architecture changes. */
1667 set_solib_svr4_fetch_link_map_offsets (struct link_map_offsets
*(*flmo
) (void))
1669 fetch_link_map_offsets_init
= flmo
;
1672 /* Initialize the value of ``fetch_link_map_offsets'' when a new
1673 architecture is created. set_solib_svr4_fetch_link_map_offsets()
1674 is used to set the value that ``fetch_link_map_offsets'' should
1675 be initialized to. */
1678 init_fetch_link_map_offsets (void)
1680 if (fetch_link_map_offsets_init
!= NULL
)
1681 fetch_link_map_offsets
= fetch_link_map_offsets_init
;
1683 fetch_link_map_offsets
= default_svr4_fetch_link_map_offsets
;
1685 fetch_link_map_offsets_init
= NULL
;
1688 static struct target_so_ops svr4_so_ops
;
1691 _initialize_svr4_solib (void)
1693 register_gdbarch_swap (&fetch_link_map_offsets
,
1694 sizeof (fetch_link_map_offsets
),
1695 init_fetch_link_map_offsets
);
1697 svr4_so_ops
.relocate_section_addresses
= svr4_relocate_section_addresses
;
1698 svr4_so_ops
.free_so
= svr4_free_so
;
1699 svr4_so_ops
.clear_solib
= svr4_clear_solib
;
1700 svr4_so_ops
.solib_create_inferior_hook
= svr4_solib_create_inferior_hook
;
1701 svr4_so_ops
.special_symbol_handling
= svr4_special_symbol_handling
;
1702 svr4_so_ops
.current_sos
= svr4_current_sos
;
1703 svr4_so_ops
.open_symbol_file_object
= open_symbol_file_object
;
1704 svr4_so_ops
.in_dynsym_resolve_code
= svr4_in_dynsym_resolve_code
;
1706 /* FIXME: Don't do this here. *_gdbarch_init() should set so_ops. */
1707 current_target_so_ops
= &svr4_so_ops
;