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