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