Update FSF address.
[deliverable/binutils-gdb.git] / gdb / osfsolib.c
CommitLineData
cef4c2e7 1/* Handle OSF/1 shared libraries for GDB, the GNU Debugger.
cef0333e 2 Copyright 1993, 1994 Free Software Foundation, Inc.
cef4c2e7
PS
3
4This file is part of GDB.
5
6This program is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2 of the License, or
9(at your option) any later version.
10
11This program is distributed in the hope that it will be useful,
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
17along with this program; if not, write to the Free Software
6c9638b4 18Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
cef4c2e7
PS
19
20/* FIXME: Most of this code could be merged with solib.c by using
21 next_link_map_member and xfer_link_map_member in solib.c. */
22
23#include "defs.h"
24
25#include <sys/types.h>
26#include <signal.h>
2b576293 27#include "gdb_string.h"
cef4c2e7
PS
28#include <fcntl.h>
29
30#include "symtab.h"
31#include "bfd.h"
32#include "symfile.h"
33#include "objfiles.h"
34#include "gdbcore.h"
35#include "command.h"
36#include "target.h"
37#include "frame.h"
38#include "regex.h"
39#include "inferior.h"
40#include "language.h"
41
17d347bd
PS
42#define MAX_PATH_SIZE 1024 /* FIXME: Should be dynamic */
43
44/* When handling shared libraries, GDB has to find out the pathnames
45 of all shared libraries that are currently loaded (to read in their
46 symbols) and where the shared libraries are loaded in memory
47 (to relocate them properly from their prelinked addresses to the
48 current load address).
49
50 Under OSF/1 there are two possibilities to get at this information:
51 1) Peek around in the runtime loader structures.
52 These are not documented, and they are not defined in the system
53 header files. The definitions below were obtained by experimentation,
54 but they seem stable enough.
55 2) Use the undocumented libxproc.a library, which contains the
56 equivalent ldr_* routines.
57 This approach is somewhat cleaner, but it requires that the GDB
58 executable is dynamically linked. In addition it requires a
59 NAT_CLIBS= -lxproc -Wl,-expect_unresolved,ldr_process_context
60 linker specification for GDB and all applications that are using
61 libgdb.
62 We will use the peeking approach until it becomes unwieldy. */
cef4c2e7
PS
63
64#ifndef USE_LDR_ROUTINES
17d347bd
PS
65
66/* Definition of runtime loader structures, found by experimentation. */
cef4c2e7
PS
67#define RLD_CONTEXT_ADDRESS 0x3ffc0000000
68
69typedef struct
70{
71 CORE_ADDR next;
72 CORE_ADDR previous;
17d347bd 73 CORE_ADDR unknown1;
cef4c2e7
PS
74 char *module_name;
75 CORE_ADDR modinfo_addr;
17d347bd
PS
76 long module_id;
77 CORE_ADDR unknown2;
78 CORE_ADDR unknown3;
79 long region_count;
80 CORE_ADDR regioninfo_addr;
cef4c2e7
PS
81} ldr_module_info_t;
82
17d347bd
PS
83typedef struct
84{
85 long unknown1;
86 CORE_ADDR regionname_addr;
87 long protection;
88 CORE_ADDR vaddr;
89 CORE_ADDR mapaddr;
90 long size;
91 long unknown2[5];
92} ldr_region_info_t;
93
cef4c2e7
PS
94typedef struct
95{
96 CORE_ADDR unknown1;
97 CORE_ADDR unknown2;
98 CORE_ADDR head;
99 CORE_ADDR tail;
100} ldr_context_t;
101
102static ldr_context_t ldr_context;
17d347bd 103
cef4c2e7 104#else
17d347bd 105
cef4c2e7 106#include <loader.h>
17d347bd
PS
107static ldr_process_t fake_ldr_process;
108
109/* Called by ldr_* routines to read memory from the current target. */
110
111static int ldr_read_memory PARAMS ((CORE_ADDR, char *, int, int));
112
113static int
114ldr_read_memory (memaddr, myaddr, len, readstring)
115 CORE_ADDR memaddr;
116 char *myaddr;
117 int len;
118 int readstring;
119{
120 int result;
121 char *buffer;
122
123 if (readstring)
124 {
125 target_read_string (memaddr, &buffer, len, &result);
126 if (result == 0)
127 strcpy (myaddr, buffer);
128 free (buffer);
129 }
130 else
131 result = target_read_memory (memaddr, myaddr, len);
132
133 if (result != 0)
134 result = -result;
135 return result;
136}
137
cef4c2e7
PS
138#endif
139
140/* Define our own link_map structure.
141 This will help to share code with solib.c. */
142
143struct link_map {
17d347bd 144 CORE_ADDR l_offset; /* prelink to load address offset */
cef4c2e7
PS
145 char *l_name; /* full name of loaded object */
146 ldr_module_info_t module_info; /* corresponding module info */
147};
148
17d347bd 149#define LM_OFFSET(so) ((so) -> lm.l_offset)
cef4c2e7
PS
150#define LM_NAME(so) ((so) -> lm.l_name)
151
152struct so_list {
153 struct so_list *next; /* next structure in linked list */
154 struct link_map lm; /* copy of link map from inferior */
155 struct link_map *lmaddr; /* addr in inferior lm was read from */
156 CORE_ADDR lmend; /* upper addr bound of mapped object */
157 char so_name[MAX_PATH_SIZE]; /* shared object lib name (FIXME) */
158 char symbols_loaded; /* flag: symbols read in yet? */
159 char from_tty; /* flag: print msgs? */
160 struct objfile *objfile; /* objfile for loaded lib */
161 struct section_table *sections;
162 struct section_table *sections_end;
163 struct section_table *textsection;
a71c0593 164 bfd *abfd;
cef4c2e7
PS
165};
166
167static struct so_list *so_list_head; /* List of known shared objects */
168
169extern int
170fdmatch PARAMS ((int, int)); /* In libiberty */
171
172/* Local function prototypes */
173
174static void
175sharedlibrary_command PARAMS ((char *, int));
176
177static void
178info_sharedlibrary_command PARAMS ((char *, int));
179
180static int
181symbol_add_stub PARAMS ((char *));
182
183static struct so_list *
184find_solib PARAMS ((struct so_list *));
185
186static struct link_map *
187first_link_map_member PARAMS ((void));
188
189static struct link_map *
190next_link_map_member PARAMS ((struct so_list *));
191
192static void
193xfer_link_map_member PARAMS ((struct so_list *, struct link_map *));
194
195static void
196solib_map_sections PARAMS ((struct so_list *));
197
cef4c2e7
PS
198/*
199
200LOCAL FUNCTION
201
202 solib_map_sections -- open bfd and build sections for shared lib
203
204SYNOPSIS
205
206 static void solib_map_sections (struct so_list *so)
207
208DESCRIPTION
209
210 Given a pointer to one of the shared objects in our list
211 of mapped objects, use the recorded name to open a bfd
212 descriptor for the object, build a section table, and then
213 relocate all the section addresses by the base address at
214 which the shared object was mapped.
215
216FIXMES
217
218 In most (all?) cases the shared object file name recorded in the
219 dynamic linkage tables will be a fully qualified pathname. For
220 cases where it isn't, do we really mimic the systems search
221 mechanism correctly in the below code (particularly the tilde
222 expansion stuff?).
223 */
224
225static void
226solib_map_sections (so)
227 struct so_list *so;
228{
229 char *filename;
230 char *scratch_pathname;
231 int scratch_chan;
232 struct section_table *p;
233 struct cleanup *old_chain;
234 bfd *abfd;
235
236 filename = tilde_expand (so -> so_name);
237 old_chain = make_cleanup (free, filename);
238
239 scratch_chan = openp (getenv ("PATH"), 1, filename, O_RDONLY, 0,
240 &scratch_pathname);
241 if (scratch_chan < 0)
242 {
243 scratch_chan = openp (getenv ("LD_LIBRARY_PATH"), 1, filename,
244 O_RDONLY, 0, &scratch_pathname);
245 }
246 if (scratch_chan < 0)
247 {
248 perror_with_name (filename);
249 }
250 /* Leave scratch_pathname allocated. bfd->name will point to it. */
251
252 abfd = bfd_fdopenr (scratch_pathname, gnutarget, scratch_chan);
253 if (!abfd)
254 {
255 close (scratch_chan);
256 error ("Could not open `%s' as an executable file: %s",
c4a081e1 257 scratch_pathname, bfd_errmsg (bfd_get_error ()));
cef4c2e7
PS
258 }
259 /* Leave bfd open, core_xfer_memory and "info files" need it. */
a71c0593 260 so -> abfd = abfd;
cef4c2e7
PS
261 abfd -> cacheable = true;
262
263 if (!bfd_check_format (abfd, bfd_object))
264 {
265 error ("\"%s\": not in executable format: %s.",
c4a081e1 266 scratch_pathname, bfd_errmsg (bfd_get_error ()));
cef4c2e7
PS
267 }
268 if (build_section_table (abfd, &so -> sections, &so -> sections_end))
269 {
270 error ("Can't find the file sections in `%s': %s",
c4a081e1 271 bfd_get_filename (exec_bfd), bfd_errmsg (bfd_get_error ()));
cef4c2e7
PS
272 }
273
274 for (p = so -> sections; p < so -> sections_end; p++)
275 {
276 /* Relocate the section binding addresses as recorded in the shared
17d347bd
PS
277 object's file by the offset to get the address to which the
278 object was actually mapped. */
279 p -> addr += LM_OFFSET (so);
280 p -> endaddr += LM_OFFSET (so);
cef4c2e7 281 so -> lmend = (CORE_ADDR) max (p -> endaddr, so -> lmend);
94d4b713 282 if (STREQ (p -> the_bfd_section -> name, ".text"))
cef4c2e7
PS
283 {
284 so -> textsection = p;
285 }
286 }
287
288 /* Free the file names, close the file now. */
289 do_cleanups (old_chain);
290}
291
292/*
293
294LOCAL FUNCTION
295
296 first_link_map_member -- locate first member in dynamic linker's map
297
298SYNOPSIS
299
300 static struct link_map *first_link_map_member (void)
301
302DESCRIPTION
303
304 Read in a copy of the first member in the inferior's dynamic
305 link map from the inferior's dynamic linker structures, and return
306 a pointer to the copy in our address space.
307*/
308
309static struct link_map *
310first_link_map_member ()
311{
312 struct link_map *lm = NULL;
313 static struct link_map first_lm;
314
315#ifdef USE_LDR_ROUTINES
316 ldr_module_t mod_id = LDR_NULL_MODULE;
317 size_t retsize;
318
17d347bd
PS
319 fake_ldr_process = ldr_core_process ();
320 ldr_set_core_reader (ldr_read_memory);
321 ldr_xdetach (fake_ldr_process);
322 if (ldr_xattach (fake_ldr_process) != 0
323 || ldr_next_module(fake_ldr_process, &mod_id) != 0
cef4c2e7 324 || mod_id == LDR_NULL_MODULE
17d347bd 325 || ldr_inq_module(fake_ldr_process, mod_id,
cef4c2e7
PS
326 &first_lm.module_info, sizeof(ldr_module_info_t),
327 &retsize) != 0)
328 return lm;
329#else
330 CORE_ADDR ldr_context_addr;
331
332 if (target_read_memory ((CORE_ADDR) RLD_CONTEXT_ADDRESS,
333 (char *) &ldr_context_addr,
334 sizeof (CORE_ADDR)) != 0
335 || target_read_memory (ldr_context_addr,
336 (char *) &ldr_context,
337 sizeof (ldr_context_t)) != 0
338 || target_read_memory ((CORE_ADDR) ldr_context.head,
339 (char *) &first_lm.module_info,
340 sizeof (ldr_module_info_t)) != 0)
341 return lm;
342#endif
343
344 lm = &first_lm;
345
346 /* The first entry is for the main program and should be skipped. */
347 lm->l_name = NULL;
348
349 return lm;
350}
351
352static struct link_map *
353next_link_map_member (so_list_ptr)
354 struct so_list *so_list_ptr;
355{
356 struct link_map *lm = NULL;
357 static struct link_map next_lm;
358#ifdef USE_LDR_ROUTINES
17d347bd 359 ldr_module_t mod_id = so_list_ptr->lm.module_info.lmi_modid;
cef4c2e7
PS
360 size_t retsize;
361
17d347bd 362 if (ldr_next_module(fake_ldr_process, &mod_id) != 0
cef4c2e7 363 || mod_id == LDR_NULL_MODULE
17d347bd 364 || ldr_inq_module(fake_ldr_process, mod_id,
cef4c2e7
PS
365 &next_lm.module_info, sizeof(ldr_module_info_t),
366 &retsize) != 0)
367 return lm;
368
369 lm = &next_lm;
370 lm->l_name = lm->module_info.lmi_name;
371#else
372 CORE_ADDR ldr_context_addr;
373
374 /* Reread context in case ldr_context.tail was updated. */
375
376 if (target_read_memory ((CORE_ADDR) RLD_CONTEXT_ADDRESS,
377 (char *) &ldr_context_addr,
378 sizeof (CORE_ADDR)) != 0
379 || target_read_memory (ldr_context_addr,
380 (char *) &ldr_context,
381 sizeof (ldr_context_t)) != 0
382 || so_list_ptr->lm.module_info.modinfo_addr == ldr_context.tail
383 || target_read_memory (so_list_ptr->lm.module_info.next,
384 (char *) &next_lm.module_info,
385 sizeof (ldr_module_info_t)) != 0)
386 return lm;
387
388 lm = &next_lm;
389 lm->l_name = lm->module_info.module_name;
390#endif
391 return lm;
392}
393
394static void
395xfer_link_map_member (so_list_ptr, lm)
396 struct so_list *so_list_ptr;
397 struct link_map *lm;
398{
17d347bd 399 int i;
cef4c2e7
PS
400 so_list_ptr->lm = *lm;
401
17d347bd
PS
402 /* OSF/1 shared libraries are pre-linked to particular addresses,
403 but the runtime loader may have to relocate them if the
404 address ranges of the libraries used by the target executable clash,
405 or if the target executable is linked with the -taso option.
406 The offset is the difference between the address where the shared
407 library is mapped and the pre-linked address of the shared library.
408
409 FIXME: GDB is currently unable to relocate the shared library
410 sections by different offsets. If sections are relocated by
411 different offsets, put out a warning and use the offset of the
412 first section for all remaining sections. */
413 LM_OFFSET (so_list_ptr) = 0;
cef4c2e7
PS
414
415 /* There is one entry that has no name (for the inferior executable)
416 since it is not a shared object. */
417 if (LM_NAME (so_list_ptr) != 0)
418 {
419
420#ifdef USE_LDR_ROUTINES
421 int len = strlen (LM_NAME (so_list_ptr) + 1);
422
423 if (len > MAX_PATH_SIZE)
424 len = MAX_PATH_SIZE;
425 strncpy (so_list_ptr->so_name, LM_NAME (so_list_ptr), MAX_PATH_SIZE);
17d347bd
PS
426 so_list_ptr->so_name[MAX_PATH_SIZE - 1] = '\0';
427
428 for (i = 0; i < lm->module_info.lmi_nregion; i++)
429 {
430 ldr_region_info_t region_info;
431 size_t retsize;
432 CORE_ADDR region_offset;
433
434 if (ldr_inq_region (fake_ldr_process, lm->module_info.lmi_modid,
435 i, &region_info, sizeof (region_info),
436 &retsize) != 0)
437 break;
438 region_offset = (CORE_ADDR) region_info.lri_mapaddr
439 - (CORE_ADDR) region_info.lri_vaddr;
440 if (i == 0)
441 LM_OFFSET (so_list_ptr) = region_offset;
442 else if (LM_OFFSET (so_list_ptr) != region_offset)
443 warning ("cannot handle shared library relocation for %s (%s)",
444 so_list_ptr->so_name, region_info.lri_name);
445 }
cef4c2e7 446#else
c485c7a9
PS
447 int errcode;
448 char *buffer;
449 target_read_string ((CORE_ADDR) LM_NAME (so_list_ptr), &buffer,
450 MAX_PATH_SIZE - 1, &errcode);
451 if (errcode != 0)
452 error ("xfer_link_map_member: Can't read pathname for load map: %s\n",
453 safe_strerror (errcode));
454 strncpy (so_list_ptr->so_name, buffer, MAX_PATH_SIZE - 1);
455 free (buffer);
c485c7a9 456 so_list_ptr->so_name[MAX_PATH_SIZE - 1] = '\0';
cef4c2e7 457
17d347bd
PS
458 for (i = 0; i < lm->module_info.region_count; i++)
459 {
460 ldr_region_info_t region_info;
461 CORE_ADDR region_offset;
462
463 if (target_read_memory (lm->module_info.regioninfo_addr
464 + i * sizeof (region_info),
465 (char *) &region_info,
466 sizeof (region_info)) != 0)
467 break;
468 region_offset = region_info.mapaddr - region_info.vaddr;
469 if (i == 0)
470 LM_OFFSET (so_list_ptr) = region_offset;
471 else if (LM_OFFSET (so_list_ptr) != region_offset)
472 {
473 char *region_name;
474 target_read_string (region_info.regionname_addr, &buffer,
475 MAX_PATH_SIZE - 1, &errcode);
476 if (errcode == 0)
477 region_name = buffer;
478 else
479 region_name = "??";
480 warning ("cannot handle shared library relocation for %s (%s)",
481 so_list_ptr->so_name, region_name);
482 free (buffer);
483 }
484 }
485#endif
486
cef4c2e7
PS
487 solib_map_sections (so_list_ptr);
488 }
489}
490
491/*
492
493LOCAL FUNCTION
494
495 find_solib -- step through list of shared objects
496
497SYNOPSIS
498
499 struct so_list *find_solib (struct so_list *so_list_ptr)
500
501DESCRIPTION
502
503 This module contains the routine which finds the names of any
504 loaded "images" in the current process. The argument in must be
505 NULL on the first call, and then the returned value must be passed
506 in on subsequent calls. This provides the capability to "step" down
507 the list of loaded objects. On the last object, a NULL value is
508 returned.
509
510 The arg and return value are "struct link_map" pointers, as defined
511 in <link.h>.
512 */
513
514static struct so_list *
515find_solib (so_list_ptr)
516 struct so_list *so_list_ptr; /* Last lm or NULL for first one */
517{
518 struct so_list *so_list_next = NULL;
519 struct link_map *lm = NULL;
520 struct so_list *new;
521
522 if (so_list_ptr == NULL)
523 {
524 /* We are setting up for a new scan through the loaded images. */
525 if ((so_list_next = so_list_head) == NULL)
526 {
527 /* Find the first link map list member. */
528 lm = first_link_map_member ();
529 }
530 }
531 else
532 {
533 /* We have been called before, and are in the process of walking
534 the shared library list. Advance to the next shared object. */
535 lm = next_link_map_member (so_list_ptr);
536 so_list_next = so_list_ptr -> next;
537 }
538 if ((so_list_next == NULL) && (lm != NULL))
539 {
540 /* Get next link map structure from inferior image and build a local
541 abbreviated load_map structure */
542 new = (struct so_list *) xmalloc (sizeof (struct so_list));
543 memset ((char *) new, 0, sizeof (struct so_list));
544 new -> lmaddr = lm;
545 /* Add the new node as the next node in the list, or as the root
546 node if this is the first one. */
547 if (so_list_ptr != NULL)
548 {
549 so_list_ptr -> next = new;
550 }
551 else
552 {
553 so_list_head = new;
554 }
555 so_list_next = new;
556 xfer_link_map_member (new, lm);
557 }
558 return (so_list_next);
559}
560
561/* A small stub to get us past the arg-passing pinhole of catch_errors. */
562
563static int
564symbol_add_stub (arg)
565 char *arg;
566{
567 register struct so_list *so = (struct so_list *) arg; /* catch_errs bogon */
568
569 so -> objfile = symbol_file_add (so -> so_name, so -> from_tty,
570 so -> textsection -> addr,
571 0, 0, 0);
572 return (1);
573}
574
575/*
576
577GLOBAL FUNCTION
578
579 solib_add -- add a shared library file to the symtab and section list
580
581SYNOPSIS
582
583 void solib_add (char *arg_string, int from_tty,
584 struct target_ops *target)
585
586DESCRIPTION
587
588*/
589
590void
591solib_add (arg_string, from_tty, target)
592 char *arg_string;
593 int from_tty;
594 struct target_ops *target;
595{
596 register struct so_list *so = NULL; /* link map state variable */
597
598 /* Last shared library that we read. */
599 struct so_list *so_last = NULL;
600
601 char *re_err;
602 int count;
603 int old;
604
605 if ((re_err = re_comp (arg_string ? arg_string : ".")) != NULL)
606 {
607 error ("Invalid regexp: %s", re_err);
608 }
609
610
611 /* Add the shared library sections to the section table of the
46d185d3 612 specified target, if any. */
cef4c2e7
PS
613 if (target)
614 {
615 /* Count how many new section_table entries there are. */
616 so = NULL;
617 count = 0;
618 while ((so = find_solib (so)) != NULL)
619 {
620 if (so -> so_name[0])
621 {
622 count += so -> sections_end - so -> sections;
623 }
624 }
625
626 if (count)
627 {
628 /* Reallocate the target's section table including the new size. */
629 if (target -> to_sections)
630 {
631 old = target -> to_sections_end - target -> to_sections;
632 target -> to_sections = (struct section_table *)
633 xrealloc ((char *)target -> to_sections,
634 (sizeof (struct section_table)) * (count + old));
635 }
636 else
637 {
638 old = 0;
639 target -> to_sections = (struct section_table *)
640 xmalloc ((sizeof (struct section_table)) * count);
641 }
642 target -> to_sections_end = target -> to_sections + (count + old);
643
644 /* Add these section table entries to the target's table. */
645 while ((so = find_solib (so)) != NULL)
646 {
647 if (so -> so_name[0])
648 {
649 count = so -> sections_end - so -> sections;
650 memcpy ((char *) (target -> to_sections + old),
651 so -> sections,
652 (sizeof (struct section_table)) * count);
653 old += count;
654 }
655 }
656 }
657 }
658
659 /* Now add the symbol files. */
660 so = NULL;
661 while ((so = find_solib (so)) != NULL)
662 {
663 if (so -> so_name[0] && re_exec (so -> so_name))
664 {
665 so -> from_tty = from_tty;
666 if (so -> symbols_loaded)
667 {
668 if (from_tty)
669 {
199b2450 670 printf_unfiltered ("Symbols already loaded for %s\n", so -> so_name);
cef4c2e7
PS
671 }
672 }
673 else if (catch_errors
674 (symbol_add_stub, (char *) so,
675 "Error while reading shared library symbols:\n",
676 RETURN_MASK_ALL))
677 {
678 so_last = so;
679 so -> symbols_loaded = 1;
680 }
681 }
682 }
46d185d3
PS
683
684 /* Getting new symbols may change our opinion about what is
685 frameless. */
54d478cd 686 if (so_last)
46d185d3 687 reinit_frame_cache ();
cef4c2e7
PS
688}
689
690/*
691
692LOCAL FUNCTION
693
694 info_sharedlibrary_command -- code for "info sharedlibrary"
695
696SYNOPSIS
697
698 static void info_sharedlibrary_command ()
699
700DESCRIPTION
701
702 Walk through the shared library list and print information
703 about each attached library.
704*/
705
706static void
707info_sharedlibrary_command (ignore, from_tty)
708 char *ignore;
709 int from_tty;
710{
711 register struct so_list *so = NULL; /* link map state variable */
712 int header_done = 0;
713
714 if (exec_bfd == NULL)
715 {
199b2450 716 printf_unfiltered ("No exec file.\n");
cef4c2e7
PS
717 return;
718 }
719 while ((so = find_solib (so)) != NULL)
720 {
721 if (so -> so_name[0])
722 {
723 unsigned long txt_start = 0;
724 unsigned long txt_end = 0;
725
726 if (!header_done)
727 {
199b2450 728 printf_unfiltered("%-20s%-20s%-12s%s\n", "From", "To", "Syms Read",
cef4c2e7
PS
729 "Shared Object Library");
730 header_done++;
731 }
732 if (so -> textsection)
733 {
734 txt_start = (unsigned long) so -> textsection -> addr;
735 txt_end = (unsigned long) so -> textsection -> endaddr;
736 }
199b2450
TL
737 printf_unfiltered ("%-20s", local_hex_string_custom (txt_start, "08l"));
738 printf_unfiltered ("%-20s", local_hex_string_custom (txt_end, "08l"));
739 printf_unfiltered ("%-12s", so -> symbols_loaded ? "Yes" : "No");
740 printf_unfiltered ("%s\n", so -> so_name);
cef4c2e7
PS
741 }
742 }
743 if (so_list_head == NULL)
744 {
199b2450 745 printf_unfiltered ("No shared libraries loaded at this time.\n");
cef4c2e7
PS
746 }
747}
748
749/*
750
751GLOBAL FUNCTION
752
753 solib_address -- check to see if an address is in a shared lib
754
755SYNOPSIS
756
757 int solib_address (CORE_ADDR address)
758
759DESCRIPTION
760
761 Provides a hook for other gdb routines to discover whether or
762 not a particular address is within the mapped address space of
763 a shared library. Any address between the base mapping address
764 and the first address beyond the end of the last mapping, is
765 considered to be within the shared library address space, for
766 our purposes.
767
768 For example, this routine is called at one point to disable
769 breakpoints which are in shared libraries that are not currently
770 mapped in.
771 */
772
773int
774solib_address (address)
775 CORE_ADDR address;
776{
777 register struct so_list *so = 0; /* link map state variable */
778
779 while ((so = find_solib (so)) != NULL)
780 {
781 if (so -> so_name[0] && so -> textsection)
782 {
783 if ((address >= (CORE_ADDR) so -> textsection -> addr) &&
784 (address < (CORE_ADDR) so -> textsection -> endaddr))
785 {
786 return (1);
787 }
788 }
789 }
790 return (0);
791}
792
793/* Called by free_all_symtabs */
794
795void
796clear_solib()
797{
798 struct so_list *next;
799 char *bfd_filename;
800
801 while (so_list_head)
802 {
803 if (so_list_head -> sections)
804 {
805 free ((PTR)so_list_head -> sections);
806 }
a71c0593 807 if (so_list_head -> abfd)
cef4c2e7 808 {
a71c0593 809 bfd_filename = bfd_get_filename (so_list_head -> abfd);
9de0904c
JK
810 if (!bfd_close (so_list_head -> abfd))
811 warning ("cannot close \"%s\": %s",
812 bfd_filename, bfd_errmsg (bfd_get_error ()));
cef4c2e7
PS
813 }
814 else
815 /* This happens for the executable on SVR4. */
816 bfd_filename = NULL;
817
818 next = so_list_head -> next;
819 if (bfd_filename)
820 free ((PTR)bfd_filename);
821 free ((PTR)so_list_head);
822 so_list_head = next;
823 }
824}
825
826/*
827
828GLOBAL FUNCTION
829
830 solib_create_inferior_hook -- shared library startup support
831
832SYNOPSIS
833
834 void solib_create_inferior_hook()
835
836DESCRIPTION
837
838 When gdb starts up the inferior, it nurses it along (through the
839 shell) until it is ready to execute it's first instruction. At this
840 point, this function gets called via expansion of the macro
841 SOLIB_CREATE_INFERIOR_HOOK.
842 For a statically bound executable, this first instruction is the
843 one at "_start", or a similar text label. No further processing is
844 needed in that case.
845 For a dynamically bound executable, this first instruction is somewhere
846 in the rld, and the actual user executable is not yet mapped in.
847 We continue the inferior again, rld then maps in the actual user
848 executable and any needed shared libraries and then sends
849 itself a SIGTRAP.
850 At that point we discover the names of all shared libraries and
851 read their symbols in.
852
853FIXME
854
855 This code does not properly handle hitting breakpoints which the
856 user might have set in the rld itself. Proper handling would have
857 to check if the SIGTRAP happened due to a kill call.
858
859 Also, what if child has exit()ed? Must exit loop somehow.
860 */
861
862void
863solib_create_inferior_hook()
864{
865
866 /* Nothing to do for statically bound executables. */
867
cef0333e
PS
868 if (symfile_objfile == NULL
869 || symfile_objfile->obfd == NULL
870 || ((bfd_get_file_flags (symfile_objfile->obfd) & DYNAMIC) == 0))
cef4c2e7
PS
871 return;
872
873 /* Now run the target. It will eventually get a SIGTRAP, at
874 which point all of the libraries will have been mapped in and we
875 can go groveling around in the rld structures to find
876 out what we need to know about them. */
877
878 clear_proceed_status ();
879 stop_soon_quietly = 1;
67ac9759 880 stop_signal = TARGET_SIGNAL_0;
cef4c2e7
PS
881 do
882 {
de43d7d0 883 target_resume (-1, 0, stop_signal);
cef4c2e7
PS
884 wait_for_inferior ();
885 }
67ac9759 886 while (stop_signal != TARGET_SIGNAL_TRAP);
cef4c2e7 887
46d185d3 888 /* solib_add will call reinit_frame_cache.
49d607d2
PS
889 But we are stopped in the runtime loader and we do not have symbols
890 for the runtime loader. So heuristic_proc_start will be called
891 and will put out an annoying warning.
cef0333e
PS
892 Delaying the resetting of stop_soon_quietly until after symbol loading
893 suppresses the warning. */
cef4c2e7 894 solib_add ((char *) 0, 0, (struct target_ops *) 0);
49d607d2 895 stop_soon_quietly = 0;
cef4c2e7
PS
896}
897
898
899/*
900
901LOCAL FUNCTION
902
903 sharedlibrary_command -- handle command to explicitly add library
904
905SYNOPSIS
906
907 static void sharedlibrary_command (char *args, int from_tty)
908
909DESCRIPTION
910
911*/
912
913static void
914sharedlibrary_command (args, from_tty)
915char *args;
916int from_tty;
917{
918 dont_repeat ();
919 solib_add (args, from_tty, (struct target_ops *) 0);
920}
921
922void
923_initialize_solib()
924{
925
926 add_com ("sharedlibrary", class_files, sharedlibrary_command,
927 "Load shared object library symbols for files matching REGEXP.");
928 add_info ("sharedlibrary", info_sharedlibrary_command,
929 "Status of loaded shared object libraries.");
930}
This page took 0.150655 seconds and 4 git commands to generate.