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