Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Native support for the SGI Iris running IRIX version 5, for GDB. |
b6ba6518 KB |
2 | Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998, |
3 | 1999, 2000, 2001 Free Software Foundation, Inc. | |
c906108c SS |
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. | |
8 | ||
c5aa993b | 9 | This file is part of GDB. |
c906108c | 10 | |
c5aa993b JM |
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. | |
c906108c | 15 | |
c5aa993b JM |
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. | |
c906108c | 20 | |
c5aa993b JM |
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. */ | |
c906108c SS |
25 | |
26 | #include "defs.h" | |
27 | #include "inferior.h" | |
28 | #include "gdbcore.h" | |
29 | #include "target.h" | |
4e052eda | 30 | #include "regcache.h" |
c906108c SS |
31 | |
32 | #include "gdb_string.h" | |
33 | #include <sys/time.h> | |
34 | #include <sys/procfs.h> | |
35 | #include <setjmp.h> /* For JB_XXX. */ | |
36 | ||
c60c0f5f MS |
37 | /* Prototypes for supply_gregset etc. */ |
38 | #include "gregset.h" | |
39 | ||
a14ed312 | 40 | static void fetch_core_registers (char *, unsigned int, int, CORE_ADDR); |
c906108c SS |
41 | |
42 | /* Size of elements in jmpbuf */ | |
43 | ||
44 | #define JB_ELEMENT_SIZE 4 | |
45 | ||
46 | /* | |
47 | * See the comment in m68k-tdep.c regarding the utility of these functions. | |
48 | * | |
49 | * These definitions are from the MIPS SVR4 ABI, so they may work for | |
50 | * any MIPS SVR4 target. | |
51 | */ | |
52 | ||
c5aa993b | 53 | void |
fba45db2 | 54 | supply_gregset (gregset_t *gregsetp) |
c906108c SS |
55 | { |
56 | register int regi; | |
57 | register greg_t *regp = &(*gregsetp)[0]; | |
58 | int gregoff = sizeof (greg_t) - MIPS_REGSIZE; | |
c5aa993b JM |
59 | static char zerobuf[MAX_REGISTER_RAW_SIZE] = |
60 | {0}; | |
c906108c | 61 | |
c5aa993b JM |
62 | for (regi = 0; regi <= CTX_RA; regi++) |
63 | supply_register (regi, (char *) (regp + regi) + gregoff); | |
c906108c | 64 | |
c5aa993b JM |
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); | |
c906108c SS |
69 | |
70 | /* Fill inaccessible registers with zero. */ | |
71 | supply_register (BADVADDR_REGNUM, zerobuf); | |
72 | } | |
73 | ||
74 | void | |
fba45db2 | 75 | fill_gregset (gregset_t *gregsetp, int regno) |
c906108c SS |
76 | { |
77 | int regi; | |
78 | register greg_t *regp = &(*gregsetp)[0]; | |
79 | ||
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. */ | |
83 | ||
84 | for (regi = 0; regi <= CTX_RA; regi++) | |
85 | if ((regno == -1) || (regno == regi)) | |
86 | *(regp + regi) = | |
87 | extract_signed_integer (®isters[REGISTER_BYTE (regi)], | |
88 | REGISTER_RAW_SIZE (regi)); | |
89 | ||
90 | if ((regno == -1) || (regno == PC_REGNUM)) | |
91 | *(regp + CTX_EPC) = | |
92 | extract_signed_integer (®isters[REGISTER_BYTE (PC_REGNUM)], | |
93 | REGISTER_RAW_SIZE (PC_REGNUM)); | |
94 | ||
95 | if ((regno == -1) || (regno == CAUSE_REGNUM)) | |
96 | *(regp + CTX_CAUSE) = | |
97 | extract_signed_integer (®isters[REGISTER_BYTE (CAUSE_REGNUM)], | |
98 | REGISTER_RAW_SIZE (CAUSE_REGNUM)); | |
99 | ||
100 | if ((regno == -1) || (regno == HI_REGNUM)) | |
101 | *(regp + CTX_MDHI) = | |
102 | extract_signed_integer (®isters[REGISTER_BYTE (HI_REGNUM)], | |
103 | REGISTER_RAW_SIZE (HI_REGNUM)); | |
104 | ||
105 | if ((regno == -1) || (regno == LO_REGNUM)) | |
106 | *(regp + CTX_MDLO) = | |
107 | extract_signed_integer (®isters[REGISTER_BYTE (LO_REGNUM)], | |
108 | REGISTER_RAW_SIZE (LO_REGNUM)); | |
109 | } | |
110 | ||
111 | /* | |
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. | |
115 | * | |
116 | * Again, see the comments in m68k-tdep.c. | |
117 | */ | |
118 | ||
119 | void | |
fba45db2 | 120 | supply_fpregset (fpregset_t *fpregsetp) |
c906108c SS |
121 | { |
122 | register int regi; | |
c5aa993b JM |
123 | static char zerobuf[MAX_REGISTER_RAW_SIZE] = |
124 | {0}; | |
c906108c SS |
125 | |
126 | /* FIXME, this is wrong for the N32 ABI which has 64 bit FP regs. */ | |
127 | ||
128 | for (regi = 0; regi < 32; regi++) | |
129 | supply_register (FP0_REGNUM + regi, | |
c5aa993b | 130 | (char *) &fpregsetp->fp_r.fp_regs[regi]); |
c906108c | 131 | |
c5aa993b | 132 | supply_register (FCRCS_REGNUM, (char *) &fpregsetp->fp_csr); |
c906108c SS |
133 | |
134 | /* FIXME: how can we supply FCRIR_REGNUM? SGI doesn't tell us. */ | |
135 | supply_register (FCRIR_REGNUM, zerobuf); | |
136 | } | |
137 | ||
138 | void | |
fba45db2 | 139 | fill_fpregset (fpregset_t *fpregsetp, int regno) |
c906108c SS |
140 | { |
141 | int regi; | |
142 | char *from, *to; | |
143 | ||
144 | /* FIXME, this is wrong for the N32 ABI which has 64 bit FP regs. */ | |
145 | ||
146 | for (regi = FP0_REGNUM; regi < FP0_REGNUM + 32; regi++) | |
147 | { | |
148 | if ((regno == -1) || (regno == regi)) | |
149 | { | |
150 | from = (char *) ®isters[REGISTER_BYTE (regi)]; | |
151 | to = (char *) &(fpregsetp->fp_r.fp_regs[regi - FP0_REGNUM]); | |
c5aa993b | 152 | memcpy (to, from, REGISTER_RAW_SIZE (regi)); |
c906108c SS |
153 | } |
154 | } | |
155 | ||
156 | if ((regno == -1) || (regno == FCRCS_REGNUM)) | |
c5aa993b | 157 | fpregsetp->fp_csr = *(unsigned *) ®isters[REGISTER_BYTE (FCRCS_REGNUM)]; |
c906108c SS |
158 | } |
159 | ||
160 | ||
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. */ | |
165 | ||
166 | int | |
fba45db2 | 167 | get_longjmp_target (CORE_ADDR *pc) |
c906108c | 168 | { |
35fc8285 | 169 | char *buf; |
c906108c SS |
170 | CORE_ADDR jb_addr; |
171 | ||
35fc8285 | 172 | buf = alloca (TARGET_PTR_BIT / TARGET_CHAR_BIT); |
c906108c SS |
173 | jb_addr = read_register (A0_REGNUM); |
174 | ||
175 | if (target_read_memory (jb_addr + JB_PC * JB_ELEMENT_SIZE, buf, | |
176 | TARGET_PTR_BIT / TARGET_CHAR_BIT)) | |
177 | return 0; | |
178 | ||
179 | *pc = extract_address (buf, TARGET_PTR_BIT / TARGET_CHAR_BIT); | |
180 | ||
181 | return 1; | |
182 | } | |
183 | ||
16bce26c KB |
184 | /* Provide registers to GDB from a core file. |
185 | ||
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. | |
189 | ||
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. | |
194 | ||
195 | REG_ADDR is also unused. */ | |
196 | ||
c906108c | 197 | static void |
16bce26c KB |
198 | fetch_core_registers (char *core_reg_sect, unsigned core_reg_size, |
199 | int which, CORE_ADDR reg_addr) | |
c906108c SS |
200 | { |
201 | if (core_reg_size == REGISTER_BYTES) | |
202 | { | |
c5aa993b | 203 | memcpy ((char *) registers, core_reg_sect, core_reg_size); |
c906108c SS |
204 | } |
205 | else if (MIPS_REGSIZE == 4 && | |
206 | core_reg_size == (2 * MIPS_REGSIZE) * NUM_REGS) | |
207 | { | |
208 | /* This is a core file from a N32 executable, 64 bits are saved | |
c5aa993b | 209 | for all registers. */ |
c906108c SS |
210 | char *srcp = core_reg_sect; |
211 | char *dstp = registers; | |
212 | int regno; | |
213 | ||
214 | for (regno = 0; regno < NUM_REGS; regno++) | |
215 | { | |
216 | if (regno >= FP0_REGNUM && regno < (FP0_REGNUM + 32)) | |
217 | { | |
218 | /* FIXME, this is wrong, N32 has 64 bit FP regs, but GDB | |
c5aa993b | 219 | currently assumes that they are 32 bit. */ |
c906108c SS |
220 | *dstp++ = *srcp++; |
221 | *dstp++ = *srcp++; | |
222 | *dstp++ = *srcp++; | |
223 | *dstp++ = *srcp++; | |
c5aa993b | 224 | if (REGISTER_RAW_SIZE (regno) == 4) |
c906108c SS |
225 | { |
226 | /* copying 4 bytes from eight bytes? | |
227 | I don't see how this can be right... */ | |
c5aa993b | 228 | srcp += 4; |
c906108c SS |
229 | } |
230 | else | |
231 | { | |
232 | /* copy all 8 bytes (sizeof(double)) */ | |
233 | *dstp++ = *srcp++; | |
234 | *dstp++ = *srcp++; | |
235 | *dstp++ = *srcp++; | |
236 | *dstp++ = *srcp++; | |
237 | } | |
238 | } | |
239 | else | |
240 | { | |
241 | srcp += 4; | |
242 | *dstp++ = *srcp++; | |
243 | *dstp++ = *srcp++; | |
244 | *dstp++ = *srcp++; | |
245 | *dstp++ = *srcp++; | |
246 | } | |
247 | } | |
248 | } | |
249 | else | |
250 | { | |
251 | warning ("wrong size gregset struct in core file"); | |
252 | return; | |
253 | } | |
254 | ||
255 | registers_fetched (); | |
256 | } | |
257 | \f | |
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. */ | |
262 | ||
263 | #include <sys/types.h> | |
264 | #include <signal.h> | |
265 | #include <sys/param.h> | |
266 | #include <fcntl.h> | |
267 | ||
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. */ | |
271 | #define __SYM_H__ | |
272 | #define __SYMCONST_H__ | |
273 | #include <obj.h> | |
274 | #ifdef HAVE_OBJLIST_H | |
275 | #include <objlist.h> | |
276 | #endif | |
277 | ||
278 | #ifdef NEW_OBJ_INFO_MAGIC | |
279 | #define HANDLE_NEW_OBJ_LIST | |
280 | #endif | |
281 | ||
282 | #include "symtab.h" | |
283 | #include "bfd.h" | |
284 | #include "symfile.h" | |
285 | #include "objfiles.h" | |
286 | #include "command.h" | |
287 | #include "frame.h" | |
88987551 | 288 | #include "gdb_regex.h" |
c906108c SS |
289 | #include "inferior.h" |
290 | #include "language.h" | |
291 | #include "gdbcmd.h" | |
292 | ||
293 | /* The symbol which starts off the list of shared libraries. */ | |
294 | #define DEBUG_BASE "__rld_obj_head" | |
295 | ||
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 | |
298 | variants. */ | |
299 | ||
300 | typedef enum | |
301 | { | |
c5aa993b JM |
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. */ | |
305 | } | |
306 | obj_list_variant; | |
c906108c SS |
307 | |
308 | /* Define our own link_map structure. | |
309 | This will help to share code with osfsolib.c and solib.c. */ | |
310 | ||
c5aa993b JM |
311 | struct link_map |
312 | { | |
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 */ | |
316 | }; | |
c906108c SS |
317 | |
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) | |
326 | ||
327 | char shadow_contents[BREAKPOINT_MAX]; /* Stash old bkpt addr contents */ | |
328 | ||
c5aa993b JM |
329 | struct so_list |
330 | { | |
331 | struct so_list *next; /* next structure in linked list */ | |
332 | struct link_map lm; | |
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; | |
343 | bfd *abfd; | |
344 | }; | |
c906108c SS |
345 | |
346 | static struct so_list *so_list_head; /* List of known shared objects */ | |
c5aa993b | 347 | static CORE_ADDR debug_base; /* Base of dynamic linker structures */ |
c906108c SS |
348 | static CORE_ADDR breakpoint_addr; /* Address where end bkpt is set */ |
349 | ||
350 | /* Local function prototypes */ | |
351 | ||
a14ed312 | 352 | static void sharedlibrary_command (char *, int); |
c906108c | 353 | |
a14ed312 | 354 | static int enable_break (void); |
c906108c | 355 | |
a14ed312 | 356 | static int disable_break (void); |
c906108c | 357 | |
a14ed312 | 358 | static void info_sharedlibrary_command (char *, int); |
c906108c | 359 | |
ac2e2ef7 | 360 | static int symbol_add_stub (void *); |
c906108c | 361 | |
a14ed312 | 362 | static struct so_list *find_solib (struct so_list *); |
c906108c | 363 | |
a14ed312 | 364 | static struct link_map *first_link_map_member (void); |
c906108c | 365 | |
a14ed312 | 366 | static struct link_map *next_link_map_member (struct so_list *); |
c906108c | 367 | |
a14ed312 | 368 | static void xfer_link_map_member (struct so_list *, struct link_map *); |
c906108c | 369 | |
a14ed312 | 370 | static CORE_ADDR locate_base (void); |
c906108c | 371 | |
ac2e2ef7 | 372 | static int solib_map_sections (void *); |
c906108c SS |
373 | |
374 | /* | |
375 | ||
c5aa993b | 376 | LOCAL FUNCTION |
c906108c | 377 | |
c5aa993b | 378 | solib_map_sections -- open bfd and build sections for shared lib |
c906108c | 379 | |
c5aa993b | 380 | SYNOPSIS |
c906108c | 381 | |
c5aa993b | 382 | static int solib_map_sections (struct so_list *so) |
c906108c | 383 | |
c5aa993b | 384 | DESCRIPTION |
c906108c | 385 | |
c5aa993b JM |
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. | |
c906108c | 391 | |
c5aa993b | 392 | FIXMES |
c906108c | 393 | |
c5aa993b JM |
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 | |
398 | expansion stuff?). | |
c906108c SS |
399 | */ |
400 | ||
401 | static int | |
ac2e2ef7 | 402 | solib_map_sections (void *arg) |
c906108c SS |
403 | { |
404 | struct so_list *so = (struct so_list *) arg; /* catch_errors bogon */ | |
405 | char *filename; | |
406 | char *scratch_pathname; | |
407 | int scratch_chan; | |
408 | struct section_table *p; | |
409 | struct cleanup *old_chain; | |
410 | bfd *abfd; | |
c5aa993b JM |
411 | |
412 | filename = tilde_expand (so->so_name); | |
b8c9b27d | 413 | old_chain = make_cleanup (xfree, filename); |
c5aa993b | 414 | |
c906108c SS |
415 | scratch_chan = openp (getenv ("PATH"), 1, filename, O_RDONLY, 0, |
416 | &scratch_pathname); | |
417 | if (scratch_chan < 0) | |
418 | { | |
419 | scratch_chan = openp (getenv ("LD_LIBRARY_PATH"), 1, filename, | |
420 | O_RDONLY, 0, &scratch_pathname); | |
421 | } | |
422 | if (scratch_chan < 0) | |
423 | { | |
424 | perror_with_name (filename); | |
425 | } | |
426 | /* Leave scratch_pathname allocated. abfd->name will point to it. */ | |
427 | ||
428 | abfd = bfd_fdopenr (scratch_pathname, gnutarget, scratch_chan); | |
429 | if (!abfd) | |
430 | { | |
431 | close (scratch_chan); | |
432 | error ("Could not open `%s' as an executable file: %s", | |
433 | scratch_pathname, bfd_errmsg (bfd_get_error ())); | |
434 | } | |
435 | /* Leave bfd open, core_xfer_memory and "info files" need it. */ | |
c5aa993b JM |
436 | so->abfd = abfd; |
437 | abfd->cacheable = true; | |
c906108c SS |
438 | |
439 | if (!bfd_check_format (abfd, bfd_object)) | |
440 | { | |
441 | error ("\"%s\": not in executable format: %s.", | |
442 | scratch_pathname, bfd_errmsg (bfd_get_error ())); | |
443 | } | |
c5aa993b | 444 | if (build_section_table (abfd, &so->sections, &so->sections_end)) |
c906108c | 445 | { |
c5aa993b | 446 | error ("Can't find the file sections in `%s': %s", |
c906108c SS |
447 | bfd_get_filename (exec_bfd), bfd_errmsg (bfd_get_error ())); |
448 | } | |
449 | ||
c5aa993b | 450 | for (p = so->sections; p < so->sections_end; p++) |
c906108c SS |
451 | { |
452 | /* Relocate the section binding addresses as recorded in the shared | |
c5aa993b JM |
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")) | |
c906108c | 459 | { |
c5aa993b | 460 | so->textsection = p; |
c906108c SS |
461 | } |
462 | } | |
463 | ||
464 | /* Free the file names, close the file now. */ | |
465 | do_cleanups (old_chain); | |
466 | ||
ac2e2ef7 | 467 | /* must be non-zero */ |
c906108c SS |
468 | return (1); |
469 | } | |
470 | ||
471 | /* | |
472 | ||
c5aa993b | 473 | LOCAL FUNCTION |
c906108c | 474 | |
c5aa993b | 475 | locate_base -- locate the base address of dynamic linker structs |
c906108c | 476 | |
c5aa993b | 477 | SYNOPSIS |
c906108c | 478 | |
c5aa993b | 479 | CORE_ADDR locate_base (void) |
c906108c | 480 | |
c5aa993b | 481 | DESCRIPTION |
c906108c | 482 | |
c5aa993b JM |
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 | |
490 | linked for example). | |
c906108c | 491 | |
c5aa993b JM |
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. | |
c906108c | 499 | |
c5aa993b JM |
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 | |
506 | symbol tables. | |
c906108c | 507 | |
c5aa993b | 508 | Irix 5 is basically like SunOS. |
c906108c | 509 | |
c5aa993b JM |
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). | |
c906108c SS |
515 | |
516 | */ | |
517 | ||
518 | static CORE_ADDR | |
fba45db2 | 519 | locate_base (void) |
c906108c SS |
520 | { |
521 | struct minimal_symbol *msymbol; | |
522 | CORE_ADDR address = 0; | |
523 | ||
524 | msymbol = lookup_minimal_symbol (DEBUG_BASE, NULL, symfile_objfile); | |
525 | if ((msymbol != NULL) && (SYMBOL_VALUE_ADDRESS (msymbol) != 0)) | |
526 | { | |
527 | address = SYMBOL_VALUE_ADDRESS (msymbol); | |
528 | } | |
529 | return (address); | |
530 | } | |
531 | ||
532 | /* | |
533 | ||
c5aa993b | 534 | LOCAL FUNCTION |
c906108c | 535 | |
c5aa993b | 536 | first_link_map_member -- locate first member in dynamic linker's map |
c906108c | 537 | |
c5aa993b | 538 | SYNOPSIS |
c906108c | 539 | |
c5aa993b | 540 | static struct link_map *first_link_map_member (void) |
c906108c | 541 | |
c5aa993b | 542 | DESCRIPTION |
c906108c | 543 | |
c5aa993b JM |
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. | |
547 | */ | |
c906108c SS |
548 | |
549 | static struct link_map * | |
fba45db2 | 550 | first_link_map_member (void) |
c906108c SS |
551 | { |
552 | struct obj_list *listp; | |
553 | struct obj_list list_old; | |
554 | struct link_map *lm; | |
555 | static struct link_map first_lm; | |
556 | CORE_ADDR lladdr; | |
557 | CORE_ADDR next_lladdr; | |
558 | ||
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 (); | |
562 | if (debug_base == 0) | |
563 | return NULL; | |
564 | ||
565 | /* Get address of first list entry. */ | |
566 | read_memory (debug_base, (char *) &listp, sizeof (struct obj_list *)); | |
567 | ||
568 | if (listp == NULL) | |
569 | return NULL; | |
570 | ||
571 | /* Get first list entry. */ | |
ac2e2ef7 AC |
572 | /* The MIPS Sign extends addresses. */ |
573 | lladdr = host_pointer_to_address (listp); | |
c906108c SS |
574 | read_memory (lladdr, (char *) &list_old, sizeof (struct obj_list)); |
575 | ||
576 | /* The first entry in the list is the object file we are debugging, | |
577 | so skip it. */ | |
ac2e2ef7 | 578 | next_lladdr = host_pointer_to_address (list_old.next); |
c906108c SS |
579 | |
580 | #ifdef HANDLE_NEW_OBJ_LIST | |
581 | if (list_old.data == NEW_OBJ_INFO_MAGIC) | |
582 | { | |
583 | Elf32_Obj_Info list_32; | |
584 | ||
585 | read_memory (lladdr, (char *) &list_32, sizeof (Elf32_Obj_Info)); | |
586 | if (list_32.oi_size != sizeof (Elf32_Obj_Info)) | |
587 | return NULL; | |
c5aa993b | 588 | next_lladdr = (CORE_ADDR) list_32.oi_next; |
c906108c SS |
589 | } |
590 | #endif | |
591 | ||
592 | if (next_lladdr == 0) | |
593 | return NULL; | |
594 | ||
595 | first_lm.l_lladdr = next_lladdr; | |
596 | lm = &first_lm; | |
597 | return lm; | |
598 | } | |
599 | ||
600 | /* | |
601 | ||
c5aa993b | 602 | LOCAL FUNCTION |
c906108c | 603 | |
c5aa993b | 604 | next_link_map_member -- locate next member in dynamic linker's map |
c906108c | 605 | |
c5aa993b | 606 | SYNOPSIS |
c906108c | 607 | |
c5aa993b | 608 | static struct link_map *next_link_map_member (so_list_ptr) |
c906108c | 609 | |
c5aa993b | 610 | DESCRIPTION |
c906108c | 611 | |
c5aa993b JM |
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. | |
615 | */ | |
c906108c SS |
616 | |
617 | static struct link_map * | |
fba45db2 | 618 | next_link_map_member (struct so_list *so_list_ptr) |
c906108c | 619 | { |
c5aa993b JM |
620 | struct link_map *lm = &so_list_ptr->lm; |
621 | CORE_ADDR next_lladdr = lm->l_next; | |
c906108c SS |
622 | static struct link_map next_lm; |
623 | ||
624 | if (next_lladdr == 0) | |
625 | { | |
626 | /* We have hit the end of the list, so check to see if any were | |
c5aa993b | 627 | added, but be quiet if we can't read from the target any more. */ |
c906108c SS |
628 | int status = 0; |
629 | ||
c5aa993b | 630 | if (lm->l_variant == OBJ_LIST_OLD) |
c906108c SS |
631 | { |
632 | struct obj_list list_old; | |
633 | ||
c5aa993b | 634 | status = target_read_memory (lm->l_lladdr, |
c906108c SS |
635 | (char *) &list_old, |
636 | sizeof (struct obj_list)); | |
ac2e2ef7 | 637 | next_lladdr = host_pointer_to_address (list_old.next); |
c906108c SS |
638 | } |
639 | #ifdef HANDLE_NEW_OBJ_LIST | |
c5aa993b | 640 | else if (lm->l_variant == OBJ_LIST_32) |
c906108c SS |
641 | { |
642 | Elf32_Obj_Info list_32; | |
c5aa993b | 643 | status = target_read_memory (lm->l_lladdr, |
c906108c SS |
644 | (char *) &list_32, |
645 | sizeof (Elf32_Obj_Info)); | |
646 | next_lladdr = (CORE_ADDR) list_32.oi_next; | |
647 | } | |
648 | #endif | |
649 | ||
650 | if (status != 0 || next_lladdr == 0) | |
651 | return NULL; | |
652 | } | |
653 | ||
654 | next_lm.l_lladdr = next_lladdr; | |
655 | lm = &next_lm; | |
656 | return lm; | |
657 | } | |
658 | ||
659 | /* | |
660 | ||
c5aa993b | 661 | LOCAL FUNCTION |
c906108c | 662 | |
c5aa993b | 663 | xfer_link_map_member -- set local variables from dynamic linker's map |
c906108c | 664 | |
c5aa993b | 665 | SYNOPSIS |
c906108c | 666 | |
c5aa993b | 667 | static void xfer_link_map_member (so_list_ptr, lm) |
c906108c | 668 | |
c5aa993b | 669 | DESCRIPTION |
c906108c | 670 | |
c5aa993b JM |
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. | |
674 | */ | |
c906108c SS |
675 | |
676 | static void | |
fba45db2 | 677 | xfer_link_map_member (struct so_list *so_list_ptr, struct link_map *lm) |
c906108c SS |
678 | { |
679 | struct obj_list list_old; | |
c5aa993b JM |
680 | CORE_ADDR lladdr = lm->l_lladdr; |
681 | struct link_map *new_lm = &so_list_ptr->lm; | |
c906108c SS |
682 | int errcode; |
683 | ||
684 | read_memory (lladdr, (char *) &list_old, sizeof (struct obj_list)); | |
685 | ||
c5aa993b JM |
686 | new_lm->l_variant = OBJ_LIST_OLD; |
687 | new_lm->l_lladdr = lladdr; | |
ac2e2ef7 | 688 | new_lm->l_next = host_pointer_to_address (list_old.next); |
c906108c SS |
689 | |
690 | #ifdef HANDLE_NEW_OBJ_LIST | |
691 | if (list_old.data == NEW_OBJ_INFO_MAGIC) | |
692 | { | |
693 | Elf32_Obj_Info list_32; | |
694 | ||
695 | read_memory (lladdr, (char *) &list_32, sizeof (Elf32_Obj_Info)); | |
696 | if (list_32.oi_size != sizeof (Elf32_Obj_Info)) | |
697 | return; | |
c5aa993b JM |
698 | new_lm->l_variant = OBJ_LIST_32; |
699 | new_lm->l_next = (CORE_ADDR) list_32.oi_next; | |
c906108c SS |
700 | |
701 | target_read_string ((CORE_ADDR) list_32.oi_pathname, | |
c5aa993b | 702 | &so_list_ptr->so_name, |
c906108c SS |
703 | list_32.oi_pathname_len + 1, &errcode); |
704 | if (errcode != 0) | |
705 | memory_error (errcode, (CORE_ADDR) list_32.oi_pathname); | |
706 | ||
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; | |
710 | } | |
711 | else | |
712 | #endif | |
713 | { | |
714 | #if defined (_MIPS_SIM_NABI32) && _MIPS_SIM == _MIPS_SIM_NABI32 | |
715 | /* If we are compiling GDB under N32 ABI, the alignments in | |
c5aa993b JM |
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 | |
719 | Irix 6.2. */ | |
c906108c SS |
720 | char buf[432]; |
721 | ||
722 | read_memory ((CORE_ADDR) list_old.data, buf, sizeof (buf)); | |
723 | ||
724 | target_read_string (extract_address (&buf[236], 4), | |
c5aa993b | 725 | &so_list_ptr->so_name, |
c906108c SS |
726 | INT_MAX, &errcode); |
727 | if (errcode != 0) | |
728 | memory_error (errcode, extract_address (&buf[236], 4)); | |
729 | ||
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); | |
733 | #else | |
734 | struct obj obj_old; | |
735 | ||
736 | read_memory ((CORE_ADDR) list_old.data, (char *) &obj_old, | |
737 | sizeof (struct obj)); | |
738 | ||
739 | target_read_string ((CORE_ADDR) obj_old.o_path, | |
c5aa993b | 740 | &so_list_ptr->so_name, |
c906108c SS |
741 | INT_MAX, &errcode); |
742 | if (errcode != 0) | |
743 | memory_error (errcode, (CORE_ADDR) obj_old.o_path); | |
744 | ||
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; | |
748 | #endif | |
749 | } | |
750 | ||
751 | catch_errors (solib_map_sections, (char *) so_list_ptr, | |
752 | "Error while mapping shared library sections:\n", | |
753 | RETURN_MASK_ALL); | |
754 | } | |
755 | ||
756 | ||
757 | /* | |
758 | ||
c5aa993b | 759 | LOCAL FUNCTION |
c906108c | 760 | |
c5aa993b | 761 | find_solib -- step through list of shared objects |
c906108c | 762 | |
c5aa993b | 763 | SYNOPSIS |
c906108c | 764 | |
c5aa993b | 765 | struct so_list *find_solib (struct so_list *so_list_ptr) |
c906108c | 766 | |
c5aa993b | 767 | DESCRIPTION |
c906108c | 768 | |
c5aa993b JM |
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 | |
774 | returned. | |
c906108c SS |
775 | */ |
776 | ||
777 | static struct so_list * | |
16bce26c | 778 | find_solib (struct so_list *so_list_ptr) |
c906108c SS |
779 | { |
780 | struct so_list *so_list_next = NULL; | |
781 | struct link_map *lm = NULL; | |
782 | struct so_list *new; | |
c5aa993b | 783 | |
c906108c SS |
784 | if (so_list_ptr == NULL) |
785 | { | |
786 | /* We are setting up for a new scan through the loaded images. */ | |
787 | if ((so_list_next = so_list_head) == NULL) | |
788 | { | |
789 | /* Find the first link map list member. */ | |
790 | lm = first_link_map_member (); | |
791 | } | |
792 | } | |
793 | else | |
794 | { | |
795 | /* We have been called before, and are in the process of walking | |
c5aa993b | 796 | the shared library list. Advance to the next shared object. */ |
c906108c | 797 | lm = next_link_map_member (so_list_ptr); |
c5aa993b | 798 | so_list_next = so_list_ptr->next; |
c906108c SS |
799 | } |
800 | if ((so_list_next == NULL) && (lm != NULL)) | |
801 | { | |
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 | |
c5aa993b | 805 | node if this is the first one. */ |
c906108c SS |
806 | if (so_list_ptr != NULL) |
807 | { | |
c5aa993b | 808 | so_list_ptr->next = new; |
c906108c SS |
809 | } |
810 | else | |
811 | { | |
812 | so_list_head = new; | |
c5aa993b | 813 | } |
c906108c SS |
814 | so_list_next = new; |
815 | xfer_link_map_member (new, lm); | |
816 | } | |
817 | return (so_list_next); | |
818 | } | |
819 | ||
820 | /* A small stub to get us past the arg-passing pinhole of catch_errors. */ | |
821 | ||
822 | static int | |
ac2e2ef7 | 823 | symbol_add_stub (void *arg) |
c906108c | 824 | { |
c5aa993b | 825 | register struct so_list *so = (struct so_list *) arg; /* catch_errs bogon */ |
c906108c | 826 | CORE_ADDR text_addr = 0; |
2acceee2 | 827 | struct section_addr_info section_addrs; |
c906108c | 828 | |
2acceee2 | 829 | memset (§ion_addrs, 0, sizeof (section_addrs)); |
c5aa993b JM |
830 | if (so->textsection) |
831 | text_addr = so->textsection->addr; | |
832 | else if (so->abfd != NULL) | |
c906108c SS |
833 | { |
834 | asection *lowest_sect; | |
835 | ||
836 | /* If we didn't find a mapped non zero sized .text section, set up | |
c5aa993b | 837 | text_addr so that the relocation in symbol_file_add does no harm. */ |
c906108c | 838 | |
c5aa993b | 839 | lowest_sect = bfd_get_section_by_name (so->abfd, ".text"); |
c906108c | 840 | if (lowest_sect == NULL) |
c5aa993b | 841 | bfd_map_over_sections (so->abfd, find_lowest_section, |
96baa820 | 842 | (PTR) &lowest_sect); |
c906108c | 843 | if (lowest_sect) |
c5aa993b | 844 | text_addr = bfd_section_vma (so->abfd, lowest_sect) + LM_OFFSET (so); |
c906108c | 845 | } |
c5aa993b | 846 | |
a034fba4 EZ |
847 | |
848 | section_addrs.other[0].name = ".text"; | |
849 | section_addrs.other[0].addr = text_addr; | |
c5aa993b | 850 | so->objfile = symbol_file_add (so->so_name, so->from_tty, |
2df3850c | 851 | §ion_addrs, 0, 0); |
ac2e2ef7 | 852 | /* must be non-zero */ |
c906108c SS |
853 | return (1); |
854 | } | |
855 | ||
856 | /* | |
857 | ||
c5aa993b | 858 | GLOBAL FUNCTION |
c906108c | 859 | |
c5aa993b | 860 | solib_add -- add a shared library file to the symtab and section list |
c906108c | 861 | |
c5aa993b | 862 | SYNOPSIS |
c906108c | 863 | |
c5aa993b | 864 | void solib_add (char *arg_string, int from_tty, |
990f9fe3 | 865 | struct target_ops *target, int readsyms) |
c906108c | 866 | |
c5aa993b | 867 | DESCRIPTION |
c906108c | 868 | |
c5aa993b | 869 | */ |
c906108c SS |
870 | |
871 | void | |
990f9fe3 | 872 | solib_add (char *arg_string, int from_tty, struct target_ops *target, int readsyms) |
c5aa993b JM |
873 | { |
874 | register struct so_list *so = NULL; /* link map state variable */ | |
c906108c SS |
875 | |
876 | /* Last shared library that we read. */ | |
877 | struct so_list *so_last = NULL; | |
878 | ||
879 | char *re_err; | |
880 | int count; | |
881 | int old; | |
c5aa993b | 882 | |
990f9fe3 FF |
883 | if (!readsyms) |
884 | return; | |
885 | ||
c906108c SS |
886 | if ((re_err = re_comp (arg_string ? arg_string : ".")) != NULL) |
887 | { | |
888 | error ("Invalid regexp: %s", re_err); | |
889 | } | |
c5aa993b | 890 | |
c906108c SS |
891 | /* Add the shared library sections to the section table of the |
892 | specified target, if any. */ | |
893 | if (target) | |
894 | { | |
895 | /* Count how many new section_table entries there are. */ | |
896 | so = NULL; | |
897 | count = 0; | |
898 | while ((so = find_solib (so)) != NULL) | |
899 | { | |
c5aa993b | 900 | if (so->so_name[0]) |
c906108c | 901 | { |
c5aa993b | 902 | count += so->sections_end - so->sections; |
c906108c SS |
903 | } |
904 | } | |
c5aa993b | 905 | |
c906108c SS |
906 | if (count) |
907 | { | |
6426a772 JM |
908 | old = target_resize_to_sections (target, count); |
909 | ||
c906108c SS |
910 | /* Add these section table entries to the target's table. */ |
911 | while ((so = find_solib (so)) != NULL) | |
912 | { | |
c5aa993b | 913 | if (so->so_name[0]) |
c906108c | 914 | { |
c5aa993b JM |
915 | count = so->sections_end - so->sections; |
916 | memcpy ((char *) (target->to_sections + old), | |
917 | so->sections, | |
c906108c SS |
918 | (sizeof (struct section_table)) * count); |
919 | old += count; | |
920 | } | |
921 | } | |
922 | } | |
923 | } | |
c5aa993b | 924 | |
c906108c SS |
925 | /* Now add the symbol files. */ |
926 | while ((so = find_solib (so)) != NULL) | |
927 | { | |
c5aa993b | 928 | if (so->so_name[0] && re_exec (so->so_name)) |
c906108c | 929 | { |
c5aa993b JM |
930 | so->from_tty = from_tty; |
931 | if (so->symbols_loaded) | |
c906108c SS |
932 | { |
933 | if (from_tty) | |
934 | { | |
c5aa993b | 935 | printf_unfiltered ("Symbols already loaded for %s\n", so->so_name); |
c906108c SS |
936 | } |
937 | } | |
938 | else if (catch_errors | |
939 | (symbol_add_stub, (char *) so, | |
940 | "Error while reading shared library symbols:\n", | |
941 | RETURN_MASK_ALL)) | |
942 | { | |
943 | so_last = so; | |
c5aa993b | 944 | so->symbols_loaded = 1; |
c906108c SS |
945 | } |
946 | } | |
947 | } | |
948 | ||
949 | /* Getting new symbols may change our opinion about what is | |
950 | frameless. */ | |
951 | if (so_last) | |
952 | reinit_frame_cache (); | |
953 | } | |
954 | ||
955 | /* | |
956 | ||
c5aa993b | 957 | LOCAL FUNCTION |
c906108c | 958 | |
c5aa993b | 959 | info_sharedlibrary_command -- code for "info sharedlibrary" |
c906108c | 960 | |
c5aa993b | 961 | SYNOPSIS |
c906108c | 962 | |
c5aa993b | 963 | static void info_sharedlibrary_command () |
c906108c | 964 | |
c5aa993b | 965 | DESCRIPTION |
c906108c | 966 | |
c5aa993b JM |
967 | Walk through the shared library list and print information |
968 | about each attached library. | |
969 | */ | |
c906108c SS |
970 | |
971 | static void | |
fba45db2 | 972 | info_sharedlibrary_command (char *ignore, int from_tty) |
c906108c | 973 | { |
c5aa993b | 974 | register struct so_list *so = NULL; /* link map state variable */ |
c906108c | 975 | int header_done = 0; |
c5aa993b | 976 | |
c906108c SS |
977 | if (exec_bfd == NULL) |
978 | { | |
4ce44c66 | 979 | printf_unfiltered ("No executable file.\n"); |
c906108c SS |
980 | return; |
981 | } | |
982 | while ((so = find_solib (so)) != NULL) | |
983 | { | |
c5aa993b | 984 | if (so->so_name[0]) |
c906108c SS |
985 | { |
986 | if (!header_done) | |
987 | { | |
c5aa993b JM |
988 | printf_unfiltered ("%-12s%-12s%-12s%s\n", "From", "To", "Syms Read", |
989 | "Shared Object Library"); | |
c906108c SS |
990 | header_done++; |
991 | } | |
992 | printf_unfiltered ("%-12s", | |
c5aa993b JM |
993 | local_hex_string_custom ((unsigned long) LM_ADDR (so), |
994 | "08l")); | |
c906108c | 995 | printf_unfiltered ("%-12s", |
c5aa993b JM |
996 | local_hex_string_custom ((unsigned long) so->lmend, |
997 | "08l")); | |
998 | printf_unfiltered ("%-12s", so->symbols_loaded ? "Yes" : "No"); | |
999 | printf_unfiltered ("%s\n", so->so_name); | |
c906108c SS |
1000 | } |
1001 | } | |
1002 | if (so_list_head == NULL) | |
1003 | { | |
c5aa993b | 1004 | printf_unfiltered ("No shared libraries loaded at this time.\n"); |
c906108c SS |
1005 | } |
1006 | } | |
1007 | ||
1008 | /* | |
1009 | ||
c5aa993b | 1010 | GLOBAL FUNCTION |
c906108c | 1011 | |
c5aa993b | 1012 | solib_address -- check to see if an address is in a shared lib |
c906108c | 1013 | |
c5aa993b | 1014 | SYNOPSIS |
c906108c | 1015 | |
c5aa993b | 1016 | char *solib_address (CORE_ADDR address) |
c906108c | 1017 | |
c5aa993b | 1018 | DESCRIPTION |
c906108c | 1019 | |
c5aa993b JM |
1020 | Provides a hook for other gdb routines to discover whether or |
1021 | not a particular address is within the mapped address space of | |
1022 | a shared library. Any address between the base mapping address | |
1023 | and the first address beyond the end of the last mapping, is | |
1024 | considered to be within the shared library address space, for | |
1025 | our purposes. | |
c906108c | 1026 | |
c5aa993b JM |
1027 | For example, this routine is called at one point to disable |
1028 | breakpoints which are in shared libraries that are not currently | |
1029 | mapped in. | |
c906108c SS |
1030 | */ |
1031 | ||
1032 | char * | |
fba45db2 | 1033 | solib_address (CORE_ADDR address) |
c906108c | 1034 | { |
c5aa993b JM |
1035 | register struct so_list *so = 0; /* link map state variable */ |
1036 | ||
c906108c SS |
1037 | while ((so = find_solib (so)) != NULL) |
1038 | { | |
c5aa993b | 1039 | if (so->so_name[0]) |
c906108c SS |
1040 | { |
1041 | if ((address >= (CORE_ADDR) LM_ADDR (so)) && | |
c5aa993b | 1042 | (address < (CORE_ADDR) so->lmend)) |
c906108c SS |
1043 | return (so->so_name); |
1044 | } | |
1045 | } | |
1046 | return (0); | |
1047 | } | |
1048 | ||
1049 | /* Called by free_all_symtabs */ | |
1050 | ||
c5aa993b | 1051 | void |
fba45db2 | 1052 | clear_solib (void) |
c906108c SS |
1053 | { |
1054 | struct so_list *next; | |
1055 | char *bfd_filename; | |
c5aa993b | 1056 | |
c906108c SS |
1057 | disable_breakpoints_in_shlibs (1); |
1058 | ||
1059 | while (so_list_head) | |
1060 | { | |
c5aa993b | 1061 | if (so_list_head->sections) |
c906108c | 1062 | { |
b8c9b27d | 1063 | xfree (so_list_head->sections); |
c906108c | 1064 | } |
c5aa993b | 1065 | if (so_list_head->abfd) |
c906108c | 1066 | { |
2069d78d | 1067 | remove_target_sections (so_list_head->abfd); |
c5aa993b JM |
1068 | bfd_filename = bfd_get_filename (so_list_head->abfd); |
1069 | if (!bfd_close (so_list_head->abfd)) | |
c906108c SS |
1070 | warning ("cannot close \"%s\": %s", |
1071 | bfd_filename, bfd_errmsg (bfd_get_error ())); | |
1072 | } | |
1073 | else | |
1074 | /* This happens for the executable on SVR4. */ | |
1075 | bfd_filename = NULL; | |
1076 | ||
c5aa993b | 1077 | next = so_list_head->next; |
c906108c | 1078 | if (bfd_filename) |
b8c9b27d KB |
1079 | xfree (bfd_filename); |
1080 | xfree (so_list_head->so_name); | |
1081 | xfree (so_list_head); | |
c906108c SS |
1082 | so_list_head = next; |
1083 | } | |
1084 | debug_base = 0; | |
1085 | } | |
1086 | ||
1087 | /* | |
1088 | ||
c5aa993b | 1089 | LOCAL FUNCTION |
c906108c | 1090 | |
c5aa993b | 1091 | disable_break -- remove the "mapping changed" breakpoint |
c906108c | 1092 | |
c5aa993b | 1093 | SYNOPSIS |
c906108c | 1094 | |
c5aa993b | 1095 | static int disable_break () |
c906108c | 1096 | |
c5aa993b | 1097 | DESCRIPTION |
c906108c | 1098 | |
c5aa993b JM |
1099 | Removes the breakpoint that gets hit when the dynamic linker |
1100 | completes a mapping change. | |
c906108c | 1101 | |
c5aa993b | 1102 | */ |
c906108c SS |
1103 | |
1104 | static int | |
fba45db2 | 1105 | disable_break (void) |
c906108c SS |
1106 | { |
1107 | int status = 1; | |
1108 | ||
1109 | ||
1110 | /* Note that breakpoint address and original contents are in our address | |
1111 | space, so we just need to write the original contents back. */ | |
1112 | ||
1113 | if (memory_remove_breakpoint (breakpoint_addr, shadow_contents) != 0) | |
1114 | { | |
1115 | status = 0; | |
1116 | } | |
1117 | ||
1118 | /* For the SVR4 version, we always know the breakpoint address. For the | |
1119 | SunOS version we don't know it until the above code is executed. | |
1120 | Grumble if we are stopped anywhere besides the breakpoint address. */ | |
1121 | ||
1122 | if (stop_pc != breakpoint_addr) | |
1123 | { | |
1124 | warning ("stopped at unknown breakpoint while handling shared libraries"); | |
1125 | } | |
1126 | ||
1127 | return (status); | |
1128 | } | |
1129 | ||
1130 | /* | |
1131 | ||
c5aa993b | 1132 | LOCAL FUNCTION |
c906108c | 1133 | |
c5aa993b | 1134 | enable_break -- arrange for dynamic linker to hit breakpoint |
c906108c | 1135 | |
c5aa993b | 1136 | SYNOPSIS |
c906108c | 1137 | |
c5aa993b | 1138 | int enable_break (void) |
c906108c | 1139 | |
c5aa993b | 1140 | DESCRIPTION |
c906108c | 1141 | |
c5aa993b JM |
1142 | This functions inserts a breakpoint at the entry point of the |
1143 | main executable, where all shared libraries are mapped in. | |
1144 | */ | |
c906108c SS |
1145 | |
1146 | static int | |
fba45db2 | 1147 | enable_break (void) |
c906108c SS |
1148 | { |
1149 | if (symfile_objfile != NULL | |
1150 | && target_insert_breakpoint (symfile_objfile->ei.entry_point, | |
1151 | shadow_contents) == 0) | |
1152 | { | |
1153 | breakpoint_addr = symfile_objfile->ei.entry_point; | |
1154 | return 1; | |
1155 | } | |
1156 | ||
1157 | return 0; | |
1158 | } | |
c5aa993b | 1159 | |
c906108c | 1160 | /* |
c5aa993b JM |
1161 | |
1162 | GLOBAL FUNCTION | |
1163 | ||
1164 | solib_create_inferior_hook -- shared library startup support | |
1165 | ||
1166 | SYNOPSIS | |
1167 | ||
1168 | void solib_create_inferior_hook() | |
1169 | ||
1170 | DESCRIPTION | |
1171 | ||
1172 | When gdb starts up the inferior, it nurses it along (through the | |
1173 | shell) until it is ready to execute it's first instruction. At this | |
1174 | point, this function gets called via expansion of the macro | |
1175 | SOLIB_CREATE_INFERIOR_HOOK. | |
1176 | ||
1177 | For SunOS executables, this first instruction is typically the | |
1178 | one at "_start", or a similar text label, regardless of whether | |
1179 | the executable is statically or dynamically linked. The runtime | |
1180 | startup code takes care of dynamically linking in any shared | |
1181 | libraries, once gdb allows the inferior to continue. | |
1182 | ||
1183 | For SVR4 executables, this first instruction is either the first | |
1184 | instruction in the dynamic linker (for dynamically linked | |
1185 | executables) or the instruction at "start" for statically linked | |
1186 | executables. For dynamically linked executables, the system | |
1187 | first exec's /lib/libc.so.N, which contains the dynamic linker, | |
1188 | and starts it running. The dynamic linker maps in any needed | |
1189 | shared libraries, maps in the actual user executable, and then | |
1190 | jumps to "start" in the user executable. | |
1191 | ||
1192 | For both SunOS shared libraries, and SVR4 shared libraries, we | |
1193 | can arrange to cooperate with the dynamic linker to discover the | |
1194 | names of shared libraries that are dynamically linked, and the | |
1195 | base addresses to which they are linked. | |
1196 | ||
1197 | This function is responsible for discovering those names and | |
1198 | addresses, and saving sufficient information about them to allow | |
1199 | their symbols to be read at a later time. | |
1200 | ||
1201 | FIXME | |
1202 | ||
1203 | Between enable_break() and disable_break(), this code does not | |
1204 | properly handle hitting breakpoints which the user might have | |
1205 | set in the startup code or in the dynamic linker itself. Proper | |
1206 | handling will probably have to wait until the implementation is | |
1207 | changed to use the "breakpoint handler function" method. | |
1208 | ||
1209 | Also, what if child has exit()ed? Must exit loop somehow. | |
1210 | */ | |
1211 | ||
1212 | void | |
fba45db2 | 1213 | solib_create_inferior_hook (void) |
c906108c SS |
1214 | { |
1215 | if (!enable_break ()) | |
1216 | { | |
1217 | warning ("shared library handler failed to enable breakpoint"); | |
1218 | return; | |
1219 | } | |
1220 | ||
1221 | /* Now run the target. It will eventually hit the breakpoint, at | |
1222 | which point all of the libraries will have been mapped in and we | |
1223 | can go groveling around in the dynamic linker structures to find | |
1224 | out what we need to know about them. */ | |
1225 | ||
1226 | clear_proceed_status (); | |
1227 | stop_soon_quietly = 1; | |
1228 | stop_signal = TARGET_SIGNAL_0; | |
1229 | do | |
1230 | { | |
39f77062 | 1231 | target_resume (pid_to_ptid (-1), 0, stop_signal); |
c906108c SS |
1232 | wait_for_inferior (); |
1233 | } | |
1234 | while (stop_signal != TARGET_SIGNAL_TRAP); | |
c5aa993b | 1235 | |
c906108c SS |
1236 | /* We are now either at the "mapping complete" breakpoint (or somewhere |
1237 | else, a condition we aren't prepared to deal with anyway), so adjust | |
1238 | the PC as necessary after a breakpoint, disable the breakpoint, and | |
1239 | add any shared libraries that were mapped in. */ | |
1240 | ||
1241 | if (DECR_PC_AFTER_BREAK) | |
1242 | { | |
1243 | stop_pc -= DECR_PC_AFTER_BREAK; | |
1244 | write_register (PC_REGNUM, stop_pc); | |
1245 | } | |
1246 | ||
1247 | if (!disable_break ()) | |
1248 | { | |
1249 | warning ("shared library handler failed to disable breakpoint"); | |
1250 | } | |
1251 | ||
1252 | /* solib_add will call reinit_frame_cache. | |
c5aa993b JM |
1253 | But we are stopped in the startup code and we might not have symbols |
1254 | for the startup code, so heuristic_proc_start could be called | |
1255 | and will put out an annoying warning. | |
1256 | Delaying the resetting of stop_soon_quietly until after symbol loading | |
1257 | suppresses the warning. */ | |
990f9fe3 | 1258 | solib_add ((char *) 0, 0, (struct target_ops *) 0, auto_solib_add); |
c906108c SS |
1259 | stop_soon_quietly = 0; |
1260 | } | |
1261 | ||
1262 | /* | |
1263 | ||
c5aa993b | 1264 | LOCAL FUNCTION |
c906108c | 1265 | |
c5aa993b | 1266 | sharedlibrary_command -- handle command to explicitly add library |
c906108c | 1267 | |
c5aa993b | 1268 | SYNOPSIS |
c906108c | 1269 | |
c5aa993b | 1270 | static void sharedlibrary_command (char *args, int from_tty) |
c906108c | 1271 | |
c5aa993b | 1272 | DESCRIPTION |
c906108c | 1273 | |
c5aa993b | 1274 | */ |
c906108c SS |
1275 | |
1276 | static void | |
fba45db2 | 1277 | sharedlibrary_command (char *args, int from_tty) |
c906108c SS |
1278 | { |
1279 | dont_repeat (); | |
990f9fe3 | 1280 | solib_add (args, from_tty, (struct target_ops *) 0, 1); |
c906108c SS |
1281 | } |
1282 | ||
1283 | void | |
fba45db2 | 1284 | _initialize_solib (void) |
c906108c SS |
1285 | { |
1286 | add_com ("sharedlibrary", class_files, sharedlibrary_command, | |
1287 | "Load shared object library symbols for files matching REGEXP."); | |
c5aa993b | 1288 | add_info ("sharedlibrary", info_sharedlibrary_command, |
c906108c SS |
1289 | "Status of loaded shared object libraries."); |
1290 | ||
1291 | add_show_from_set | |
b7209cb4 | 1292 | (add_set_cmd ("auto-solib-add", class_support, var_boolean, |
c906108c SS |
1293 | (char *) &auto_solib_add, |
1294 | "Set autoloading of shared library symbols.\n\ | |
b7209cb4 FF |
1295 | If \"on\", symbols from all shared object libraries will be loaded\n\ |
1296 | automatically when the inferior begins execution, when the dynamic linker\n\ | |
1297 | informs gdb that a new library has been loaded, or when attaching to the\n\ | |
1298 | inferior. Otherwise, symbols must be loaded manually, using `sharedlibrary'.", | |
c906108c SS |
1299 | &setlist), |
1300 | &showlist); | |
1301 | } | |
c906108c | 1302 | \f |
c5aa993b | 1303 | |
c906108c SS |
1304 | /* Register that we are able to handle irix5 core file formats. |
1305 | This really is bfd_target_unknown_flavour */ | |
1306 | ||
1307 | static struct core_fns irix5_core_fns = | |
1308 | { | |
2acceee2 JM |
1309 | bfd_target_unknown_flavour, /* core_flavour */ |
1310 | default_check_format, /* check_format */ | |
1311 | default_core_sniffer, /* core_sniffer */ | |
1312 | fetch_core_registers, /* core_read_registers */ | |
1313 | NULL /* next */ | |
c906108c SS |
1314 | }; |
1315 | ||
1316 | void | |
fba45db2 | 1317 | _initialize_core_irix5 (void) |
c906108c SS |
1318 | { |
1319 | add_core_fns (&irix5_core_fns); | |
1320 | } |