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