1 /* Handle SunOS and SVR4 shared libraries for GDB, the GNU Debugger.
2 Copyright 1990, 91, 92, 93, 94, 95, 96, 98, 1999, 2000, 2001
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 #define _SYSCALL32 /* for Sparc64 cross Sparc32 */
26 #include <sys/types.h>
28 #include "gdb_string.h"
29 #include <sys/param.h>
32 #ifndef SVR4_SHARED_LIBS
33 /* SunOS shared libs need the nlist structure. */
36 #include "elf/external.h"
51 #include "gdb_regex.h"
58 #include "solib-svr4.h"
60 /* Link map info to include in an allocated so_list entry */
64 /* Pointer to copy of link map from inferior. The type is char *
65 rather than void *, so that we may use byte offsets to find the
66 various fields without the need for a cast. */
70 /* On SVR4 systems, a list of symbols in the dynamic linker where
71 GDB can try to place a breakpoint to monitor shared library
74 If none of these symbols are found, or other errors occur, then
75 SVR4 systems will fall back to using a symbol as the "startup
76 mapping complete" breakpoint address. */
78 #ifdef SVR4_SHARED_LIBS
79 static char *solib_break_names
[] =
90 #define BKPT_AT_SYMBOL 1
92 #if defined (BKPT_AT_SYMBOL) && defined (SVR4_SHARED_LIBS)
93 static char *bkpt_names
[] =
95 #ifdef SOLIB_BKPT_NAME
96 SOLIB_BKPT_NAME
, /* Prefer configured name if it exists. */
104 /* Symbols which are used to locate the base of the link map structures. */
106 #ifndef SVR4_SHARED_LIBS
107 static char *debug_base_symbols
[] =
115 static char *main_name_list
[] =
122 /* Fetch (and possibly build) an appropriate link_map_offsets structure
123 for native targets using struct definitions from link.h. */
125 struct link_map_offsets
*
126 default_svr4_fetch_link_map_offsets (void)
129 static struct link_map_offsets lmo
;
130 static struct link_map_offsets
*lmp
= 0;
131 #if defined (HAVE_STRUCT_LINK_MAP32)
132 static struct link_map_offsets lmo32
;
133 static struct link_map_offsets
*lmp32
= 0;
137 #define offsetof(TYPE, MEMBER) ((unsigned long) &((TYPE *)0)->MEMBER)
139 #define fieldsize(TYPE, MEMBER) (sizeof (((TYPE *)0)->MEMBER))
145 #ifdef SVR4_SHARED_LIBS
146 lmo
.r_debug_size
= sizeof (struct r_debug
);
148 lmo
.r_map_offset
= offsetof (struct r_debug
, r_map
);
149 lmo
.r_map_size
= fieldsize (struct r_debug
, r_map
);
151 lmo
.link_map_size
= sizeof (struct link_map
);
153 lmo
.l_addr_offset
= offsetof (struct link_map
, l_addr
);
154 lmo
.l_addr_size
= fieldsize (struct link_map
, l_addr
);
156 lmo
.l_next_offset
= offsetof (struct link_map
, l_next
);
157 lmo
.l_next_size
= fieldsize (struct link_map
, l_next
);
159 lmo
.l_prev_offset
= offsetof (struct link_map
, l_prev
);
160 lmo
.l_prev_size
= fieldsize (struct link_map
, l_prev
);
162 lmo
.l_name_offset
= offsetof (struct link_map
, l_name
);
163 lmo
.l_name_size
= fieldsize (struct link_map
, l_name
);
164 #else /* !SVR4_SHARED_LIBS */
165 lmo
.link_map_size
= sizeof (struct link_map
);
167 lmo
.l_addr_offset
= offsetof (struct link_map
, lm_addr
);
168 lmo
.l_addr_size
= fieldsize (struct link_map
, lm_addr
);
170 lmo
.l_next_offset
= offsetof (struct link_map
, lm_next
);
171 lmo
.l_next_size
= fieldsize (struct link_map
, lm_next
);
173 lmo
.l_name_offset
= offsetof (struct link_map
, lm_name
);
174 lmo
.l_name_size
= fieldsize (struct link_map
, lm_name
);
175 #endif /* SVR4_SHARED_LIBS */
178 #if defined (HAVE_STRUCT_LINK_MAP32)
183 lmo32
.r_debug_size
= sizeof (struct r_debug32
);
185 lmo32
.r_map_offset
= offsetof (struct r_debug32
, r_map
);
186 lmo32
.r_map_size
= fieldsize (struct r_debug32
, r_map
);
188 lmo32
.link_map_size
= sizeof (struct link_map32
);
190 lmo32
.l_addr_offset
= offsetof (struct link_map32
, l_addr
);
191 lmo32
.l_addr_size
= fieldsize (struct link_map32
, l_addr
);
193 lmo32
.l_next_offset
= offsetof (struct link_map32
, l_next
);
194 lmo32
.l_next_size
= fieldsize (struct link_map32
, l_next
);
196 lmo32
.l_prev_offset
= offsetof (struct link_map32
, l_prev
);
197 lmo32
.l_prev_size
= fieldsize (struct link_map32
, l_prev
);
199 lmo32
.l_name_offset
= offsetof (struct link_map32
, l_name
);
200 lmo32
.l_name_size
= fieldsize (struct link_map32
, l_name
);
202 #endif /* defined (HAVE_STRUCT_LINK_MAP32) */
204 #if defined (HAVE_STRUCT_LINK_MAP32)
205 if (bfd_get_arch_size (exec_bfd
) == 32)
213 internal_error (__FILE__
, __LINE__
,
214 "default_svr4_fetch_link_map_offsets called without HAVE_LINK_H defined.");
217 #endif /* HAVE_LINK_H */
220 /* Macro to extract an address from a solib structure.
221 When GDB is configured for some 32-bit targets (e.g. Solaris 2.7
222 sparc), BFD is configured to handle 64-bit targets, so CORE_ADDR is
223 64 bits. We have to extract only the significant bits of addresses
224 to get the right address when accessing the core file BFD. */
226 #define SOLIB_EXTRACT_ADDRESS(MEMBER) \
227 extract_address (&(MEMBER), sizeof (MEMBER))
229 /* local data declarations */
231 #ifndef SVR4_SHARED_LIBS
233 /* NOTE: converted the macros LM_ADDR, LM_NEXT, LM_NAME and
234 IGNORE_FIRST_LINK_MAP_ENTRY into functions (see below).
237 static struct link_dynamic dynamic_copy
;
238 static struct link_dynamic_2 ld_2_copy
;
239 static struct ld_debug debug_copy
;
240 static CORE_ADDR debug_addr
;
241 static CORE_ADDR flag_addr
;
243 #endif /* !SVR4_SHARED_LIBS */
245 /* link map access functions */
248 LM_ADDR (struct so_list
*so
)
250 struct link_map_offsets
*lmo
= SVR4_FETCH_LINK_MAP_OFFSETS ();
252 return (CORE_ADDR
) extract_signed_integer (so
->lm_info
->lm
+ lmo
->l_addr_offset
,
257 LM_NEXT (struct so_list
*so
)
259 struct link_map_offsets
*lmo
= SVR4_FETCH_LINK_MAP_OFFSETS ();
261 return extract_address (so
->lm_info
->lm
+ lmo
->l_next_offset
, lmo
->l_next_size
);
265 LM_NAME (struct so_list
*so
)
267 struct link_map_offsets
*lmo
= SVR4_FETCH_LINK_MAP_OFFSETS ();
269 return extract_address (so
->lm_info
->lm
+ lmo
->l_name_offset
, lmo
->l_name_size
);
272 #ifndef SVR4_SHARED_LIBS
275 IGNORE_FIRST_LINK_MAP_ENTRY (struct so_list
*so
)
280 #else /* SVR4_SHARED_LIBS */
283 IGNORE_FIRST_LINK_MAP_ENTRY (struct so_list
*so
)
285 struct link_map_offsets
*lmo
= SVR4_FETCH_LINK_MAP_OFFSETS ();
287 return extract_address (so
->lm_info
->lm
+ lmo
->l_prev_offset
,
288 lmo
->l_prev_size
) == 0;
291 #endif /* !SVR4_SHARED_LIBS */
293 static CORE_ADDR debug_base
; /* Base of dynamic linker structures */
294 static CORE_ADDR breakpoint_addr
; /* Address where end bkpt is set */
296 /* Local function prototypes */
298 static int match_main (char *);
300 #ifndef SVR4_SHARED_LIBS
302 /* Allocate the runtime common object file. */
305 allocate_rt_common_objfile (void)
307 struct objfile
*objfile
;
308 struct objfile
*last_one
;
310 objfile
= (struct objfile
*) xmalloc (sizeof (struct objfile
));
311 memset (objfile
, 0, sizeof (struct objfile
));
313 obstack_specify_allocation (&objfile
->psymbol_cache
.cache
, 0, 0,
315 obstack_specify_allocation (&objfile
->psymbol_obstack
, 0, 0, xmalloc
,
317 obstack_specify_allocation (&objfile
->symbol_obstack
, 0, 0, xmalloc
,
319 obstack_specify_allocation (&objfile
->type_obstack
, 0, 0, xmalloc
,
321 objfile
->name
= mstrsave (objfile
->md
, "rt_common");
323 /* Add this file onto the tail of the linked list of other such files. */
325 objfile
->next
= NULL
;
326 if (object_files
== NULL
)
327 object_files
= objfile
;
330 for (last_one
= object_files
;
332 last_one
= last_one
->next
);
333 last_one
->next
= objfile
;
336 rt_common_objfile
= objfile
;
339 /* Read all dynamically loaded common symbol definitions from the inferior
340 and put them into the minimal symbol table for the runtime common
344 solib_add_common_symbols (CORE_ADDR rtc_symp
)
346 struct rtc_symb inferior_rtc_symb
;
347 struct nlist inferior_rtc_nlist
;
351 /* Remove any runtime common symbols from previous runs. */
353 if (rt_common_objfile
!= NULL
&& rt_common_objfile
->minimal_symbol_count
)
355 obstack_free (&rt_common_objfile
->symbol_obstack
, 0);
356 obstack_specify_allocation (&rt_common_objfile
->symbol_obstack
, 0, 0,
358 rt_common_objfile
->minimal_symbol_count
= 0;
359 rt_common_objfile
->msymbols
= NULL
;
362 init_minimal_symbol_collection ();
363 make_cleanup_discard_minimal_symbols ();
367 read_memory (rtc_symp
,
368 (char *) &inferior_rtc_symb
,
369 sizeof (inferior_rtc_symb
));
370 read_memory (SOLIB_EXTRACT_ADDRESS (inferior_rtc_symb
.rtc_sp
),
371 (char *) &inferior_rtc_nlist
,
372 sizeof (inferior_rtc_nlist
));
373 if (inferior_rtc_nlist
.n_type
== N_COMM
)
375 /* FIXME: The length of the symbol name is not available, but in the
376 current implementation the common symbol is allocated immediately
377 behind the name of the symbol. */
378 len
= inferior_rtc_nlist
.n_value
- inferior_rtc_nlist
.n_un
.n_strx
;
380 name
= xmalloc (len
);
381 read_memory (SOLIB_EXTRACT_ADDRESS (inferior_rtc_nlist
.n_un
.n_name
),
384 /* Allocate the runtime common objfile if necessary. */
385 if (rt_common_objfile
== NULL
)
386 allocate_rt_common_objfile ();
388 prim_record_minimal_symbol (name
, inferior_rtc_nlist
.n_value
,
389 mst_bss
, rt_common_objfile
);
392 rtc_symp
= SOLIB_EXTRACT_ADDRESS (inferior_rtc_symb
.rtc_next
);
395 /* Install any minimal symbols that have been collected as the current
396 minimal symbols for the runtime common objfile. */
398 install_minimal_symbols (rt_common_objfile
);
401 #endif /* SVR4_SHARED_LIBS */
404 #ifdef SVR4_SHARED_LIBS
406 static CORE_ADDR
bfd_lookup_symbol (bfd
*, char *);
412 bfd_lookup_symbol -- lookup the value for a specific symbol
416 CORE_ADDR bfd_lookup_symbol (bfd *abfd, char *symname)
420 An expensive way to lookup the value of a single symbol for
421 bfd's that are only temporary anyway. This is used by the
422 shared library support to find the address of the debugger
423 interface structures in the shared library.
425 Note that 0 is specifically allowed as an error return (no
430 bfd_lookup_symbol (bfd
*abfd
, char *symname
)
432 unsigned int storage_needed
;
434 asymbol
**symbol_table
;
435 unsigned int number_of_symbols
;
437 struct cleanup
*back_to
;
438 CORE_ADDR symaddr
= 0;
440 storage_needed
= bfd_get_symtab_upper_bound (abfd
);
442 if (storage_needed
> 0)
444 symbol_table
= (asymbol
**) xmalloc (storage_needed
);
445 back_to
= make_cleanup (xfree
, (PTR
) symbol_table
);
446 number_of_symbols
= bfd_canonicalize_symtab (abfd
, symbol_table
);
448 for (i
= 0; i
< number_of_symbols
; i
++)
450 sym
= *symbol_table
++;
451 if (STREQ (sym
->name
, symname
))
453 /* Bfd symbols are section relative. */
454 symaddr
= sym
->value
+ sym
->section
->vma
;
458 do_cleanups (back_to
);
464 /* On FreeBSD, the dynamic linker is stripped by default. So we'll
465 have to check the dynamic string table too. */
467 storage_needed
= bfd_get_dynamic_symtab_upper_bound (abfd
);
469 if (storage_needed
> 0)
471 symbol_table
= (asymbol
**) xmalloc (storage_needed
);
472 back_to
= make_cleanup (xfree
, (PTR
) symbol_table
);
473 number_of_symbols
= bfd_canonicalize_dynamic_symtab (abfd
, symbol_table
);
475 for (i
= 0; i
< number_of_symbols
; i
++)
477 sym
= *symbol_table
++;
478 if (STREQ (sym
->name
, symname
))
480 /* Bfd symbols are section relative. */
481 symaddr
= sym
->value
+ sym
->section
->vma
;
485 do_cleanups (back_to
);
491 #ifdef HANDLE_SVR4_EXEC_EMULATORS
494 Solaris BCP (the part of Solaris which allows it to run SunOS4
495 a.out files) throws in another wrinkle. Solaris does not fill
496 in the usual a.out link map structures when running BCP programs,
497 the only way to get at them is via groping around in the dynamic
499 The dynamic linker and it's structures are located in the shared
500 C library, which gets run as the executable's "interpreter" by
503 Note that we can assume nothing about the process state at the time
504 we need to find these structures. We may be stopped on the first
505 instruction of the interpreter (C shared library), the first
506 instruction of the executable itself, or somewhere else entirely
507 (if we attached to the process for example).
510 static char *debug_base_symbols
[] =
512 "r_debug", /* Solaris 2.3 */
513 "_r_debug", /* Solaris 2.1, 2.2 */
517 static int look_for_base (int, CORE_ADDR
);
523 look_for_base -- examine file for each mapped address segment
527 static int look_for_base (int fd, CORE_ADDR baseaddr)
531 This function is passed to proc_iterate_over_mappings, which
532 causes it to get called once for each mapped address space, with
533 an open file descriptor for the file mapped to that space, and the
534 base address of that mapped space.
536 Our job is to find the debug base symbol in the file that this
537 fd is open on, if it exists, and if so, initialize the dynamic
538 linker structure base address debug_base.
540 Note that this is a computationally expensive proposition, since
541 we basically have to open a bfd on every call, so we specifically
542 avoid opening the exec file.
546 look_for_base (int fd
, CORE_ADDR baseaddr
)
549 CORE_ADDR address
= 0;
552 /* If the fd is -1, then there is no file that corresponds to this
553 mapped memory segment, so skip it. Also, if the fd corresponds
554 to the exec file, skip it as well. */
558 && fdmatch (fileno ((FILE *) (exec_bfd
->iostream
)), fd
)))
563 /* Try to open whatever random file this fd corresponds to. Note that
564 we have no way currently to find the filename. Don't gripe about
565 any problems we might have, just fail. */
567 if ((interp_bfd
= bfd_fdopenr ("unnamed", gnutarget
, fd
)) == NULL
)
571 if (!bfd_check_format (interp_bfd
, bfd_object
))
573 /* FIXME-leak: on failure, might not free all memory associated with
575 bfd_close (interp_bfd
);
579 /* Now try to find our debug base symbol in this file, which we at
580 least know to be a valid ELF executable or shared library. */
582 for (symbolp
= debug_base_symbols
; *symbolp
!= NULL
; symbolp
++)
584 address
= bfd_lookup_symbol (interp_bfd
, *symbolp
);
592 /* FIXME-leak: on failure, might not free all memory associated with
594 bfd_close (interp_bfd
);
598 /* Eureka! We found the symbol. But now we may need to relocate it
599 by the base address. If the symbol's value is less than the base
600 address of the shared library, then it hasn't yet been relocated
601 by the dynamic linker, and we have to do it ourself. FIXME: Note
602 that we make the assumption that the first segment that corresponds
603 to the shared library has the base address to which the library
606 if (address
< baseaddr
)
610 debug_base
= address
;
611 /* FIXME-leak: on failure, might not free all memory associated with
613 bfd_close (interp_bfd
);
616 #endif /* HANDLE_SVR4_EXEC_EMULATORS */
622 elf_locate_base -- locate the base address of dynamic linker structs
623 for SVR4 elf targets.
627 CORE_ADDR elf_locate_base (void)
631 For SVR4 elf targets the address of the dynamic linker's runtime
632 structure is contained within the dynamic info section in the
633 executable file. The dynamic section is also mapped into the
634 inferior address space. Because the runtime loader fills in the
635 real address before starting the inferior, we have to read in the
636 dynamic info section from the inferior address space.
637 If there are any errors while trying to find the address, we
638 silently return 0, otherwise the found address is returned.
643 elf_locate_base (void)
645 sec_ptr dyninfo_sect
;
646 int dyninfo_sect_size
;
647 CORE_ADDR dyninfo_addr
;
652 /* Find the start address of the .dynamic section. */
653 dyninfo_sect
= bfd_get_section_by_name (exec_bfd
, ".dynamic");
654 if (dyninfo_sect
== NULL
)
656 dyninfo_addr
= bfd_section_vma (exec_bfd
, dyninfo_sect
);
658 /* Read in .dynamic section, silently ignore errors. */
659 dyninfo_sect_size
= bfd_section_size (exec_bfd
, dyninfo_sect
);
660 buf
= alloca (dyninfo_sect_size
);
661 if (target_read_memory (dyninfo_addr
, buf
, dyninfo_sect_size
))
664 /* Find the DT_DEBUG entry in the the .dynamic section.
665 For mips elf we look for DT_MIPS_RLD_MAP, mips elf apparently has
666 no DT_DEBUG entries. */
668 arch_size
= bfd_get_arch_size (exec_bfd
);
669 if (arch_size
== -1) /* failure */
674 for (bufend
= buf
+ dyninfo_sect_size
;
676 buf
+= sizeof (Elf32_External_Dyn
))
678 Elf32_External_Dyn
*x_dynp
= (Elf32_External_Dyn
*) buf
;
682 dyn_tag
= bfd_h_get_32 (exec_bfd
, (bfd_byte
*) x_dynp
->d_tag
);
683 if (dyn_tag
== DT_NULL
)
685 else if (dyn_tag
== DT_DEBUG
)
687 dyn_ptr
= bfd_h_get_32 (exec_bfd
,
688 (bfd_byte
*) x_dynp
->d_un
.d_ptr
);
691 #ifdef DT_MIPS_RLD_MAP
692 else if (dyn_tag
== DT_MIPS_RLD_MAP
)
696 pbuf
= alloca (TARGET_PTR_BIT
/ HOST_CHAR_BIT
);
697 /* DT_MIPS_RLD_MAP contains a pointer to the address
698 of the dynamic link structure. */
699 dyn_ptr
= bfd_h_get_32 (exec_bfd
,
700 (bfd_byte
*) x_dynp
->d_un
.d_ptr
);
701 if (target_read_memory (dyn_ptr
, pbuf
, sizeof (pbuf
)))
703 return extract_unsigned_integer (pbuf
, sizeof (pbuf
));
708 else /* 64-bit elf */
710 for (bufend
= buf
+ dyninfo_sect_size
;
712 buf
+= sizeof (Elf64_External_Dyn
))
714 Elf64_External_Dyn
*x_dynp
= (Elf64_External_Dyn
*) buf
;
718 dyn_tag
= bfd_h_get_64 (exec_bfd
, (bfd_byte
*) x_dynp
->d_tag
);
719 if (dyn_tag
== DT_NULL
)
721 else if (dyn_tag
== DT_DEBUG
)
723 dyn_ptr
= bfd_h_get_64 (exec_bfd
,
724 (bfd_byte
*) x_dynp
->d_un
.d_ptr
);
730 /* DT_DEBUG entry not found. */
734 #endif /* SVR4_SHARED_LIBS */
740 locate_base -- locate the base address of dynamic linker structs
744 CORE_ADDR locate_base (void)
748 For both the SunOS and SVR4 shared library implementations, if the
749 inferior executable has been linked dynamically, there is a single
750 address somewhere in the inferior's data space which is the key to
751 locating all of the dynamic linker's runtime structures. This
752 address is the value of the debug base symbol. The job of this
753 function is to find and return that address, or to return 0 if there
754 is no such address (the executable is statically linked for example).
756 For SunOS, the job is almost trivial, since the dynamic linker and
757 all of it's structures are statically linked to the executable at
758 link time. Thus the symbol for the address we are looking for has
759 already been added to the minimal symbol table for the executable's
760 objfile at the time the symbol file's symbols were read, and all we
761 have to do is look it up there. Note that we explicitly do NOT want
762 to find the copies in the shared library.
764 The SVR4 version is a bit more complicated because the address
765 is contained somewhere in the dynamic info section. We have to go
766 to a lot more work to discover the address of the debug base symbol.
767 Because of this complexity, we cache the value we find and return that
768 value on subsequent invocations. Note there is no copy in the
769 executable symbol tables.
777 #ifndef SVR4_SHARED_LIBS
779 struct minimal_symbol
*msymbol
;
780 CORE_ADDR address
= 0;
783 /* For SunOS, we want to limit the search for the debug base symbol to the
784 executable being debugged, since there is a duplicate named symbol in the
785 shared library. We don't want the shared library versions. */
787 for (symbolp
= debug_base_symbols
; *symbolp
!= NULL
; symbolp
++)
789 msymbol
= lookup_minimal_symbol (*symbolp
, NULL
, symfile_objfile
);
790 if ((msymbol
!= NULL
) && (SYMBOL_VALUE_ADDRESS (msymbol
) != 0))
792 address
= SYMBOL_VALUE_ADDRESS (msymbol
);
798 #else /* SVR4_SHARED_LIBS */
800 /* Check to see if we have a currently valid address, and if so, avoid
801 doing all this work again and just return the cached address. If
802 we have no cached address, try to locate it in the dynamic info
803 section for ELF executables. */
808 && bfd_get_flavour (exec_bfd
) == bfd_target_elf_flavour
)
809 debug_base
= elf_locate_base ();
810 #ifdef HANDLE_SVR4_EXEC_EMULATORS
811 /* Try it the hard way for emulated executables. */
812 else if (inferior_pid
!= 0 && target_has_execution
)
813 proc_iterate_over_mappings (look_for_base
);
818 #endif /* !SVR4_SHARED_LIBS */
826 first_link_map_member -- locate first member in dynamic linker's map
830 static CORE_ADDR first_link_map_member (void)
834 Find the first element in the inferior's dynamic link map, and
835 return its address in the inferior. This function doesn't copy the
836 link map entry itself into our address space; current_sos actually
840 first_link_map_member (void)
844 #ifndef SVR4_SHARED_LIBS
846 read_memory (debug_base
, (char *) &dynamic_copy
, sizeof (dynamic_copy
));
847 if (dynamic_copy
.ld_version
>= 2)
849 /* It is a version that we can deal with, so read in the secondary
850 structure and find the address of the link map list from it. */
851 read_memory (SOLIB_EXTRACT_ADDRESS (dynamic_copy
.ld_un
.ld_2
),
852 (char *) &ld_2_copy
, sizeof (struct link_dynamic_2
));
853 lm
= SOLIB_EXTRACT_ADDRESS (ld_2_copy
.ld_loaded
);
856 #else /* SVR4_SHARED_LIBS */
857 struct link_map_offsets
*lmo
= SVR4_FETCH_LINK_MAP_OFFSETS ();
858 char *r_map_buf
= xmalloc (lmo
->r_map_size
);
859 struct cleanup
*cleanups
= make_cleanup (xfree
, r_map_buf
);
861 read_memory (debug_base
+ lmo
->r_map_offset
, r_map_buf
, lmo
->r_map_size
);
863 lm
= extract_address (r_map_buf
, lmo
->r_map_size
);
865 /* FIXME: Perhaps we should validate the info somehow, perhaps by
866 checking r_version for a known version number, or r_state for
869 do_cleanups (cleanups
);
871 #endif /* !SVR4_SHARED_LIBS */
876 #ifdef SVR4_SHARED_LIBS
881 open_symbol_file_object
885 void open_symbol_file_object (void *from_tty)
889 If no open symbol file, attempt to locate and open the main symbol
890 file. On SVR4 systems, this is the first link map entry. If its
891 name is here, we can open it. Useful when attaching to a process
892 without first loading its symbol file.
894 If FROM_TTYP dereferences to a non-zero integer, allow messages to
895 be printed. This parameter is a pointer rather than an int because
896 open_symbol_file_object() is called via catch_errors() and
897 catch_errors() requires a pointer argument. */
900 open_symbol_file_object (void *from_ttyp
)
902 CORE_ADDR lm
, l_name
;
905 int from_tty
= *(int *)from_ttyp
;
906 struct link_map_offsets
*lmo
= SVR4_FETCH_LINK_MAP_OFFSETS ();
907 char *l_name_buf
= xmalloc (lmo
->l_name_size
);
908 struct cleanup
*cleanups
= make_cleanup (xfree
, l_name_buf
);
911 if (!query ("Attempt to reload symbols from process? "))
914 if ((debug_base
= locate_base ()) == 0)
915 return 0; /* failed somehow... */
917 /* First link map member should be the executable. */
918 if ((lm
= first_link_map_member ()) == 0)
919 return 0; /* failed somehow... */
921 /* Read address of name from target memory to GDB. */
922 read_memory (lm
+ lmo
->l_name_offset
, l_name_buf
, lmo
->l_name_size
);
924 /* Convert the address to host format. */
925 l_name
= extract_address (l_name_buf
, lmo
->l_name_size
);
927 /* Free l_name_buf. */
928 do_cleanups (cleanups
);
931 return 0; /* No filename. */
933 /* Now fetch the filename from target memory. */
934 target_read_string (l_name
, &filename
, SO_NAME_MAX_PATH_SIZE
- 1, &errcode
);
938 warning ("failed to read exec filename from attached file: %s",
939 safe_strerror (errcode
));
943 make_cleanup (xfree
, filename
);
944 /* Have a pathname: read the symbol file. */
945 symbol_file_add_main (filename
, from_tty
);
952 open_symbol_file_object (int *from_ttyp
)
957 #endif /* SVR4_SHARED_LIBS */
962 current_sos -- build a list of currently loaded shared objects
966 struct so_list *current_sos ()
970 Build a list of `struct so_list' objects describing the shared
971 objects currently loaded in the inferior. This list does not
972 include an entry for the main executable file.
974 Note that we only gather information directly available from the
975 inferior --- we don't examine any of the shared library files
976 themselves. The declaration of `struct so_list' says which fields
977 we provide values for. */
979 static struct so_list
*
980 svr4_current_sos (void)
983 struct so_list
*head
= 0;
984 struct so_list
**link_ptr
= &head
;
986 /* Make sure we've looked up the inferior's dynamic linker's base
990 debug_base
= locate_base ();
992 /* If we can't find the dynamic linker's base structure, this
993 must not be a dynamically linked executable. Hmm. */
998 /* Walk the inferior's link map list, and build our list of
999 `struct so_list' nodes. */
1000 lm
= first_link_map_member ();
1003 struct link_map_offsets
*lmo
= SVR4_FETCH_LINK_MAP_OFFSETS ();
1005 = (struct so_list
*) xmalloc (sizeof (struct so_list
));
1006 struct cleanup
*old_chain
= make_cleanup (xfree
, new);
1008 memset (new, 0, sizeof (*new));
1010 new->lm_info
= xmalloc (sizeof (struct lm_info
));
1011 make_cleanup (xfree
, new->lm_info
);
1013 new->lm_info
->lm
= xmalloc (lmo
->link_map_size
);
1014 make_cleanup (xfree
, new->lm_info
->lm
);
1015 memset (new->lm_info
->lm
, 0, lmo
->link_map_size
);
1017 read_memory (lm
, new->lm_info
->lm
, lmo
->link_map_size
);
1021 /* For SVR4 versions, the first entry in the link map is for the
1022 inferior executable, so we must ignore it. For some versions of
1023 SVR4, it has no name. For others (Solaris 2.3 for example), it
1024 does have a name, so we can no longer use a missing name to
1025 decide when to ignore it. */
1026 if (IGNORE_FIRST_LINK_MAP_ENTRY (new))
1033 /* Extract this shared object's name. */
1034 target_read_string (LM_NAME (new), &buffer
,
1035 SO_NAME_MAX_PATH_SIZE
- 1, &errcode
);
1038 warning ("current_sos: Can't read pathname for load map: %s\n",
1039 safe_strerror (errcode
));
1043 strncpy (new->so_name
, buffer
, SO_NAME_MAX_PATH_SIZE
- 1);
1044 new->so_name
[SO_NAME_MAX_PATH_SIZE
- 1] = '\0';
1046 strcpy (new->so_original_name
, new->so_name
);
1049 /* If this entry has no name, or its name matches the name
1050 for the main executable, don't include it in the list. */
1051 if (! new->so_name
[0]
1052 || match_main (new->so_name
))
1058 link_ptr
= &new->next
;
1062 discard_cleanups (old_chain
);
1069 /* On some systems, the only way to recognize the link map entry for
1070 the main executable file is by looking at its name. Return
1071 non-zero iff SONAME matches one of the known main executable names. */
1074 match_main (char *soname
)
1078 for (mainp
= main_name_list
; *mainp
!= NULL
; mainp
++)
1080 if (strcmp (soname
, *mainp
) == 0)
1088 /* Return 1 if PC lies in the dynamic symbol resolution code of the
1089 SVR4 run time loader. */
1090 #ifdef SVR4_SHARED_LIBS
1091 static CORE_ADDR interp_text_sect_low
;
1092 static CORE_ADDR interp_text_sect_high
;
1093 static CORE_ADDR interp_plt_sect_low
;
1094 static CORE_ADDR interp_plt_sect_high
;
1097 svr4_in_dynsym_resolve_code (CORE_ADDR pc
)
1099 return ((pc
>= interp_text_sect_low
&& pc
< interp_text_sect_high
)
1100 || (pc
>= interp_plt_sect_low
&& pc
< interp_plt_sect_high
)
1101 || in_plt_section (pc
, NULL
));
1103 #else /* !SVR4_SHARED_LIBS */
1105 svr4_in_dynsym_resolve_code (CORE_ADDR pc
)
1109 #endif /* SVR4_SHARED_LIBS */
1115 disable_break -- remove the "mapping changed" breakpoint
1119 static int disable_break ()
1123 Removes the breakpoint that gets hit when the dynamic linker
1124 completes a mapping change.
1128 #ifndef SVR4_SHARED_LIBS
1131 disable_break (void)
1135 int in_debugger
= 0;
1137 /* Read the debugger structure from the inferior to retrieve the
1138 address of the breakpoint and the original contents of the
1139 breakpoint address. Remove the breakpoint by writing the original
1142 read_memory (debug_addr
, (char *) &debug_copy
, sizeof (debug_copy
));
1144 /* Set `in_debugger' to zero now. */
1146 write_memory (flag_addr
, (char *) &in_debugger
, sizeof (in_debugger
));
1148 breakpoint_addr
= SOLIB_EXTRACT_ADDRESS (debug_copy
.ldd_bp_addr
);
1149 write_memory (breakpoint_addr
, (char *) &debug_copy
.ldd_bp_inst
,
1150 sizeof (debug_copy
.ldd_bp_inst
));
1152 /* For the SVR4 version, we always know the breakpoint address. For the
1153 SunOS version we don't know it until the above code is executed.
1154 Grumble if we are stopped anywhere besides the breakpoint address. */
1156 if (stop_pc
!= breakpoint_addr
)
1158 warning ("stopped at unknown breakpoint while handling shared libraries");
1164 #endif /* #ifdef SVR4_SHARED_LIBS */
1170 enable_break -- arrange for dynamic linker to hit breakpoint
1174 int enable_break (void)
1178 Both the SunOS and the SVR4 dynamic linkers have, as part of their
1179 debugger interface, support for arranging for the inferior to hit
1180 a breakpoint after mapping in the shared libraries. This function
1181 enables that breakpoint.
1183 For SunOS, there is a special flag location (in_debugger) which we
1184 set to 1. When the dynamic linker sees this flag set, it will set
1185 a breakpoint at a location known only to itself, after saving the
1186 original contents of that place and the breakpoint address itself,
1187 in it's own internal structures. When we resume the inferior, it
1188 will eventually take a SIGTRAP when it runs into the breakpoint.
1189 We handle this (in a different place) by restoring the contents of
1190 the breakpointed location (which is only known after it stops),
1191 chasing around to locate the shared libraries that have been
1192 loaded, then resuming.
1194 For SVR4, the debugger interface structure contains a member (r_brk)
1195 which is statically initialized at the time the shared library is
1196 built, to the offset of a function (_r_debug_state) which is guaran-
1197 teed to be called once before mapping in a library, and again when
1198 the mapping is complete. At the time we are examining this member,
1199 it contains only the unrelocated offset of the function, so we have
1200 to do our own relocation. Later, when the dynamic linker actually
1201 runs, it relocates r_brk to be the actual address of _r_debug_state().
1203 The debugger interface structure also contains an enumeration which
1204 is set to either RT_ADD or RT_DELETE prior to changing the mapping,
1205 depending upon whether or not the library is being mapped or unmapped,
1206 and then set to RT_CONSISTENT after the library is mapped/unmapped.
1214 #ifndef SVR4_SHARED_LIBS
1219 /* Get link_dynamic structure */
1221 j
= target_read_memory (debug_base
, (char *) &dynamic_copy
,
1222 sizeof (dynamic_copy
));
1229 /* Calc address of debugger interface structure */
1231 debug_addr
= SOLIB_EXTRACT_ADDRESS (dynamic_copy
.ldd
);
1233 /* Calc address of `in_debugger' member of debugger interface structure */
1235 flag_addr
= debug_addr
+ (CORE_ADDR
) ((char *) &debug_copy
.ldd_in_debugger
-
1236 (char *) &debug_copy
);
1238 /* Write a value of 1 to this member. */
1241 write_memory (flag_addr
, (char *) &in_debugger
, sizeof (in_debugger
));
1244 #else /* SVR4_SHARED_LIBS */
1246 #ifdef BKPT_AT_SYMBOL
1248 struct minimal_symbol
*msymbol
;
1250 asection
*interp_sect
;
1252 /* First, remove all the solib event breakpoints. Their addresses
1253 may have changed since the last time we ran the program. */
1254 remove_solib_event_breakpoints ();
1256 #ifdef SVR4_SHARED_LIBS
1257 interp_text_sect_low
= interp_text_sect_high
= 0;
1258 interp_plt_sect_low
= interp_plt_sect_high
= 0;
1260 /* Find the .interp section; if not found, warn the user and drop
1261 into the old breakpoint at symbol code. */
1262 interp_sect
= bfd_get_section_by_name (exec_bfd
, ".interp");
1265 unsigned int interp_sect_size
;
1267 CORE_ADDR load_addr
;
1268 bfd
*tmp_bfd
= NULL
;
1270 char *tmp_pathname
= NULL
;
1271 CORE_ADDR sym_addr
= 0;
1273 /* Read the contents of the .interp section into a local buffer;
1274 the contents specify the dynamic linker this program uses. */
1275 interp_sect_size
= bfd_section_size (exec_bfd
, interp_sect
);
1276 buf
= alloca (interp_sect_size
);
1277 bfd_get_section_contents (exec_bfd
, interp_sect
,
1278 buf
, 0, interp_sect_size
);
1280 /* Now we need to figure out where the dynamic linker was
1281 loaded so that we can load its symbols and place a breakpoint
1282 in the dynamic linker itself.
1284 This address is stored on the stack. However, I've been unable
1285 to find any magic formula to find it for Solaris (appears to
1286 be trivial on GNU/Linux). Therefore, we have to try an alternate
1287 mechanism to find the dynamic linker's base address. */
1289 tmp_fd
= solib_open (buf
, &tmp_pathname
);
1291 tmp_bfd
= bfd_fdopenr (tmp_pathname
, gnutarget
, tmp_fd
);
1293 if (tmp_bfd
== NULL
)
1294 goto bkpt_at_symbol
;
1296 /* Make sure the dynamic linker's really a useful object. */
1297 if (!bfd_check_format (tmp_bfd
, bfd_object
))
1299 warning ("Unable to grok dynamic linker %s as an object file", buf
);
1300 bfd_close (tmp_bfd
);
1301 goto bkpt_at_symbol
;
1304 /* We find the dynamic linker's base address by examining the
1305 current pc (which point at the entry point for the dynamic
1306 linker) and subtracting the offset of the entry point. */
1307 load_addr
= read_pc () - tmp_bfd
->start_address
;
1309 /* Record the relocated start and end address of the dynamic linker
1310 text and plt section for svr4_in_dynsym_resolve_code. */
1311 interp_sect
= bfd_get_section_by_name (tmp_bfd
, ".text");
1314 interp_text_sect_low
=
1315 bfd_section_vma (tmp_bfd
, interp_sect
) + load_addr
;
1316 interp_text_sect_high
=
1317 interp_text_sect_low
+ bfd_section_size (tmp_bfd
, interp_sect
);
1319 interp_sect
= bfd_get_section_by_name (tmp_bfd
, ".plt");
1322 interp_plt_sect_low
=
1323 bfd_section_vma (tmp_bfd
, interp_sect
) + load_addr
;
1324 interp_plt_sect_high
=
1325 interp_plt_sect_low
+ bfd_section_size (tmp_bfd
, interp_sect
);
1328 /* Now try to set a breakpoint in the dynamic linker. */
1329 for (bkpt_namep
= solib_break_names
; *bkpt_namep
!= NULL
; bkpt_namep
++)
1331 sym_addr
= bfd_lookup_symbol (tmp_bfd
, *bkpt_namep
);
1336 /* We're done with the temporary bfd. */
1337 bfd_close (tmp_bfd
);
1341 create_solib_event_breakpoint (load_addr
+ sym_addr
);
1345 /* For whatever reason we couldn't set a breakpoint in the dynamic
1346 linker. Warn and drop into the old code. */
1348 warning ("Unable to find dynamic linker breakpoint function.\nGDB will be unable to debug shared library initializers\nand track explicitly loaded dynamic code.");
1352 /* Scan through the list of symbols, trying to look up the symbol and
1353 set a breakpoint there. Terminate loop when we/if we succeed. */
1355 breakpoint_addr
= 0;
1356 for (bkpt_namep
= bkpt_names
; *bkpt_namep
!= NULL
; bkpt_namep
++)
1358 msymbol
= lookup_minimal_symbol (*bkpt_namep
, NULL
, symfile_objfile
);
1359 if ((msymbol
!= NULL
) && (SYMBOL_VALUE_ADDRESS (msymbol
) != 0))
1361 create_solib_event_breakpoint (SYMBOL_VALUE_ADDRESS (msymbol
));
1366 /* Nothing good happened. */
1369 #endif /* BKPT_AT_SYMBOL */
1371 #endif /* !SVR4_SHARED_LIBS */
1380 special_symbol_handling -- additional shared library symbol handling
1384 void special_symbol_handling ()
1388 Once the symbols from a shared object have been loaded in the usual
1389 way, we are called to do any system specific symbol handling that
1392 For SunOS4, this consists of grunging around in the dynamic
1393 linkers structures to find symbol definitions for "common" symbols
1394 and adding them to the minimal symbol table for the runtime common
1400 svr4_special_symbol_handling (void)
1402 #ifndef SVR4_SHARED_LIBS
1405 if (debug_addr
== 0)
1407 /* Get link_dynamic structure */
1409 j
= target_read_memory (debug_base
, (char *) &dynamic_copy
,
1410 sizeof (dynamic_copy
));
1417 /* Calc address of debugger interface structure */
1418 /* FIXME, this needs work for cross-debugging of core files
1419 (byteorder, size, alignment, etc). */
1421 debug_addr
= SOLIB_EXTRACT_ADDRESS (dynamic_copy
.ldd
);
1424 /* Read the debugger structure from the inferior, just to make sure
1425 we have a current copy. */
1427 j
= target_read_memory (debug_addr
, (char *) &debug_copy
,
1428 sizeof (debug_copy
));
1430 return; /* unreadable */
1432 /* Get common symbol definitions for the loaded object. */
1434 if (debug_copy
.ldd_cp
)
1436 solib_add_common_symbols (SOLIB_EXTRACT_ADDRESS (debug_copy
.ldd_cp
));
1439 #endif /* !SVR4_SHARED_LIBS */
1442 /* Relocate the main executable. This function should be called upon
1443 stopping the inferior process at the entry point to the program.
1444 The entry point from BFD is compared to the PC and if they are
1445 different, the main executable is relocated by the proper amount.
1447 As written it will only attempt to relocate executables which
1448 lack interpreter sections. It seems likely that only dynamic
1449 linker executables will get relocated, though it should work
1450 properly for a position-independent static executable as well. */
1453 svr4_relocate_main_executable (void)
1455 asection
*interp_sect
;
1456 CORE_ADDR pc
= read_pc ();
1458 /* Decide if the objfile needs to be relocated. As indicated above,
1459 we will only be here when execution is stopped at the beginning
1460 of the program. Relocation is necessary if the address at which
1461 we are presently stopped differs from the start address stored in
1462 the executable AND there's no interpreter section. The condition
1463 regarding the interpreter section is very important because if
1464 there *is* an interpreter section, execution will begin there
1465 instead. When there is an interpreter section, the start address
1466 is (presumably) used by the interpreter at some point to start
1467 execution of the program.
1469 If there is an interpreter, it is normal for it to be set to an
1470 arbitrary address at the outset. The job of finding it is
1471 handled in enable_break().
1473 So, to summarize, relocations are necessary when there is no
1474 interpreter section and the start address obtained from the
1475 executable is different from the address at which GDB is
1478 [ The astute reader will note that we also test to make sure that
1479 the executable in question has the DYNAMIC flag set. It is my
1480 opinion that this test is unnecessary (undesirable even). It
1481 was added to avoid inadvertent relocation of an executable
1482 whose e_type member in the ELF header is not ET_DYN. There may
1483 be a time in the future when it is desirable to do relocations
1484 on other types of files as well in which case this condition
1485 should either be removed or modified to accomodate the new file
1486 type. (E.g, an ET_EXEC executable which has been built to be
1487 position-independent could safely be relocated by the OS if
1488 desired. It is true that this violates the ABI, but the ABI
1489 has been known to be bent from time to time.) - Kevin, Nov 2000. ]
1492 interp_sect
= bfd_get_section_by_name (exec_bfd
, ".interp");
1493 if (interp_sect
== NULL
1494 && (bfd_get_file_flags (exec_bfd
) & DYNAMIC
) != 0
1495 && bfd_get_start_address (exec_bfd
) != pc
)
1497 struct cleanup
*old_chain
;
1498 struct section_offsets
*new_offsets
;
1500 CORE_ADDR displacement
;
1502 /* It is necessary to relocate the objfile. The amount to
1503 relocate by is simply the address at which we are stopped
1504 minus the starting address from the executable.
1506 We relocate all of the sections by the same amount. This
1507 behavior is mandated by recent editions of the System V ABI.
1508 According to the System V Application Binary Interface,
1509 Edition 4.1, page 5-5:
1511 ... Though the system chooses virtual addresses for
1512 individual processes, it maintains the segments' relative
1513 positions. Because position-independent code uses relative
1514 addressesing between segments, the difference between
1515 virtual addresses in memory must match the difference
1516 between virtual addresses in the file. The difference
1517 between the virtual address of any segment in memory and
1518 the corresponding virtual address in the file is thus a
1519 single constant value for any one executable or shared
1520 object in a given process. This difference is the base
1521 address. One use of the base address is to relocate the
1522 memory image of the program during dynamic linking.
1524 The same language also appears in Edition 4.0 of the System V
1525 ABI and is left unspecified in some of the earlier editions. */
1527 displacement
= pc
- bfd_get_start_address (exec_bfd
);
1530 new_offsets
= xcalloc (sizeof (struct section_offsets
),
1531 symfile_objfile
->num_sections
);
1532 old_chain
= make_cleanup (xfree
, new_offsets
);
1534 for (i
= 0; i
< symfile_objfile
->num_sections
; i
++)
1536 if (displacement
!= ANOFFSET (symfile_objfile
->section_offsets
, i
))
1538 new_offsets
->offsets
[i
] = displacement
;
1542 objfile_relocate (symfile_objfile
, new_offsets
);
1544 do_cleanups (old_chain
);
1552 svr4_solib_create_inferior_hook -- shared library startup support
1556 void svr4_solib_create_inferior_hook()
1560 When gdb starts up the inferior, it nurses it along (through the
1561 shell) until it is ready to execute it's first instruction. At this
1562 point, this function gets called via expansion of the macro
1563 SOLIB_CREATE_INFERIOR_HOOK.
1565 For SunOS executables, this first instruction is typically the
1566 one at "_start", or a similar text label, regardless of whether
1567 the executable is statically or dynamically linked. The runtime
1568 startup code takes care of dynamically linking in any shared
1569 libraries, once gdb allows the inferior to continue.
1571 For SVR4 executables, this first instruction is either the first
1572 instruction in the dynamic linker (for dynamically linked
1573 executables) or the instruction at "start" for statically linked
1574 executables. For dynamically linked executables, the system
1575 first exec's /lib/libc.so.N, which contains the dynamic linker,
1576 and starts it running. The dynamic linker maps in any needed
1577 shared libraries, maps in the actual user executable, and then
1578 jumps to "start" in the user executable.
1580 For both SunOS shared libraries, and SVR4 shared libraries, we
1581 can arrange to cooperate with the dynamic linker to discover the
1582 names of shared libraries that are dynamically linked, and the
1583 base addresses to which they are linked.
1585 This function is responsible for discovering those names and
1586 addresses, and saving sufficient information about them to allow
1587 their symbols to be read at a later time.
1591 Between enable_break() and disable_break(), this code does not
1592 properly handle hitting breakpoints which the user might have
1593 set in the startup code or in the dynamic linker itself. Proper
1594 handling will probably have to wait until the implementation is
1595 changed to use the "breakpoint handler function" method.
1597 Also, what if child has exit()ed? Must exit loop somehow.
1601 svr4_solib_create_inferior_hook (void)
1603 /* Relocate the main executable if necessary. */
1604 svr4_relocate_main_executable ();
1606 /* If we are using the BKPT_AT_SYMBOL code, then we don't need the base
1607 yet. In fact, in the case of a SunOS4 executable being run on
1608 Solaris, we can't get it yet. current_sos will get it when it needs
1610 #if !(defined (SVR4_SHARED_LIBS) && defined (BKPT_AT_SYMBOL))
1611 if ((debug_base
= locate_base ()) == 0)
1613 /* Can't find the symbol or the executable is statically linked. */
1618 if (!enable_break ())
1620 warning ("shared library handler failed to enable breakpoint");
1624 #if !defined(SVR4_SHARED_LIBS) || defined(_SCO_DS)
1625 /* SCO and SunOS need the loop below, other systems should be using the
1626 special shared library breakpoints and the shared library breakpoint
1629 Now run the target. It will eventually hit the breakpoint, at
1630 which point all of the libraries will have been mapped in and we
1631 can go groveling around in the dynamic linker structures to find
1632 out what we need to know about them. */
1634 clear_proceed_status ();
1635 stop_soon_quietly
= 1;
1636 stop_signal
= TARGET_SIGNAL_0
;
1639 target_resume (-1, 0, stop_signal
);
1640 wait_for_inferior ();
1642 while (stop_signal
!= TARGET_SIGNAL_TRAP
);
1643 stop_soon_quietly
= 0;
1645 #if !defined(_SCO_DS)
1646 /* We are now either at the "mapping complete" breakpoint (or somewhere
1647 else, a condition we aren't prepared to deal with anyway), so adjust
1648 the PC as necessary after a breakpoint, disable the breakpoint, and
1649 add any shared libraries that were mapped in. */
1651 if (DECR_PC_AFTER_BREAK
)
1653 stop_pc
-= DECR_PC_AFTER_BREAK
;
1654 write_register (PC_REGNUM
, stop_pc
);
1657 if (!disable_break ())
1659 warning ("shared library handler failed to disable breakpoint");
1663 solib_add ((char *) 0, 0, (struct target_ops
*) 0);
1664 #endif /* ! _SCO_DS */
1669 svr4_clear_solib (void)
1675 svr4_free_so (struct so_list
*so
)
1677 xfree (so
->lm_info
->lm
);
1678 xfree (so
->lm_info
);
1682 svr4_relocate_section_addresses (struct so_list
*so
,
1683 struct section_table
*sec
)
1685 sec
->addr
+= LM_ADDR (so
);
1686 sec
->endaddr
+= LM_ADDR (so
);
1689 static struct target_so_ops svr4_so_ops
;
1692 _initialize_svr4_solib (void)
1694 svr4_so_ops
.relocate_section_addresses
= svr4_relocate_section_addresses
;
1695 svr4_so_ops
.free_so
= svr4_free_so
;
1696 svr4_so_ops
.clear_solib
= svr4_clear_solib
;
1697 svr4_so_ops
.solib_create_inferior_hook
= svr4_solib_create_inferior_hook
;
1698 svr4_so_ops
.special_symbol_handling
= svr4_special_symbol_handling
;
1699 svr4_so_ops
.current_sos
= svr4_current_sos
;
1700 svr4_so_ops
.open_symbol_file_object
= open_symbol_file_object
;
1701 svr4_so_ops
.open_symbol_file_object
= open_symbol_file_object
;
1702 svr4_so_ops
.in_dynsym_resolve_code
= svr4_in_dynsym_resolve_code
;
1704 /* FIXME: Don't do this here. *_gdbarch_init() should set so_ops. */
1705 current_target_so_ops
= &svr4_so_ops
;