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