1 /* Native support for the SGI Iris running IRIX version 5, for GDB.
2 Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998
3 Free Software Foundation, Inc.
4 Contributed by Alessandro Forin(af@cs.cmu.edu) at CMU
5 and by Per Bothner(bothner@cs.wisc.edu) at U.Wisconsin.
6 Implemented for Irix 4.x by Garrett A. Wollman.
7 Modified for Irix 5.x by Ian Lance Taylor.
9 This file is part of GDB.
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
30 #include "gdb_string.h"
32 #include <sys/procfs.h>
33 #include <setjmp.h> /* For JB_XXX. */
36 fetch_core_registers
PARAMS ((char *, unsigned int, int, CORE_ADDR
));
38 /* Size of elements in jmpbuf */
40 #define JB_ELEMENT_SIZE 4
43 * See the comment in m68k-tdep.c regarding the utility of these functions.
45 * These definitions are from the MIPS SVR4 ABI, so they may work for
46 * any MIPS SVR4 target.
50 supply_gregset (gregsetp
)
54 register greg_t
*regp
= &(*gregsetp
)[0];
55 int gregoff
= sizeof (greg_t
) - MIPS_REGSIZE
;
56 static char zerobuf
[MAX_REGISTER_RAW_SIZE
] = {0};
58 for(regi
= 0; regi
<= CTX_RA
; regi
++)
59 supply_register (regi
, (char *)(regp
+ regi
) + gregoff
);
61 supply_register (PC_REGNUM
, (char *)(regp
+ CTX_EPC
) + gregoff
);
62 supply_register (HI_REGNUM
, (char *)(regp
+ CTX_MDHI
) + gregoff
);
63 supply_register (LO_REGNUM
, (char *)(regp
+ CTX_MDLO
) + gregoff
);
64 supply_register (CAUSE_REGNUM
, (char *)(regp
+ CTX_CAUSE
) + gregoff
);
66 /* Fill inaccessible registers with zero. */
67 supply_register (BADVADDR_REGNUM
, zerobuf
);
71 fill_gregset (gregsetp
, regno
)
76 register greg_t
*regp
= &(*gregsetp
)[0];
78 /* Under Irix6, if GDB is built with N32 ABI and is debugging an O32
79 executable, we have to sign extend the registers to 64 bits before
80 filling in the gregset structure. */
82 for (regi
= 0; regi
<= CTX_RA
; regi
++)
83 if ((regno
== -1) || (regno
== regi
))
85 extract_signed_integer (®isters
[REGISTER_BYTE (regi
)],
86 REGISTER_RAW_SIZE (regi
));
88 if ((regno
== -1) || (regno
== PC_REGNUM
))
90 extract_signed_integer (®isters
[REGISTER_BYTE (PC_REGNUM
)],
91 REGISTER_RAW_SIZE (PC_REGNUM
));
93 if ((regno
== -1) || (regno
== CAUSE_REGNUM
))
95 extract_signed_integer (®isters
[REGISTER_BYTE (CAUSE_REGNUM
)],
96 REGISTER_RAW_SIZE (CAUSE_REGNUM
));
98 if ((regno
== -1) || (regno
== HI_REGNUM
))
100 extract_signed_integer (®isters
[REGISTER_BYTE (HI_REGNUM
)],
101 REGISTER_RAW_SIZE (HI_REGNUM
));
103 if ((regno
== -1) || (regno
== LO_REGNUM
))
105 extract_signed_integer (®isters
[REGISTER_BYTE (LO_REGNUM
)],
106 REGISTER_RAW_SIZE (LO_REGNUM
));
110 * Now we do the same thing for floating-point registers.
111 * We don't bother to condition on FP0_REGNUM since any
112 * reasonable MIPS configuration has an R3010 in it.
114 * Again, see the comments in m68k-tdep.c.
118 supply_fpregset (fpregsetp
)
119 fpregset_t
*fpregsetp
;
122 static char zerobuf
[MAX_REGISTER_RAW_SIZE
] = {0};
124 /* FIXME, this is wrong for the N32 ABI which has 64 bit FP regs. */
126 for (regi
= 0; regi
< 32; regi
++)
127 supply_register (FP0_REGNUM
+ regi
,
128 (char *)&fpregsetp
->fp_r
.fp_regs
[regi
]);
130 supply_register (FCRCS_REGNUM
, (char *)&fpregsetp
->fp_csr
);
132 /* FIXME: how can we supply FCRIR_REGNUM? SGI doesn't tell us. */
133 supply_register (FCRIR_REGNUM
, zerobuf
);
137 fill_fpregset (fpregsetp
, regno
)
138 fpregset_t
*fpregsetp
;
144 /* FIXME, this is wrong for the N32 ABI which has 64 bit FP regs. */
146 for (regi
= FP0_REGNUM
; regi
< FP0_REGNUM
+ 32; regi
++)
148 if ((regno
== -1) || (regno
== regi
))
150 from
= (char *) ®isters
[REGISTER_BYTE (regi
)];
151 to
= (char *) &(fpregsetp
->fp_r
.fp_regs
[regi
- FP0_REGNUM
]);
152 memcpy(to
, from
, REGISTER_RAW_SIZE (regi
));
156 if ((regno
== -1) || (regno
== FCRCS_REGNUM
))
157 fpregsetp
->fp_csr
= *(unsigned *) ®isters
[REGISTER_BYTE(FCRCS_REGNUM
)];
161 /* Figure out where the longjmp will land.
162 We expect the first arg to be a pointer to the jmp_buf structure from which
163 we extract the pc (JB_PC) that we will land at. The pc is copied into PC.
164 This routine returns true on success. */
167 get_longjmp_target (pc
)
170 char buf
[TARGET_PTR_BIT
/ TARGET_CHAR_BIT
];
173 jb_addr
= read_register (A0_REGNUM
);
175 if (target_read_memory (jb_addr
+ JB_PC
* JB_ELEMENT_SIZE
, buf
,
176 TARGET_PTR_BIT
/ TARGET_CHAR_BIT
))
179 *pc
= extract_address (buf
, TARGET_PTR_BIT
/ TARGET_CHAR_BIT
);
185 fetch_core_registers (core_reg_sect
, core_reg_size
, which
, reg_addr
)
187 unsigned core_reg_size
;
188 int which
; /* Unused */
189 CORE_ADDR reg_addr
; /* Unused */
191 if (core_reg_size
== REGISTER_BYTES
)
193 memcpy ((char *)registers
, core_reg_sect
, core_reg_size
);
195 else if (core_reg_size
== (2 * REGISTER_BYTES
) && MIPS_REGSIZE
== 4)
197 /* This is a core file from a N32 executable, 64 bits are saved
198 for all registers. */
199 char *srcp
= core_reg_sect
;
200 char *dstp
= registers
;
203 for (regno
= 0; regno
< NUM_REGS
; regno
++)
205 if (regno
>= FP0_REGNUM
&& regno
< (FP0_REGNUM
+ 32))
207 /* FIXME, this is wrong, N32 has 64 bit FP regs, but GDB
208 currently assumes that they are 32 bit. */
227 warning ("wrong size gregset struct in core file");
231 registers_fetched ();
234 /* Irix 5 uses what appears to be a unique form of shared library
235 support. This is a copy of solib.c modified for Irix 5. */
236 /* FIXME: Most of this code could be merged with osfsolib.c and solib.c
237 by using next_link_map_member and xfer_link_map_member in solib.c. */
239 #include <sys/types.h>
241 #include <sys/param.h>
244 /* <obj.h> includes <sym.h> and <symconst.h>, which causes conflicts
245 with our versions of those files included by tm-mips.h. Prevent
246 <obj.h> from including them with some appropriate defines. */
248 #define __SYMCONST_H__
250 #ifdef HAVE_OBJLIST_H
254 #ifdef NEW_OBJ_INFO_MAGIC
255 #define HANDLE_NEW_OBJ_LIST
261 #include "objfiles.h"
264 #include "gnu-regex.h"
265 #include "inferior.h"
266 #include "language.h"
269 /* The symbol which starts off the list of shared libraries. */
270 #define DEBUG_BASE "__rld_obj_head"
272 /* Irix 6.x introduces a new variant of object lists.
273 To be able to debug O32 executables under Irix 6, we have to handle both
278 OBJ_LIST_OLD
, /* Pre Irix 6.x object list. */
279 OBJ_LIST_32
, /* 32 Bit Elf32_Obj_Info. */
280 OBJ_LIST_64
/* 64 Bit Elf64_Obj_Info, FIXME not yet implemented. */
283 /* Define our own link_map structure.
284 This will help to share code with osfsolib.c and solib.c. */
287 obj_list_variant l_variant
; /* which variant of object list */
288 CORE_ADDR l_lladdr
; /* addr in inferior list was read from */
289 CORE_ADDR l_next
; /* address of next object list entry */
292 /* Irix 5 shared objects are pre-linked to particular addresses
293 although the dynamic linker may have to relocate them if the
294 address ranges of the libraries used by the main program clash.
295 The offset is the difference between the address where the object
296 is mapped and the binding address of the shared library. */
297 #define LM_OFFSET(so) ((so) -> offset)
298 /* Loaded address of shared library. */
299 #define LM_ADDR(so) ((so) -> lmstart)
301 char shadow_contents
[BREAKPOINT_MAX
]; /* Stash old bkpt addr contents */
304 struct so_list
*next
; /* next structure in linked list */
306 CORE_ADDR offset
; /* prelink to load address offset */
307 char *so_name
; /* shared object lib name */
308 CORE_ADDR lmstart
; /* lower addr bound of mapped object */
309 CORE_ADDR lmend
; /* upper addr bound of mapped object */
310 char symbols_loaded
; /* flag: symbols read in yet? */
311 char from_tty
; /* flag: print msgs? */
312 struct objfile
*objfile
; /* objfile for loaded lib */
313 struct section_table
*sections
;
314 struct section_table
*sections_end
;
315 struct section_table
*textsection
;
319 static struct so_list
*so_list_head
; /* List of known shared objects */
320 static CORE_ADDR debug_base
; /* Base of dynamic linker structures */
321 static CORE_ADDR breakpoint_addr
; /* Address where end bkpt is set */
323 /* Local function prototypes */
326 sharedlibrary_command
PARAMS ((char *, int));
329 enable_break
PARAMS ((void));
332 disable_break
PARAMS ((void));
335 info_sharedlibrary_command
PARAMS ((char *, int));
338 symbol_add_stub
PARAMS ((char *));
340 static struct so_list
*
341 find_solib
PARAMS ((struct so_list
*));
343 static struct link_map
*
344 first_link_map_member
PARAMS ((void));
346 static struct link_map
*
347 next_link_map_member
PARAMS ((struct so_list
*));
350 xfer_link_map_member
PARAMS ((struct so_list
*, struct link_map
*));
353 locate_base
PARAMS ((void));
356 solib_map_sections
PARAMS ((char *));
362 solib_map_sections -- open bfd and build sections for shared lib
366 static int solib_map_sections (struct so_list *so)
370 Given a pointer to one of the shared objects in our list
371 of mapped objects, use the recorded name to open a bfd
372 descriptor for the object, build a section table, and then
373 relocate all the section addresses by the base address at
374 which the shared object was mapped.
378 In most (all?) cases the shared object file name recorded in the
379 dynamic linkage tables will be a fully qualified pathname. For
380 cases where it isn't, do we really mimic the systems search
381 mechanism correctly in the below code (particularly the tilde
386 solib_map_sections (arg
)
389 struct so_list
*so
= (struct so_list
*) arg
; /* catch_errors bogon */
391 char *scratch_pathname
;
393 struct section_table
*p
;
394 struct cleanup
*old_chain
;
397 filename
= tilde_expand (so
-> so_name
);
398 old_chain
= make_cleanup (free
, filename
);
400 scratch_chan
= openp (getenv ("PATH"), 1, filename
, O_RDONLY
, 0,
402 if (scratch_chan
< 0)
404 scratch_chan
= openp (getenv ("LD_LIBRARY_PATH"), 1, filename
,
405 O_RDONLY
, 0, &scratch_pathname
);
407 if (scratch_chan
< 0)
409 perror_with_name (filename
);
411 /* Leave scratch_pathname allocated. abfd->name will point to it. */
413 abfd
= bfd_fdopenr (scratch_pathname
, gnutarget
, scratch_chan
);
416 close (scratch_chan
);
417 error ("Could not open `%s' as an executable file: %s",
418 scratch_pathname
, bfd_errmsg (bfd_get_error ()));
420 /* Leave bfd open, core_xfer_memory and "info files" need it. */
422 abfd
-> cacheable
= true;
424 if (!bfd_check_format (abfd
, bfd_object
))
426 error ("\"%s\": not in executable format: %s.",
427 scratch_pathname
, bfd_errmsg (bfd_get_error ()));
429 if (build_section_table (abfd
, &so
-> sections
, &so
-> sections_end
))
431 error ("Can't find the file sections in `%s': %s",
432 bfd_get_filename (exec_bfd
), bfd_errmsg (bfd_get_error ()));
435 for (p
= so
-> sections
; p
< so
-> sections_end
; p
++)
437 /* Relocate the section binding addresses as recorded in the shared
438 object's file by the offset to get the address to which the
439 object was actually mapped. */
440 p
-> addr
+= LM_OFFSET (so
);
441 p
-> endaddr
+= LM_OFFSET (so
);
442 so
-> lmend
= (CORE_ADDR
) max (p
-> endaddr
, so
-> lmend
);
443 if (STREQ (p
-> the_bfd_section
-> name
, ".text"))
445 so
-> textsection
= p
;
449 /* Free the file names, close the file now. */
450 do_cleanups (old_chain
);
459 locate_base -- locate the base address of dynamic linker structs
463 CORE_ADDR locate_base (void)
467 For both the SunOS and SVR4 shared library implementations, if the
468 inferior executable has been linked dynamically, there is a single
469 address somewhere in the inferior's data space which is the key to
470 locating all of the dynamic linker's runtime structures. This
471 address is the value of the symbol defined by the macro DEBUG_BASE.
472 The job of this function is to find and return that address, or to
473 return 0 if there is no such address (the executable is statically
476 For SunOS, the job is almost trivial, since the dynamic linker and
477 all of it's structures are statically linked to the executable at
478 link time. Thus the symbol for the address we are looking for has
479 already been added to the minimal symbol table for the executable's
480 objfile at the time the symbol file's symbols were read, and all we
481 have to do is look it up there. Note that we explicitly do NOT want
482 to find the copies in the shared library.
484 The SVR4 version is much more complicated because the dynamic linker
485 and it's structures are located in the shared C library, which gets
486 run as the executable's "interpreter" by the kernel. We have to go
487 to a lot more work to discover the address of DEBUG_BASE. Because
488 of this complexity, we cache the value we find and return that value
489 on subsequent invocations. Note there is no copy in the executable
492 Irix 5 is basically like SunOS.
494 Note that we can assume nothing about the process state at the time
495 we need to find this address. We may be stopped on the first instruc-
496 tion of the interpreter (C shared library), the first instruction of
497 the executable itself, or somewhere else entirely (if we attached
498 to the process for example).
505 struct minimal_symbol
*msymbol
;
506 CORE_ADDR address
= 0;
508 msymbol
= lookup_minimal_symbol (DEBUG_BASE
, NULL
, symfile_objfile
);
509 if ((msymbol
!= NULL
) && (SYMBOL_VALUE_ADDRESS (msymbol
) != 0))
511 address
= SYMBOL_VALUE_ADDRESS (msymbol
);
520 first_link_map_member -- locate first member in dynamic linker's map
524 static struct link_map *first_link_map_member (void)
528 Read in a copy of the first member in the inferior's dynamic
529 link map from the inferior's dynamic linker structures, and return
530 a pointer to the link map descriptor.
533 static struct link_map
*
534 first_link_map_member ()
536 struct obj_list
*listp
;
537 struct obj_list list_old
;
539 static struct link_map first_lm
;
541 CORE_ADDR next_lladdr
;
543 /* We have not already read in the dynamic linking structures
544 from the inferior, lookup the address of the base structure. */
545 debug_base
= locate_base ();
549 /* Get address of first list entry. */
550 read_memory (debug_base
, (char *) &listp
, sizeof (struct obj_list
*));
555 /* Get first list entry. */
556 lladdr
= (CORE_ADDR
) listp
;
557 read_memory (lladdr
, (char *) &list_old
, sizeof (struct obj_list
));
559 /* The first entry in the list is the object file we are debugging,
561 next_lladdr
= (CORE_ADDR
) list_old
.next
;
563 #ifdef HANDLE_NEW_OBJ_LIST
564 if (list_old
.data
== NEW_OBJ_INFO_MAGIC
)
566 Elf32_Obj_Info list_32
;
568 read_memory (lladdr
, (char *) &list_32
, sizeof (Elf32_Obj_Info
));
569 if (list_32
.oi_size
!= sizeof (Elf32_Obj_Info
))
571 next_lladdr
= (CORE_ADDR
) list_32
.oi_next
;
575 if (next_lladdr
== 0)
578 first_lm
.l_lladdr
= next_lladdr
;
587 next_link_map_member -- locate next member in dynamic linker's map
591 static struct link_map *next_link_map_member (so_list_ptr)
595 Read in a copy of the next member in the inferior's dynamic
596 link map from the inferior's dynamic linker structures, and return
597 a pointer to the link map descriptor.
600 static struct link_map
*
601 next_link_map_member (so_list_ptr
)
602 struct so_list
*so_list_ptr
;
604 struct link_map
*lm
= &so_list_ptr
-> lm
;
605 CORE_ADDR next_lladdr
= lm
-> l_next
;
606 static struct link_map next_lm
;
608 if (next_lladdr
== 0)
610 /* We have hit the end of the list, so check to see if any were
611 added, but be quiet if we can't read from the target any more. */
614 if (lm
-> l_variant
== OBJ_LIST_OLD
)
616 struct obj_list list_old
;
618 status
= target_read_memory (lm
-> l_lladdr
,
620 sizeof (struct obj_list
));
621 next_lladdr
= (CORE_ADDR
) list_old
.next
;
623 #ifdef HANDLE_NEW_OBJ_LIST
624 else if (lm
-> l_variant
== OBJ_LIST_32
)
626 Elf32_Obj_Info list_32
;
627 status
= target_read_memory (lm
-> l_lladdr
,
629 sizeof (Elf32_Obj_Info
));
630 next_lladdr
= (CORE_ADDR
) list_32
.oi_next
;
634 if (status
!= 0 || next_lladdr
== 0)
638 next_lm
.l_lladdr
= next_lladdr
;
647 xfer_link_map_member -- set local variables from dynamic linker's map
651 static void xfer_link_map_member (so_list_ptr, lm)
655 Read in a copy of the requested member in the inferior's dynamic
656 link map from the inferior's dynamic linker structures, and fill
657 in the necessary so_list_ptr elements.
661 xfer_link_map_member (so_list_ptr
, lm
)
662 struct so_list
*so_list_ptr
;
665 struct obj_list list_old
;
666 CORE_ADDR lladdr
= lm
-> l_lladdr
;
667 struct link_map
*new_lm
= &so_list_ptr
-> lm
;
670 read_memory (lladdr
, (char *) &list_old
, sizeof (struct obj_list
));
672 new_lm
-> l_variant
= OBJ_LIST_OLD
;
673 new_lm
-> l_lladdr
= lladdr
;
674 new_lm
-> l_next
= (CORE_ADDR
) list_old
.next
;
676 #ifdef HANDLE_NEW_OBJ_LIST
677 if (list_old
.data
== NEW_OBJ_INFO_MAGIC
)
679 Elf32_Obj_Info list_32
;
681 read_memory (lladdr
, (char *) &list_32
, sizeof (Elf32_Obj_Info
));
682 if (list_32
.oi_size
!= sizeof (Elf32_Obj_Info
))
684 new_lm
-> l_variant
= OBJ_LIST_32
;
685 new_lm
-> l_next
= (CORE_ADDR
) list_32
.oi_next
;
687 target_read_string ((CORE_ADDR
) list_32
.oi_pathname
,
688 &so_list_ptr
-> so_name
,
689 list_32
.oi_pathname_len
+ 1, &errcode
);
691 memory_error (errcode
, (CORE_ADDR
) list_32
.oi_pathname
);
693 LM_ADDR (so_list_ptr
) = (CORE_ADDR
) list_32
.oi_ehdr
;
694 LM_OFFSET (so_list_ptr
) =
695 (CORE_ADDR
) list_32
.oi_ehdr
- (CORE_ADDR
) list_32
.oi_orig_ehdr
;
700 #if defined (_MIPS_SIM_NABI32) && _MIPS_SIM == _MIPS_SIM_NABI32
701 /* If we are compiling GDB under N32 ABI, the alignments in
702 the obj struct are different from the O32 ABI and we will get
703 wrong values when accessing the struct.
704 As a workaround we use fixed values which are good for
708 read_memory ((CORE_ADDR
) list_old
.data
, buf
, sizeof (buf
));
710 target_read_string (extract_address (&buf
[236], 4),
711 &so_list_ptr
-> so_name
,
714 memory_error (errcode
, extract_address (&buf
[236], 4));
716 LM_ADDR (so_list_ptr
) = extract_address (&buf
[196], 4);
717 LM_OFFSET (so_list_ptr
) =
718 extract_address (&buf
[196], 4) - extract_address (&buf
[248], 4);
722 read_memory ((CORE_ADDR
) list_old
.data
, (char *) &obj_old
,
723 sizeof (struct obj
));
725 target_read_string ((CORE_ADDR
) obj_old
.o_path
,
726 &so_list_ptr
-> so_name
,
729 memory_error (errcode
, (CORE_ADDR
) obj_old
.o_path
);
731 LM_ADDR (so_list_ptr
) = (CORE_ADDR
) obj_old
.o_praw
;
732 LM_OFFSET (so_list_ptr
) =
733 (CORE_ADDR
) obj_old
.o_praw
- obj_old
.o_base_address
;
737 catch_errors (solib_map_sections
, (char *) so_list_ptr
,
738 "Error while mapping shared library sections:\n",
747 find_solib -- step through list of shared objects
751 struct so_list *find_solib (struct so_list *so_list_ptr)
755 This module contains the routine which finds the names of any
756 loaded "images" in the current process. The argument in must be
757 NULL on the first call, and then the returned value must be passed
758 in on subsequent calls. This provides the capability to "step" down
759 the list of loaded objects. On the last object, a NULL value is
763 static struct so_list
*
764 find_solib (so_list_ptr
)
765 struct so_list
*so_list_ptr
; /* Last lm or NULL for first one */
767 struct so_list
*so_list_next
= NULL
;
768 struct link_map
*lm
= NULL
;
771 if (so_list_ptr
== NULL
)
773 /* We are setting up for a new scan through the loaded images. */
774 if ((so_list_next
= so_list_head
) == NULL
)
776 /* Find the first link map list member. */
777 lm
= first_link_map_member ();
782 /* We have been called before, and are in the process of walking
783 the shared library list. Advance to the next shared object. */
784 lm
= next_link_map_member (so_list_ptr
);
785 so_list_next
= so_list_ptr
-> next
;
787 if ((so_list_next
== NULL
) && (lm
!= NULL
))
789 new = (struct so_list
*) xmalloc (sizeof (struct so_list
));
790 memset ((char *) new, 0, sizeof (struct so_list
));
791 /* Add the new node as the next node in the list, or as the root
792 node if this is the first one. */
793 if (so_list_ptr
!= NULL
)
795 so_list_ptr
-> next
= new;
802 xfer_link_map_member (new, lm
);
804 return (so_list_next
);
807 /* A small stub to get us past the arg-passing pinhole of catch_errors. */
810 symbol_add_stub (arg
)
813 register struct so_list
*so
= (struct so_list
*) arg
; /* catch_errs bogon */
814 CORE_ADDR text_addr
= 0;
816 if (so
-> textsection
)
817 text_addr
= so
-> textsection
-> addr
;
818 else if (so
-> abfd
!= NULL
)
820 asection
*lowest_sect
;
822 /* If we didn't find a mapped non zero sized .text section, set up
823 text_addr so that the relocation in symbol_file_add does no harm. */
825 lowest_sect
= bfd_get_section_by_name (so
-> abfd
, ".text");
826 if (lowest_sect
== NULL
)
827 bfd_map_over_sections (so
-> abfd
, find_lowest_section
,
830 text_addr
= bfd_section_vma (so
-> abfd
, lowest_sect
) + LM_OFFSET (so
);
833 so
-> objfile
= symbol_file_add (so
-> so_name
, so
-> from_tty
,
843 solib_add -- add a shared library file to the symtab and section list
847 void solib_add (char *arg_string, int from_tty,
848 struct target_ops *target)
855 solib_add (arg_string
, from_tty
, target
)
858 struct target_ops
*target
;
860 register struct so_list
*so
= NULL
; /* link map state variable */
862 /* Last shared library that we read. */
863 struct so_list
*so_last
= NULL
;
869 if ((re_err
= re_comp (arg_string
? arg_string
: ".")) != NULL
)
871 error ("Invalid regexp: %s", re_err
);
874 /* Add the shared library sections to the section table of the
875 specified target, if any. */
878 /* Count how many new section_table entries there are. */
881 while ((so
= find_solib (so
)) != NULL
)
883 if (so
-> so_name
[0])
885 count
+= so
-> sections_end
- so
-> sections
;
893 /* We must update the to_sections field in the core_ops structure
894 here, otherwise we dereference a potential dangling pointer
895 for each call to target_read/write_memory within this routine. */
896 update_coreops
= core_ops
.to_sections
== target
->to_sections
;
898 /* Reallocate the target's section table including the new size. */
899 if (target
-> to_sections
)
901 old
= target
-> to_sections_end
- target
-> to_sections
;
902 target
-> to_sections
= (struct section_table
*)
903 xrealloc ((char *)target
-> to_sections
,
904 (sizeof (struct section_table
)) * (count
+ old
));
909 target
-> to_sections
= (struct section_table
*)
910 xmalloc ((sizeof (struct section_table
)) * count
);
912 target
-> to_sections_end
= target
-> to_sections
+ (count
+ old
);
914 /* Update the to_sections field in the core_ops structure
918 core_ops
.to_sections
= target
->to_sections
;
919 core_ops
.to_sections_end
= target
->to_sections_end
;
922 /* Add these section table entries to the target's table. */
923 while ((so
= find_solib (so
)) != NULL
)
925 if (so
-> so_name
[0])
927 count
= so
-> sections_end
- so
-> sections
;
928 memcpy ((char *) (target
-> to_sections
+ old
),
930 (sizeof (struct section_table
)) * count
);
937 /* Now add the symbol files. */
938 while ((so
= find_solib (so
)) != NULL
)
940 if (so
-> so_name
[0] && re_exec (so
-> so_name
))
942 so
-> from_tty
= from_tty
;
943 if (so
-> symbols_loaded
)
947 printf_unfiltered ("Symbols already loaded for %s\n", so
-> so_name
);
950 else if (catch_errors
951 (symbol_add_stub
, (char *) so
,
952 "Error while reading shared library symbols:\n",
956 so
-> symbols_loaded
= 1;
961 /* Getting new symbols may change our opinion about what is
964 reinit_frame_cache ();
971 info_sharedlibrary_command -- code for "info sharedlibrary"
975 static void info_sharedlibrary_command ()
979 Walk through the shared library list and print information
980 about each attached library.
984 info_sharedlibrary_command (ignore
, from_tty
)
988 register struct so_list
*so
= NULL
; /* link map state variable */
991 if (exec_bfd
== NULL
)
993 printf_unfiltered ("No exec file.\n");
996 while ((so
= find_solib (so
)) != NULL
)
998 if (so
-> so_name
[0])
1002 printf_unfiltered("%-12s%-12s%-12s%s\n", "From", "To", "Syms Read",
1003 "Shared Object Library");
1006 printf_unfiltered ("%-12s",
1007 local_hex_string_custom ((unsigned long) LM_ADDR (so
),
1009 printf_unfiltered ("%-12s",
1010 local_hex_string_custom ((unsigned long) so
-> lmend
,
1012 printf_unfiltered ("%-12s", so
-> symbols_loaded
? "Yes" : "No");
1013 printf_unfiltered ("%s\n", so
-> so_name
);
1016 if (so_list_head
== NULL
)
1018 printf_unfiltered ("No shared libraries loaded at this time.\n");
1026 solib_address -- check to see if an address is in a shared lib
1030 char *solib_address (CORE_ADDR address)
1034 Provides a hook for other gdb routines to discover whether or
1035 not a particular address is within the mapped address space of
1036 a shared library. Any address between the base mapping address
1037 and the first address beyond the end of the last mapping, is
1038 considered to be within the shared library address space, for
1041 For example, this routine is called at one point to disable
1042 breakpoints which are in shared libraries that are not currently
1047 solib_address (address
)
1050 register struct so_list
*so
= 0; /* link map state variable */
1052 while ((so
= find_solib (so
)) != NULL
)
1054 if (so
-> so_name
[0])
1056 if ((address
>= (CORE_ADDR
) LM_ADDR (so
)) &&
1057 (address
< (CORE_ADDR
) so
-> lmend
))
1058 return (so
->so_name
);
1064 /* Called by free_all_symtabs */
1069 struct so_list
*next
;
1072 while (so_list_head
)
1074 if (so_list_head
-> sections
)
1076 free ((PTR
)so_list_head
-> sections
);
1078 if (so_list_head
-> abfd
)
1080 bfd_filename
= bfd_get_filename (so_list_head
-> abfd
);
1081 if (!bfd_close (so_list_head
-> abfd
))
1082 warning ("cannot close \"%s\": %s",
1083 bfd_filename
, bfd_errmsg (bfd_get_error ()));
1086 /* This happens for the executable on SVR4. */
1087 bfd_filename
= NULL
;
1089 next
= so_list_head
-> next
;
1091 free ((PTR
)bfd_filename
);
1092 free (so_list_head
->so_name
);
1093 free ((PTR
)so_list_head
);
1094 so_list_head
= next
;
1103 disable_break -- remove the "mapping changed" breakpoint
1107 static int disable_break ()
1111 Removes the breakpoint that gets hit when the dynamic linker
1112 completes a mapping change.
1122 /* Note that breakpoint address and original contents are in our address
1123 space, so we just need to write the original contents back. */
1125 if (memory_remove_breakpoint (breakpoint_addr
, shadow_contents
) != 0)
1130 /* For the SVR4 version, we always know the breakpoint address. For the
1131 SunOS version we don't know it until the above code is executed.
1132 Grumble if we are stopped anywhere besides the breakpoint address. */
1134 if (stop_pc
!= breakpoint_addr
)
1136 warning ("stopped at unknown breakpoint while handling shared libraries");
1146 enable_break -- arrange for dynamic linker to hit breakpoint
1150 int enable_break (void)
1154 This functions inserts a breakpoint at the entry point of the
1155 main executable, where all shared libraries are mapped in.
1161 if (symfile_objfile
!= NULL
1162 && target_insert_breakpoint (symfile_objfile
->ei
.entry_point
,
1163 shadow_contents
) == 0)
1165 breakpoint_addr
= symfile_objfile
->ei
.entry_point
;
1176 solib_create_inferior_hook -- shared library startup support
1180 void solib_create_inferior_hook()
1184 When gdb starts up the inferior, it nurses it along (through the
1185 shell) until it is ready to execute it's first instruction. At this
1186 point, this function gets called via expansion of the macro
1187 SOLIB_CREATE_INFERIOR_HOOK.
1189 For SunOS executables, this first instruction is typically the
1190 one at "_start", or a similar text label, regardless of whether
1191 the executable is statically or dynamically linked. The runtime
1192 startup code takes care of dynamically linking in any shared
1193 libraries, once gdb allows the inferior to continue.
1195 For SVR4 executables, this first instruction is either the first
1196 instruction in the dynamic linker (for dynamically linked
1197 executables) or the instruction at "start" for statically linked
1198 executables. For dynamically linked executables, the system
1199 first exec's /lib/libc.so.N, which contains the dynamic linker,
1200 and starts it running. The dynamic linker maps in any needed
1201 shared libraries, maps in the actual user executable, and then
1202 jumps to "start" in the user executable.
1204 For both SunOS shared libraries, and SVR4 shared libraries, we
1205 can arrange to cooperate with the dynamic linker to discover the
1206 names of shared libraries that are dynamically linked, and the
1207 base addresses to which they are linked.
1209 This function is responsible for discovering those names and
1210 addresses, and saving sufficient information about them to allow
1211 their symbols to be read at a later time.
1215 Between enable_break() and disable_break(), this code does not
1216 properly handle hitting breakpoints which the user might have
1217 set in the startup code or in the dynamic linker itself. Proper
1218 handling will probably have to wait until the implementation is
1219 changed to use the "breakpoint handler function" method.
1221 Also, what if child has exit()ed? Must exit loop somehow.
1225 solib_create_inferior_hook()
1227 if (!enable_break ())
1229 warning ("shared library handler failed to enable breakpoint");
1233 /* Now run the target. It will eventually hit the breakpoint, at
1234 which point all of the libraries will have been mapped in and we
1235 can go groveling around in the dynamic linker structures to find
1236 out what we need to know about them. */
1238 clear_proceed_status ();
1239 stop_soon_quietly
= 1;
1240 stop_signal
= TARGET_SIGNAL_0
;
1243 target_resume (-1, 0, stop_signal
);
1244 wait_for_inferior ();
1246 while (stop_signal
!= TARGET_SIGNAL_TRAP
);
1248 /* We are now either at the "mapping complete" breakpoint (or somewhere
1249 else, a condition we aren't prepared to deal with anyway), so adjust
1250 the PC as necessary after a breakpoint, disable the breakpoint, and
1251 add any shared libraries that were mapped in. */
1253 if (DECR_PC_AFTER_BREAK
)
1255 stop_pc
-= DECR_PC_AFTER_BREAK
;
1256 write_register (PC_REGNUM
, stop_pc
);
1259 if (!disable_break ())
1261 warning ("shared library handler failed to disable breakpoint");
1264 /* solib_add will call reinit_frame_cache.
1265 But we are stopped in the startup code and we might not have symbols
1266 for the startup code, so heuristic_proc_start could be called
1267 and will put out an annoying warning.
1268 Delaying the resetting of stop_soon_quietly until after symbol loading
1269 suppresses the warning. */
1271 solib_add ((char *) 0, 0, (struct target_ops
*) 0);
1272 stop_soon_quietly
= 0;
1279 sharedlibrary_command -- handle command to explicitly add library
1283 static void sharedlibrary_command (char *args, int from_tty)
1290 sharedlibrary_command (args
, from_tty
)
1295 solib_add (args
, from_tty
, (struct target_ops
*) 0);
1301 add_com ("sharedlibrary", class_files
, sharedlibrary_command
,
1302 "Load shared object library symbols for files matching REGEXP.");
1303 add_info ("sharedlibrary", info_sharedlibrary_command
,
1304 "Status of loaded shared object libraries.");
1307 (add_set_cmd ("auto-solib-add", class_support
, var_zinteger
,
1308 (char *) &auto_solib_add
,
1309 "Set autoloading of shared library symbols.\n\
1310 If nonzero, symbols from all shared object libraries will be loaded\n\
1311 automatically when the inferior begins execution or when the dynamic linker\n\
1312 informs gdb that a new library has been loaded. Otherwise, symbols\n\
1313 must be loaded manually, using `sharedlibrary'.",
1319 /* Register that we are able to handle irix5 core file formats.
1320 This really is bfd_target_unknown_flavour */
1322 static struct core_fns irix5_core_fns
=
1324 bfd_target_unknown_flavour
,
1325 fetch_core_registers
,
1330 _initialize_core_irix5 ()
1332 add_core_fns (&irix5_core_fns
);