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>
38 extern char *getenv ();
39 extern char *elf_interpreter (); /* Interpreter name from exec file */
40 extern char *re_comp ();
42 #define MAX_PATH_SIZE 256 /* FIXME: Should be dynamic */
44 /* On SVR4 systems, for the initial implementation, use main() as the
45 "startup mapping complete" breakpoint address. The models for SunOS
46 and SVR4 dynamic linking debugger support are different in that SunOS
47 hits one breakpoint when all mapping is complete while using the SVR4
48 debugger support takes two breakpoint hits for each file mapped, and
49 there is no way to know when the "last" one is hit. Both these
50 mechanisms should be tied to a "breakpoint service routine" that
51 gets automatically executed whenever one of the breakpoints indicating
52 a change in mapping is hit. This is a future enhancement. (FIXME) */
54 #define BKPT_AT_MAIN 1
56 /* local data declarations */
60 #define DEBUG_BASE "_DYNAMIC"
61 #define LM_ADDR(so) ((so) -> lm.lm_addr)
62 #define LM_NEXT(so) ((so) -> lm.lm_next)
63 #define LM_NAME(so) ((so) -> lm.lm_name)
64 static struct link_dynamic dynamic_copy
;
65 static struct link_dynamic_2 ld_2_copy
;
66 static struct ld_debug debug_copy
;
67 static CORE_ADDR debug_addr
;
68 static CORE_ADDR flag_addr
;
72 #define DEBUG_BASE "_r_debug"
73 #define LM_ADDR(so) ((so) -> lm.l_addr)
74 #define LM_NEXT(so) ((so) -> lm.l_next)
75 #define LM_NAME(so) ((so) -> lm.l_name)
76 static struct r_debug debug_copy
;
77 static CORE_ADDR shlib_base
; /* Base address of shared library */
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 ();
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
);
185 bfd_lookup_symbol -- lookup the value for a specific symbol
189 CORE_ADDR bfd_lookup_symbol (bfd *abfd, char *symname)
193 An expensive way to lookup the value of a single symbol for
194 bfd's that are only temporary anyway. This is used by the
195 shared library support to find the address of the debugger
196 interface structures in the shared library.
198 Note that 0 is specifically allowed as an error return (no
201 FIXME: See if there is a less "expensive" way of doing this.
202 Also see if there is already another bfd or gdb function
203 that specifically does this, and if so, use it.
207 DEFUN (bfd_lookup_symbol
, (abfd
, symname
),
211 unsigned int storage_needed
;
213 asymbol
**symbol_table
;
214 unsigned int number_of_symbols
;
216 struct cleanup
*back_to
;
217 CORE_ADDR symaddr
= 0;
218 enum misc_function_type mf_type
;
220 storage_needed
= get_symtab_upper_bound (abfd
);
222 if (storage_needed
> 0)
224 symbol_table
= (asymbol
**) bfd_xmalloc (storage_needed
);
225 back_to
= make_cleanup (free
, symbol_table
);
226 number_of_symbols
= bfd_canonicalize_symtab (abfd
, symbol_table
);
228 for (i
= 0; i
< number_of_symbols
; i
++)
230 sym
= *symbol_table
++;
231 if (strcmp (sym
-> name
, symname
) == 0)
233 symaddr
= sym
-> value
;
237 do_cleanups (back_to
);
246 locate_base -- locate the base address of dynamic linker structs
250 CORE_ADDR locate_base (void)
254 For both the SunOS and SVR4 shared library implementations, if the
255 inferior executable has been linked dynamically, there is a single
256 address somewhere in the inferior's data space which is the key to
257 locating all of the dynamic linker's runtime structures, and this
258 address is the value of the symbol defined by the macro DEBUG_BASE.
259 The job of this function is to find and return that address, or to
260 return 0 if there is no such address (the executable is statically
263 For SunOS, the job is almost trivial, since the dynamic linker and
264 all of it's structures are statically linked to the executable at
265 link time. Thus the symbol for the address we are looking for has
266 already been added to the misc function vector at the time the symbol
267 file's symbols were read.
269 The SVR4 version is much more complicated because the dynamic linker
270 and it's structures are located in the shared library itself, which
271 gets run as the executable's "interpreter" by the kernel. Because
272 of this complexity, we cache the value we find and return that value
273 on subsequent invocations, if it is non-zero.
275 First we must decide if we are stopped at the entry point of the
276 shared C library, which is set to be the entry point of the dynamic
277 linker code (the function _rt_boot() to be precise), or at the entry
278 point given in the inferior's exec file (for statically linked
281 If we are not stopped at the inferior's exec file entry point then
282 we are either stopped at the interpreter's entry point or somewhere
283 else (I.E. totally lost). Use the /proc interface to get an open
284 file descriptor on the file that is mapped at the current stop_pc
285 value and try to open a bfd for it.
289 The SVR4 strategy does NOT work when gdb is attaching to an existing
290 process because the stop_pc is not in the library code, so we can't
291 use the /proc interface to get an open fd for the library. So we
292 need to rethink the method for finding the debugger interface struct.
294 For SunOS we could look around in the executable code to find
295 DEBUG_BASE, if it isn't in the symbol table. It's not that hard to
296 find. Then we can debug stripped executables using shared library
304 CORE_ADDR address
= 0;
310 i
= lookup_misc_func (DEBUG_BASE
);
311 if (i
>= 0 && misc_function_vector
[i
].address
!= 0)
313 address
= misc_function_vector
[i
].address
;
318 int stop_pc_fd
; /* File descriptor for mapped file */
319 int interp_fd
; /* File descriptor for interpreter */
320 char *interp_name
; /* Name of interpreter */
321 char *full_interp_name
; /* Full pathname of interpreter */
323 CORE_ADDR interp_base
;
327 /* We have a currently valid address, so avoid doing all the work
331 if (bfd_get_start_address (exec_bfd
) == stop_pc
)
333 /* We are stopped at the entry point to the exec file, so there
334 are no shared libs to deal with. */
337 if ((stop_pc_fd
= proc_address_to_fd (stop_pc
)) < 0)
339 /* We are stopped at an address for which we can't seem to get an open
340 file descriptor from the /proc interface. We should already have
341 printed a suitable warning message. */
344 if ((interp_name
= elf_interpreter (exec_bfd
)) == NULL
)
346 /* There is no interpreter specified in the exec file, thus this is
347 not a normal dynamically linked file. */
350 if ((interp_fd
= openp (getenv ("PATH"), 1, interp_name
, O_RDONLY
, 0,
351 &full_interp_name
)) < 0)
353 /* We can't find and open the interpreter. This is a problem. */
356 if (!fdmatch (stop_pc_fd
, interp_fd
))
358 /* The file for the mapped region is not the interpreter, something
362 free (full_interp_name
);
365 interp_bfd
= bfd_fdopenr (full_interp_name
, NULL
, interp_fd
);
368 warning ("Could not open `%s' as an executable file: %s",
369 full_interp_name
, bfd_errmsg (bfd_error
));
372 if (!bfd_check_format (interp_bfd
, bfd_object
))
374 warning ("\"%s\": not in executable format: %s.",
375 full_interp_name
, bfd_errmsg (bfd_error
));
379 /* Lookup the unrelocated value of the symbol that defines the location
380 of the debugger interface structure for the dynamic linker in the shared
381 library. Then find the base address of the text segment in the
382 inferior's mapped in dynamic library, which gives the relocation to
383 apply to find the actual mapped address of the debugger interface
386 if ((address
= bfd_lookup_symbol (interp_bfd
, DEBUG_BASE
)) == 0)
388 warning ("can't find symbol %s in shared library", DEBUG_BASE
);
391 if ((interp_base
= proc_base_address (stop_pc
)) == 0)
393 warning ("can't find base address for shared library text segment");
396 shlib_base
= interp_base
;
397 address
+= interp_base
;
399 if ((interp_base
+ bfd_get_start_address (interp_bfd
)) != stop_pc
)
401 /* We are not stopped at the entry point to the dynamic linker,
402 so grumble and skip startup shared library processing. */
403 warning ("not stopped at entry point of dynamic linker");
404 warning ("shared library processing suppressed");
408 bfd_close (interp_bfd
);
416 static struct link_map
*
417 first_link_map_member ()
419 struct link_map
*lm
= NULL
;
423 read_memory (debug_base
, &dynamic_copy
, sizeof (dynamic_copy
));
424 if (dynamic_copy
.ld_version
>= 2)
426 /* It is a version that we can deal with, so read in the secondary
427 structure and find the address of the link map list from it. */
428 read_memory ((CORE_ADDR
) dynamic_copy
.ld_un
.ld_2
, &ld_2_copy
,
429 sizeof (struct link_dynamic_2
));
430 lm
= ld_2_copy
.ld_loaded
;
435 read_memory (debug_base
, &debug_copy
, sizeof (struct r_debug
));
436 lm
= debug_copy
.r_map
;
447 find_solib -- step through list of shared objects
451 struct so_list *find_solib (struct so_list *so_list_ptr)
455 This module contains the routine which finds the names of any
456 loaded "images" in the current process. The argument in must be
457 NULL on the first call, and then the returned value must be passed
458 in on subsequent calls. This provides the capability to "step" down
459 the list of loaded objects. On the last object, a NULL value is
462 The arg and return value are "struct link_map" pointers, as defined
467 find_solib (so_list_ptr
)
468 struct so_list
*so_list_ptr
; /* Last lm or NULL for first one */
470 struct so_list
*so_list_next
= NULL
;
471 struct link_map
*lm
= NULL
;
474 if (so_list_ptr
== NULL
)
476 /* We are setting up for a new scan through the loaded images. */
477 if ((so_list_next
= so_list_head
) == NULL
)
479 /* We have not already read in the dynamic linking structures
480 from the inferior, lookup the address of the base structure. */
481 debug_base
= locate_base ();
484 /* Read the base structure in and find the address of the first
485 link map list member. */
486 lm
= first_link_map_member ();
492 /* We have been called before, and are in the process of walking
493 the shared library list. Advance to the next shared object. */
494 if ((lm
= LM_NEXT (so_list_ptr
)) == NULL
)
496 /* We have hit the end of the list, so check to see if any were
497 added, but be quiet if we can't read from the target any more. */
498 int status
= target_read_memory ((CORE_ADDR
) so_list_ptr
-> lmaddr
,
499 (char *) &(so_list_ptr
-> lm
),
500 sizeof (struct link_map
));
503 lm
= LM_NEXT (so_list_ptr
);
510 so_list_next
= so_list_ptr
-> next
;
512 if ((so_list_next
== NULL
) && (lm
!= NULL
))
514 /* Get next link map structure from inferior image and build a local
515 abbreviated load_map structure */
516 new = (struct so_list
*) xmalloc (sizeof (struct so_list
));
517 (void) memset ((char *) new, 0, sizeof (struct so_list
));
519 /* Add the new node as the next node in the list, or as the root
520 node if this is the first one. */
521 if (so_list_ptr
!= NULL
)
523 so_list_ptr
-> next
= new;
530 read_memory ((CORE_ADDR
) lm
, &(new -> lm
), sizeof (struct link_map
));
531 /* For the SVR4 version, there is one entry that has no name
532 (for the inferior executable) since it is not a shared object. */
533 if (LM_NAME (new) != 0)
535 read_memory((CORE_ADDR
) LM_NAME (new), new -> so_name
,
537 new -> so_name
[MAX_PATH_SIZE
- 1] = 0;
538 solib_map_sections (new);
541 return (so_list_next
);
544 /* A small stub to get us past the arg-passing pinhole of catch_errors. */
547 symbol_add_stub (arg
)
550 register struct so_list
*so
= (struct so_list
*) arg
; /* catch_errs bogon */
552 symbol_file_add (so
-> so_name
, so
-> from_tty
,
553 (unsigned int) LM_ADDR (so
), 0);
561 solib_add -- add a shared library file to the symtab and section list
565 void solib_add (char *arg_string, int from_tty,
566 struct target_ops *target)
573 solib_add (arg_string
, from_tty
, target
)
576 struct target_ops
*target
;
578 register struct so_list
*so
= NULL
; /* link map state variable */
583 if ((re_err
= re_comp (arg_string
? arg_string
: ".")) != NULL
)
585 error ("Invalid regexp: %s", re_err
);
588 /* Getting new symbols may change our opinion about what is
590 reinit_frame_cache ();
592 while ((so
= find_solib (so
)) != NULL
)
594 if (so
-> so_name
[0] && re_exec (so
-> so_name
))
596 if (so
-> symbols_loaded
)
600 printf ("Symbols already loaded for %s\n", so
-> so_name
);
605 so
-> symbols_loaded
= 1;
606 so
-> from_tty
= from_tty
;
607 catch_errors (symbol_add_stub
, (char *) so
,
608 "Error while reading shared library symbols:\n");
613 /* Now add the shared library sections to the section table of the
614 specified target, if any. */
617 /* Count how many new section_table entries there are. */
620 while ((so
= find_solib (so
)) != NULL
)
622 if (so
-> so_name
[0])
624 count
+= so
-> sections_end
- so
-> sections
;
630 /* Reallocate the target's section table including the new size. */
631 if (target
-> sections
)
633 old
= target
-> sections_end
- target
-> sections
;
634 target
-> sections
= (struct section_table
*)
635 realloc ((char *)target
-> sections
,
636 (sizeof (struct section_table
)) * (count
+ old
));
641 target
-> sections
= (struct section_table
*)
642 malloc ((sizeof (struct section_table
)) * count
);
644 target
-> sections_end
= target
-> sections
+ (count
+ old
);
646 /* Add these section table entries to the target's table. */
647 while ((so
= find_solib (so
)) != NULL
)
649 if (so
-> so_name
[0])
651 count
= so
-> sections_end
- so
-> sections
;
652 bcopy (so
-> sections
, (char *)(target
-> sections
+ old
),
653 (sizeof (struct section_table
)) * count
);
665 info_sharedlibrary_command -- code for "info sharedlibrary"
669 static void info_sharedlibrary_command ()
673 Walk through the shared library list and print information
674 about each attached library.
678 info_sharedlibrary_command ()
680 register struct so_list
*so
= NULL
; /* link map state variable */
683 if (exec_bfd
== NULL
)
685 printf ("No exec file.\n");
688 while ((so
= find_solib (so
)) != NULL
)
690 if (so
-> so_name
[0])
694 printf("%-12s%-12s%-12s%s\n", "From", "To", "Syms Read",
695 "Shared Object Library");
698 printf ("%-12s", local_hex_string_custom (LM_ADDR (so
), "08"));
699 printf ("%-12s", local_hex_string_custom (so
-> lmend
, "08"));
700 printf ("%-12s", so
-> symbols_loaded
? "Yes" : "No");
701 printf ("%s\n", so
-> so_name
);
704 if (so_list_head
== NULL
)
706 printf ("No shared libraries loaded at this time.\n");
714 solib_address -- check to see if an address is in a shared lib
718 int solib_address (CORE_ADDR address)
722 Provides a hook for other gdb routines to discover whether or
723 not a particular address is within the mapped address space of
724 a shared library. Any address between the base mapping address
725 and the first address beyond the end of the last mapping, is
726 considered to be within the shared library address space, for
729 For example, this routine is called at one point to disable
730 breakpoints which are in shared libraries that are not currently
735 solib_address (address
)
738 register struct so_list
*so
= 0; /* link map state variable */
740 while ((so
= find_solib (so
)) != NULL
)
742 if (so
-> so_name
[0])
744 if ((address
>= (CORE_ADDR
) LM_ADDR (so
)) &&
745 (address
< (CORE_ADDR
) so
-> lmend
))
754 /* Called by free_all_symtabs */
759 struct so_list
*next
;
763 if (so_list_head
-> sections
)
765 free (so_list_head
-> sections
);
767 if (so_list_head
-> so_bfd
)
769 bfd_close (so_list_head
-> so_bfd
);
771 next
= so_list_head
-> next
;
782 disable_break -- remove the "mapping changed" breakpoint
786 static int disable_break ()
790 Removes the breakpoint that gets hit when the dynamic linker
791 completes a mapping change.
802 /* FIXME: maybe we should add the common symbols from the ldd_cp chain
803 to the misc_function_vector ? */
807 /* Set `in_debugger' to zero now. */
809 write_memory (flag_addr
, &in_debugger
, sizeof (in_debugger
));
811 /* Read the debugger structure from the inferior to retrieve the
812 address of the breakpoint and the original contents of the
813 breakpoint address. Remove the breakpoint by writing the original
816 read_memory (debug_addr
, &debug_copy
, sizeof (debug_copy
));
817 breakpoint_addr
= (CORE_ADDR
) debug_copy
.ldd_bp_addr
;
818 write_memory (breakpoint_addr
, &debug_copy
.ldd_bp_inst
,
819 sizeof (debug_copy
.ldd_bp_inst
));
823 /* Note that breakpoint address and original contents are in our address
824 space, so we just need to write the original contents back. */
826 if (memory_remove_breakpoint (breakpoint_addr
, shadow_contents
) != 0)
833 /* For the SVR4 version, we always know the breakpoint address. For the
834 SunOS version we don't know it until the above code is executed.
835 Grumble if we are stopped anywhere besides the breakpoint address. */
837 if (stop_pc
!= breakpoint_addr
)
839 warning ("stopped at unknown breakpoint while handling shared libraries");
849 enable_break -- arrange for dynamic linker to hit breakpoint
853 int enable_break (void)
857 Both the SunOS and the SVR4 dynamic linkers have, as part of their
858 debugger interface, support for arranging for the inferior to hit
859 a breakpoint after mapping in the shared libraries. This function
860 enables that breakpoint.
862 For SunOS, there is a special flag location (in_debugger) which we
863 set to 1. When the dynamic linker sees this flag set, it will set
864 a breakpoint at a location known only to itself, after saving the
865 original contents of that place and the breakpoint address itself,
866 in it's own internal structures. When we resume the inferior, it
867 will eventually take a SIGTRAP when it runs into the breakpoint.
868 We handle this (in a different place) by restoring the contents of
869 the breakpointed location (which is only known after it stops),
870 chasing around to locate the shared libraries that have been
871 loaded, then resuming.
873 For SVR4, the debugger interface structure contains a member (r_brk)
874 which is statically initialized at the time the shared library is
875 built, to the offset of a function (_r_debug_state) which is guaran-
876 teed to be called once before mapping in a library, and again when
877 the mapping is complete. At the time we are examining this member,
878 it contains only the unrelocated offset of the function, so we have
879 to do our own relocation. Later, when the dynamic linker actually
880 runs, it relocates r_brk to be the actual address of _r_debug_state().
882 The debugger interface structure also contains an enumeration which
883 is set to either RT_ADD or RT_DELETE prior to changing the mapping,
884 depending upon whether or not the library is being mapped or unmapped,
885 and then set to RT_CONSISTENT after the library is mapped/unmapped.
898 /* Get link_dynamic structure */
900 j
= target_read_memory (debug_base
, (char *) &dynamic_copy
,
901 sizeof (dynamic_copy
));
908 /* Calc address of debugger interface structure */
910 debug_addr
= (CORE_ADDR
) dynamic_copy
.ldd
;
912 /* Calc address of `in_debugger' member of debugger interface structure */
914 flag_addr
= debug_addr
+ (CORE_ADDR
) ((char *) &debug_copy
.ldd_in_debugger
-
915 (char *) &debug_copy
);
917 /* Write a value of 1 to this member. */
921 write_memory (flag_addr
, &in_debugger
, sizeof (in_debugger
));
929 i
= lookup_misc_func ("main");
930 if (i
>= 0 && misc_function_vector
[i
].address
!= 0)
932 breakpoint_addr
= misc_function_vector
[i
].address
;
939 if (target_insert_breakpoint (breakpoint_addr
, shadow_contents
) != 0)
944 #else /* !BKPT_AT_MAIN */
946 struct symtab_and_line sal
;
948 /* Read the debugger interface structure directly. */
950 read_memory (debug_base
, (char *) &debug_copy
, sizeof (debug_copy
));
952 /* Set breakpoint at the debugger interface stub routine that will
953 be called just prior to each mapping change and again after the
954 mapping change is complete. Set up the (nonexistent) handler to
955 deal with hitting these breakpoints. (FIXME). */
957 warning ("'%s': line %d: missing SVR4 support code", __FILE__
, __LINE__
);
959 #endif /* BKPT_AT_MAIN */
970 solib_create_inferior_hook -- shared library startup support
974 void solib_create_inferior_hook()
978 When gdb starts up the inferior, it nurses it along (through the
979 shell) until it is ready to execute it's first instruction. At this
980 point, this function gets called via expansion of the macro
981 SOLIB_CREATE_INFERIOR_HOOK.
983 For both SunOS shared libraries, and SVR4 shared libraries, we
984 can arrange to cooperate with the dynamic linker to discover the
985 names of shared libraries that are dynamically linked, and the
986 base addresses to which they are linked.
988 This function is responsible for discovering those names and
989 addresses, and saving sufficient information about them to allow
990 their symbols to be read at a later time.
994 Between enable_break() and disable_break(), this code does not
995 properly handle hitting breakpoints which the user might have
996 set in the startup code or in the dynamic linker itself. Proper
997 handling will probably have to wait until the implementation is
998 changed to use the "breakpoint handler function" method.
1000 Also, what if child has exit()ed? Must exit loop somehow.
1004 solib_create_inferior_hook()
1006 CORE_ADDR debug_addr
;
1008 CORE_ADDR in_debugger_addr
;
1009 CORE_ADDR breakpoint_addr
;
1012 if ((debug_base
= locate_base ()) == 0)
1014 /* Can't find the symbol or the executable is statically linked. */
1018 if (!enable_break ())
1020 warning ("shared library handler failed to enable breakpoint");
1024 /* Now run the target. It will eventually hit the breakpoint, at
1025 which point all of the libraries will have been mapped in and we
1026 can go groveling around in the dynamic linker structures to find
1027 out what we need to know about them. */
1029 clear_proceed_status ();
1030 stop_soon_quietly
= 1;
1034 target_resume (0, stop_signal
);
1035 wait_for_inferior ();
1037 while (stop_signal
!= SIGTRAP
);
1038 stop_soon_quietly
= 0;
1040 /* We are now either at the "mapping complete" breakpoint (or somewhere
1041 else, a condition we aren't prepared to deal with anyway), so adjust
1042 the PC as necessary after a breakpoint, disable the breakpoint, and
1043 add any shared libraries that were mapped in. */
1045 if (DECR_PC_AFTER_BREAK
)
1047 stop_pc
-= DECR_PC_AFTER_BREAK
;
1048 write_register (PC_REGNUM
, stop_pc
);
1051 if (!disable_break ())
1053 warning ("shared library handler failed to disable breakpoint");
1056 solib_add ((char *) 0, 0, (struct target_ops
*) 0);
1063 sharedlibrary_command -- handle command to explicitly add library
1067 void sharedlibrary_command (char *args, int from_tty)
1074 sharedlibrary_command (args
, from_tty
)
1079 solib_add (args
, from_tty
, (struct target_ops
*) 0);
1086 add_com ("sharedlibrary", class_files
, sharedlibrary_command
,
1087 "Load shared object library symbols for files matching REGEXP.");
1088 add_info ("sharedlibrary", info_sharedlibrary_command
,
1089 "Status of loaded shared object libraries.");