* gdb.base/a1-selftest.exp: Change initial stepping to know about
[deliverable/binutils-gdb.git] / gdb / solib.c
1 /* Handle SunOS and SVR4 shared libraries for GDB, the GNU Debugger.
2 Copyright 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
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.
10
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.
15
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. */
19
20
21 #include "defs.h"
22
23 #include <sys/types.h>
24 #include <signal.h>
25 #include <string.h>
26 #include <link.h>
27 #include <sys/param.h>
28 #include <fcntl.h>
29
30 #ifndef SVR4_SHARED_LIBS
31 /* SunOS shared libs need the nlist structure. */
32 #include <a.out.h>
33 #else
34 #include "libelf.h"
35 #ifndef DT_MIPS_RLD_MAP
36 #include "elf/mips.h"
37 #endif
38 #endif
39
40 #include "symtab.h"
41 #include "bfd.h"
42 #include "symfile.h"
43 #include "objfiles.h"
44 #include "gdbcore.h"
45 #include "command.h"
46 #include "target.h"
47 #include "frame.h"
48 #include "regex.h"
49 #include "inferior.h"
50 #include "language.h"
51
52 #define MAX_PATH_SIZE 256 /* FIXME: Should be dynamic */
53
54 /* On SVR4 systems, for the initial implementation, use some runtime startup
55 symbol as the "startup mapping complete" breakpoint address. The models
56 for SunOS and SVR4 dynamic linking debugger support are different in that
57 SunOS hits one breakpoint when all mapping is complete while using the SVR4
58 debugger support takes two breakpoint hits for each file mapped, and
59 there is no way to know when the "last" one is hit. Both these
60 mechanisms should be tied to a "breakpoint service routine" that
61 gets automatically executed whenever one of the breakpoints indicating
62 a change in mapping is hit. This is a future enhancement. (FIXME) */
63
64 #define BKPT_AT_SYMBOL 1
65
66 #if defined (BKPT_AT_SYMBOL) && defined (SVR4_SHARED_LIBS)
67 static char *bkpt_names[] = {
68 #ifdef SOLIB_BKPT_NAME
69 SOLIB_BKPT_NAME, /* Prefer configured name if it exists. */
70 #endif
71 "_start",
72 "main",
73 NULL
74 };
75 #endif
76
77 /* Symbols which are used to locate the base of the link map structures. */
78
79 #ifndef SVR4_SHARED_LIBS
80 static char *debug_base_symbols[] = {
81 "_DYNAMIC",
82 NULL
83 };
84 #endif
85
86 /* local data declarations */
87
88 #ifndef SVR4_SHARED_LIBS
89
90 #define LM_ADDR(so) ((so) -> lm.lm_addr)
91 #define LM_NEXT(so) ((so) -> lm.lm_next)
92 #define LM_NAME(so) ((so) -> lm.lm_name)
93 /* Test for first link map entry; first entry is a shared library. */
94 #define IGNORE_FIRST_LINK_MAP_ENTRY(x) (0)
95 static struct link_dynamic dynamic_copy;
96 static struct link_dynamic_2 ld_2_copy;
97 static struct ld_debug debug_copy;
98 static CORE_ADDR debug_addr;
99 static CORE_ADDR flag_addr;
100
101 #else /* SVR4_SHARED_LIBS */
102
103 #define LM_ADDR(so) ((so) -> lm.l_addr)
104 #define LM_NEXT(so) ((so) -> lm.l_next)
105 #define LM_NAME(so) ((so) -> lm.l_name)
106 /* Test for first link map entry; first entry is the exec-file. */
107 #define IGNORE_FIRST_LINK_MAP_ENTRY(x) ((x).l_prev == NULL)
108 static struct r_debug debug_copy;
109 char shadow_contents[BREAKPOINT_MAX]; /* Stash old bkpt addr contents */
110
111 #endif /* !SVR4_SHARED_LIBS */
112
113 struct so_list {
114 struct so_list *next; /* next structure in linked list */
115 struct link_map lm; /* copy of link map from inferior */
116 struct link_map *lmaddr; /* addr in inferior lm was read from */
117 CORE_ADDR lmend; /* upper addr bound of mapped object */
118 char so_name[MAX_PATH_SIZE]; /* shared object lib name (FIXME) */
119 char symbols_loaded; /* flag: symbols read in yet? */
120 char from_tty; /* flag: print msgs? */
121 struct objfile *objfile; /* objfile for loaded lib */
122 struct section_table *sections;
123 struct section_table *sections_end;
124 struct section_table *textsection;
125 bfd *abfd;
126 };
127
128 static struct so_list *so_list_head; /* List of known shared objects */
129 static CORE_ADDR debug_base; /* Base of dynamic linker structures */
130 static CORE_ADDR breakpoint_addr; /* Address where end bkpt is set */
131
132 extern int
133 fdmatch PARAMS ((int, int)); /* In libiberty */
134
135 /* Local function prototypes */
136
137 static void
138 special_symbol_handling PARAMS ((struct so_list *));
139
140 static void
141 sharedlibrary_command PARAMS ((char *, int));
142
143 static int
144 enable_break PARAMS ((void));
145
146 static int
147 disable_break PARAMS ((void));
148
149 static void
150 info_sharedlibrary_command PARAMS ((char *, int));
151
152 static int
153 symbol_add_stub PARAMS ((char *));
154
155 static struct so_list *
156 find_solib PARAMS ((struct so_list *));
157
158 static struct link_map *
159 first_link_map_member PARAMS ((void));
160
161 static CORE_ADDR
162 locate_base PARAMS ((void));
163
164 static void
165 solib_map_sections PARAMS ((struct so_list *));
166
167 #ifdef SVR4_SHARED_LIBS
168
169 static CORE_ADDR
170 elf_locate_base PARAMS ((void));
171
172 #else
173
174 static void
175 solib_add_common_symbols PARAMS ((struct rtc_symb *, struct objfile *));
176
177 #endif
178
179 /*
180
181 LOCAL FUNCTION
182
183 solib_map_sections -- open bfd and build sections for shared lib
184
185 SYNOPSIS
186
187 static void solib_map_sections (struct so_list *so)
188
189 DESCRIPTION
190
191 Given a pointer to one of the shared objects in our list
192 of mapped objects, use the recorded name to open a bfd
193 descriptor for the object, build a section table, and then
194 relocate all the section addresses by the base address at
195 which the shared object was mapped.
196
197 FIXMES
198
199 In most (all?) cases the shared object file name recorded in the
200 dynamic linkage tables will be a fully qualified pathname. For
201 cases where it isn't, do we really mimic the systems search
202 mechanism correctly in the below code (particularly the tilde
203 expansion stuff?).
204 */
205
206 static void
207 solib_map_sections (so)
208 struct so_list *so;
209 {
210 char *filename;
211 char *scratch_pathname;
212 int scratch_chan;
213 struct section_table *p;
214 struct cleanup *old_chain;
215 bfd *abfd;
216
217 filename = tilde_expand (so -> so_name);
218 old_chain = make_cleanup (free, filename);
219
220 scratch_chan = openp (getenv ("PATH"), 1, filename, O_RDONLY, 0,
221 &scratch_pathname);
222 if (scratch_chan < 0)
223 {
224 scratch_chan = openp (getenv ("LD_LIBRARY_PATH"), 1, filename,
225 O_RDONLY, 0, &scratch_pathname);
226 }
227 if (scratch_chan < 0)
228 {
229 perror_with_name (filename);
230 }
231 /* Leave scratch_pathname allocated. abfd->name will point to it. */
232
233 abfd = bfd_fdopenr (scratch_pathname, gnutarget, scratch_chan);
234 if (!abfd)
235 {
236 close (scratch_chan);
237 error ("Could not open `%s' as an executable file: %s",
238 scratch_pathname, bfd_errmsg (bfd_get_error ()));
239 }
240 /* Leave bfd open, core_xfer_memory and "info files" need it. */
241 so -> abfd = abfd;
242 abfd -> cacheable = true;
243
244 if (!bfd_check_format (abfd, bfd_object))
245 {
246 error ("\"%s\": not in executable format: %s.",
247 scratch_pathname, bfd_errmsg (bfd_get_error ()));
248 }
249 if (build_section_table (abfd, &so -> sections, &so -> sections_end))
250 {
251 error ("Can't find the file sections in `%s': %s",
252 bfd_get_filename (abfd), bfd_errmsg (bfd_get_error ()));
253 }
254
255 for (p = so -> sections; p < so -> sections_end; p++)
256 {
257 /* Relocate the section binding addresses as recorded in the shared
258 object's file by the base address to which the object was actually
259 mapped. */
260 p -> addr += (CORE_ADDR) LM_ADDR (so);
261 p -> endaddr += (CORE_ADDR) LM_ADDR (so);
262 so -> lmend = (CORE_ADDR) max (p -> endaddr, so -> lmend);
263 if (STREQ (p -> the_bfd_section -> name, ".text"))
264 {
265 so -> textsection = p;
266 }
267 }
268
269 /* Free the file names, close the file now. */
270 do_cleanups (old_chain);
271 }
272
273 /* Read all dynamically loaded common symbol definitions from the inferior
274 and add them to the minimal symbol table for the shared library objfile. */
275
276 #ifndef SVR4_SHARED_LIBS
277
278 /* In GDB 4.9 this routine was a real performance hog. According to
279 some gprof data which mtranle@paris.IntelliCorp.COM (Minh Tran-Le)
280 sent, almost all the time spend in solib_add (up to 20 minutes with
281 35 shared libraries) was spent here, with 5/6 in
282 lookup_minimal_symbol and 1/6 in read_memory.
283
284 To fix this, we moved the call to special_symbol_handling out of the
285 loop in solib_add, so this only gets called once, rather than once
286 for every shared library, and also removed the call to lookup_minimal_symbol
287 in this routine. */
288
289 static void
290 solib_add_common_symbols (rtc_symp, objfile)
291 struct rtc_symb *rtc_symp;
292 struct objfile *objfile;
293 {
294 struct rtc_symb inferior_rtc_symb;
295 struct nlist inferior_rtc_nlist;
296 int len;
297 char *name;
298 char *origname;
299
300 init_minimal_symbol_collection ();
301 make_cleanup (discard_minimal_symbols, 0);
302
303 while (rtc_symp)
304 {
305 read_memory ((CORE_ADDR) rtc_symp,
306 (char *) &inferior_rtc_symb,
307 sizeof (inferior_rtc_symb));
308 read_memory ((CORE_ADDR) inferior_rtc_symb.rtc_sp,
309 (char *) &inferior_rtc_nlist,
310 sizeof(inferior_rtc_nlist));
311 if (inferior_rtc_nlist.n_type == N_COMM)
312 {
313 /* FIXME: The length of the symbol name is not available, but in the
314 current implementation the common symbol is allocated immediately
315 behind the name of the symbol. */
316 len = inferior_rtc_nlist.n_value - inferior_rtc_nlist.n_un.n_strx;
317
318 origname = name = xmalloc (len);
319 read_memory ((CORE_ADDR) inferior_rtc_nlist.n_un.n_name, name, len);
320
321 /* Don't enter the symbol twice if the target is re-run. */
322
323 if (name[0] == bfd_get_symbol_leading_char (objfile->obfd))
324 {
325 name++;
326 }
327
328 #if 0
329 /* I think this is unnecessary, GDB can probably deal with
330 duplicate minimal symbols, more or less. And the duplication
331 which used to happen because this was called for each shared
332 library is gone now that we are just called once. */
333 /* FIXME: Do we really want to exclude symbols which happen
334 to match symbols for other locations in the inferior's
335 address space, even when they are in different linkage units? */
336 if (lookup_minimal_symbol (name, (struct objfile *) NULL) == NULL)
337 #endif
338 {
339 name = obsavestring (name, strlen (name),
340 &objfile -> symbol_obstack);
341 prim_record_minimal_symbol (name, inferior_rtc_nlist.n_value,
342 mst_bss, objfile);
343 }
344 free (origname);
345 }
346 rtc_symp = inferior_rtc_symb.rtc_next;
347 }
348
349 /* Install any minimal symbols that have been collected as the current
350 minimal symbols for this objfile. */
351
352 install_minimal_symbols (objfile);
353 }
354
355 #endif /* SVR4_SHARED_LIBS */
356
357
358 #ifdef SVR4_SHARED_LIBS
359
360 #ifdef HANDLE_SVR4_EXEC_EMULATORS
361
362 /*
363 Solaris BCP (the part of Solaris which allows it to run SunOS4
364 a.out files) throws in another wrinkle. Solaris does not fill
365 in the usual a.out link map structures when running BCP programs,
366 the only way to get at them is via groping around in the dynamic
367 linker.
368 The dynamic linker and it's structures are located in the shared
369 C library, which gets run as the executable's "interpreter" by
370 the kernel.
371
372 Note that we can assume nothing about the process state at the time
373 we need to find these structures. We may be stopped on the first
374 instruction of the interpreter (C shared library), the first
375 instruction of the executable itself, or somewhere else entirely
376 (if we attached to the process for example).
377 */
378
379 static char *debug_base_symbols[] = {
380 "r_debug", /* Solaris 2.3 */
381 "_r_debug", /* Solaris 2.1, 2.2 */
382 NULL
383 };
384
385 static int
386 look_for_base PARAMS ((int, CORE_ADDR));
387
388 static CORE_ADDR
389 bfd_lookup_symbol PARAMS ((bfd *, char *));
390
391 /*
392
393 LOCAL FUNCTION
394
395 bfd_lookup_symbol -- lookup the value for a specific symbol
396
397 SYNOPSIS
398
399 CORE_ADDR bfd_lookup_symbol (bfd *abfd, char *symname)
400
401 DESCRIPTION
402
403 An expensive way to lookup the value of a single symbol for
404 bfd's that are only temporary anyway. This is used by the
405 shared library support to find the address of the debugger
406 interface structures in the shared library.
407
408 Note that 0 is specifically allowed as an error return (no
409 such symbol).
410 */
411
412 static CORE_ADDR
413 bfd_lookup_symbol (abfd, symname)
414 bfd *abfd;
415 char *symname;
416 {
417 unsigned int storage_needed;
418 asymbol *sym;
419 asymbol **symbol_table;
420 unsigned int number_of_symbols;
421 unsigned int i;
422 struct cleanup *back_to;
423 CORE_ADDR symaddr = 0;
424
425 storage_needed = bfd_get_symtab_upper_bound (abfd);
426
427 if (storage_needed > 0)
428 {
429 symbol_table = (asymbol **) xmalloc (storage_needed);
430 back_to = make_cleanup (free, (PTR)symbol_table);
431 number_of_symbols = bfd_canonicalize_symtab (abfd, symbol_table);
432
433 for (i = 0; i < number_of_symbols; i++)
434 {
435 sym = *symbol_table++;
436 if (STREQ (sym -> name, symname))
437 {
438 /* Bfd symbols are section relative. */
439 symaddr = sym -> value + sym -> section -> vma;
440 break;
441 }
442 }
443 do_cleanups (back_to);
444 }
445 return (symaddr);
446 }
447
448 /*
449
450 LOCAL FUNCTION
451
452 look_for_base -- examine file for each mapped address segment
453
454 SYNOPSYS
455
456 static int look_for_base (int fd, CORE_ADDR baseaddr)
457
458 DESCRIPTION
459
460 This function is passed to proc_iterate_over_mappings, which
461 causes it to get called once for each mapped address space, with
462 an open file descriptor for the file mapped to that space, and the
463 base address of that mapped space.
464
465 Our job is to find the debug base symbol in the file that this
466 fd is open on, if it exists, and if so, initialize the dynamic
467 linker structure base address debug_base.
468
469 Note that this is a computationally expensive proposition, since
470 we basically have to open a bfd on every call, so we specifically
471 avoid opening the exec file.
472 */
473
474 static int
475 look_for_base (fd, baseaddr)
476 int fd;
477 CORE_ADDR baseaddr;
478 {
479 bfd *interp_bfd;
480 CORE_ADDR address = 0;
481 char **symbolp;
482
483 /* If the fd is -1, then there is no file that corresponds to this
484 mapped memory segment, so skip it. Also, if the fd corresponds
485 to the exec file, skip it as well. */
486
487 if (fd == -1
488 || (exec_bfd != NULL
489 && fdmatch (fileno ((GDB_FILE *)(exec_bfd -> iostream)), fd)))
490 {
491 return (0);
492 }
493
494 /* Try to open whatever random file this fd corresponds to. Note that
495 we have no way currently to find the filename. Don't gripe about
496 any problems we might have, just fail. */
497
498 if ((interp_bfd = bfd_fdopenr ("unnamed", gnutarget, fd)) == NULL)
499 {
500 return (0);
501 }
502 if (!bfd_check_format (interp_bfd, bfd_object))
503 {
504 bfd_close (interp_bfd);
505 return (0);
506 }
507
508 /* Now try to find our debug base symbol in this file, which we at
509 least know to be a valid ELF executable or shared library. */
510
511 for (symbolp = debug_base_symbols; *symbolp != NULL; symbolp++)
512 {
513 address = bfd_lookup_symbol (interp_bfd, *symbolp);
514 if (address != 0)
515 {
516 break;
517 }
518 }
519 if (address == 0)
520 {
521 bfd_close (interp_bfd);
522 return (0);
523 }
524
525 /* Eureka! We found the symbol. But now we may need to relocate it
526 by the base address. If the symbol's value is less than the base
527 address of the shared library, then it hasn't yet been relocated
528 by the dynamic linker, and we have to do it ourself. FIXME: Note
529 that we make the assumption that the first segment that corresponds
530 to the shared library has the base address to which the library
531 was relocated. */
532
533 if (address < baseaddr)
534 {
535 address += baseaddr;
536 }
537 debug_base = address;
538 bfd_close (interp_bfd);
539 return (1);
540 }
541 #endif /* HANDLE_SVR4_EXEC_EMULATORS */
542
543 /*
544
545 LOCAL FUNCTION
546
547 elf_locate_base -- locate the base address of dynamic linker structs
548 for SVR4 elf targets.
549
550 SYNOPSIS
551
552 CORE_ADDR elf_locate_base (void)
553
554 DESCRIPTION
555
556 For SVR4 elf targets the address of the dynamic linker's runtime
557 structure is contained within the dynamic info section in the
558 executable file. The dynamic section is also mapped into the
559 inferior address space. Because the runtime loader fills in the
560 real address before starting the inferior, we have to read in the
561 dynamic info section from the inferior address space.
562 If there are any errors while trying to find the address, we
563 silently return 0, otherwise the found address is returned.
564
565 */
566
567 static CORE_ADDR
568 elf_locate_base ()
569 {
570 struct elf_internal_shdr *dyninfo_sect;
571 int dyninfo_sect_size;
572 CORE_ADDR dyninfo_addr;
573 char *buf;
574 char *bufend;
575
576 /* Find the start address of the .dynamic section. */
577 dyninfo_sect = bfd_elf_find_section (exec_bfd, ".dynamic");
578 if (dyninfo_sect == NULL)
579 return 0;
580 dyninfo_addr = dyninfo_sect->sh_addr;
581
582 /* Read in .dynamic section, silently ignore errors. */
583 dyninfo_sect_size = dyninfo_sect->sh_size;
584 buf = alloca (dyninfo_sect_size);
585 if (target_read_memory (dyninfo_addr, buf, dyninfo_sect_size))
586 return 0;
587
588 /* Find the DT_DEBUG entry in the the .dynamic section.
589 For mips elf we look for DT_MIPS_RLD_MAP, mips elf apparently has
590 no DT_DEBUG entries. */
591 /* FIXME: In lack of a 64 bit ELF ABI the following code assumes
592 a 32 bit ELF ABI target. */
593 for (bufend = buf + dyninfo_sect_size;
594 buf < bufend;
595 buf += sizeof (Elf32_External_Dyn))
596 {
597 Elf32_External_Dyn *x_dynp = (Elf32_External_Dyn *)buf;
598 long dyn_tag;
599 CORE_ADDR dyn_ptr;
600
601 dyn_tag = bfd_h_get_32 (exec_bfd, (bfd_byte *) x_dynp->d_tag);
602 if (dyn_tag == DT_NULL)
603 break;
604 else if (dyn_tag == DT_DEBUG)
605 {
606 dyn_ptr = bfd_h_get_32 (exec_bfd, (bfd_byte *) x_dynp->d_un.d_ptr);
607 return dyn_ptr;
608 }
609 else if (dyn_tag == DT_MIPS_RLD_MAP)
610 {
611 char pbuf[TARGET_PTR_BIT / HOST_CHAR_BIT];
612
613 /* DT_MIPS_RLD_MAP contains a pointer to the address
614 of the dynamic link structure. */
615 dyn_ptr = bfd_h_get_32 (exec_bfd, (bfd_byte *) x_dynp->d_un.d_ptr);
616 if (target_read_memory (dyn_ptr, pbuf, sizeof (pbuf)))
617 return 0;
618 return extract_unsigned_integer (pbuf, sizeof (pbuf));
619 }
620 }
621
622 /* DT_DEBUG entry not found. */
623 return 0;
624 }
625
626 #endif /* SVR4_SHARED_LIBS */
627
628 /*
629
630 LOCAL FUNCTION
631
632 locate_base -- locate the base address of dynamic linker structs
633
634 SYNOPSIS
635
636 CORE_ADDR locate_base (void)
637
638 DESCRIPTION
639
640 For both the SunOS and SVR4 shared library implementations, if the
641 inferior executable has been linked dynamically, there is a single
642 address somewhere in the inferior's data space which is the key to
643 locating all of the dynamic linker's runtime structures. This
644 address is the value of the debug base symbol. The job of this
645 function is to find and return that address, or to return 0 if there
646 is no such address (the executable is statically linked for example).
647
648 For SunOS, the job is almost trivial, since the dynamic linker and
649 all of it's structures are statically linked to the executable at
650 link time. Thus the symbol for the address we are looking for has
651 already been added to the minimal symbol table for the executable's
652 objfile at the time the symbol file's symbols were read, and all we
653 have to do is look it up there. Note that we explicitly do NOT want
654 to find the copies in the shared library.
655
656 The SVR4 version is a bit more complicated because the address
657 is contained somewhere in the dynamic info section. We have to go
658 to a lot more work to discover the address of the debug base symbol.
659 Because of this complexity, we cache the value we find and return that
660 value on subsequent invocations. Note there is no copy in the
661 executable symbol tables.
662
663 */
664
665 static CORE_ADDR
666 locate_base ()
667 {
668
669 #ifndef SVR4_SHARED_LIBS
670
671 struct minimal_symbol *msymbol;
672 CORE_ADDR address = 0;
673 char **symbolp;
674
675 /* For SunOS, we want to limit the search for the debug base symbol to the
676 executable being debugged, since there is a duplicate named symbol in the
677 shared library. We don't want the shared library versions. */
678
679 for (symbolp = debug_base_symbols; *symbolp != NULL; symbolp++)
680 {
681 msymbol = lookup_minimal_symbol (*symbolp, symfile_objfile);
682 if ((msymbol != NULL) && (SYMBOL_VALUE_ADDRESS (msymbol) != 0))
683 {
684 address = SYMBOL_VALUE_ADDRESS (msymbol);
685 return (address);
686 }
687 }
688 return (0);
689
690 #else /* SVR4_SHARED_LIBS */
691
692 /* Check to see if we have a currently valid address, and if so, avoid
693 doing all this work again and just return the cached address. If
694 we have no cached address, try to locate it in the dynamic info
695 section for ELF executables. */
696
697 if (debug_base == 0)
698 {
699 if (exec_bfd != NULL
700 && bfd_get_flavour (exec_bfd) == bfd_target_elf_flavour)
701 debug_base = elf_locate_base ();
702 #ifdef HANDLE_SVR4_EXEC_EMULATORS
703 /* Try it the hard way for emulated executables. */
704 else if (inferior_pid != 0)
705 proc_iterate_over_mappings (look_for_base);
706 #endif
707 }
708 return (debug_base);
709
710 #endif /* !SVR4_SHARED_LIBS */
711
712 }
713
714 /*
715
716 LOCAL FUNCTION
717
718 first_link_map_member -- locate first member in dynamic linker's map
719
720 SYNOPSIS
721
722 static struct link_map *first_link_map_member (void)
723
724 DESCRIPTION
725
726 Read in a copy of the first member in the inferior's dynamic
727 link map from the inferior's dynamic linker structures, and return
728 a pointer to the copy in our address space.
729 */
730
731 static struct link_map *
732 first_link_map_member ()
733 {
734 struct link_map *lm = NULL;
735
736 #ifndef SVR4_SHARED_LIBS
737
738 read_memory (debug_base, (char *) &dynamic_copy, sizeof (dynamic_copy));
739 if (dynamic_copy.ld_version >= 2)
740 {
741 /* It is a version that we can deal with, so read in the secondary
742 structure and find the address of the link map list from it. */
743 read_memory ((CORE_ADDR) dynamic_copy.ld_un.ld_2, (char *) &ld_2_copy,
744 sizeof (struct link_dynamic_2));
745 lm = ld_2_copy.ld_loaded;
746 }
747
748 #else /* SVR4_SHARED_LIBS */
749
750 read_memory (debug_base, (char *) &debug_copy, sizeof (struct r_debug));
751 /* FIXME: Perhaps we should validate the info somehow, perhaps by
752 checking r_version for a known version number, or r_state for
753 RT_CONSISTENT. */
754 lm = debug_copy.r_map;
755
756 #endif /* !SVR4_SHARED_LIBS */
757
758 return (lm);
759 }
760
761 /*
762
763 LOCAL FUNCTION
764
765 find_solib -- step through list of shared objects
766
767 SYNOPSIS
768
769 struct so_list *find_solib (struct so_list *so_list_ptr)
770
771 DESCRIPTION
772
773 This module contains the routine which finds the names of any
774 loaded "images" in the current process. The argument in must be
775 NULL on the first call, and then the returned value must be passed
776 in on subsequent calls. This provides the capability to "step" down
777 the list of loaded objects. On the last object, a NULL value is
778 returned.
779
780 The arg and return value are "struct link_map" pointers, as defined
781 in <link.h>.
782 */
783
784 static struct so_list *
785 find_solib (so_list_ptr)
786 struct so_list *so_list_ptr; /* Last lm or NULL for first one */
787 {
788 struct so_list *so_list_next = NULL;
789 struct link_map *lm = NULL;
790 struct so_list *new;
791
792 if (so_list_ptr == NULL)
793 {
794 /* We are setting up for a new scan through the loaded images. */
795 if ((so_list_next = so_list_head) == NULL)
796 {
797 /* We have not already read in the dynamic linking structures
798 from the inferior, lookup the address of the base structure. */
799 debug_base = locate_base ();
800 if (debug_base != 0)
801 {
802 /* Read the base structure in and find the address of the first
803 link map list member. */
804 lm = first_link_map_member ();
805 }
806 }
807 }
808 else
809 {
810 /* We have been called before, and are in the process of walking
811 the shared library list. Advance to the next shared object. */
812 if ((lm = LM_NEXT (so_list_ptr)) == NULL)
813 {
814 /* We have hit the end of the list, so check to see if any were
815 added, but be quiet if we can't read from the target any more. */
816 int status = target_read_memory ((CORE_ADDR) so_list_ptr -> lmaddr,
817 (char *) &(so_list_ptr -> lm),
818 sizeof (struct link_map));
819 if (status == 0)
820 {
821 lm = LM_NEXT (so_list_ptr);
822 }
823 else
824 {
825 lm = NULL;
826 }
827 }
828 so_list_next = so_list_ptr -> next;
829 }
830 if ((so_list_next == NULL) && (lm != NULL))
831 {
832 /* Get next link map structure from inferior image and build a local
833 abbreviated load_map structure */
834 new = (struct so_list *) xmalloc (sizeof (struct so_list));
835 memset ((char *) new, 0, sizeof (struct so_list));
836 new -> lmaddr = lm;
837 /* Add the new node as the next node in the list, or as the root
838 node if this is the first one. */
839 if (so_list_ptr != NULL)
840 {
841 so_list_ptr -> next = new;
842 }
843 else
844 {
845 so_list_head = new;
846 }
847 so_list_next = new;
848 read_memory ((CORE_ADDR) lm, (char *) &(new -> lm),
849 sizeof (struct link_map));
850 /* For SVR4 versions, the first entry in the link map is for the
851 inferior executable, so we must ignore it. For some versions of
852 SVR4, it has no name. For others (Solaris 2.3 for example), it
853 does have a name, so we can no longer use a missing name to
854 decide when to ignore it. */
855 if (!IGNORE_FIRST_LINK_MAP_ENTRY (new -> lm))
856 {
857 int errcode;
858 char *buffer;
859 target_read_string ((CORE_ADDR) LM_NAME (new), &buffer,
860 MAX_PATH_SIZE - 1, &errcode);
861 if (errcode != 0)
862 error ("find_solib: Can't read pathname for load map: %s\n",
863 safe_strerror (errcode));
864 strncpy (new -> so_name, buffer, MAX_PATH_SIZE - 1);
865 new -> so_name[MAX_PATH_SIZE - 1] = '\0';
866 free (buffer);
867 solib_map_sections (new);
868 }
869 }
870 return (so_list_next);
871 }
872
873 /* A small stub to get us past the arg-passing pinhole of catch_errors. */
874
875 static int
876 symbol_add_stub (arg)
877 char *arg;
878 {
879 register struct so_list *so = (struct so_list *) arg; /* catch_errs bogon */
880
881 so -> objfile =
882 symbol_file_add (so -> so_name, so -> from_tty,
883 (so->textsection == NULL
884 ? 0
885 : (unsigned int) so -> textsection -> addr),
886 0, 0, 0);
887 return (1);
888 }
889
890 /*
891
892 GLOBAL FUNCTION
893
894 solib_add -- add a shared library file to the symtab and section list
895
896 SYNOPSIS
897
898 void solib_add (char *arg_string, int from_tty,
899 struct target_ops *target)
900
901 DESCRIPTION
902
903 */
904
905 void
906 solib_add (arg_string, from_tty, target)
907 char *arg_string;
908 int from_tty;
909 struct target_ops *target;
910 {
911 register struct so_list *so = NULL; /* link map state variable */
912
913 /* Last shared library that we read. */
914 struct so_list *so_last = NULL;
915
916 char *re_err;
917 int count;
918 int old;
919
920 if ((re_err = re_comp (arg_string ? arg_string : ".")) != NULL)
921 {
922 error ("Invalid regexp: %s", re_err);
923 }
924
925 /* Add the shared library sections to the section table of the
926 specified target, if any. */
927 if (target)
928 {
929 /* Count how many new section_table entries there are. */
930 so = NULL;
931 count = 0;
932 while ((so = find_solib (so)) != NULL)
933 {
934 if (so -> so_name[0])
935 {
936 count += so -> sections_end - so -> sections;
937 }
938 }
939
940 if (count)
941 {
942 /* Reallocate the target's section table including the new size. */
943 if (target -> to_sections)
944 {
945 old = target -> to_sections_end - target -> to_sections;
946 target -> to_sections = (struct section_table *)
947 xrealloc ((char *)target -> to_sections,
948 (sizeof (struct section_table)) * (count + old));
949 }
950 else
951 {
952 old = 0;
953 target -> to_sections = (struct section_table *)
954 xmalloc ((sizeof (struct section_table)) * count);
955 }
956 target -> to_sections_end = target -> to_sections + (count + old);
957
958 /* Add these section table entries to the target's table. */
959 while ((so = find_solib (so)) != NULL)
960 {
961 if (so -> so_name[0])
962 {
963 count = so -> sections_end - so -> sections;
964 memcpy ((char *) (target -> to_sections + old),
965 so -> sections,
966 (sizeof (struct section_table)) * count);
967 old += count;
968 }
969 }
970 }
971 }
972
973 /* Now add the symbol files. */
974 while ((so = find_solib (so)) != NULL)
975 {
976 if (so -> so_name[0] && re_exec (so -> so_name))
977 {
978 so -> from_tty = from_tty;
979 if (so -> symbols_loaded)
980 {
981 if (from_tty)
982 {
983 printf_unfiltered ("Symbols already loaded for %s\n", so -> so_name);
984 }
985 }
986 else if (catch_errors
987 (symbol_add_stub, (char *) so,
988 "Error while reading shared library symbols:\n",
989 RETURN_MASK_ALL))
990 {
991 so_last = so;
992 so -> symbols_loaded = 1;
993 }
994 }
995 }
996
997 /* Getting new symbols may change our opinion about what is
998 frameless. */
999 if (so_last)
1000 reinit_frame_cache ();
1001
1002 /* Calling this once at the end means that we put all the minimal
1003 symbols for commons into the objfile for the last shared library.
1004 Since they are in common, this should not be a problem. If we
1005 delete the objfile with the minimal symbols, we can put all the
1006 symbols into a new objfile (and will on the next call to solib_add).
1007
1008 An alternate approach would be to create an objfile just for
1009 common minsyms, thus not needing any objfile argument to
1010 solib_add_common_symbols. */
1011
1012 if (so_last)
1013 special_symbol_handling (so_last);
1014 }
1015
1016 /*
1017
1018 LOCAL FUNCTION
1019
1020 info_sharedlibrary_command -- code for "info sharedlibrary"
1021
1022 SYNOPSIS
1023
1024 static void info_sharedlibrary_command ()
1025
1026 DESCRIPTION
1027
1028 Walk through the shared library list and print information
1029 about each attached library.
1030 */
1031
1032 static void
1033 info_sharedlibrary_command (ignore, from_tty)
1034 char *ignore;
1035 int from_tty;
1036 {
1037 register struct so_list *so = NULL; /* link map state variable */
1038 int header_done = 0;
1039
1040 if (exec_bfd == NULL)
1041 {
1042 printf_unfiltered ("No exec file.\n");
1043 return;
1044 }
1045 while ((so = find_solib (so)) != NULL)
1046 {
1047 if (so -> so_name[0])
1048 {
1049 if (!header_done)
1050 {
1051 printf_unfiltered("%-12s%-12s%-12s%s\n", "From", "To", "Syms Read",
1052 "Shared Object Library");
1053 header_done++;
1054 }
1055 /* FIXME-32x64: need print_address_numeric with field width or
1056 some such. */
1057 printf_unfiltered ("%-12s",
1058 local_hex_string_custom ((unsigned long) LM_ADDR (so),
1059 "08l"));
1060 printf_unfiltered ("%-12s",
1061 local_hex_string_custom ((unsigned long) so -> lmend,
1062 "08l"));
1063 printf_unfiltered ("%-12s", so -> symbols_loaded ? "Yes" : "No");
1064 printf_unfiltered ("%s\n", so -> so_name);
1065 }
1066 }
1067 if (so_list_head == NULL)
1068 {
1069 printf_unfiltered ("No shared libraries loaded at this time.\n");
1070 }
1071 }
1072
1073 /*
1074
1075 GLOBAL FUNCTION
1076
1077 solib_address -- check to see if an address is in a shared lib
1078
1079 SYNOPSIS
1080
1081 int solib_address (CORE_ADDR address)
1082
1083 DESCRIPTION
1084
1085 Provides a hook for other gdb routines to discover whether or
1086 not a particular address is within the mapped address space of
1087 a shared library. Any address between the base mapping address
1088 and the first address beyond the end of the last mapping, is
1089 considered to be within the shared library address space, for
1090 our purposes.
1091
1092 For example, this routine is called at one point to disable
1093 breakpoints which are in shared libraries that are not currently
1094 mapped in.
1095 */
1096
1097 int
1098 solib_address (address)
1099 CORE_ADDR address;
1100 {
1101 register struct so_list *so = 0; /* link map state variable */
1102
1103 while ((so = find_solib (so)) != NULL)
1104 {
1105 if (so -> so_name[0])
1106 {
1107 if ((address >= (CORE_ADDR) LM_ADDR (so)) &&
1108 (address < (CORE_ADDR) so -> lmend))
1109 {
1110 return (1);
1111 }
1112 }
1113 }
1114 return (0);
1115 }
1116
1117 /* Called by free_all_symtabs */
1118
1119 void
1120 clear_solib()
1121 {
1122 struct so_list *next;
1123 char *bfd_filename;
1124
1125 while (so_list_head)
1126 {
1127 if (so_list_head -> sections)
1128 {
1129 free ((PTR)so_list_head -> sections);
1130 }
1131 if (so_list_head -> abfd)
1132 {
1133 bfd_filename = bfd_get_filename (so_list_head -> abfd);
1134 bfd_close (so_list_head -> abfd);
1135 }
1136 else
1137 /* This happens for the executable on SVR4. */
1138 bfd_filename = NULL;
1139
1140 next = so_list_head -> next;
1141 if (bfd_filename)
1142 free ((PTR)bfd_filename);
1143 free ((PTR)so_list_head);
1144 so_list_head = next;
1145 }
1146 debug_base = 0;
1147 }
1148
1149 /*
1150
1151 LOCAL FUNCTION
1152
1153 disable_break -- remove the "mapping changed" breakpoint
1154
1155 SYNOPSIS
1156
1157 static int disable_break ()
1158
1159 DESCRIPTION
1160
1161 Removes the breakpoint that gets hit when the dynamic linker
1162 completes a mapping change.
1163
1164 */
1165
1166 static int
1167 disable_break ()
1168 {
1169 int status = 1;
1170
1171 #ifndef SVR4_SHARED_LIBS
1172
1173 int in_debugger = 0;
1174
1175 /* Read the debugger structure from the inferior to retrieve the
1176 address of the breakpoint and the original contents of the
1177 breakpoint address. Remove the breakpoint by writing the original
1178 contents back. */
1179
1180 read_memory (debug_addr, (char *) &debug_copy, sizeof (debug_copy));
1181
1182 /* Set `in_debugger' to zero now. */
1183
1184 write_memory (flag_addr, (char *) &in_debugger, sizeof (in_debugger));
1185
1186 breakpoint_addr = (CORE_ADDR) debug_copy.ldd_bp_addr;
1187 write_memory (breakpoint_addr, (char *) &debug_copy.ldd_bp_inst,
1188 sizeof (debug_copy.ldd_bp_inst));
1189
1190 #else /* SVR4_SHARED_LIBS */
1191
1192 /* Note that breakpoint address and original contents are in our address
1193 space, so we just need to write the original contents back. */
1194
1195 if (memory_remove_breakpoint (breakpoint_addr, shadow_contents) != 0)
1196 {
1197 status = 0;
1198 }
1199
1200 #endif /* !SVR4_SHARED_LIBS */
1201
1202 /* For the SVR4 version, we always know the breakpoint address. For the
1203 SunOS version we don't know it until the above code is executed.
1204 Grumble if we are stopped anywhere besides the breakpoint address. */
1205
1206 if (stop_pc != breakpoint_addr)
1207 {
1208 warning ("stopped at unknown breakpoint while handling shared libraries");
1209 }
1210
1211 return (status);
1212 }
1213
1214 /*
1215
1216 LOCAL FUNCTION
1217
1218 enable_break -- arrange for dynamic linker to hit breakpoint
1219
1220 SYNOPSIS
1221
1222 int enable_break (void)
1223
1224 DESCRIPTION
1225
1226 Both the SunOS and the SVR4 dynamic linkers have, as part of their
1227 debugger interface, support for arranging for the inferior to hit
1228 a breakpoint after mapping in the shared libraries. This function
1229 enables that breakpoint.
1230
1231 For SunOS, there is a special flag location (in_debugger) which we
1232 set to 1. When the dynamic linker sees this flag set, it will set
1233 a breakpoint at a location known only to itself, after saving the
1234 original contents of that place and the breakpoint address itself,
1235 in it's own internal structures. When we resume the inferior, it
1236 will eventually take a SIGTRAP when it runs into the breakpoint.
1237 We handle this (in a different place) by restoring the contents of
1238 the breakpointed location (which is only known after it stops),
1239 chasing around to locate the shared libraries that have been
1240 loaded, then resuming.
1241
1242 For SVR4, the debugger interface structure contains a member (r_brk)
1243 which is statically initialized at the time the shared library is
1244 built, to the offset of a function (_r_debug_state) which is guaran-
1245 teed to be called once before mapping in a library, and again when
1246 the mapping is complete. At the time we are examining this member,
1247 it contains only the unrelocated offset of the function, so we have
1248 to do our own relocation. Later, when the dynamic linker actually
1249 runs, it relocates r_brk to be the actual address of _r_debug_state().
1250
1251 The debugger interface structure also contains an enumeration which
1252 is set to either RT_ADD or RT_DELETE prior to changing the mapping,
1253 depending upon whether or not the library is being mapped or unmapped,
1254 and then set to RT_CONSISTENT after the library is mapped/unmapped.
1255 */
1256
1257 static int
1258 enable_break ()
1259 {
1260 int success = 0;
1261
1262 #ifndef SVR4_SHARED_LIBS
1263
1264 int j;
1265 int in_debugger;
1266
1267 /* Get link_dynamic structure */
1268
1269 j = target_read_memory (debug_base, (char *) &dynamic_copy,
1270 sizeof (dynamic_copy));
1271 if (j)
1272 {
1273 /* unreadable */
1274 return (0);
1275 }
1276
1277 /* Calc address of debugger interface structure */
1278
1279 debug_addr = (CORE_ADDR) dynamic_copy.ldd;
1280
1281 /* Calc address of `in_debugger' member of debugger interface structure */
1282
1283 flag_addr = debug_addr + (CORE_ADDR) ((char *) &debug_copy.ldd_in_debugger -
1284 (char *) &debug_copy);
1285
1286 /* Write a value of 1 to this member. */
1287
1288 in_debugger = 1;
1289 write_memory (flag_addr, (char *) &in_debugger, sizeof (in_debugger));
1290 success = 1;
1291
1292 #else /* SVR4_SHARED_LIBS */
1293
1294 #ifdef BKPT_AT_SYMBOL
1295
1296 struct minimal_symbol *msymbol;
1297 char **bkpt_namep;
1298 CORE_ADDR bkpt_addr;
1299
1300 /* Scan through the list of symbols, trying to look up the symbol and
1301 set a breakpoint there. Terminate loop when we/if we succeed. */
1302
1303 breakpoint_addr = 0;
1304 for (bkpt_namep = bkpt_names; *bkpt_namep != NULL; bkpt_namep++)
1305 {
1306 msymbol = lookup_minimal_symbol (*bkpt_namep, symfile_objfile);
1307 if ((msymbol != NULL) && (SYMBOL_VALUE_ADDRESS (msymbol) != 0))
1308 {
1309 bkpt_addr = SYMBOL_VALUE_ADDRESS (msymbol);
1310 if (target_insert_breakpoint (bkpt_addr, shadow_contents) == 0)
1311 {
1312 breakpoint_addr = bkpt_addr;
1313 success = 1;
1314 break;
1315 }
1316 }
1317 }
1318
1319 #else /* !BKPT_AT_SYMBOL */
1320
1321 struct symtab_and_line sal;
1322
1323 /* Read the debugger interface structure directly. */
1324
1325 read_memory (debug_base, (char *) &debug_copy, sizeof (debug_copy));
1326
1327 /* Set breakpoint at the debugger interface stub routine that will
1328 be called just prior to each mapping change and again after the
1329 mapping change is complete. Set up the (nonexistent) handler to
1330 deal with hitting these breakpoints. (FIXME). */
1331
1332 warning ("'%s': line %d: missing SVR4 support code", __FILE__, __LINE__);
1333 success = 1;
1334
1335 #endif /* BKPT_AT_SYMBOL */
1336
1337 #endif /* !SVR4_SHARED_LIBS */
1338
1339 return (success);
1340 }
1341
1342 /*
1343
1344 GLOBAL FUNCTION
1345
1346 solib_create_inferior_hook -- shared library startup support
1347
1348 SYNOPSIS
1349
1350 void solib_create_inferior_hook()
1351
1352 DESCRIPTION
1353
1354 When gdb starts up the inferior, it nurses it along (through the
1355 shell) until it is ready to execute it's first instruction. At this
1356 point, this function gets called via expansion of the macro
1357 SOLIB_CREATE_INFERIOR_HOOK.
1358
1359 For SunOS executables, this first instruction is typically the
1360 one at "_start", or a similar text label, regardless of whether
1361 the executable is statically or dynamically linked. The runtime
1362 startup code takes care of dynamically linking in any shared
1363 libraries, once gdb allows the inferior to continue.
1364
1365 For SVR4 executables, this first instruction is either the first
1366 instruction in the dynamic linker (for dynamically linked
1367 executables) or the instruction at "start" for statically linked
1368 executables. For dynamically linked executables, the system
1369 first exec's /lib/libc.so.N, which contains the dynamic linker,
1370 and starts it running. The dynamic linker maps in any needed
1371 shared libraries, maps in the actual user executable, and then
1372 jumps to "start" in the user executable.
1373
1374 For both SunOS shared libraries, and SVR4 shared libraries, we
1375 can arrange to cooperate with the dynamic linker to discover the
1376 names of shared libraries that are dynamically linked, and the
1377 base addresses to which they are linked.
1378
1379 This function is responsible for discovering those names and
1380 addresses, and saving sufficient information about them to allow
1381 their symbols to be read at a later time.
1382
1383 FIXME
1384
1385 Between enable_break() and disable_break(), this code does not
1386 properly handle hitting breakpoints which the user might have
1387 set in the startup code or in the dynamic linker itself. Proper
1388 handling will probably have to wait until the implementation is
1389 changed to use the "breakpoint handler function" method.
1390
1391 Also, what if child has exit()ed? Must exit loop somehow.
1392 */
1393
1394 void
1395 solib_create_inferior_hook()
1396 {
1397 /* If we are using the BKPT_AT_SYMBOL code, then we don't need the base
1398 yet. In fact, in the case of a SunOS4 executable being run on
1399 Solaris, we can't get it yet. find_solib will get it when it needs
1400 it. */
1401 #if !(defined (SVR4_SHARED_LIBS) && defined (BKPT_AT_SYMBOL))
1402 if ((debug_base = locate_base ()) == 0)
1403 {
1404 /* Can't find the symbol or the executable is statically linked. */
1405 return;
1406 }
1407 #endif
1408
1409 if (!enable_break ())
1410 {
1411 warning ("shared library handler failed to enable breakpoint");
1412 return;
1413 }
1414
1415 /* Now run the target. It will eventually hit the breakpoint, at
1416 which point all of the libraries will have been mapped in and we
1417 can go groveling around in the dynamic linker structures to find
1418 out what we need to know about them. */
1419
1420 clear_proceed_status ();
1421 stop_soon_quietly = 1;
1422 stop_signal = TARGET_SIGNAL_0;
1423 do
1424 {
1425 target_resume (-1, 0, stop_signal);
1426 wait_for_inferior ();
1427 }
1428 while (stop_signal != TARGET_SIGNAL_TRAP);
1429 stop_soon_quietly = 0;
1430
1431 /* We are now either at the "mapping complete" breakpoint (or somewhere
1432 else, a condition we aren't prepared to deal with anyway), so adjust
1433 the PC as necessary after a breakpoint, disable the breakpoint, and
1434 add any shared libraries that were mapped in. */
1435
1436 if (DECR_PC_AFTER_BREAK)
1437 {
1438 stop_pc -= DECR_PC_AFTER_BREAK;
1439 write_register (PC_REGNUM, stop_pc);
1440 }
1441
1442 if (!disable_break ())
1443 {
1444 warning ("shared library handler failed to disable breakpoint");
1445 }
1446
1447 solib_add ((char *) 0, 0, (struct target_ops *) 0);
1448 }
1449
1450 /*
1451
1452 LOCAL FUNCTION
1453
1454 special_symbol_handling -- additional shared library symbol handling
1455
1456 SYNOPSIS
1457
1458 void special_symbol_handling (struct so_list *so)
1459
1460 DESCRIPTION
1461
1462 Once the symbols from a shared object have been loaded in the usual
1463 way, we are called to do any system specific symbol handling that
1464 is needed.
1465
1466 For Suns, this consists of grunging around in the dynamic linkers
1467 structures to find symbol definitions for "common" symbols and
1468 adding them to the minimal symbol table for the corresponding
1469 objfile.
1470
1471 */
1472
1473 static void
1474 special_symbol_handling (so)
1475 struct so_list *so;
1476 {
1477 #ifndef SVR4_SHARED_LIBS
1478 int j;
1479
1480 if (debug_addr == 0)
1481 {
1482 /* Get link_dynamic structure */
1483
1484 j = target_read_memory (debug_base, (char *) &dynamic_copy,
1485 sizeof (dynamic_copy));
1486 if (j)
1487 {
1488 /* unreadable */
1489 return;
1490 }
1491
1492 /* Calc address of debugger interface structure */
1493 /* FIXME, this needs work for cross-debugging of core files
1494 (byteorder, size, alignment, etc). */
1495
1496 debug_addr = (CORE_ADDR) dynamic_copy.ldd;
1497 }
1498
1499 /* Read the debugger structure from the inferior, just to make sure
1500 we have a current copy. */
1501
1502 j = target_read_memory (debug_addr, (char *) &debug_copy,
1503 sizeof (debug_copy));
1504 if (j)
1505 return; /* unreadable */
1506
1507 /* Get common symbol definitions for the loaded object. */
1508
1509 if (debug_copy.ldd_cp)
1510 {
1511 solib_add_common_symbols (debug_copy.ldd_cp, so -> objfile);
1512 }
1513
1514 #endif /* !SVR4_SHARED_LIBS */
1515 }
1516
1517
1518 /*
1519
1520 LOCAL FUNCTION
1521
1522 sharedlibrary_command -- handle command to explicitly add library
1523
1524 SYNOPSIS
1525
1526 static void sharedlibrary_command (char *args, int from_tty)
1527
1528 DESCRIPTION
1529
1530 */
1531
1532 static void
1533 sharedlibrary_command (args, from_tty)
1534 char *args;
1535 int from_tty;
1536 {
1537 dont_repeat ();
1538 solib_add (args, from_tty, (struct target_ops *) 0);
1539 }
1540
1541 void
1542 _initialize_solib()
1543 {
1544
1545 add_com ("sharedlibrary", class_files, sharedlibrary_command,
1546 "Load shared object library symbols for files matching REGEXP.");
1547 add_info ("sharedlibrary", info_sharedlibrary_command,
1548 "Status of loaded shared object libraries.");
1549 }
This page took 0.060563 seconds and 4 git commands to generate.