1 /* Handle SunOS and SVR4 shared libraries for GDB, the GNU Debugger.
2 Copyright 1990, 1991 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
21 #include <sys/types.h>
25 #include <sys/param.h>
39 extern char *getenv ();
40 extern char *elf_interpreter (); /* Interpreter name from exec file */
41 extern char *re_comp ();
43 #define MAX_PATH_SIZE 256 /* FIXME: Should be dynamic */
45 /* On SVR4 systems, for the initial implementation, use main() as the
46 "startup mapping complete" breakpoint address. The models for SunOS
47 and SVR4 dynamic linking debugger support are different in that SunOS
48 hits one breakpoint when all mapping is complete while using the SVR4
49 debugger support takes two breakpoint hits for each file mapped, and
50 there is no way to know when the "last" one is hit. Both these
51 mechanisms should be tied to a "breakpoint service routine" that
52 gets automatically executed whenever one of the breakpoints indicating
53 a change in mapping is hit. This is a future enhancement. (FIXME) */
55 #define BKPT_AT_MAIN 1
57 /* local data declarations */
59 #ifndef SVR4_SHARED_LIBS
61 #define DEBUG_BASE "_DYNAMIC"
62 #define LM_ADDR(so) ((so) -> lm.lm_addr)
63 #define LM_NEXT(so) ((so) -> lm.lm_next)
64 #define LM_NAME(so) ((so) -> lm.lm_name)
65 static struct link_dynamic dynamic_copy
;
66 static struct link_dynamic_2 ld_2_copy
;
67 static struct ld_debug debug_copy
;
68 static CORE_ADDR debug_addr
;
69 static CORE_ADDR flag_addr
;
71 #else /* SVR4_SHARED_LIBS */
73 #define DEBUG_BASE "_r_debug"
74 #define LM_ADDR(so) ((so) -> lm.l_addr)
75 #define LM_NEXT(so) ((so) -> lm.l_next)
76 #define LM_NAME(so) ((so) -> lm.l_name)
77 static struct r_debug debug_copy
;
78 char shadow_contents
[BREAKPOINT_MAX
]; /* Stash old bkpt addr contents */
79 extern CORE_ADDR
proc_base_address ();
80 extern int proc_address_to_fd ();
82 #endif /* !SVR4_SHARED_LIBS */
85 struct so_list
*next
; /* next structure in linked list */
86 struct link_map lm
; /* copy of link map from inferior */
87 struct link_map
*lmaddr
; /* addr in inferior lm was read from */
88 CORE_ADDR lmend
; /* upper addr bound of mapped object */
89 char so_name
[MAX_PATH_SIZE
]; /* shared object lib name (FIXME) */
90 char symbols_loaded
; /* flag: symbols read in yet? */
91 char from_tty
; /* flag: print msgs? */
92 bfd
*so_bfd
; /* bfd for so_name */
93 struct section_table
*sections
;
94 struct section_table
*sections_end
;
97 static struct so_list
*so_list_head
; /* List of known shared objects */
98 static CORE_ADDR debug_base
; /* Base of dynamic linker structures */
99 static CORE_ADDR breakpoint_addr
; /* Address where end bkpt is set */
106 solib_map_sections -- open bfd and build sections for shared lib
110 static void solib_map_sections (struct so_list *so)
114 Given a pointer to one of the shared objects in our list
115 of mapped objects, use the recorded name to open a bfd
116 descriptor for the object, build a section table, and then
117 relocate all the section addresses by the base address at
118 which the shared object was mapped.
122 In most (all?) cases the shared object file name recorded in the
123 dynamic linkage tables will be a fully qualified pathname. For
124 cases where it isn't, do we really mimic the systems search
125 mechanism correctly in the below code (particularly the tilde
130 solib_map_sections (so
)
134 char *scratch_pathname
;
136 struct section_table
*p
;
138 filename
= tilde_expand (so
-> so_name
);
139 make_cleanup (free
, filename
);
141 scratch_chan
= openp (getenv ("PATH"), 1, filename
, O_RDONLY
, 0,
143 if (scratch_chan
< 0)
145 scratch_chan
= openp (getenv ("LD_LIBRARY_PATH"), 1, filename
,
146 O_RDONLY
, 0, &scratch_pathname
);
148 if (scratch_chan
< 0)
150 perror_with_name (filename
);
153 so
-> so_bfd
= bfd_fdopenr (scratch_pathname
, NULL
, scratch_chan
);
156 error ("Could not open `%s' as an executable file: %s",
157 scratch_pathname
, bfd_errmsg (bfd_error
));
159 if (!bfd_check_format (so
-> so_bfd
, bfd_object
))
161 error ("\"%s\": not in executable format: %s.",
162 scratch_pathname
, bfd_errmsg (bfd_error
));
164 if (build_section_table (so
-> so_bfd
, &so
-> sections
, &so
-> sections_end
))
166 error ("Can't find the file sections in `%s': %s",
167 exec_bfd
-> filename
, bfd_errmsg (bfd_error
));
170 for (p
= so
-> sections
; p
< so
-> sections_end
; p
++)
172 /* Relocate the section binding addresses as recorded in the shared
173 object's file by the base address to which the object was actually
175 p
-> addr
+= (CORE_ADDR
) LM_ADDR (so
);
176 p
-> endaddr
+= (CORE_ADDR
) LM_ADDR (so
);
177 so
-> lmend
= (CORE_ADDR
) max (p
-> endaddr
, so
-> lmend
);
181 /* Read all dynamically loaded common symbol definitions from the inferior
182 and add them to the misc_function_vector. */
185 solib_add_common_symbols (rtc_symp
)
186 struct rtc_symb
*rtc_symp
;
188 struct rtc_symb inferior_rtc_symb
;
189 struct nlist inferior_rtc_nlist
;
190 extern void discard_misc_bunches();
192 init_misc_bunches ();
193 make_cleanup (discard_misc_bunches
, 0);
197 read_memory((CORE_ADDR
)rtc_symp
,
199 sizeof(inferior_rtc_symb
));
200 read_memory((CORE_ADDR
)inferior_rtc_symb
.rtc_sp
,
202 sizeof(inferior_rtc_nlist
));
203 if (inferior_rtc_nlist
.n_type
== N_COMM
)
205 /* FIXME: The length of the symbol name is not available, but in the
206 current implementation the common symbol is allocated immediately
207 behind the name of the symbol. */
208 int len
= inferior_rtc_nlist
.n_value
- inferior_rtc_nlist
.n_un
.n_strx
;
209 char *name
, *origname
;
211 origname
= name
= xmalloc (len
);
212 read_memory((CORE_ADDR
)inferior_rtc_nlist
.n_un
.n_name
, name
, len
);
214 /* Don't enter the symbol twice if the target is re-run. */
216 #ifdef NAMES_HAVE_UNDERSCORE
220 if (lookup_misc_func (name
) < 0)
221 prim_record_misc_function (obsavestring (name
, strlen (name
)),
222 inferior_rtc_nlist
.n_value
,
226 rtc_symp
= inferior_rtc_symb
.rtc_next
;
229 condense_misc_bunches (1);
236 bfd_lookup_symbol -- lookup the value for a specific symbol
240 CORE_ADDR bfd_lookup_symbol (bfd *abfd, char *symname)
244 An expensive way to lookup the value of a single symbol for
245 bfd's that are only temporary anyway. This is used by the
246 shared library support to find the address of the debugger
247 interface structures in the shared library.
249 Note that 0 is specifically allowed as an error return (no
252 FIXME: See if there is a less "expensive" way of doing this.
253 Also see if there is already another bfd or gdb function
254 that specifically does this, and if so, use it.
258 DEFUN (bfd_lookup_symbol
, (abfd
, symname
),
262 unsigned int storage_needed
;
264 asymbol
**symbol_table
;
265 unsigned int number_of_symbols
;
267 struct cleanup
*back_to
;
268 CORE_ADDR symaddr
= 0;
269 enum misc_function_type mf_type
;
271 storage_needed
= get_symtab_upper_bound (abfd
);
273 if (storage_needed
> 0)
275 symbol_table
= (asymbol
**) bfd_xmalloc (storage_needed
);
276 back_to
= make_cleanup (free
, symbol_table
);
277 number_of_symbols
= bfd_canonicalize_symtab (abfd
, symbol_table
);
279 for (i
= 0; i
< number_of_symbols
; i
++)
281 sym
= *symbol_table
++;
282 if (strcmp (sym
-> name
, symname
) == 0)
284 symaddr
= sym
-> value
;
288 do_cleanups (back_to
);
297 look_for_base -- examine file for each mapped address segment
301 static int look_for_base (int fd, CORE_ADDR baseaddr)
305 This function is passed to proc_iterate_over_mappings, which
306 causes it to get called once for each mapped address space, with
307 an open file descriptor for the file mapped to that space, and the
308 base address of that mapped space.
310 Our job is to find the symbol DEBUG_BASE in the file that this
311 fd is open on, if it exists, and if so, initialize the dynamic
312 linker structure base address debug_base.
314 Note that this is a computationally expensive proposition, since
315 we basically have to open a bfd on every call, so we specifically
316 avoid opening the exec file.
320 DEFUN (look_for_base
, (fd
, baseaddr
),
327 /* If the fd is -1, then there is no file that corresponds to this
328 mapped memory segment, so skip it. Also, if the fd corresponds
329 to the exec file, skip it as well. */
331 if ((fd
== -1) || fdmatch (fileno ((FILE *)(exec_bfd
-> iostream
)), fd
))
336 /* Try to open whatever random file this fd corresponds to. Note that
337 we have no way currently to find the filename. Don't gripe about
338 any problems we might have, just fail. */
340 if ((interp_bfd
= bfd_fdopenr ("unnamed", NULL
, fd
)) == NULL
)
344 if (!bfd_check_format (interp_bfd
, bfd_object
))
346 bfd_close (interp_bfd
);
350 /* Now try to find our DEBUG_BASE symbol in this file, which we at
351 least know to be a valid ELF executable or shared library. */
353 if ((address
= bfd_lookup_symbol (interp_bfd
, DEBUG_BASE
)) == 0)
355 bfd_close (interp_bfd
);
359 /* Eureka! We found the symbol. But now we may need to relocate it
360 by the base address. If the symbol's value is less than the base
361 address of the shared library, then it hasn't yet been relocated
362 by the dynamic linker, and we have to do it ourself. FIXME: Note
363 that we make the assumption that the first segment that corresponds
364 to the shared library has the base address to which the library
367 if (address
< baseaddr
)
371 debug_base
= address
;
372 bfd_close (interp_bfd
);
380 locate_base -- locate the base address of dynamic linker structs
384 CORE_ADDR locate_base (void)
388 For both the SunOS and SVR4 shared library implementations, if the
389 inferior executable has been linked dynamically, there is a single
390 address somewhere in the inferior's data space which is the key to
391 locating all of the dynamic linker's runtime structures. This
392 address is the value of the symbol defined by the macro DEBUG_BASE.
393 The job of this function is to find and return that address, or to
394 return 0 if there is no such address (the executable is statically
397 For SunOS, the job is almost trivial, since the dynamic linker and
398 all of it's structures are statically linked to the executable at
399 link time. Thus the symbol for the address we are looking for has
400 already been added to the misc function vector at the time the symbol
401 file's symbols were read, and all we have to do is look it up there.
403 The SVR4 version is much more complicated because the dynamic linker
404 and it's structures are located in the shared C library, which gets
405 run as the executable's "interpreter" by the kernel. We have to go
406 to a lot more work to discover the address of DEBUG_BASE. Because
407 of this complexity, we cache the value we find and return that value
408 on subsequent invocations.
410 Note that we can assume nothing about the process state at the time
411 we need to find this address. We may be stopped on the first instruc-
412 tion of the interpreter (C shared library), the first instruction of
413 the executable itself, or somewhere else entirely (if we attached
414 to the process for example).
422 #ifndef SVR4_SHARED_LIBS
425 CORE_ADDR address
= 0;
427 i
= lookup_misc_func (DEBUG_BASE
);
428 if (i
>= 0 && misc_function_vector
[i
].address
!= 0)
430 address
= misc_function_vector
[i
].address
;
434 #else /* SVR4_SHARED_LIBS */
436 /* Check to see if we have a currently valid address, and if so, avoid
437 doing all this work again and just return the cached address. If
438 we have no cached address, ask the /proc support interface to iterate
439 over the list of mapped address segments, calling look_for_base() for
440 each segment. When we are done, we will have either found the base
445 proc_iterate_over_mappings (look_for_base
);
449 #endif /* !SVR4_SHARED_LIBS */
453 static struct link_map
*
454 first_link_map_member ()
456 struct link_map
*lm
= NULL
;
458 #ifndef SVR4_SHARED_LIBS
460 read_memory (debug_base
, &dynamic_copy
, sizeof (dynamic_copy
));
461 if (dynamic_copy
.ld_version
>= 2)
463 /* It is a version that we can deal with, so read in the secondary
464 structure and find the address of the link map list from it. */
465 read_memory ((CORE_ADDR
) dynamic_copy
.ld_un
.ld_2
, &ld_2_copy
,
466 sizeof (struct link_dynamic_2
));
467 lm
= ld_2_copy
.ld_loaded
;
470 #else /* SVR4_SHARED_LIBS */
472 read_memory (debug_base
, &debug_copy
, sizeof (struct r_debug
));
473 lm
= debug_copy
.r_map
;
475 #endif /* !SVR4_SHARED_LIBS */
484 find_solib -- step through list of shared objects
488 struct so_list *find_solib (struct so_list *so_list_ptr)
492 This module contains the routine which finds the names of any
493 loaded "images" in the current process. The argument in must be
494 NULL on the first call, and then the returned value must be passed
495 in on subsequent calls. This provides the capability to "step" down
496 the list of loaded objects. On the last object, a NULL value is
499 The arg and return value are "struct link_map" pointers, as defined
504 find_solib (so_list_ptr
)
505 struct so_list
*so_list_ptr
; /* Last lm or NULL for first one */
507 struct so_list
*so_list_next
= NULL
;
508 struct link_map
*lm
= NULL
;
511 if (so_list_ptr
== NULL
)
513 /* We are setting up for a new scan through the loaded images. */
514 if ((so_list_next
= so_list_head
) == NULL
)
516 /* We have not already read in the dynamic linking structures
517 from the inferior, lookup the address of the base structure. */
518 debug_base
= locate_base ();
521 /* Read the base structure in and find the address of the first
522 link map list member. */
523 lm
= first_link_map_member ();
529 /* We have been called before, and are in the process of walking
530 the shared library list. Advance to the next shared object. */
531 if ((lm
= LM_NEXT (so_list_ptr
)) == NULL
)
533 /* We have hit the end of the list, so check to see if any were
534 added, but be quiet if we can't read from the target any more. */
535 int status
= target_read_memory ((CORE_ADDR
) so_list_ptr
-> lmaddr
,
536 (char *) &(so_list_ptr
-> lm
),
537 sizeof (struct link_map
));
540 lm
= LM_NEXT (so_list_ptr
);
547 so_list_next
= so_list_ptr
-> next
;
549 if ((so_list_next
== NULL
) && (lm
!= NULL
))
551 /* Get next link map structure from inferior image and build a local
552 abbreviated load_map structure */
553 new = (struct so_list
*) xmalloc (sizeof (struct so_list
));
554 (void) memset ((char *) new, 0, sizeof (struct so_list
));
556 /* Add the new node as the next node in the list, or as the root
557 node if this is the first one. */
558 if (so_list_ptr
!= NULL
)
560 so_list_ptr
-> next
= new;
567 read_memory ((CORE_ADDR
) lm
, &(new -> lm
), sizeof (struct link_map
));
568 /* For the SVR4 version, there is one entry that has no name
569 (for the inferior executable) since it is not a shared object. */
570 if (LM_NAME (new) != 0)
572 (void) target_read_string((CORE_ADDR
) LM_NAME (new), new -> so_name
,
574 new -> so_name
[MAX_PATH_SIZE
- 1] = 0;
575 solib_map_sections (new);
578 return (so_list_next
);
581 /* A small stub to get us past the arg-passing pinhole of catch_errors. */
584 symbol_add_stub (arg
)
587 register struct so_list
*so
= (struct so_list
*) arg
; /* catch_errs bogon */
589 symbol_file_add (so
-> so_name
, so
-> from_tty
,
590 (unsigned int) LM_ADDR (so
), 0);
598 solib_add -- add a shared library file to the symtab and section list
602 void solib_add (char *arg_string, int from_tty,
603 struct target_ops *target)
610 solib_add (arg_string
, from_tty
, target
)
613 struct target_ops
*target
;
615 register struct so_list
*so
= NULL
; /* link map state variable */
620 if ((re_err
= re_comp (arg_string
? arg_string
: ".")) != NULL
)
622 error ("Invalid regexp: %s", re_err
);
625 /* Getting new symbols may change our opinion about what is
627 reinit_frame_cache ();
629 while ((so
= find_solib (so
)) != NULL
)
631 if (so
-> so_name
[0] && re_exec (so
-> so_name
))
633 if (so
-> symbols_loaded
)
637 printf ("Symbols already loaded for %s\n", so
-> so_name
);
642 so
-> symbols_loaded
= 1;
643 so
-> from_tty
= from_tty
;
644 catch_errors (symbol_add_stub
, (char *) so
,
645 "Error while reading shared library symbols:\n");
650 /* Now add the shared library sections to the section table of the
651 specified target, if any. */
654 /* Count how many new section_table entries there are. */
657 while ((so
= find_solib (so
)) != NULL
)
659 if (so
-> so_name
[0])
661 count
+= so
-> sections_end
- so
-> sections
;
667 /* Reallocate the target's section table including the new size. */
668 if (target
-> sections
)
670 old
= target
-> sections_end
- target
-> sections
;
671 target
-> sections
= (struct section_table
*)
672 realloc ((char *)target
-> sections
,
673 (sizeof (struct section_table
)) * (count
+ old
));
678 target
-> sections
= (struct section_table
*)
679 malloc ((sizeof (struct section_table
)) * count
);
681 target
-> sections_end
= target
-> sections
+ (count
+ old
);
683 /* Add these section table entries to the target's table. */
684 while ((so
= find_solib (so
)) != NULL
)
686 if (so
-> so_name
[0])
688 count
= so
-> sections_end
- so
-> sections
;
689 bcopy (so
-> sections
, (char *)(target
-> sections
+ old
),
690 (sizeof (struct section_table
)) * count
);
702 info_sharedlibrary_command -- code for "info sharedlibrary"
706 static void info_sharedlibrary_command ()
710 Walk through the shared library list and print information
711 about each attached library.
715 info_sharedlibrary_command ()
717 register struct so_list
*so
= NULL
; /* link map state variable */
720 if (exec_bfd
== NULL
)
722 printf ("No exec file.\n");
725 while ((so
= find_solib (so
)) != NULL
)
727 if (so
-> so_name
[0])
731 printf("%-12s%-12s%-12s%s\n", "From", "To", "Syms Read",
732 "Shared Object Library");
735 printf ("%-12s", local_hex_string_custom (LM_ADDR (so
), "08"));
736 printf ("%-12s", local_hex_string_custom (so
-> lmend
, "08"));
737 printf ("%-12s", so
-> symbols_loaded
? "Yes" : "No");
738 printf ("%s\n", so
-> so_name
);
741 if (so_list_head
== NULL
)
743 printf ("No shared libraries loaded at this time.\n");
751 solib_address -- check to see if an address is in a shared lib
755 int solib_address (CORE_ADDR address)
759 Provides a hook for other gdb routines to discover whether or
760 not a particular address is within the mapped address space of
761 a shared library. Any address between the base mapping address
762 and the first address beyond the end of the last mapping, is
763 considered to be within the shared library address space, for
766 For example, this routine is called at one point to disable
767 breakpoints which are in shared libraries that are not currently
772 solib_address (address
)
775 register struct so_list
*so
= 0; /* link map state variable */
777 while ((so
= find_solib (so
)) != NULL
)
779 if (so
-> so_name
[0])
781 if ((address
>= (CORE_ADDR
) LM_ADDR (so
)) &&
782 (address
< (CORE_ADDR
) so
-> lmend
))
791 /* Called by free_all_symtabs */
796 struct so_list
*next
;
800 if (so_list_head
-> sections
)
802 free (so_list_head
-> sections
);
804 if (so_list_head
-> so_bfd
)
806 bfd_close (so_list_head
-> so_bfd
);
808 next
= so_list_head
-> next
;
819 disable_break -- remove the "mapping changed" breakpoint
823 static int disable_break ()
827 Removes the breakpoint that gets hit when the dynamic linker
828 completes a mapping change.
837 #ifndef SVR4_SHARED_LIBS
841 /* Read the debugger structure from the inferior to retrieve the
842 address of the breakpoint and the original contents of the
843 breakpoint address. Remove the breakpoint by writing the original
846 read_memory (debug_addr
, &debug_copy
, sizeof (debug_copy
));
848 /* Get common symbol definitions for the loaded object. */
849 if (debug_copy
.ldd_cp
)
850 solib_add_common_symbols (debug_copy
.ldd_cp
);
852 /* Set `in_debugger' to zero now. */
854 write_memory (flag_addr
, &in_debugger
, sizeof (in_debugger
));
856 breakpoint_addr
= (CORE_ADDR
) debug_copy
.ldd_bp_addr
;
857 write_memory (breakpoint_addr
, &debug_copy
.ldd_bp_inst
,
858 sizeof (debug_copy
.ldd_bp_inst
));
860 #else /* SVR4_SHARED_LIBS */
862 /* Note that breakpoint address and original contents are in our address
863 space, so we just need to write the original contents back. */
865 if (memory_remove_breakpoint (breakpoint_addr
, shadow_contents
) != 0)
870 #endif /* !SVR4_SHARED_LIBS */
872 /* For the SVR4 version, we always know the breakpoint address. For the
873 SunOS version we don't know it until the above code is executed.
874 Grumble if we are stopped anywhere besides the breakpoint address. */
876 if (stop_pc
!= breakpoint_addr
)
878 warning ("stopped at unknown breakpoint while handling shared libraries");
888 enable_break -- arrange for dynamic linker to hit breakpoint
892 int enable_break (void)
896 Both the SunOS and the SVR4 dynamic linkers have, as part of their
897 debugger interface, support for arranging for the inferior to hit
898 a breakpoint after mapping in the shared libraries. This function
899 enables that breakpoint.
901 For SunOS, there is a special flag location (in_debugger) which we
902 set to 1. When the dynamic linker sees this flag set, it will set
903 a breakpoint at a location known only to itself, after saving the
904 original contents of that place and the breakpoint address itself,
905 in it's own internal structures. When we resume the inferior, it
906 will eventually take a SIGTRAP when it runs into the breakpoint.
907 We handle this (in a different place) by restoring the contents of
908 the breakpointed location (which is only known after it stops),
909 chasing around to locate the shared libraries that have been
910 loaded, then resuming.
912 For SVR4, the debugger interface structure contains a member (r_brk)
913 which is statically initialized at the time the shared library is
914 built, to the offset of a function (_r_debug_state) which is guaran-
915 teed to be called once before mapping in a library, and again when
916 the mapping is complete. At the time we are examining this member,
917 it contains only the unrelocated offset of the function, so we have
918 to do our own relocation. Later, when the dynamic linker actually
919 runs, it relocates r_brk to be the actual address of _r_debug_state().
921 The debugger interface structure also contains an enumeration which
922 is set to either RT_ADD or RT_DELETE prior to changing the mapping,
923 depending upon whether or not the library is being mapped or unmapped,
924 and then set to RT_CONSISTENT after the library is mapped/unmapped.
933 #ifndef SVR4_SHARED_LIBS
937 /* Get link_dynamic structure */
939 j
= target_read_memory (debug_base
, (char *) &dynamic_copy
,
940 sizeof (dynamic_copy
));
947 /* Calc address of debugger interface structure */
949 debug_addr
= (CORE_ADDR
) dynamic_copy
.ldd
;
951 /* Calc address of `in_debugger' member of debugger interface structure */
953 flag_addr
= debug_addr
+ (CORE_ADDR
) ((char *) &debug_copy
.ldd_in_debugger
-
954 (char *) &debug_copy
);
956 /* Write a value of 1 to this member. */
960 write_memory (flag_addr
, &in_debugger
, sizeof (in_debugger
));
962 #else /* SVR4_SHARED_LIBS */
968 i
= lookup_misc_func ("main");
969 if (i
>= 0 && misc_function_vector
[i
].address
!= 0)
971 breakpoint_addr
= misc_function_vector
[i
].address
;
978 if (target_insert_breakpoint (breakpoint_addr
, shadow_contents
) != 0)
983 #else /* !BKPT_AT_MAIN */
985 struct symtab_and_line sal
;
987 /* Read the debugger interface structure directly. */
989 read_memory (debug_base
, (char *) &debug_copy
, sizeof (debug_copy
));
991 /* Set breakpoint at the debugger interface stub routine that will
992 be called just prior to each mapping change and again after the
993 mapping change is complete. Set up the (nonexistent) handler to
994 deal with hitting these breakpoints. (FIXME). */
996 warning ("'%s': line %d: missing SVR4 support code", __FILE__
, __LINE__
);
998 #endif /* BKPT_AT_MAIN */
1000 #endif /* !SVR4_SHARED_LIBS */
1009 solib_create_inferior_hook -- shared library startup support
1013 void solib_create_inferior_hook()
1017 When gdb starts up the inferior, it nurses it along (through the
1018 shell) until it is ready to execute it's first instruction. At this
1019 point, this function gets called via expansion of the macro
1020 SOLIB_CREATE_INFERIOR_HOOK.
1022 For both SunOS shared libraries, and SVR4 shared libraries, we
1023 can arrange to cooperate with the dynamic linker to discover the
1024 names of shared libraries that are dynamically linked, and the
1025 base addresses to which they are linked.
1027 This function is responsible for discovering those names and
1028 addresses, and saving sufficient information about them to allow
1029 their symbols to be read at a later time.
1033 Between enable_break() and disable_break(), this code does not
1034 properly handle hitting breakpoints which the user might have
1035 set in the startup code or in the dynamic linker itself. Proper
1036 handling will probably have to wait until the implementation is
1037 changed to use the "breakpoint handler function" method.
1039 Also, what if child has exit()ed? Must exit loop somehow.
1043 solib_create_inferior_hook()
1045 CORE_ADDR debug_addr
;
1047 CORE_ADDR in_debugger_addr
;
1048 CORE_ADDR breakpoint_addr
;
1051 if ((debug_base
= locate_base ()) == 0)
1053 /* Can't find the symbol or the executable is statically linked. */
1057 if (!enable_break ())
1059 warning ("shared library handler failed to enable breakpoint");
1063 /* Now run the target. It will eventually hit the breakpoint, at
1064 which point all of the libraries will have been mapped in and we
1065 can go groveling around in the dynamic linker structures to find
1066 out what we need to know about them. */
1068 clear_proceed_status ();
1069 stop_soon_quietly
= 1;
1073 target_resume (0, stop_signal
);
1074 wait_for_inferior ();
1076 while (stop_signal
!= SIGTRAP
);
1077 stop_soon_quietly
= 0;
1079 /* We are now either at the "mapping complete" breakpoint (or somewhere
1080 else, a condition we aren't prepared to deal with anyway), so adjust
1081 the PC as necessary after a breakpoint, disable the breakpoint, and
1082 add any shared libraries that were mapped in. */
1084 if (DECR_PC_AFTER_BREAK
)
1086 stop_pc
-= DECR_PC_AFTER_BREAK
;
1087 write_register (PC_REGNUM
, stop_pc
);
1090 if (!disable_break ())
1092 warning ("shared library handler failed to disable breakpoint");
1095 solib_add ((char *) 0, 0, (struct target_ops
*) 0);
1102 sharedlibrary_command -- handle command to explicitly add library
1106 void sharedlibrary_command (char *args, int from_tty)
1113 sharedlibrary_command (args
, from_tty
)
1118 solib_add (args
, from_tty
, (struct target_ops
*) 0);
1125 add_com ("sharedlibrary", class_files
, sharedlibrary_command
,
1126 "Load shared object library symbols for files matching REGEXP.");
1127 add_info ("sharedlibrary", info_sharedlibrary_command
,
1128 "Status of loaded shared object libraries.");