* armdefs.h (ARMul_State): New member `verbose'.
[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"
811f1bdc 38#include "gnu-regex.h"
cef4c2e7
PS
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 {
148070cc
JL
628 int update_coreops;
629
630 /* We must update the to_sections field in the core_ops structure
631 here, otherwise we dereference a potential dangling pointer
632 for each call to target_read/write_memory within this routine. */
633 update_coreops = core_ops.to_sections == target->to_sections;
634
cef4c2e7
PS
635 /* Reallocate the target's section table including the new size. */
636 if (target -> to_sections)
637 {
638 old = target -> to_sections_end - target -> to_sections;
639 target -> to_sections = (struct section_table *)
640 xrealloc ((char *)target -> to_sections,
641 (sizeof (struct section_table)) * (count + old));
642 }
643 else
644 {
645 old = 0;
646 target -> to_sections = (struct section_table *)
647 xmalloc ((sizeof (struct section_table)) * count);
648 }
649 target -> to_sections_end = target -> to_sections + (count + old);
650
148070cc
JL
651 /* Update the to_sections field in the core_ops structure
652 if needed. */
653 if (update_coreops)
654 {
655 core_ops.to_sections = target->to_sections;
656 core_ops.to_sections_end = target->to_sections_end;
657 }
658
cef4c2e7
PS
659 /* Add these section table entries to the target's table. */
660 while ((so = find_solib (so)) != NULL)
661 {
662 if (so -> so_name[0])
663 {
664 count = so -> sections_end - so -> sections;
665 memcpy ((char *) (target -> to_sections + old),
666 so -> sections,
667 (sizeof (struct section_table)) * count);
668 old += count;
669 }
670 }
671 }
672 }
673
674 /* Now add the symbol files. */
675 so = NULL;
676 while ((so = find_solib (so)) != NULL)
677 {
678 if (so -> so_name[0] && re_exec (so -> so_name))
679 {
680 so -> from_tty = from_tty;
681 if (so -> symbols_loaded)
682 {
683 if (from_tty)
684 {
199b2450 685 printf_unfiltered ("Symbols already loaded for %s\n", so -> so_name);
cef4c2e7
PS
686 }
687 }
688 else if (catch_errors
689 (symbol_add_stub, (char *) so,
690 "Error while reading shared library symbols:\n",
691 RETURN_MASK_ALL))
692 {
693 so_last = so;
694 so -> symbols_loaded = 1;
695 }
696 }
697 }
46d185d3
PS
698
699 /* Getting new symbols may change our opinion about what is
700 frameless. */
54d478cd 701 if (so_last)
46d185d3 702 reinit_frame_cache ();
cef4c2e7
PS
703}
704
705/*
706
707LOCAL FUNCTION
708
709 info_sharedlibrary_command -- code for "info sharedlibrary"
710
711SYNOPSIS
712
713 static void info_sharedlibrary_command ()
714
715DESCRIPTION
716
717 Walk through the shared library list and print information
718 about each attached library.
719*/
720
721static void
722info_sharedlibrary_command (ignore, from_tty)
723 char *ignore;
724 int from_tty;
725{
726 register struct so_list *so = NULL; /* link map state variable */
727 int header_done = 0;
728
729 if (exec_bfd == NULL)
730 {
199b2450 731 printf_unfiltered ("No exec file.\n");
cef4c2e7
PS
732 return;
733 }
734 while ((so = find_solib (so)) != NULL)
735 {
736 if (so -> so_name[0])
737 {
738 unsigned long txt_start = 0;
739 unsigned long txt_end = 0;
740
741 if (!header_done)
742 {
199b2450 743 printf_unfiltered("%-20s%-20s%-12s%s\n", "From", "To", "Syms Read",
cef4c2e7
PS
744 "Shared Object Library");
745 header_done++;
746 }
747 if (so -> textsection)
748 {
749 txt_start = (unsigned long) so -> textsection -> addr;
750 txt_end = (unsigned long) so -> textsection -> endaddr;
751 }
199b2450
TL
752 printf_unfiltered ("%-20s", local_hex_string_custom (txt_start, "08l"));
753 printf_unfiltered ("%-20s", local_hex_string_custom (txt_end, "08l"));
754 printf_unfiltered ("%-12s", so -> symbols_loaded ? "Yes" : "No");
755 printf_unfiltered ("%s\n", so -> so_name);
cef4c2e7
PS
756 }
757 }
758 if (so_list_head == NULL)
759 {
199b2450 760 printf_unfiltered ("No shared libraries loaded at this time.\n");
cef4c2e7
PS
761 }
762}
763
764/*
765
766GLOBAL FUNCTION
767
768 solib_address -- check to see if an address is in a shared lib
769
770SYNOPSIS
771
772 int solib_address (CORE_ADDR address)
773
774DESCRIPTION
775
776 Provides a hook for other gdb routines to discover whether or
777 not a particular address is within the mapped address space of
778 a shared library. Any address between the base mapping address
779 and the first address beyond the end of the last mapping, is
780 considered to be within the shared library address space, for
781 our purposes.
782
783 For example, this routine is called at one point to disable
784 breakpoints which are in shared libraries that are not currently
785 mapped in.
786 */
787
788int
789solib_address (address)
790 CORE_ADDR address;
791{
792 register struct so_list *so = 0; /* link map state variable */
793
794 while ((so = find_solib (so)) != NULL)
795 {
796 if (so -> so_name[0] && so -> textsection)
797 {
798 if ((address >= (CORE_ADDR) so -> textsection -> addr) &&
799 (address < (CORE_ADDR) so -> textsection -> endaddr))
800 {
801 return (1);
802 }
803 }
804 }
805 return (0);
806}
807
808/* Called by free_all_symtabs */
809
810void
811clear_solib()
812{
813 struct so_list *next;
814 char *bfd_filename;
815
816 while (so_list_head)
817 {
818 if (so_list_head -> sections)
819 {
820 free ((PTR)so_list_head -> sections);
821 }
a71c0593 822 if (so_list_head -> abfd)
cef4c2e7 823 {
a71c0593 824 bfd_filename = bfd_get_filename (so_list_head -> abfd);
9de0904c
JK
825 if (!bfd_close (so_list_head -> abfd))
826 warning ("cannot close \"%s\": %s",
827 bfd_filename, bfd_errmsg (bfd_get_error ()));
cef4c2e7
PS
828 }
829 else
830 /* This happens for the executable on SVR4. */
831 bfd_filename = NULL;
832
833 next = so_list_head -> next;
834 if (bfd_filename)
835 free ((PTR)bfd_filename);
836 free ((PTR)so_list_head);
837 so_list_head = next;
838 }
839}
840
841/*
842
843GLOBAL FUNCTION
844
845 solib_create_inferior_hook -- shared library startup support
846
847SYNOPSIS
848
849 void solib_create_inferior_hook()
850
851DESCRIPTION
852
853 When gdb starts up the inferior, it nurses it along (through the
854 shell) until it is ready to execute it's first instruction. At this
855 point, this function gets called via expansion of the macro
856 SOLIB_CREATE_INFERIOR_HOOK.
857 For a statically bound executable, this first instruction is the
858 one at "_start", or a similar text label. No further processing is
859 needed in that case.
860 For a dynamically bound executable, this first instruction is somewhere
861 in the rld, and the actual user executable is not yet mapped in.
862 We continue the inferior again, rld then maps in the actual user
863 executable and any needed shared libraries and then sends
864 itself a SIGTRAP.
865 At that point we discover the names of all shared libraries and
866 read their symbols in.
867
868FIXME
869
870 This code does not properly handle hitting breakpoints which the
871 user might have set in the rld itself. Proper handling would have
872 to check if the SIGTRAP happened due to a kill call.
873
874 Also, what if child has exit()ed? Must exit loop somehow.
875 */
876
877void
878solib_create_inferior_hook()
879{
880
881 /* Nothing to do for statically bound executables. */
882
cef0333e
PS
883 if (symfile_objfile == NULL
884 || symfile_objfile->obfd == NULL
885 || ((bfd_get_file_flags (symfile_objfile->obfd) & DYNAMIC) == 0))
cef4c2e7
PS
886 return;
887
888 /* Now run the target. It will eventually get a SIGTRAP, at
889 which point all of the libraries will have been mapped in and we
890 can go groveling around in the rld structures to find
891 out what we need to know about them. */
892
893 clear_proceed_status ();
894 stop_soon_quietly = 1;
67ac9759 895 stop_signal = TARGET_SIGNAL_0;
cef4c2e7
PS
896 do
897 {
de43d7d0 898 target_resume (-1, 0, stop_signal);
cef4c2e7
PS
899 wait_for_inferior ();
900 }
67ac9759 901 while (stop_signal != TARGET_SIGNAL_TRAP);
cef4c2e7 902
46d185d3 903 /* solib_add will call reinit_frame_cache.
49d607d2
PS
904 But we are stopped in the runtime loader and we do not have symbols
905 for the runtime loader. So heuristic_proc_start will be called
906 and will put out an annoying warning.
cef0333e
PS
907 Delaying the resetting of stop_soon_quietly until after symbol loading
908 suppresses the warning. */
cef4c2e7 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{
940
941 add_com ("sharedlibrary", class_files, sharedlibrary_command,
942 "Load shared object library symbols for files matching REGEXP.");
943 add_info ("sharedlibrary", info_sharedlibrary_command,
944 "Status of loaded shared object libraries.");
945}
This page took 0.168359 seconds and 4 git commands to generate.