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. */
184 #ifndef SVR4_SHARED_LIBS
187 solib_add_common_symbols (rtc_symp
)
188 struct rtc_symb
*rtc_symp
;
190 struct rtc_symb inferior_rtc_symb
;
191 struct nlist inferior_rtc_nlist
;
192 extern void discard_misc_bunches();
194 init_misc_bunches ();
195 make_cleanup (discard_misc_bunches
, 0);
199 read_memory((CORE_ADDR
)rtc_symp
,
201 sizeof(inferior_rtc_symb
));
202 read_memory((CORE_ADDR
)inferior_rtc_symb
.rtc_sp
,
204 sizeof(inferior_rtc_nlist
));
205 if (inferior_rtc_nlist
.n_type
== N_COMM
)
207 /* FIXME: The length of the symbol name is not available, but in the
208 current implementation the common symbol is allocated immediately
209 behind the name of the symbol. */
210 int len
= inferior_rtc_nlist
.n_value
- inferior_rtc_nlist
.n_un
.n_strx
;
211 char *name
, *origname
;
213 origname
= name
= xmalloc (len
);
214 read_memory((CORE_ADDR
)inferior_rtc_nlist
.n_un
.n_name
, name
, len
);
216 /* Don't enter the symbol twice if the target is re-run. */
218 #ifdef NAMES_HAVE_UNDERSCORE
222 if (lookup_misc_func (name
) < 0)
223 prim_record_misc_function (obsavestring (name
, strlen (name
)),
224 inferior_rtc_nlist
.n_value
,
228 rtc_symp
= inferior_rtc_symb
.rtc_next
;
231 condense_misc_bunches (1);
234 #endif /* SVR4_SHARED_LIBS */
240 bfd_lookup_symbol -- lookup the value for a specific symbol
244 CORE_ADDR bfd_lookup_symbol (bfd *abfd, char *symname)
248 An expensive way to lookup the value of a single symbol for
249 bfd's that are only temporary anyway. This is used by the
250 shared library support to find the address of the debugger
251 interface structures in the shared library.
253 Note that 0 is specifically allowed as an error return (no
256 FIXME: See if there is a less "expensive" way of doing this.
257 Also see if there is already another bfd or gdb function
258 that specifically does this, and if so, use it.
262 DEFUN (bfd_lookup_symbol
, (abfd
, symname
),
266 unsigned int storage_needed
;
268 asymbol
**symbol_table
;
269 unsigned int number_of_symbols
;
271 struct cleanup
*back_to
;
272 CORE_ADDR symaddr
= 0;
273 enum misc_function_type mf_type
;
275 storage_needed
= get_symtab_upper_bound (abfd
);
277 if (storage_needed
> 0)
279 symbol_table
= (asymbol
**) bfd_xmalloc (storage_needed
);
280 back_to
= make_cleanup (free
, symbol_table
);
281 number_of_symbols
= bfd_canonicalize_symtab (abfd
, symbol_table
);
283 for (i
= 0; i
< number_of_symbols
; i
++)
285 sym
= *symbol_table
++;
286 if (strcmp (sym
-> name
, symname
) == 0)
288 symaddr
= sym
-> value
;
292 do_cleanups (back_to
);
301 look_for_base -- examine file for each mapped address segment
305 static int look_for_base (int fd, CORE_ADDR baseaddr)
309 This function is passed to proc_iterate_over_mappings, which
310 causes it to get called once for each mapped address space, with
311 an open file descriptor for the file mapped to that space, and the
312 base address of that mapped space.
314 Our job is to find the symbol DEBUG_BASE in the file that this
315 fd is open on, if it exists, and if so, initialize the dynamic
316 linker structure base address debug_base.
318 Note that this is a computationally expensive proposition, since
319 we basically have to open a bfd on every call, so we specifically
320 avoid opening the exec file.
324 DEFUN (look_for_base
, (fd
, baseaddr
),
331 /* If the fd is -1, then there is no file that corresponds to this
332 mapped memory segment, so skip it. Also, if the fd corresponds
333 to the exec file, skip it as well. */
335 if ((fd
== -1) || fdmatch (fileno ((FILE *)(exec_bfd
-> iostream
)), fd
))
340 /* Try to open whatever random file this fd corresponds to. Note that
341 we have no way currently to find the filename. Don't gripe about
342 any problems we might have, just fail. */
344 if ((interp_bfd
= bfd_fdopenr ("unnamed", NULL
, fd
)) == NULL
)
348 if (!bfd_check_format (interp_bfd
, bfd_object
))
350 bfd_close (interp_bfd
);
354 /* Now try to find our DEBUG_BASE symbol in this file, which we at
355 least know to be a valid ELF executable or shared library. */
357 if ((address
= bfd_lookup_symbol (interp_bfd
, DEBUG_BASE
)) == 0)
359 bfd_close (interp_bfd
);
363 /* Eureka! We found the symbol. But now we may need to relocate it
364 by the base address. If the symbol's value is less than the base
365 address of the shared library, then it hasn't yet been relocated
366 by the dynamic linker, and we have to do it ourself. FIXME: Note
367 that we make the assumption that the first segment that corresponds
368 to the shared library has the base address to which the library
371 if (address
< baseaddr
)
375 debug_base
= address
;
376 bfd_close (interp_bfd
);
384 locate_base -- locate the base address of dynamic linker structs
388 CORE_ADDR locate_base (void)
392 For both the SunOS and SVR4 shared library implementations, if the
393 inferior executable has been linked dynamically, there is a single
394 address somewhere in the inferior's data space which is the key to
395 locating all of the dynamic linker's runtime structures. This
396 address is the value of the symbol defined by the macro DEBUG_BASE.
397 The job of this function is to find and return that address, or to
398 return 0 if there is no such address (the executable is statically
401 For SunOS, the job is almost trivial, since the dynamic linker and
402 all of it's structures are statically linked to the executable at
403 link time. Thus the symbol for the address we are looking for has
404 already been added to the misc function vector at the time the symbol
405 file's symbols were read, and all we have to do is look it up there.
407 The SVR4 version is much more complicated because the dynamic linker
408 and it's structures are located in the shared C library, which gets
409 run as the executable's "interpreter" by the kernel. We have to go
410 to a lot more work to discover the address of DEBUG_BASE. Because
411 of this complexity, we cache the value we find and return that value
412 on subsequent invocations.
414 Note that we can assume nothing about the process state at the time
415 we need to find this address. We may be stopped on the first instruc-
416 tion of the interpreter (C shared library), the first instruction of
417 the executable itself, or somewhere else entirely (if we attached
418 to the process for example).
426 #ifndef SVR4_SHARED_LIBS
429 CORE_ADDR address
= 0;
431 i
= lookup_misc_func (DEBUG_BASE
);
432 if (i
>= 0 && misc_function_vector
[i
].address
!= 0)
434 address
= misc_function_vector
[i
].address
;
438 #else /* SVR4_SHARED_LIBS */
440 /* Check to see if we have a currently valid address, and if so, avoid
441 doing all this work again and just return the cached address. If
442 we have no cached address, ask the /proc support interface to iterate
443 over the list of mapped address segments, calling look_for_base() for
444 each segment. When we are done, we will have either found the base
449 proc_iterate_over_mappings (look_for_base
);
453 #endif /* !SVR4_SHARED_LIBS */
457 static struct link_map
*
458 first_link_map_member ()
460 struct link_map
*lm
= NULL
;
462 #ifndef SVR4_SHARED_LIBS
464 read_memory (debug_base
, &dynamic_copy
, sizeof (dynamic_copy
));
465 if (dynamic_copy
.ld_version
>= 2)
467 /* It is a version that we can deal with, so read in the secondary
468 structure and find the address of the link map list from it. */
469 read_memory ((CORE_ADDR
) dynamic_copy
.ld_un
.ld_2
, &ld_2_copy
,
470 sizeof (struct link_dynamic_2
));
471 lm
= ld_2_copy
.ld_loaded
;
474 #else /* SVR4_SHARED_LIBS */
476 read_memory (debug_base
, &debug_copy
, sizeof (struct r_debug
));
477 lm
= debug_copy
.r_map
;
479 #endif /* !SVR4_SHARED_LIBS */
488 find_solib -- step through list of shared objects
492 struct so_list *find_solib (struct so_list *so_list_ptr)
496 This module contains the routine which finds the names of any
497 loaded "images" in the current process. The argument in must be
498 NULL on the first call, and then the returned value must be passed
499 in on subsequent calls. This provides the capability to "step" down
500 the list of loaded objects. On the last object, a NULL value is
503 The arg and return value are "struct link_map" pointers, as defined
508 find_solib (so_list_ptr
)
509 struct so_list
*so_list_ptr
; /* Last lm or NULL for first one */
511 struct so_list
*so_list_next
= NULL
;
512 struct link_map
*lm
= NULL
;
515 if (so_list_ptr
== NULL
)
517 /* We are setting up for a new scan through the loaded images. */
518 if ((so_list_next
= so_list_head
) == NULL
)
520 /* We have not already read in the dynamic linking structures
521 from the inferior, lookup the address of the base structure. */
522 debug_base
= locate_base ();
525 /* Read the base structure in and find the address of the first
526 link map list member. */
527 lm
= first_link_map_member ();
533 /* We have been called before, and are in the process of walking
534 the shared library list. Advance to the next shared object. */
535 if ((lm
= LM_NEXT (so_list_ptr
)) == NULL
)
537 /* We have hit the end of the list, so check to see if any were
538 added, but be quiet if we can't read from the target any more. */
539 int status
= target_read_memory ((CORE_ADDR
) so_list_ptr
-> lmaddr
,
540 (char *) &(so_list_ptr
-> lm
),
541 sizeof (struct link_map
));
544 lm
= LM_NEXT (so_list_ptr
);
551 so_list_next
= so_list_ptr
-> next
;
553 if ((so_list_next
== NULL
) && (lm
!= NULL
))
555 /* Get next link map structure from inferior image and build a local
556 abbreviated load_map structure */
557 new = (struct so_list
*) xmalloc (sizeof (struct so_list
));
558 (void) memset ((char *) new, 0, sizeof (struct so_list
));
560 /* Add the new node as the next node in the list, or as the root
561 node if this is the first one. */
562 if (so_list_ptr
!= NULL
)
564 so_list_ptr
-> next
= new;
571 read_memory ((CORE_ADDR
) lm
, &(new -> lm
), sizeof (struct link_map
));
572 /* For the SVR4 version, there is one entry that has no name
573 (for the inferior executable) since it is not a shared object. */
574 if (LM_NAME (new) != 0)
576 (void) target_read_string((CORE_ADDR
) LM_NAME (new), new -> so_name
,
578 new -> so_name
[MAX_PATH_SIZE
- 1] = 0;
579 solib_map_sections (new);
582 return (so_list_next
);
585 /* A small stub to get us past the arg-passing pinhole of catch_errors. */
588 symbol_add_stub (arg
)
591 register struct so_list
*so
= (struct so_list
*) arg
; /* catch_errs bogon */
593 symbol_file_add (so
-> so_name
, so
-> from_tty
,
594 (unsigned int) LM_ADDR (so
), 0);
602 solib_add -- add a shared library file to the symtab and section list
606 void solib_add (char *arg_string, int from_tty,
607 struct target_ops *target)
614 solib_add (arg_string
, from_tty
, target
)
617 struct target_ops
*target
;
619 register struct so_list
*so
= NULL
; /* link map state variable */
624 if ((re_err
= re_comp (arg_string
? arg_string
: ".")) != NULL
)
626 error ("Invalid regexp: %s", re_err
);
629 /* Getting new symbols may change our opinion about what is
631 reinit_frame_cache ();
633 while ((so
= find_solib (so
)) != NULL
)
635 if (so
-> so_name
[0] && re_exec (so
-> so_name
))
637 if (so
-> symbols_loaded
)
641 printf ("Symbols already loaded for %s\n", so
-> so_name
);
646 so
-> symbols_loaded
= 1;
647 so
-> from_tty
= from_tty
;
648 catch_errors (symbol_add_stub
, (char *) so
,
649 "Error while reading shared library symbols:\n");
654 /* Now add the shared library sections to the section table of the
655 specified target, if any. */
658 /* Count how many new section_table entries there are. */
661 while ((so
= find_solib (so
)) != NULL
)
663 if (so
-> so_name
[0])
665 count
+= so
-> sections_end
- so
-> sections
;
671 /* Reallocate the target's section table including the new size. */
672 if (target
-> sections
)
674 old
= target
-> sections_end
- target
-> sections
;
675 target
-> sections
= (struct section_table
*)
676 realloc ((char *)target
-> sections
,
677 (sizeof (struct section_table
)) * (count
+ old
));
682 target
-> sections
= (struct section_table
*)
683 malloc ((sizeof (struct section_table
)) * count
);
685 target
-> sections_end
= target
-> sections
+ (count
+ old
);
687 /* Add these section table entries to the target's table. */
688 while ((so
= find_solib (so
)) != NULL
)
690 if (so
-> so_name
[0])
692 count
= so
-> sections_end
- so
-> sections
;
693 bcopy (so
-> sections
, (char *)(target
-> sections
+ old
),
694 (sizeof (struct section_table
)) * count
);
706 info_sharedlibrary_command -- code for "info sharedlibrary"
710 static void info_sharedlibrary_command ()
714 Walk through the shared library list and print information
715 about each attached library.
719 info_sharedlibrary_command ()
721 register struct so_list
*so
= NULL
; /* link map state variable */
724 if (exec_bfd
== NULL
)
726 printf ("No exec file.\n");
729 while ((so
= find_solib (so
)) != NULL
)
731 if (so
-> so_name
[0])
735 printf("%-12s%-12s%-12s%s\n", "From", "To", "Syms Read",
736 "Shared Object Library");
739 printf ("%-12s", local_hex_string_custom (LM_ADDR (so
), "08"));
740 printf ("%-12s", local_hex_string_custom (so
-> lmend
, "08"));
741 printf ("%-12s", so
-> symbols_loaded
? "Yes" : "No");
742 printf ("%s\n", so
-> so_name
);
745 if (so_list_head
== NULL
)
747 printf ("No shared libraries loaded at this time.\n");
755 solib_address -- check to see if an address is in a shared lib
759 int solib_address (CORE_ADDR address)
763 Provides a hook for other gdb routines to discover whether or
764 not a particular address is within the mapped address space of
765 a shared library. Any address between the base mapping address
766 and the first address beyond the end of the last mapping, is
767 considered to be within the shared library address space, for
770 For example, this routine is called at one point to disable
771 breakpoints which are in shared libraries that are not currently
776 solib_address (address
)
779 register struct so_list
*so
= 0; /* link map state variable */
781 while ((so
= find_solib (so
)) != NULL
)
783 if (so
-> so_name
[0])
785 if ((address
>= (CORE_ADDR
) LM_ADDR (so
)) &&
786 (address
< (CORE_ADDR
) so
-> lmend
))
795 /* Called by free_all_symtabs */
800 struct so_list
*next
;
804 if (so_list_head
-> sections
)
806 free (so_list_head
-> sections
);
808 if (so_list_head
-> so_bfd
)
810 bfd_close (so_list_head
-> so_bfd
);
812 next
= so_list_head
-> next
;
823 disable_break -- remove the "mapping changed" breakpoint
827 static int disable_break ()
831 Removes the breakpoint that gets hit when the dynamic linker
832 completes a mapping change.
841 #ifndef SVR4_SHARED_LIBS
845 /* Read the debugger structure from the inferior to retrieve the
846 address of the breakpoint and the original contents of the
847 breakpoint address. Remove the breakpoint by writing the original
850 read_memory (debug_addr
, &debug_copy
, sizeof (debug_copy
));
852 /* Get common symbol definitions for the loaded object. */
853 if (debug_copy
.ldd_cp
)
854 solib_add_common_symbols (debug_copy
.ldd_cp
);
856 /* Set `in_debugger' to zero now. */
858 write_memory (flag_addr
, &in_debugger
, sizeof (in_debugger
));
860 breakpoint_addr
= (CORE_ADDR
) debug_copy
.ldd_bp_addr
;
861 write_memory (breakpoint_addr
, &debug_copy
.ldd_bp_inst
,
862 sizeof (debug_copy
.ldd_bp_inst
));
864 #else /* SVR4_SHARED_LIBS */
866 /* Note that breakpoint address and original contents are in our address
867 space, so we just need to write the original contents back. */
869 if (memory_remove_breakpoint (breakpoint_addr
, shadow_contents
) != 0)
874 #endif /* !SVR4_SHARED_LIBS */
876 /* For the SVR4 version, we always know the breakpoint address. For the
877 SunOS version we don't know it until the above code is executed.
878 Grumble if we are stopped anywhere besides the breakpoint address. */
880 if (stop_pc
!= breakpoint_addr
)
882 warning ("stopped at unknown breakpoint while handling shared libraries");
892 enable_break -- arrange for dynamic linker to hit breakpoint
896 int enable_break (void)
900 Both the SunOS and the SVR4 dynamic linkers have, as part of their
901 debugger interface, support for arranging for the inferior to hit
902 a breakpoint after mapping in the shared libraries. This function
903 enables that breakpoint.
905 For SunOS, there is a special flag location (in_debugger) which we
906 set to 1. When the dynamic linker sees this flag set, it will set
907 a breakpoint at a location known only to itself, after saving the
908 original contents of that place and the breakpoint address itself,
909 in it's own internal structures. When we resume the inferior, it
910 will eventually take a SIGTRAP when it runs into the breakpoint.
911 We handle this (in a different place) by restoring the contents of
912 the breakpointed location (which is only known after it stops),
913 chasing around to locate the shared libraries that have been
914 loaded, then resuming.
916 For SVR4, the debugger interface structure contains a member (r_brk)
917 which is statically initialized at the time the shared library is
918 built, to the offset of a function (_r_debug_state) which is guaran-
919 teed to be called once before mapping in a library, and again when
920 the mapping is complete. At the time we are examining this member,
921 it contains only the unrelocated offset of the function, so we have
922 to do our own relocation. Later, when the dynamic linker actually
923 runs, it relocates r_brk to be the actual address of _r_debug_state().
925 The debugger interface structure also contains an enumeration which
926 is set to either RT_ADD or RT_DELETE prior to changing the mapping,
927 depending upon whether or not the library is being mapped or unmapped,
928 and then set to RT_CONSISTENT after the library is mapped/unmapped.
937 #ifndef SVR4_SHARED_LIBS
941 /* Get link_dynamic structure */
943 j
= target_read_memory (debug_base
, (char *) &dynamic_copy
,
944 sizeof (dynamic_copy
));
951 /* Calc address of debugger interface structure */
953 debug_addr
= (CORE_ADDR
) dynamic_copy
.ldd
;
955 /* Calc address of `in_debugger' member of debugger interface structure */
957 flag_addr
= debug_addr
+ (CORE_ADDR
) ((char *) &debug_copy
.ldd_in_debugger
-
958 (char *) &debug_copy
);
960 /* Write a value of 1 to this member. */
964 write_memory (flag_addr
, &in_debugger
, sizeof (in_debugger
));
966 #else /* SVR4_SHARED_LIBS */
972 i
= lookup_misc_func ("main");
973 if (i
>= 0 && misc_function_vector
[i
].address
!= 0)
975 breakpoint_addr
= misc_function_vector
[i
].address
;
982 if (target_insert_breakpoint (breakpoint_addr
, shadow_contents
) != 0)
987 #else /* !BKPT_AT_MAIN */
989 struct symtab_and_line sal
;
991 /* Read the debugger interface structure directly. */
993 read_memory (debug_base
, (char *) &debug_copy
, sizeof (debug_copy
));
995 /* Set breakpoint at the debugger interface stub routine that will
996 be called just prior to each mapping change and again after the
997 mapping change is complete. Set up the (nonexistent) handler to
998 deal with hitting these breakpoints. (FIXME). */
1000 warning ("'%s': line %d: missing SVR4 support code", __FILE__
, __LINE__
);
1002 #endif /* BKPT_AT_MAIN */
1004 #endif /* !SVR4_SHARED_LIBS */
1013 solib_create_inferior_hook -- shared library startup support
1017 void solib_create_inferior_hook()
1021 When gdb starts up the inferior, it nurses it along (through the
1022 shell) until it is ready to execute it's first instruction. At this
1023 point, this function gets called via expansion of the macro
1024 SOLIB_CREATE_INFERIOR_HOOK.
1026 For both SunOS shared libraries, and SVR4 shared libraries, we
1027 can arrange to cooperate with the dynamic linker to discover the
1028 names of shared libraries that are dynamically linked, and the
1029 base addresses to which they are linked.
1031 This function is responsible for discovering those names and
1032 addresses, and saving sufficient information about them to allow
1033 their symbols to be read at a later time.
1037 Between enable_break() and disable_break(), this code does not
1038 properly handle hitting breakpoints which the user might have
1039 set in the startup code or in the dynamic linker itself. Proper
1040 handling will probably have to wait until the implementation is
1041 changed to use the "breakpoint handler function" method.
1043 Also, what if child has exit()ed? Must exit loop somehow.
1047 solib_create_inferior_hook()
1049 CORE_ADDR debug_addr
;
1051 CORE_ADDR in_debugger_addr
;
1052 CORE_ADDR breakpoint_addr
;
1055 if ((debug_base
= locate_base ()) == 0)
1057 /* Can't find the symbol or the executable is statically linked. */
1061 if (!enable_break ())
1063 warning ("shared library handler failed to enable breakpoint");
1067 /* Now run the target. It will eventually hit the breakpoint, at
1068 which point all of the libraries will have been mapped in and we
1069 can go groveling around in the dynamic linker structures to find
1070 out what we need to know about them. */
1072 clear_proceed_status ();
1073 stop_soon_quietly
= 1;
1077 target_resume (0, stop_signal
);
1078 wait_for_inferior ();
1080 while (stop_signal
!= SIGTRAP
);
1081 stop_soon_quietly
= 0;
1083 /* We are now either at the "mapping complete" breakpoint (or somewhere
1084 else, a condition we aren't prepared to deal with anyway), so adjust
1085 the PC as necessary after a breakpoint, disable the breakpoint, and
1086 add any shared libraries that were mapped in. */
1088 if (DECR_PC_AFTER_BREAK
)
1090 stop_pc
-= DECR_PC_AFTER_BREAK
;
1091 write_register (PC_REGNUM
, stop_pc
);
1094 if (!disable_break ())
1096 warning ("shared library handler failed to disable breakpoint");
1099 solib_add ((char *) 0, 0, (struct target_ops
*) 0);
1106 sharedlibrary_command -- handle command to explicitly add library
1110 void sharedlibrary_command (char *args, int from_tty)
1117 sharedlibrary_command (args
, from_tty
)
1122 solib_add (args
, from_tty
, (struct target_ops
*) 0);
1129 add_com ("sharedlibrary", class_files
, sharedlibrary_command
,
1130 "Load shared object library symbols for files matching REGEXP.");
1131 add_info ("sharedlibrary", info_sharedlibrary_command
,
1132 "Status of loaded shared object libraries.");