1 /* Native support for the SGI Iris running IRIX version 5, for GDB.
2 Copyright 1988, 89, 90, 91, 92, 93, 94, 95, 96, 98, 1999
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,
24 Boston, MA 02111-1307, USA. */
31 #include "gdb_string.h"
33 #include <sys/procfs.h>
34 #include <setjmp.h> /* For JB_XXX. */
36 /* Prototypes for supply_gregset etc. */
40 fetch_core_registers
PARAMS ((char *, unsigned int, int, CORE_ADDR
));
42 /* Size of elements in jmpbuf */
44 #define JB_ELEMENT_SIZE 4
47 * See the comment in m68k-tdep.c regarding the utility of these functions.
49 * These definitions are from the MIPS SVR4 ABI, so they may work for
50 * any MIPS SVR4 target.
54 supply_gregset (gregsetp
)
58 register greg_t
*regp
= &(*gregsetp
)[0];
59 int gregoff
= sizeof (greg_t
) - MIPS_REGSIZE
;
60 static char zerobuf
[MAX_REGISTER_RAW_SIZE
] =
63 for (regi
= 0; regi
<= CTX_RA
; regi
++)
64 supply_register (regi
, (char *) (regp
+ regi
) + gregoff
);
66 supply_register (PC_REGNUM
, (char *) (regp
+ CTX_EPC
) + gregoff
);
67 supply_register (HI_REGNUM
, (char *) (regp
+ CTX_MDHI
) + gregoff
);
68 supply_register (LO_REGNUM
, (char *) (regp
+ CTX_MDLO
) + gregoff
);
69 supply_register (CAUSE_REGNUM
, (char *) (regp
+ CTX_CAUSE
) + gregoff
);
71 /* Fill inaccessible registers with zero. */
72 supply_register (BADVADDR_REGNUM
, zerobuf
);
76 fill_gregset (gregsetp
, regno
)
81 register greg_t
*regp
= &(*gregsetp
)[0];
83 /* Under Irix6, if GDB is built with N32 ABI and is debugging an O32
84 executable, we have to sign extend the registers to 64 bits before
85 filling in the gregset structure. */
87 for (regi
= 0; regi
<= CTX_RA
; regi
++)
88 if ((regno
== -1) || (regno
== regi
))
90 extract_signed_integer (®isters
[REGISTER_BYTE (regi
)],
91 REGISTER_RAW_SIZE (regi
));
93 if ((regno
== -1) || (regno
== PC_REGNUM
))
95 extract_signed_integer (®isters
[REGISTER_BYTE (PC_REGNUM
)],
96 REGISTER_RAW_SIZE (PC_REGNUM
));
98 if ((regno
== -1) || (regno
== CAUSE_REGNUM
))
100 extract_signed_integer (®isters
[REGISTER_BYTE (CAUSE_REGNUM
)],
101 REGISTER_RAW_SIZE (CAUSE_REGNUM
));
103 if ((regno
== -1) || (regno
== HI_REGNUM
))
105 extract_signed_integer (®isters
[REGISTER_BYTE (HI_REGNUM
)],
106 REGISTER_RAW_SIZE (HI_REGNUM
));
108 if ((regno
== -1) || (regno
== LO_REGNUM
))
110 extract_signed_integer (®isters
[REGISTER_BYTE (LO_REGNUM
)],
111 REGISTER_RAW_SIZE (LO_REGNUM
));
115 * Now we do the same thing for floating-point registers.
116 * We don't bother to condition on FP0_REGNUM since any
117 * reasonable MIPS configuration has an R3010 in it.
119 * Again, see the comments in m68k-tdep.c.
123 supply_fpregset (fpregsetp
)
124 fpregset_t
*fpregsetp
;
127 static char zerobuf
[MAX_REGISTER_RAW_SIZE
] =
130 /* FIXME, this is wrong for the N32 ABI which has 64 bit FP regs. */
132 for (regi
= 0; regi
< 32; regi
++)
133 supply_register (FP0_REGNUM
+ regi
,
134 (char *) &fpregsetp
->fp_r
.fp_regs
[regi
]);
136 supply_register (FCRCS_REGNUM
, (char *) &fpregsetp
->fp_csr
);
138 /* FIXME: how can we supply FCRIR_REGNUM? SGI doesn't tell us. */
139 supply_register (FCRIR_REGNUM
, zerobuf
);
143 fill_fpregset (fpregsetp
, regno
)
144 fpregset_t
*fpregsetp
;
150 /* FIXME, this is wrong for the N32 ABI which has 64 bit FP regs. */
152 for (regi
= FP0_REGNUM
; regi
< FP0_REGNUM
+ 32; regi
++)
154 if ((regno
== -1) || (regno
== regi
))
156 from
= (char *) ®isters
[REGISTER_BYTE (regi
)];
157 to
= (char *) &(fpregsetp
->fp_r
.fp_regs
[regi
- FP0_REGNUM
]);
158 memcpy (to
, from
, REGISTER_RAW_SIZE (regi
));
162 if ((regno
== -1) || (regno
== FCRCS_REGNUM
))
163 fpregsetp
->fp_csr
= *(unsigned *) ®isters
[REGISTER_BYTE (FCRCS_REGNUM
)];
167 /* Figure out where the longjmp will land.
168 We expect the first arg to be a pointer to the jmp_buf structure from which
169 we extract the pc (JB_PC) that we will land at. The pc is copied into PC.
170 This routine returns true on success. */
173 get_longjmp_target (pc
)
176 char buf
[TARGET_PTR_BIT
/ TARGET_CHAR_BIT
];
179 jb_addr
= read_register (A0_REGNUM
);
181 if (target_read_memory (jb_addr
+ JB_PC
* JB_ELEMENT_SIZE
, buf
,
182 TARGET_PTR_BIT
/ TARGET_CHAR_BIT
))
185 *pc
= extract_address (buf
, TARGET_PTR_BIT
/ TARGET_CHAR_BIT
);
191 fetch_core_registers (core_reg_sect
, core_reg_size
, which
, reg_addr
)
193 unsigned core_reg_size
;
194 int which
; /* Unused */
195 CORE_ADDR reg_addr
; /* Unused */
197 if (core_reg_size
== REGISTER_BYTES
)
199 memcpy ((char *) registers
, core_reg_sect
, core_reg_size
);
201 else if (MIPS_REGSIZE
== 4 &&
202 core_reg_size
== (2 * MIPS_REGSIZE
) * NUM_REGS
)
204 /* This is a core file from a N32 executable, 64 bits are saved
205 for all registers. */
206 char *srcp
= core_reg_sect
;
207 char *dstp
= registers
;
210 for (regno
= 0; regno
< NUM_REGS
; regno
++)
212 if (regno
>= FP0_REGNUM
&& regno
< (FP0_REGNUM
+ 32))
214 /* FIXME, this is wrong, N32 has 64 bit FP regs, but GDB
215 currently assumes that they are 32 bit. */
220 if (REGISTER_RAW_SIZE (regno
) == 4)
222 /* copying 4 bytes from eight bytes?
223 I don't see how this can be right... */
228 /* copy all 8 bytes (sizeof(double)) */
247 warning ("wrong size gregset struct in core file");
251 registers_fetched ();
254 /* Irix 5 uses what appears to be a unique form of shared library
255 support. This is a copy of solib.c modified for Irix 5. */
256 /* FIXME: Most of this code could be merged with osfsolib.c and solib.c
257 by using next_link_map_member and xfer_link_map_member in solib.c. */
259 #include <sys/types.h>
261 #include <sys/param.h>
264 /* <obj.h> includes <sym.h> and <symconst.h>, which causes conflicts
265 with our versions of those files included by tm-mips.h. Prevent
266 <obj.h> from including them with some appropriate defines. */
268 #define __SYMCONST_H__
270 #ifdef HAVE_OBJLIST_H
274 #ifdef NEW_OBJ_INFO_MAGIC
275 #define HANDLE_NEW_OBJ_LIST
281 #include "objfiles.h"
284 #include "gdb_regex.h"
285 #include "inferior.h"
286 #include "language.h"
289 /* The symbol which starts off the list of shared libraries. */
290 #define DEBUG_BASE "__rld_obj_head"
292 /* Irix 6.x introduces a new variant of object lists.
293 To be able to debug O32 executables under Irix 6, we have to handle both
298 OBJ_LIST_OLD
, /* Pre Irix 6.x object list. */
299 OBJ_LIST_32
, /* 32 Bit Elf32_Obj_Info. */
300 OBJ_LIST_64
/* 64 Bit Elf64_Obj_Info, FIXME not yet implemented. */
304 /* Define our own link_map structure.
305 This will help to share code with osfsolib.c and solib.c. */
309 obj_list_variant l_variant
; /* which variant of object list */
310 CORE_ADDR l_lladdr
; /* addr in inferior list was read from */
311 CORE_ADDR l_next
; /* address of next object list entry */
314 /* Irix 5 shared objects are pre-linked to particular addresses
315 although the dynamic linker may have to relocate them if the
316 address ranges of the libraries used by the main program clash.
317 The offset is the difference between the address where the object
318 is mapped and the binding address of the shared library. */
319 #define LM_OFFSET(so) ((so) -> offset)
320 /* Loaded address of shared library. */
321 #define LM_ADDR(so) ((so) -> lmstart)
323 char shadow_contents
[BREAKPOINT_MAX
]; /* Stash old bkpt addr contents */
327 struct so_list
*next
; /* next structure in linked list */
329 CORE_ADDR offset
; /* prelink to load address offset */
330 char *so_name
; /* shared object lib name */
331 CORE_ADDR lmstart
; /* lower addr bound of mapped object */
332 CORE_ADDR lmend
; /* upper addr bound of mapped object */
333 char symbols_loaded
; /* flag: symbols read in yet? */
334 char from_tty
; /* flag: print msgs? */
335 struct objfile
*objfile
; /* objfile for loaded lib */
336 struct section_table
*sections
;
337 struct section_table
*sections_end
;
338 struct section_table
*textsection
;
342 static struct so_list
*so_list_head
; /* List of known shared objects */
343 static CORE_ADDR debug_base
; /* Base of dynamic linker structures */
344 static CORE_ADDR breakpoint_addr
; /* Address where end bkpt is set */
346 /* Local function prototypes */
349 sharedlibrary_command
PARAMS ((char *, int));
352 enable_break
PARAMS ((void));
355 disable_break
PARAMS ((void));
358 info_sharedlibrary_command
PARAMS ((char *, int));
361 symbol_add_stub
PARAMS ((char *));
363 static struct so_list
*
364 find_solib
PARAMS ((struct so_list
*));
366 static struct link_map
*
367 first_link_map_member
PARAMS ((void));
369 static struct link_map
*
370 next_link_map_member
PARAMS ((struct so_list
*));
373 xfer_link_map_member
PARAMS ((struct so_list
*, struct link_map
*));
376 locate_base
PARAMS ((void));
379 solib_map_sections
PARAMS ((char *));
385 solib_map_sections -- open bfd and build sections for shared lib
389 static int solib_map_sections (struct so_list *so)
393 Given a pointer to one of the shared objects in our list
394 of mapped objects, use the recorded name to open a bfd
395 descriptor for the object, build a section table, and then
396 relocate all the section addresses by the base address at
397 which the shared object was mapped.
401 In most (all?) cases the shared object file name recorded in the
402 dynamic linkage tables will be a fully qualified pathname. For
403 cases where it isn't, do we really mimic the systems search
404 mechanism correctly in the below code (particularly the tilde
409 solib_map_sections (arg
)
412 struct so_list
*so
= (struct so_list
*) arg
; /* catch_errors bogon */
414 char *scratch_pathname
;
416 struct section_table
*p
;
417 struct cleanup
*old_chain
;
420 filename
= tilde_expand (so
->so_name
);
421 old_chain
= make_cleanup (free
, filename
);
423 scratch_chan
= openp (getenv ("PATH"), 1, filename
, O_RDONLY
, 0,
425 if (scratch_chan
< 0)
427 scratch_chan
= openp (getenv ("LD_LIBRARY_PATH"), 1, filename
,
428 O_RDONLY
, 0, &scratch_pathname
);
430 if (scratch_chan
< 0)
432 perror_with_name (filename
);
434 /* Leave scratch_pathname allocated. abfd->name will point to it. */
436 abfd
= bfd_fdopenr (scratch_pathname
, gnutarget
, scratch_chan
);
439 close (scratch_chan
);
440 error ("Could not open `%s' as an executable file: %s",
441 scratch_pathname
, bfd_errmsg (bfd_get_error ()));
443 /* Leave bfd open, core_xfer_memory and "info files" need it. */
445 abfd
->cacheable
= true;
447 if (!bfd_check_format (abfd
, bfd_object
))
449 error ("\"%s\": not in executable format: %s.",
450 scratch_pathname
, bfd_errmsg (bfd_get_error ()));
452 if (build_section_table (abfd
, &so
->sections
, &so
->sections_end
))
454 error ("Can't find the file sections in `%s': %s",
455 bfd_get_filename (exec_bfd
), bfd_errmsg (bfd_get_error ()));
458 for (p
= so
->sections
; p
< so
->sections_end
; p
++)
460 /* Relocate the section binding addresses as recorded in the shared
461 object's file by the offset to get the address to which the
462 object was actually mapped. */
463 p
->addr
+= LM_OFFSET (so
);
464 p
->endaddr
+= LM_OFFSET (so
);
465 so
->lmend
= (CORE_ADDR
) max (p
->endaddr
, so
->lmend
);
466 if (STREQ (p
->the_bfd_section
->name
, ".text"))
472 /* Free the file names, close the file now. */
473 do_cleanups (old_chain
);
482 locate_base -- locate the base address of dynamic linker structs
486 CORE_ADDR locate_base (void)
490 For both the SunOS and SVR4 shared library implementations, if the
491 inferior executable has been linked dynamically, there is a single
492 address somewhere in the inferior's data space which is the key to
493 locating all of the dynamic linker's runtime structures. This
494 address is the value of the symbol defined by the macro DEBUG_BASE.
495 The job of this function is to find and return that address, or to
496 return 0 if there is no such address (the executable is statically
499 For SunOS, the job is almost trivial, since the dynamic linker and
500 all of it's structures are statically linked to the executable at
501 link time. Thus the symbol for the address we are looking for has
502 already been added to the minimal symbol table for the executable's
503 objfile at the time the symbol file's symbols were read, and all we
504 have to do is look it up there. Note that we explicitly do NOT want
505 to find the copies in the shared library.
507 The SVR4 version is much more complicated because the dynamic linker
508 and it's structures are located in the shared C library, which gets
509 run as the executable's "interpreter" by the kernel. We have to go
510 to a lot more work to discover the address of DEBUG_BASE. Because
511 of this complexity, we cache the value we find and return that value
512 on subsequent invocations. Note there is no copy in the executable
515 Irix 5 is basically like SunOS.
517 Note that we can assume nothing about the process state at the time
518 we need to find this address. We may be stopped on the first instruc-
519 tion of the interpreter (C shared library), the first instruction of
520 the executable itself, or somewhere else entirely (if we attached
521 to the process for example).
528 struct minimal_symbol
*msymbol
;
529 CORE_ADDR address
= 0;
531 msymbol
= lookup_minimal_symbol (DEBUG_BASE
, NULL
, symfile_objfile
);
532 if ((msymbol
!= NULL
) && (SYMBOL_VALUE_ADDRESS (msymbol
) != 0))
534 address
= SYMBOL_VALUE_ADDRESS (msymbol
);
543 first_link_map_member -- locate first member in dynamic linker's map
547 static struct link_map *first_link_map_member (void)
551 Read in a copy of the first member in the inferior's dynamic
552 link map from the inferior's dynamic linker structures, and return
553 a pointer to the link map descriptor.
556 static struct link_map
*
557 first_link_map_member ()
559 struct obj_list
*listp
;
560 struct obj_list list_old
;
562 static struct link_map first_lm
;
564 CORE_ADDR next_lladdr
;
566 /* We have not already read in the dynamic linking structures
567 from the inferior, lookup the address of the base structure. */
568 debug_base
= locate_base ();
572 /* Get address of first list entry. */
573 read_memory (debug_base
, (char *) &listp
, sizeof (struct obj_list
*));
578 /* Get first list entry. */
579 lladdr
= (CORE_ADDR
) listp
;
580 read_memory (lladdr
, (char *) &list_old
, sizeof (struct obj_list
));
582 /* The first entry in the list is the object file we are debugging,
584 next_lladdr
= (CORE_ADDR
) list_old
.next
;
586 #ifdef HANDLE_NEW_OBJ_LIST
587 if (list_old
.data
== NEW_OBJ_INFO_MAGIC
)
589 Elf32_Obj_Info list_32
;
591 read_memory (lladdr
, (char *) &list_32
, sizeof (Elf32_Obj_Info
));
592 if (list_32
.oi_size
!= sizeof (Elf32_Obj_Info
))
594 next_lladdr
= (CORE_ADDR
) list_32
.oi_next
;
598 if (next_lladdr
== 0)
601 first_lm
.l_lladdr
= next_lladdr
;
610 next_link_map_member -- locate next member in dynamic linker's map
614 static struct link_map *next_link_map_member (so_list_ptr)
618 Read in a copy of the next member in the inferior's dynamic
619 link map from the inferior's dynamic linker structures, and return
620 a pointer to the link map descriptor.
623 static struct link_map
*
624 next_link_map_member (so_list_ptr
)
625 struct so_list
*so_list_ptr
;
627 struct link_map
*lm
= &so_list_ptr
->lm
;
628 CORE_ADDR next_lladdr
= lm
->l_next
;
629 static struct link_map next_lm
;
631 if (next_lladdr
== 0)
633 /* We have hit the end of the list, so check to see if any were
634 added, but be quiet if we can't read from the target any more. */
637 if (lm
->l_variant
== OBJ_LIST_OLD
)
639 struct obj_list list_old
;
641 status
= target_read_memory (lm
->l_lladdr
,
643 sizeof (struct obj_list
));
644 next_lladdr
= (CORE_ADDR
) list_old
.next
;
646 #ifdef HANDLE_NEW_OBJ_LIST
647 else if (lm
->l_variant
== OBJ_LIST_32
)
649 Elf32_Obj_Info list_32
;
650 status
= target_read_memory (lm
->l_lladdr
,
652 sizeof (Elf32_Obj_Info
));
653 next_lladdr
= (CORE_ADDR
) list_32
.oi_next
;
657 if (status
!= 0 || next_lladdr
== 0)
661 next_lm
.l_lladdr
= next_lladdr
;
670 xfer_link_map_member -- set local variables from dynamic linker's map
674 static void xfer_link_map_member (so_list_ptr, lm)
678 Read in a copy of the requested member in the inferior's dynamic
679 link map from the inferior's dynamic linker structures, and fill
680 in the necessary so_list_ptr elements.
684 xfer_link_map_member (so_list_ptr
, lm
)
685 struct so_list
*so_list_ptr
;
688 struct obj_list list_old
;
689 CORE_ADDR lladdr
= lm
->l_lladdr
;
690 struct link_map
*new_lm
= &so_list_ptr
->lm
;
693 read_memory (lladdr
, (char *) &list_old
, sizeof (struct obj_list
));
695 new_lm
->l_variant
= OBJ_LIST_OLD
;
696 new_lm
->l_lladdr
= lladdr
;
697 new_lm
->l_next
= (CORE_ADDR
) list_old
.next
;
699 #ifdef HANDLE_NEW_OBJ_LIST
700 if (list_old
.data
== NEW_OBJ_INFO_MAGIC
)
702 Elf32_Obj_Info list_32
;
704 read_memory (lladdr
, (char *) &list_32
, sizeof (Elf32_Obj_Info
));
705 if (list_32
.oi_size
!= sizeof (Elf32_Obj_Info
))
707 new_lm
->l_variant
= OBJ_LIST_32
;
708 new_lm
->l_next
= (CORE_ADDR
) list_32
.oi_next
;
710 target_read_string ((CORE_ADDR
) list_32
.oi_pathname
,
711 &so_list_ptr
->so_name
,
712 list_32
.oi_pathname_len
+ 1, &errcode
);
714 memory_error (errcode
, (CORE_ADDR
) list_32
.oi_pathname
);
716 LM_ADDR (so_list_ptr
) = (CORE_ADDR
) list_32
.oi_ehdr
;
717 LM_OFFSET (so_list_ptr
) =
718 (CORE_ADDR
) list_32
.oi_ehdr
- (CORE_ADDR
) list_32
.oi_orig_ehdr
;
723 #if defined (_MIPS_SIM_NABI32) && _MIPS_SIM == _MIPS_SIM_NABI32
724 /* If we are compiling GDB under N32 ABI, the alignments in
725 the obj struct are different from the O32 ABI and we will get
726 wrong values when accessing the struct.
727 As a workaround we use fixed values which are good for
731 read_memory ((CORE_ADDR
) list_old
.data
, buf
, sizeof (buf
));
733 target_read_string (extract_address (&buf
[236], 4),
734 &so_list_ptr
->so_name
,
737 memory_error (errcode
, extract_address (&buf
[236], 4));
739 LM_ADDR (so_list_ptr
) = extract_address (&buf
[196], 4);
740 LM_OFFSET (so_list_ptr
) =
741 extract_address (&buf
[196], 4) - extract_address (&buf
[248], 4);
745 read_memory ((CORE_ADDR
) list_old
.data
, (char *) &obj_old
,
746 sizeof (struct obj
));
748 target_read_string ((CORE_ADDR
) obj_old
.o_path
,
749 &so_list_ptr
->so_name
,
752 memory_error (errcode
, (CORE_ADDR
) obj_old
.o_path
);
754 LM_ADDR (so_list_ptr
) = (CORE_ADDR
) obj_old
.o_praw
;
755 LM_OFFSET (so_list_ptr
) =
756 (CORE_ADDR
) obj_old
.o_praw
- obj_old
.o_base_address
;
760 catch_errors (solib_map_sections
, (char *) so_list_ptr
,
761 "Error while mapping shared library sections:\n",
770 find_solib -- step through list of shared objects
774 struct so_list *find_solib (struct so_list *so_list_ptr)
778 This module contains the routine which finds the names of any
779 loaded "images" in the current process. The argument in must be
780 NULL on the first call, and then the returned value must be passed
781 in on subsequent calls. This provides the capability to "step" down
782 the list of loaded objects. On the last object, a NULL value is
786 static struct so_list
*
787 find_solib (so_list_ptr
)
788 struct so_list
*so_list_ptr
; /* Last lm or NULL for first one */
790 struct so_list
*so_list_next
= NULL
;
791 struct link_map
*lm
= NULL
;
794 if (so_list_ptr
== NULL
)
796 /* We are setting up for a new scan through the loaded images. */
797 if ((so_list_next
= so_list_head
) == NULL
)
799 /* Find the first link map list member. */
800 lm
= first_link_map_member ();
805 /* We have been called before, and are in the process of walking
806 the shared library list. Advance to the next shared object. */
807 lm
= next_link_map_member (so_list_ptr
);
808 so_list_next
= so_list_ptr
->next
;
810 if ((so_list_next
== NULL
) && (lm
!= NULL
))
812 new = (struct so_list
*) xmalloc (sizeof (struct so_list
));
813 memset ((char *) new, 0, sizeof (struct so_list
));
814 /* Add the new node as the next node in the list, or as the root
815 node if this is the first one. */
816 if (so_list_ptr
!= NULL
)
818 so_list_ptr
->next
= new;
825 xfer_link_map_member (new, lm
);
827 return (so_list_next
);
830 /* A small stub to get us past the arg-passing pinhole of catch_errors. */
833 symbol_add_stub (arg
)
836 register struct so_list
*so
= (struct so_list
*) arg
; /* catch_errs bogon */
837 CORE_ADDR text_addr
= 0;
838 struct section_addr_info section_addrs
;
840 memset (§ion_addrs
, 0, sizeof (section_addrs
));
842 text_addr
= so
->textsection
->addr
;
843 else if (so
->abfd
!= NULL
)
845 asection
*lowest_sect
;
847 /* If we didn't find a mapped non zero sized .text section, set up
848 text_addr so that the relocation in symbol_file_add does no harm. */
850 lowest_sect
= bfd_get_section_by_name (so
->abfd
, ".text");
851 if (lowest_sect
== NULL
)
852 bfd_map_over_sections (so
->abfd
, find_lowest_section
,
855 text_addr
= bfd_section_vma (so
->abfd
, lowest_sect
) + LM_OFFSET (so
);
859 section_addrs
.other
[0].name
= ".text";
860 section_addrs
.other
[0].addr
= text_addr
;
861 so
->objfile
= symbol_file_add (so
->so_name
, so
->from_tty
,
862 §ion_addrs
, 0, 0);
870 solib_add -- add a shared library file to the symtab and section list
874 void solib_add (char *arg_string, int from_tty,
875 struct target_ops *target)
882 solib_add (arg_string
, from_tty
, target
)
885 struct target_ops
*target
;
887 register struct so_list
*so
= NULL
; /* link map state variable */
889 /* Last shared library that we read. */
890 struct so_list
*so_last
= NULL
;
896 if ((re_err
= re_comp (arg_string
? arg_string
: ".")) != NULL
)
898 error ("Invalid regexp: %s", re_err
);
901 /* Add the shared library sections to the section table of the
902 specified target, if any. */
905 /* Count how many new section_table entries there are. */
908 while ((so
= find_solib (so
)) != NULL
)
912 count
+= so
->sections_end
- so
->sections
;
918 old
= target_resize_to_sections (target
, count
);
920 /* Add these section table entries to the target's table. */
921 while ((so
= find_solib (so
)) != NULL
)
925 count
= so
->sections_end
- so
->sections
;
926 memcpy ((char *) (target
->to_sections
+ old
),
928 (sizeof (struct section_table
)) * count
);
935 /* Now add the symbol files. */
936 while ((so
= find_solib (so
)) != NULL
)
938 if (so
->so_name
[0] && re_exec (so
->so_name
))
940 so
->from_tty
= from_tty
;
941 if (so
->symbols_loaded
)
945 printf_unfiltered ("Symbols already loaded for %s\n", so
->so_name
);
948 else if (catch_errors
949 (symbol_add_stub
, (char *) so
,
950 "Error while reading shared library symbols:\n",
954 so
->symbols_loaded
= 1;
959 /* Getting new symbols may change our opinion about what is
962 reinit_frame_cache ();
969 info_sharedlibrary_command -- code for "info sharedlibrary"
973 static void info_sharedlibrary_command ()
977 Walk through the shared library list and print information
978 about each attached library.
982 info_sharedlibrary_command (ignore
, from_tty
)
986 register struct so_list
*so
= NULL
; /* link map state variable */
989 if (exec_bfd
== NULL
)
991 printf_unfiltered ("No executable file.\n");
994 while ((so
= find_solib (so
)) != NULL
)
1000 printf_unfiltered ("%-12s%-12s%-12s%s\n", "From", "To", "Syms Read",
1001 "Shared Object Library");
1004 printf_unfiltered ("%-12s",
1005 local_hex_string_custom ((unsigned long) LM_ADDR (so
),
1007 printf_unfiltered ("%-12s",
1008 local_hex_string_custom ((unsigned long) so
->lmend
,
1010 printf_unfiltered ("%-12s", so
->symbols_loaded
? "Yes" : "No");
1011 printf_unfiltered ("%s\n", so
->so_name
);
1014 if (so_list_head
== NULL
)
1016 printf_unfiltered ("No shared libraries loaded at this time.\n");
1024 solib_address -- check to see if an address is in a shared lib
1028 char *solib_address (CORE_ADDR address)
1032 Provides a hook for other gdb routines to discover whether or
1033 not a particular address is within the mapped address space of
1034 a shared library. Any address between the base mapping address
1035 and the first address beyond the end of the last mapping, is
1036 considered to be within the shared library address space, for
1039 For example, this routine is called at one point to disable
1040 breakpoints which are in shared libraries that are not currently
1045 solib_address (address
)
1048 register struct so_list
*so
= 0; /* link map state variable */
1050 while ((so
= find_solib (so
)) != NULL
)
1054 if ((address
>= (CORE_ADDR
) LM_ADDR (so
)) &&
1055 (address
< (CORE_ADDR
) so
->lmend
))
1056 return (so
->so_name
);
1062 /* Called by free_all_symtabs */
1067 struct so_list
*next
;
1070 disable_breakpoints_in_shlibs (1);
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);
1299 _initialize_solib ()
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
, /* core_flavour */
1325 default_check_format
, /* check_format */
1326 default_core_sniffer
, /* core_sniffer */
1327 fetch_core_registers
, /* core_read_registers */
1332 _initialize_core_irix5 ()
1334 add_core_fns (&irix5_core_fns
);