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, 2001 Free
3 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. */
32 #include "gdb_string.h"
34 #include <sys/procfs.h>
35 #include <setjmp.h> /* For JB_XXX. */
37 /* Prototypes for supply_gregset etc. */
40 static void fetch_core_registers (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 (gregset_t
*gregsetp
)
57 register greg_t
*regp
= &(*gregsetp
)[0];
58 int gregoff
= sizeof (greg_t
) - MIPS_REGSIZE
;
59 static char zerobuf
[MAX_REGISTER_RAW_SIZE
] =
62 for (regi
= 0; regi
<= CTX_RA
; regi
++)
63 supply_register (regi
, (char *) (regp
+ regi
) + gregoff
);
65 supply_register (PC_REGNUM
, (char *) (regp
+ CTX_EPC
) + gregoff
);
66 supply_register (HI_REGNUM
, (char *) (regp
+ CTX_MDHI
) + gregoff
);
67 supply_register (LO_REGNUM
, (char *) (regp
+ CTX_MDLO
) + gregoff
);
68 supply_register (CAUSE_REGNUM
, (char *) (regp
+ CTX_CAUSE
) + gregoff
);
70 /* Fill inaccessible registers with zero. */
71 supply_register (BADVADDR_REGNUM
, zerobuf
);
75 fill_gregset (gregset_t
*gregsetp
, int regno
)
78 register greg_t
*regp
= &(*gregsetp
)[0];
80 /* Under Irix6, if GDB is built with N32 ABI and is debugging an O32
81 executable, we have to sign extend the registers to 64 bits before
82 filling in the gregset structure. */
84 for (regi
= 0; regi
<= CTX_RA
; regi
++)
85 if ((regno
== -1) || (regno
== regi
))
87 extract_signed_integer (®isters
[REGISTER_BYTE (regi
)],
88 REGISTER_RAW_SIZE (regi
));
90 if ((regno
== -1) || (regno
== PC_REGNUM
))
92 extract_signed_integer (®isters
[REGISTER_BYTE (PC_REGNUM
)],
93 REGISTER_RAW_SIZE (PC_REGNUM
));
95 if ((regno
== -1) || (regno
== CAUSE_REGNUM
))
97 extract_signed_integer (®isters
[REGISTER_BYTE (CAUSE_REGNUM
)],
98 REGISTER_RAW_SIZE (CAUSE_REGNUM
));
100 if ((regno
== -1) || (regno
== HI_REGNUM
))
102 extract_signed_integer (®isters
[REGISTER_BYTE (HI_REGNUM
)],
103 REGISTER_RAW_SIZE (HI_REGNUM
));
105 if ((regno
== -1) || (regno
== LO_REGNUM
))
107 extract_signed_integer (®isters
[REGISTER_BYTE (LO_REGNUM
)],
108 REGISTER_RAW_SIZE (LO_REGNUM
));
112 * Now we do the same thing for floating-point registers.
113 * We don't bother to condition on FP0_REGNUM since any
114 * reasonable MIPS configuration has an R3010 in it.
116 * Again, see the comments in m68k-tdep.c.
120 supply_fpregset (fpregset_t
*fpregsetp
)
123 static char zerobuf
[MAX_REGISTER_RAW_SIZE
] =
126 /* FIXME, this is wrong for the N32 ABI which has 64 bit FP regs. */
128 for (regi
= 0; regi
< 32; regi
++)
129 supply_register (FP0_REGNUM
+ regi
,
130 (char *) &fpregsetp
->fp_r
.fp_regs
[regi
]);
132 supply_register (FCRCS_REGNUM
, (char *) &fpregsetp
->fp_csr
);
134 /* FIXME: how can we supply FCRIR_REGNUM? SGI doesn't tell us. */
135 supply_register (FCRIR_REGNUM
, zerobuf
);
139 fill_fpregset (fpregset_t
*fpregsetp
, int regno
)
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 (CORE_ADDR
*pc
)
172 buf
= alloca (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
);
184 /* Provide registers to GDB from a core file.
186 CORE_REG_SECT points to an array of bytes, which were obtained from
187 a core file which BFD thinks might contain register contents.
188 CORE_REG_SIZE is its size.
190 Normally, WHICH says which register set corelow suspects this is:
191 0 --- the general-purpose register set
192 2 --- the floating-point register set
193 However, for Irix 5, WHICH isn't used.
195 REG_ADDR is also unused. */
198 fetch_core_registers (char *core_reg_sect
, unsigned core_reg_size
,
199 int which
, CORE_ADDR reg_addr
)
201 if (core_reg_size
== REGISTER_BYTES
)
203 memcpy ((char *) registers
, core_reg_sect
, core_reg_size
);
205 else if (MIPS_REGSIZE
== 4 &&
206 core_reg_size
== (2 * MIPS_REGSIZE
) * NUM_REGS
)
208 /* This is a core file from a N32 executable, 64 bits are saved
209 for all registers. */
210 char *srcp
= core_reg_sect
;
211 char *dstp
= registers
;
214 for (regno
= 0; regno
< NUM_REGS
; regno
++)
216 if (regno
>= FP0_REGNUM
&& regno
< (FP0_REGNUM
+ 32))
218 /* FIXME, this is wrong, N32 has 64 bit FP regs, but GDB
219 currently assumes that they are 32 bit. */
224 if (REGISTER_RAW_SIZE (regno
) == 4)
226 /* copying 4 bytes from eight bytes?
227 I don't see how this can be right... */
232 /* copy all 8 bytes (sizeof(double)) */
251 warning ("wrong size gregset struct in core file");
255 registers_fetched ();
258 /* Irix 5 uses what appears to be a unique form of shared library
259 support. This is a copy of solib.c modified for Irix 5. */
260 /* FIXME: Most of this code could be merged with osfsolib.c and solib.c
261 by using next_link_map_member and xfer_link_map_member in solib.c. */
263 #include <sys/types.h>
265 #include <sys/param.h>
268 /* <obj.h> includes <sym.h> and <symconst.h>, which causes conflicts
269 with our versions of those files included by tm-mips.h. Prevent
270 <obj.h> from including them with some appropriate defines. */
272 #define __SYMCONST_H__
274 #ifdef HAVE_OBJLIST_H
278 #ifdef NEW_OBJ_INFO_MAGIC
279 #define HANDLE_NEW_OBJ_LIST
285 #include "objfiles.h"
288 #include "gdb_regex.h"
289 #include "inferior.h"
290 #include "language.h"
293 /* The symbol which starts off the list of shared libraries. */
294 #define DEBUG_BASE "__rld_obj_head"
296 /* Irix 6.x introduces a new variant of object lists.
297 To be able to debug O32 executables under Irix 6, we have to handle both
302 OBJ_LIST_OLD
, /* Pre Irix 6.x object list. */
303 OBJ_LIST_32
, /* 32 Bit Elf32_Obj_Info. */
304 OBJ_LIST_64
/* 64 Bit Elf64_Obj_Info, FIXME not yet implemented. */
308 /* Define our own link_map structure.
309 This will help to share code with osfsolib.c and solib.c. */
313 obj_list_variant l_variant
; /* which variant of object list */
314 CORE_ADDR l_lladdr
; /* addr in inferior list was read from */
315 CORE_ADDR l_next
; /* address of next object list entry */
318 /* Irix 5 shared objects are pre-linked to particular addresses
319 although the dynamic linker may have to relocate them if the
320 address ranges of the libraries used by the main program clash.
321 The offset is the difference between the address where the object
322 is mapped and the binding address of the shared library. */
323 #define LM_OFFSET(so) ((so) -> offset)
324 /* Loaded address of shared library. */
325 #define LM_ADDR(so) ((so) -> lmstart)
327 char shadow_contents
[BREAKPOINT_MAX
]; /* Stash old bkpt addr contents */
331 struct so_list
*next
; /* next structure in linked list */
333 CORE_ADDR offset
; /* prelink to load address offset */
334 char *so_name
; /* shared object lib name */
335 CORE_ADDR lmstart
; /* lower addr bound of mapped object */
336 CORE_ADDR lmend
; /* upper addr bound of mapped object */
337 char symbols_loaded
; /* flag: symbols read in yet? */
338 char from_tty
; /* flag: print msgs? */
339 struct objfile
*objfile
; /* objfile for loaded lib */
340 struct section_table
*sections
;
341 struct section_table
*sections_end
;
342 struct section_table
*textsection
;
346 static struct so_list
*so_list_head
; /* List of known shared objects */
347 static CORE_ADDR debug_base
; /* Base of dynamic linker structures */
348 static CORE_ADDR breakpoint_addr
; /* Address where end bkpt is set */
350 /* Local function prototypes */
352 static void sharedlibrary_command (char *, int);
354 static int enable_break (void);
356 static int disable_break (void);
358 static void info_sharedlibrary_command (char *, int);
360 static int symbol_add_stub (void *);
362 static struct so_list
*find_solib (struct so_list
*);
364 static struct link_map
*first_link_map_member (void);
366 static struct link_map
*next_link_map_member (struct so_list
*);
368 static void xfer_link_map_member (struct so_list
*, struct link_map
*);
370 static CORE_ADDR
locate_base (void);
372 static int solib_map_sections (void *);
378 solib_map_sections -- open bfd and build sections for shared lib
382 static int solib_map_sections (struct so_list *so)
386 Given a pointer to one of the shared objects in our list
387 of mapped objects, use the recorded name to open a bfd
388 descriptor for the object, build a section table, and then
389 relocate all the section addresses by the base address at
390 which the shared object was mapped.
394 In most (all?) cases the shared object file name recorded in the
395 dynamic linkage tables will be a fully qualified pathname. For
396 cases where it isn't, do we really mimic the systems search
397 mechanism correctly in the below code (particularly the tilde
402 solib_map_sections (void *arg
)
404 struct so_list
*so
= (struct so_list
*) arg
; /* catch_errors bogon */
406 char *scratch_pathname
;
408 struct section_table
*p
;
409 struct cleanup
*old_chain
;
412 filename
= tilde_expand (so
->so_name
);
413 old_chain
= make_cleanup (xfree
, filename
);
415 scratch_chan
= openp (getenv ("PATH"), 1, filename
, O_RDONLY
, 0,
417 if (scratch_chan
< 0)
419 scratch_chan
= openp (getenv ("LD_LIBRARY_PATH"), 1, filename
,
420 O_RDONLY
, 0, &scratch_pathname
);
422 if (scratch_chan
< 0)
424 perror_with_name (filename
);
426 /* Leave scratch_pathname allocated. abfd->name will point to it. */
428 abfd
= bfd_fdopenr (scratch_pathname
, gnutarget
, scratch_chan
);
431 close (scratch_chan
);
432 error ("Could not open `%s' as an executable file: %s",
433 scratch_pathname
, bfd_errmsg (bfd_get_error ()));
435 /* Leave bfd open, core_xfer_memory and "info files" need it. */
437 abfd
->cacheable
= true;
439 if (!bfd_check_format (abfd
, bfd_object
))
441 error ("\"%s\": not in executable format: %s.",
442 scratch_pathname
, bfd_errmsg (bfd_get_error ()));
444 if (build_section_table (abfd
, &so
->sections
, &so
->sections_end
))
446 error ("Can't find the file sections in `%s': %s",
447 bfd_get_filename (exec_bfd
), bfd_errmsg (bfd_get_error ()));
450 for (p
= so
->sections
; p
< so
->sections_end
; p
++)
452 /* Relocate the section binding addresses as recorded in the shared
453 object's file by the offset to get the address to which the
454 object was actually mapped. */
455 p
->addr
+= LM_OFFSET (so
);
456 p
->endaddr
+= LM_OFFSET (so
);
457 so
->lmend
= (CORE_ADDR
) max (p
->endaddr
, so
->lmend
);
458 if (STREQ (p
->the_bfd_section
->name
, ".text"))
464 /* Free the file names, close the file now. */
465 do_cleanups (old_chain
);
467 /* must be non-zero */
475 locate_base -- locate the base address of dynamic linker structs
479 CORE_ADDR locate_base (void)
483 For both the SunOS and SVR4 shared library implementations, if the
484 inferior executable has been linked dynamically, there is a single
485 address somewhere in the inferior's data space which is the key to
486 locating all of the dynamic linker's runtime structures. This
487 address is the value of the symbol defined by the macro DEBUG_BASE.
488 The job of this function is to find and return that address, or to
489 return 0 if there is no such address (the executable is statically
492 For SunOS, the job is almost trivial, since the dynamic linker and
493 all of it's structures are statically linked to the executable at
494 link time. Thus the symbol for the address we are looking for has
495 already been added to the minimal symbol table for the executable's
496 objfile at the time the symbol file's symbols were read, and all we
497 have to do is look it up there. Note that we explicitly do NOT want
498 to find the copies in the shared library.
500 The SVR4 version is much more complicated because the dynamic linker
501 and it's structures are located in the shared C library, which gets
502 run as the executable's "interpreter" by the kernel. We have to go
503 to a lot more work to discover the address of DEBUG_BASE. Because
504 of this complexity, we cache the value we find and return that value
505 on subsequent invocations. Note there is no copy in the executable
508 Irix 5 is basically like SunOS.
510 Note that we can assume nothing about the process state at the time
511 we need to find this address. We may be stopped on the first instruc-
512 tion of the interpreter (C shared library), the first instruction of
513 the executable itself, or somewhere else entirely (if we attached
514 to the process for example).
521 struct minimal_symbol
*msymbol
;
522 CORE_ADDR address
= 0;
524 msymbol
= lookup_minimal_symbol (DEBUG_BASE
, NULL
, symfile_objfile
);
525 if ((msymbol
!= NULL
) && (SYMBOL_VALUE_ADDRESS (msymbol
) != 0))
527 address
= SYMBOL_VALUE_ADDRESS (msymbol
);
536 first_link_map_member -- locate first member in dynamic linker's map
540 static struct link_map *first_link_map_member (void)
544 Read in a copy of the first member in the inferior's dynamic
545 link map from the inferior's dynamic linker structures, and return
546 a pointer to the link map descriptor.
549 static struct link_map
*
550 first_link_map_member (void)
552 struct obj_list
*listp
;
553 struct obj_list list_old
;
555 static struct link_map first_lm
;
557 CORE_ADDR next_lladdr
;
559 /* We have not already read in the dynamic linking structures
560 from the inferior, lookup the address of the base structure. */
561 debug_base
= locate_base ();
565 /* Get address of first list entry. */
566 read_memory (debug_base
, (char *) &listp
, sizeof (struct obj_list
*));
571 /* Get first list entry. */
572 /* The MIPS Sign extends addresses. */
573 lladdr
= host_pointer_to_address (listp
);
574 read_memory (lladdr
, (char *) &list_old
, sizeof (struct obj_list
));
576 /* The first entry in the list is the object file we are debugging,
578 next_lladdr
= host_pointer_to_address (list_old
.next
);
580 #ifdef HANDLE_NEW_OBJ_LIST
581 if (list_old
.data
== NEW_OBJ_INFO_MAGIC
)
583 Elf32_Obj_Info list_32
;
585 read_memory (lladdr
, (char *) &list_32
, sizeof (Elf32_Obj_Info
));
586 if (list_32
.oi_size
!= sizeof (Elf32_Obj_Info
))
588 next_lladdr
= (CORE_ADDR
) list_32
.oi_next
;
592 if (next_lladdr
== 0)
595 first_lm
.l_lladdr
= next_lladdr
;
604 next_link_map_member -- locate next member in dynamic linker's map
608 static struct link_map *next_link_map_member (so_list_ptr)
612 Read in a copy of the next member in the inferior's dynamic
613 link map from the inferior's dynamic linker structures, and return
614 a pointer to the link map descriptor.
617 static struct link_map
*
618 next_link_map_member (struct so_list
*so_list_ptr
)
620 struct link_map
*lm
= &so_list_ptr
->lm
;
621 CORE_ADDR next_lladdr
= lm
->l_next
;
622 static struct link_map next_lm
;
624 if (next_lladdr
== 0)
626 /* We have hit the end of the list, so check to see if any were
627 added, but be quiet if we can't read from the target any more. */
630 if (lm
->l_variant
== OBJ_LIST_OLD
)
632 struct obj_list list_old
;
634 status
= target_read_memory (lm
->l_lladdr
,
636 sizeof (struct obj_list
));
637 next_lladdr
= host_pointer_to_address (list_old
.next
);
639 #ifdef HANDLE_NEW_OBJ_LIST
640 else if (lm
->l_variant
== OBJ_LIST_32
)
642 Elf32_Obj_Info list_32
;
643 status
= target_read_memory (lm
->l_lladdr
,
645 sizeof (Elf32_Obj_Info
));
646 next_lladdr
= (CORE_ADDR
) list_32
.oi_next
;
650 if (status
!= 0 || next_lladdr
== 0)
654 next_lm
.l_lladdr
= next_lladdr
;
663 xfer_link_map_member -- set local variables from dynamic linker's map
667 static void xfer_link_map_member (so_list_ptr, lm)
671 Read in a copy of the requested member in the inferior's dynamic
672 link map from the inferior's dynamic linker structures, and fill
673 in the necessary so_list_ptr elements.
677 xfer_link_map_member (struct so_list
*so_list_ptr
, struct link_map
*lm
)
679 struct obj_list list_old
;
680 CORE_ADDR lladdr
= lm
->l_lladdr
;
681 struct link_map
*new_lm
= &so_list_ptr
->lm
;
684 read_memory (lladdr
, (char *) &list_old
, sizeof (struct obj_list
));
686 new_lm
->l_variant
= OBJ_LIST_OLD
;
687 new_lm
->l_lladdr
= lladdr
;
688 new_lm
->l_next
= host_pointer_to_address (list_old
.next
);
690 #ifdef HANDLE_NEW_OBJ_LIST
691 if (list_old
.data
== NEW_OBJ_INFO_MAGIC
)
693 Elf32_Obj_Info list_32
;
695 read_memory (lladdr
, (char *) &list_32
, sizeof (Elf32_Obj_Info
));
696 if (list_32
.oi_size
!= sizeof (Elf32_Obj_Info
))
698 new_lm
->l_variant
= OBJ_LIST_32
;
699 new_lm
->l_next
= (CORE_ADDR
) list_32
.oi_next
;
701 target_read_string ((CORE_ADDR
) list_32
.oi_pathname
,
702 &so_list_ptr
->so_name
,
703 list_32
.oi_pathname_len
+ 1, &errcode
);
705 memory_error (errcode
, (CORE_ADDR
) list_32
.oi_pathname
);
707 LM_ADDR (so_list_ptr
) = (CORE_ADDR
) list_32
.oi_ehdr
;
708 LM_OFFSET (so_list_ptr
) =
709 (CORE_ADDR
) list_32
.oi_ehdr
- (CORE_ADDR
) list_32
.oi_orig_ehdr
;
714 #if defined (_MIPS_SIM_NABI32) && _MIPS_SIM == _MIPS_SIM_NABI32
715 /* If we are compiling GDB under N32 ABI, the alignments in
716 the obj struct are different from the O32 ABI and we will get
717 wrong values when accessing the struct.
718 As a workaround we use fixed values which are good for
722 read_memory ((CORE_ADDR
) list_old
.data
, buf
, sizeof (buf
));
724 target_read_string (extract_address (&buf
[236], 4),
725 &so_list_ptr
->so_name
,
728 memory_error (errcode
, extract_address (&buf
[236], 4));
730 LM_ADDR (so_list_ptr
) = extract_address (&buf
[196], 4);
731 LM_OFFSET (so_list_ptr
) =
732 extract_address (&buf
[196], 4) - extract_address (&buf
[248], 4);
736 read_memory ((CORE_ADDR
) list_old
.data
, (char *) &obj_old
,
737 sizeof (struct obj
));
739 target_read_string ((CORE_ADDR
) obj_old
.o_path
,
740 &so_list_ptr
->so_name
,
743 memory_error (errcode
, (CORE_ADDR
) obj_old
.o_path
);
745 LM_ADDR (so_list_ptr
) = (CORE_ADDR
) obj_old
.o_praw
;
746 LM_OFFSET (so_list_ptr
) =
747 (CORE_ADDR
) obj_old
.o_praw
- obj_old
.o_base_address
;
751 catch_errors (solib_map_sections
, (char *) so_list_ptr
,
752 "Error while mapping shared library sections:\n",
761 find_solib -- step through list of shared objects
765 struct so_list *find_solib (struct so_list *so_list_ptr)
769 This module contains the routine which finds the names of any
770 loaded "images" in the current process. The argument in must be
771 NULL on the first call, and then the returned value must be passed
772 in on subsequent calls. This provides the capability to "step" down
773 the list of loaded objects. On the last object, a NULL value is
777 static struct so_list
*
778 find_solib (struct so_list
*so_list_ptr
)
780 struct so_list
*so_list_next
= NULL
;
781 struct link_map
*lm
= NULL
;
784 if (so_list_ptr
== NULL
)
786 /* We are setting up for a new scan through the loaded images. */
787 if ((so_list_next
= so_list_head
) == NULL
)
789 /* Find the first link map list member. */
790 lm
= first_link_map_member ();
795 /* We have been called before, and are in the process of walking
796 the shared library list. Advance to the next shared object. */
797 lm
= next_link_map_member (so_list_ptr
);
798 so_list_next
= so_list_ptr
->next
;
800 if ((so_list_next
== NULL
) && (lm
!= NULL
))
802 new = (struct so_list
*) xmalloc (sizeof (struct so_list
));
803 memset ((char *) new, 0, sizeof (struct so_list
));
804 /* Add the new node as the next node in the list, or as the root
805 node if this is the first one. */
806 if (so_list_ptr
!= NULL
)
808 so_list_ptr
->next
= new;
815 xfer_link_map_member (new, lm
);
817 return (so_list_next
);
820 /* A small stub to get us past the arg-passing pinhole of catch_errors. */
823 symbol_add_stub (void *arg
)
825 register struct so_list
*so
= (struct so_list
*) arg
; /* catch_errs bogon */
826 CORE_ADDR text_addr
= 0;
827 struct section_addr_info section_addrs
;
829 memset (§ion_addrs
, 0, sizeof (section_addrs
));
831 text_addr
= so
->textsection
->addr
;
832 else if (so
->abfd
!= NULL
)
834 asection
*lowest_sect
;
836 /* If we didn't find a mapped non zero sized .text section, set up
837 text_addr so that the relocation in symbol_file_add does no harm. */
839 lowest_sect
= bfd_get_section_by_name (so
->abfd
, ".text");
840 if (lowest_sect
== NULL
)
841 bfd_map_over_sections (so
->abfd
, find_lowest_section
,
844 text_addr
= bfd_section_vma (so
->abfd
, lowest_sect
) + LM_OFFSET (so
);
848 section_addrs
.other
[0].name
= ".text";
849 section_addrs
.other
[0].addr
= text_addr
;
850 so
->objfile
= symbol_file_add (so
->so_name
, so
->from_tty
,
851 §ion_addrs
, 0, 0);
852 /* must be non-zero */
860 solib_add -- add a shared library file to the symtab and section list
864 void solib_add (char *arg_string, int from_tty,
865 struct target_ops *target)
872 solib_add (char *arg_string
, int from_tty
, struct target_ops
*target
)
874 register struct so_list
*so
= NULL
; /* link map state variable */
876 /* Last shared library that we read. */
877 struct so_list
*so_last
= NULL
;
883 if ((re_err
= re_comp (arg_string
? arg_string
: ".")) != NULL
)
885 error ("Invalid regexp: %s", re_err
);
888 /* Add the shared library sections to the section table of the
889 specified target, if any. */
892 /* Count how many new section_table entries there are. */
895 while ((so
= find_solib (so
)) != NULL
)
899 count
+= so
->sections_end
- so
->sections
;
905 old
= target_resize_to_sections (target
, count
);
907 /* Add these section table entries to the target's table. */
908 while ((so
= find_solib (so
)) != NULL
)
912 count
= so
->sections_end
- so
->sections
;
913 memcpy ((char *) (target
->to_sections
+ old
),
915 (sizeof (struct section_table
)) * count
);
922 /* Now add the symbol files. */
923 while ((so
= find_solib (so
)) != NULL
)
925 if (so
->so_name
[0] && re_exec (so
->so_name
))
927 so
->from_tty
= from_tty
;
928 if (so
->symbols_loaded
)
932 printf_unfiltered ("Symbols already loaded for %s\n", so
->so_name
);
935 else if (catch_errors
936 (symbol_add_stub
, (char *) so
,
937 "Error while reading shared library symbols:\n",
941 so
->symbols_loaded
= 1;
946 /* Getting new symbols may change our opinion about what is
949 reinit_frame_cache ();
956 info_sharedlibrary_command -- code for "info sharedlibrary"
960 static void info_sharedlibrary_command ()
964 Walk through the shared library list and print information
965 about each attached library.
969 info_sharedlibrary_command (char *ignore
, int from_tty
)
971 register struct so_list
*so
= NULL
; /* link map state variable */
974 if (exec_bfd
== NULL
)
976 printf_unfiltered ("No executable file.\n");
979 while ((so
= find_solib (so
)) != NULL
)
985 printf_unfiltered ("%-12s%-12s%-12s%s\n", "From", "To", "Syms Read",
986 "Shared Object Library");
989 printf_unfiltered ("%-12s",
990 local_hex_string_custom ((unsigned long) LM_ADDR (so
),
992 printf_unfiltered ("%-12s",
993 local_hex_string_custom ((unsigned long) so
->lmend
,
995 printf_unfiltered ("%-12s", so
->symbols_loaded
? "Yes" : "No");
996 printf_unfiltered ("%s\n", so
->so_name
);
999 if (so_list_head
== NULL
)
1001 printf_unfiltered ("No shared libraries loaded at this time.\n");
1009 solib_address -- check to see if an address is in a shared lib
1013 char *solib_address (CORE_ADDR address)
1017 Provides a hook for other gdb routines to discover whether or
1018 not a particular address is within the mapped address space of
1019 a shared library. Any address between the base mapping address
1020 and the first address beyond the end of the last mapping, is
1021 considered to be within the shared library address space, for
1024 For example, this routine is called at one point to disable
1025 breakpoints which are in shared libraries that are not currently
1030 solib_address (CORE_ADDR address
)
1032 register struct so_list
*so
= 0; /* link map state variable */
1034 while ((so
= find_solib (so
)) != NULL
)
1038 if ((address
>= (CORE_ADDR
) LM_ADDR (so
)) &&
1039 (address
< (CORE_ADDR
) so
->lmend
))
1040 return (so
->so_name
);
1046 /* Called by free_all_symtabs */
1051 struct so_list
*next
;
1054 disable_breakpoints_in_shlibs (1);
1056 while (so_list_head
)
1058 if (so_list_head
->sections
)
1060 xfree (so_list_head
->sections
);
1062 if (so_list_head
->abfd
)
1064 bfd_filename
= bfd_get_filename (so_list_head
->abfd
);
1065 if (!bfd_close (so_list_head
->abfd
))
1066 warning ("cannot close \"%s\": %s",
1067 bfd_filename
, bfd_errmsg (bfd_get_error ()));
1070 /* This happens for the executable on SVR4. */
1071 bfd_filename
= NULL
;
1073 next
= so_list_head
->next
;
1075 xfree (bfd_filename
);
1076 xfree (so_list_head
->so_name
);
1077 xfree (so_list_head
);
1078 so_list_head
= next
;
1087 disable_break -- remove the "mapping changed" breakpoint
1091 static int disable_break ()
1095 Removes the breakpoint that gets hit when the dynamic linker
1096 completes a mapping change.
1101 disable_break (void)
1106 /* Note that breakpoint address and original contents are in our address
1107 space, so we just need to write the original contents back. */
1109 if (memory_remove_breakpoint (breakpoint_addr
, shadow_contents
) != 0)
1114 /* For the SVR4 version, we always know the breakpoint address. For the
1115 SunOS version we don't know it until the above code is executed.
1116 Grumble if we are stopped anywhere besides the breakpoint address. */
1118 if (stop_pc
!= breakpoint_addr
)
1120 warning ("stopped at unknown breakpoint while handling shared libraries");
1130 enable_break -- arrange for dynamic linker to hit breakpoint
1134 int enable_break (void)
1138 This functions inserts a breakpoint at the entry point of the
1139 main executable, where all shared libraries are mapped in.
1145 if (symfile_objfile
!= NULL
1146 && target_insert_breakpoint (symfile_objfile
->ei
.entry_point
,
1147 shadow_contents
) == 0)
1149 breakpoint_addr
= symfile_objfile
->ei
.entry_point
;
1160 solib_create_inferior_hook -- shared library startup support
1164 void solib_create_inferior_hook()
1168 When gdb starts up the inferior, it nurses it along (through the
1169 shell) until it is ready to execute it's first instruction. At this
1170 point, this function gets called via expansion of the macro
1171 SOLIB_CREATE_INFERIOR_HOOK.
1173 For SunOS executables, this first instruction is typically the
1174 one at "_start", or a similar text label, regardless of whether
1175 the executable is statically or dynamically linked. The runtime
1176 startup code takes care of dynamically linking in any shared
1177 libraries, once gdb allows the inferior to continue.
1179 For SVR4 executables, this first instruction is either the first
1180 instruction in the dynamic linker (for dynamically linked
1181 executables) or the instruction at "start" for statically linked
1182 executables. For dynamically linked executables, the system
1183 first exec's /lib/libc.so.N, which contains the dynamic linker,
1184 and starts it running. The dynamic linker maps in any needed
1185 shared libraries, maps in the actual user executable, and then
1186 jumps to "start" in the user executable.
1188 For both SunOS shared libraries, and SVR4 shared libraries, we
1189 can arrange to cooperate with the dynamic linker to discover the
1190 names of shared libraries that are dynamically linked, and the
1191 base addresses to which they are linked.
1193 This function is responsible for discovering those names and
1194 addresses, and saving sufficient information about them to allow
1195 their symbols to be read at a later time.
1199 Between enable_break() and disable_break(), this code does not
1200 properly handle hitting breakpoints which the user might have
1201 set in the startup code or in the dynamic linker itself. Proper
1202 handling will probably have to wait until the implementation is
1203 changed to use the "breakpoint handler function" method.
1205 Also, what if child has exit()ed? Must exit loop somehow.
1209 solib_create_inferior_hook (void)
1211 if (!enable_break ())
1213 warning ("shared library handler failed to enable breakpoint");
1217 /* Now run the target. It will eventually hit the breakpoint, at
1218 which point all of the libraries will have been mapped in and we
1219 can go groveling around in the dynamic linker structures to find
1220 out what we need to know about them. */
1222 clear_proceed_status ();
1223 stop_soon_quietly
= 1;
1224 stop_signal
= TARGET_SIGNAL_0
;
1227 target_resume (-1, 0, stop_signal
);
1228 wait_for_inferior ();
1230 while (stop_signal
!= TARGET_SIGNAL_TRAP
);
1232 /* We are now either at the "mapping complete" breakpoint (or somewhere
1233 else, a condition we aren't prepared to deal with anyway), so adjust
1234 the PC as necessary after a breakpoint, disable the breakpoint, and
1235 add any shared libraries that were mapped in. */
1237 if (DECR_PC_AFTER_BREAK
)
1239 stop_pc
-= DECR_PC_AFTER_BREAK
;
1240 write_register (PC_REGNUM
, stop_pc
);
1243 if (!disable_break ())
1245 warning ("shared library handler failed to disable breakpoint");
1248 /* solib_add will call reinit_frame_cache.
1249 But we are stopped in the startup code and we might not have symbols
1250 for the startup code, so heuristic_proc_start could be called
1251 and will put out an annoying warning.
1252 Delaying the resetting of stop_soon_quietly until after symbol loading
1253 suppresses the warning. */
1255 solib_add ((char *) 0, 0, (struct target_ops
*) 0);
1256 stop_soon_quietly
= 0;
1263 sharedlibrary_command -- handle command to explicitly add library
1267 static void sharedlibrary_command (char *args, int from_tty)
1274 sharedlibrary_command (char *args
, int from_tty
)
1277 solib_add (args
, from_tty
, (struct target_ops
*) 0);
1281 _initialize_solib (void)
1283 add_com ("sharedlibrary", class_files
, sharedlibrary_command
,
1284 "Load shared object library symbols for files matching REGEXP.");
1285 add_info ("sharedlibrary", info_sharedlibrary_command
,
1286 "Status of loaded shared object libraries.");
1289 (add_set_cmd ("auto-solib-add", class_support
, var_zinteger
,
1290 (char *) &auto_solib_add
,
1291 "Set autoloading of shared library symbols.\n\
1292 If nonzero, symbols from all shared object libraries will be loaded\n\
1293 automatically when the inferior begins execution or when the dynamic linker\n\
1294 informs gdb that a new library has been loaded. Otherwise, symbols\n\
1295 must be loaded manually, using `sharedlibrary'.",
1301 /* Register that we are able to handle irix5 core file formats.
1302 This really is bfd_target_unknown_flavour */
1304 static struct core_fns irix5_core_fns
=
1306 bfd_target_unknown_flavour
, /* core_flavour */
1307 default_check_format
, /* check_format */
1308 default_core_sniffer
, /* core_sniffer */
1309 fetch_core_registers
, /* core_read_registers */
1314 _initialize_core_irix5 (void)
1316 add_core_fns (&irix5_core_fns
);