Commit | Line | Data |
---|---|---|
dabbe2c0 | 1 | /* Shared library support for IRIX. |
0b302171 JB |
2 | Copyright (C) 1993-1996, 1998-2002, 2004, 2007-2012 Free Software |
3 | Foundation, Inc. | |
dabbe2c0 KB |
4 | |
5 | This file was created using portions of irix5-nat.c originally | |
6 | contributed to GDB by Ian Lance Taylor. | |
7 | ||
8 | This file is part of GDB. | |
9 | ||
10 | This program is free software; you can redistribute it and/or modify | |
11 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 12 | the Free Software Foundation; either version 3 of the License, or |
dabbe2c0 KB |
13 | (at your option) any later version. |
14 | ||
15 | This program is distributed in the hope that it will be useful, | |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | GNU General Public License for more details. | |
19 | ||
20 | You should have received a copy of the GNU General Public License | |
a9762ec7 | 21 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
dabbe2c0 KB |
22 | |
23 | #include "defs.h" | |
24 | ||
25 | #include "symtab.h" | |
26 | #include "bfd.h" | |
9ab9195f EZ |
27 | /* FIXME: ezannoni/2004-02-13 Verify that the include below is |
28 | really needed. */ | |
dabbe2c0 KB |
29 | #include "symfile.h" |
30 | #include "objfiles.h" | |
31 | #include "gdbcore.h" | |
32 | #include "target.h" | |
33 | #include "inferior.h" | |
2020b7ab | 34 | #include "gdbthread.h" |
dabbe2c0 KB |
35 | |
36 | #include "solist.h" | |
734598d9 UW |
37 | #include "solib.h" |
38 | #include "solib-irix.h" | |
39 | ||
dabbe2c0 KB |
40 | |
41 | /* Link map info to include in an allocate so_list entry. Unlike some | |
42 | of the other solib backends, this (Irix) backend chooses to decode | |
43 | the link map info obtained from the target and store it as (mostly) | |
44 | CORE_ADDRs which need no further decoding. This is more convenient | |
45 | because there are three different link map formats to worry about. | |
46 | We use a single routine (fetch_lm_info) to read (and decode) the target | |
47 | specific link map data. */ | |
48 | ||
49 | struct lm_info | |
50 | { | |
51 | CORE_ADDR addr; /* address of obj_info or obj_list | |
52 | struct on target (from which the | |
53 | following information is obtained). */ | |
54 | CORE_ADDR next; /* address of next item in list. */ | |
55 | CORE_ADDR reloc_offset; /* amount to relocate by */ | |
56 | CORE_ADDR pathname_addr; /* address of pathname */ | |
57 | int pathname_len; /* length of pathname */ | |
58 | }; | |
59 | ||
60 | /* It's not desirable to use the system header files to obtain the | |
61 | structure of the obj_list or obj_info structs. Therefore, we use a | |
62 | platform neutral representation which has been derived from the IRIX | |
63 | header files. */ | |
64 | ||
65 | typedef struct | |
66 | { | |
725a826f | 67 | gdb_byte b[4]; |
dabbe2c0 KB |
68 | } |
69 | gdb_int32_bytes; | |
70 | typedef struct | |
71 | { | |
725a826f | 72 | gdb_byte b[8]; |
dabbe2c0 KB |
73 | } |
74 | gdb_int64_bytes; | |
75 | ||
76 | /* The "old" obj_list struct. This is used with old (o32) binaries. | |
77 | The ``data'' member points at a much larger and more complicated | |
78 | struct which we will only refer to by offsets. See | |
79 | fetch_lm_info(). */ | |
80 | ||
81 | struct irix_obj_list | |
82 | { | |
83 | gdb_int32_bytes data; | |
84 | gdb_int32_bytes next; | |
85 | gdb_int32_bytes prev; | |
86 | }; | |
87 | ||
88 | /* The ELF32 and ELF64 versions of the above struct. The oi_magic value | |
89 | corresponds to the ``data'' value in the "old" struct. When this value | |
90 | is 0xffffffff, the data will be in one of the following formats. The | |
91 | ``oi_size'' field is used to decide which one we actually have. */ | |
92 | ||
93 | struct irix_elf32_obj_info | |
94 | { | |
95 | gdb_int32_bytes oi_magic; | |
96 | gdb_int32_bytes oi_size; | |
97 | gdb_int32_bytes oi_next; | |
98 | gdb_int32_bytes oi_prev; | |
99 | gdb_int32_bytes oi_ehdr; | |
100 | gdb_int32_bytes oi_orig_ehdr; | |
101 | gdb_int32_bytes oi_pathname; | |
102 | gdb_int32_bytes oi_pathname_len; | |
103 | }; | |
104 | ||
105 | struct irix_elf64_obj_info | |
106 | { | |
107 | gdb_int32_bytes oi_magic; | |
108 | gdb_int32_bytes oi_size; | |
109 | gdb_int64_bytes oi_next; | |
110 | gdb_int64_bytes oi_prev; | |
111 | gdb_int64_bytes oi_ehdr; | |
112 | gdb_int64_bytes oi_orig_ehdr; | |
113 | gdb_int64_bytes oi_pathname; | |
114 | gdb_int32_bytes oi_pathname_len; | |
115 | gdb_int32_bytes padding; | |
116 | }; | |
117 | ||
118 | /* Union of all of the above (plus a split out magic field). */ | |
119 | ||
120 | union irix_obj_info | |
121 | { | |
122 | gdb_int32_bytes magic; | |
123 | struct irix_obj_list ol32; | |
124 | struct irix_elf32_obj_info oi32; | |
125 | struct irix_elf64_obj_info oi64; | |
126 | }; | |
127 | ||
128 | /* MIPS sign extends its 32 bit addresses. We could conceivably use | |
129 | extract_typed_address here, but to do so, we'd have to construct an | |
ae0167b9 | 130 | appropriate type. Calling extract_signed_integer seems simpler. */ |
dabbe2c0 KB |
131 | |
132 | static CORE_ADDR | |
e17a4113 | 133 | extract_mips_address (void *addr, int len, enum bfd_endian byte_order) |
dabbe2c0 | 134 | { |
e17a4113 | 135 | return extract_signed_integer (addr, len, byte_order); |
dabbe2c0 KB |
136 | } |
137 | ||
138 | /* Fetch and return the link map data associated with ADDR. Note that | |
139 | this routine automatically determines which (of three) link map | |
140 | formats is in use by the target. */ | |
141 | ||
63807e1d | 142 | static struct lm_info |
dabbe2c0 KB |
143 | fetch_lm_info (CORE_ADDR addr) |
144 | { | |
e17a4113 | 145 | enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch); |
dabbe2c0 KB |
146 | struct lm_info li; |
147 | union irix_obj_info buf; | |
148 | ||
149 | li.addr = addr; | |
150 | ||
151 | /* The smallest region that we'll need is for buf.ol32. We'll read | |
152 | that first. We'll read more of the buffer later if we have to deal | |
153 | with one of the other cases. (We don't want to incur a memory error | |
154 | if we were to read a larger region that generates an error due to | |
155 | being at the end of a page or the like.) */ | |
156 | read_memory (addr, (char *) &buf, sizeof (buf.ol32)); | |
157 | ||
e17a4113 UW |
158 | if (extract_unsigned_integer (buf.magic.b, sizeof (buf.magic), byte_order) |
159 | != 0xffffffff) | |
dabbe2c0 | 160 | { |
c378eb4e | 161 | /* Use buf.ol32... */ |
dabbe2c0 KB |
162 | char obj_buf[432]; |
163 | CORE_ADDR obj_addr = extract_mips_address (&buf.ol32.data, | |
e17a4113 UW |
164 | sizeof (buf.ol32.data), |
165 | byte_order); | |
433759f7 | 166 | |
e17a4113 UW |
167 | li.next = extract_mips_address (&buf.ol32.next, |
168 | sizeof (buf.ol32.next), byte_order); | |
dabbe2c0 KB |
169 | |
170 | read_memory (obj_addr, obj_buf, sizeof (obj_buf)); | |
171 | ||
e17a4113 | 172 | li.pathname_addr = extract_mips_address (&obj_buf[236], 4, byte_order); |
dabbe2c0 | 173 | li.pathname_len = 0; /* unknown */ |
e17a4113 UW |
174 | li.reloc_offset = extract_mips_address (&obj_buf[196], 4, byte_order) |
175 | - extract_mips_address (&obj_buf[248], 4, byte_order); | |
dabbe2c0 KB |
176 | |
177 | } | |
725a826f | 178 | else if (extract_unsigned_integer (buf.oi32.oi_size.b, |
e17a4113 | 179 | sizeof (buf.oi32.oi_size), byte_order) |
dabbe2c0 KB |
180 | == sizeof (buf.oi32)) |
181 | { | |
182 | /* Use buf.oi32... */ | |
183 | ||
184 | /* Read rest of buffer. */ | |
185 | read_memory (addr + sizeof (buf.ol32), | |
186 | ((char *) &buf) + sizeof (buf.ol32), | |
187 | sizeof (buf.oi32) - sizeof (buf.ol32)); | |
188 | ||
189 | /* Fill in fields using buffer contents. */ | |
190 | li.next = extract_mips_address (&buf.oi32.oi_next, | |
e17a4113 | 191 | sizeof (buf.oi32.oi_next), byte_order); |
dabbe2c0 | 192 | li.reloc_offset = extract_mips_address (&buf.oi32.oi_ehdr, |
e17a4113 UW |
193 | sizeof (buf.oi32.oi_ehdr), |
194 | byte_order) | |
dabbe2c0 | 195 | - extract_mips_address (&buf.oi32.oi_orig_ehdr, |
e17a4113 | 196 | sizeof (buf.oi32.oi_orig_ehdr), byte_order); |
dabbe2c0 | 197 | li.pathname_addr = extract_mips_address (&buf.oi32.oi_pathname, |
e17a4113 UW |
198 | sizeof (buf.oi32.oi_pathname), |
199 | byte_order); | |
725a826f | 200 | li.pathname_len = extract_unsigned_integer (buf.oi32.oi_pathname_len.b, |
dabbe2c0 | 201 | sizeof (buf.oi32. |
e17a4113 UW |
202 | oi_pathname_len), |
203 | byte_order); | |
dabbe2c0 | 204 | } |
725a826f | 205 | else if (extract_unsigned_integer (buf.oi64.oi_size.b, |
e17a4113 | 206 | sizeof (buf.oi64.oi_size), byte_order) |
dabbe2c0 KB |
207 | == sizeof (buf.oi64)) |
208 | { | |
209 | /* Use buf.oi64... */ | |
210 | ||
211 | /* Read rest of buffer. */ | |
212 | read_memory (addr + sizeof (buf.ol32), | |
213 | ((char *) &buf) + sizeof (buf.ol32), | |
214 | sizeof (buf.oi64) - sizeof (buf.ol32)); | |
215 | ||
216 | /* Fill in fields using buffer contents. */ | |
217 | li.next = extract_mips_address (&buf.oi64.oi_next, | |
e17a4113 | 218 | sizeof (buf.oi64.oi_next), byte_order); |
dabbe2c0 | 219 | li.reloc_offset = extract_mips_address (&buf.oi64.oi_ehdr, |
e17a4113 UW |
220 | sizeof (buf.oi64.oi_ehdr), |
221 | byte_order) | |
dabbe2c0 | 222 | - extract_mips_address (&buf.oi64.oi_orig_ehdr, |
e17a4113 | 223 | sizeof (buf.oi64.oi_orig_ehdr), byte_order); |
dabbe2c0 | 224 | li.pathname_addr = extract_mips_address (&buf.oi64.oi_pathname, |
e17a4113 UW |
225 | sizeof (buf.oi64.oi_pathname), |
226 | byte_order); | |
725a826f | 227 | li.pathname_len = extract_unsigned_integer (buf.oi64.oi_pathname_len.b, |
dabbe2c0 | 228 | sizeof (buf.oi64. |
e17a4113 UW |
229 | oi_pathname_len), |
230 | byte_order); | |
dabbe2c0 KB |
231 | } |
232 | else | |
233 | { | |
8a3fe4f8 | 234 | error (_("Unable to fetch shared library obj_info or obj_list info.")); |
dabbe2c0 KB |
235 | } |
236 | ||
237 | return li; | |
238 | } | |
239 | ||
240 | /* The symbol which starts off the list of shared libraries. */ | |
241 | #define DEBUG_BASE "__rld_obj_head" | |
242 | ||
8181d85f | 243 | static void *base_breakpoint; |
dabbe2c0 | 244 | |
c378eb4e | 245 | static CORE_ADDR debug_base; /* Base of dynamic linker structures. */ |
dabbe2c0 | 246 | |
7f86f058 | 247 | /* Locate the base address of dynamic linker structs. |
dabbe2c0 KB |
248 | |
249 | For both the SunOS and SVR4 shared library implementations, if the | |
250 | inferior executable has been linked dynamically, there is a single | |
251 | address somewhere in the inferior's data space which is the key to | |
252 | locating all of the dynamic linker's runtime structures. This | |
253 | address is the value of the symbol defined by the macro DEBUG_BASE. | |
254 | The job of this function is to find and return that address, or to | |
255 | return 0 if there is no such address (the executable is statically | |
256 | linked for example). | |
257 | ||
258 | For SunOS, the job is almost trivial, since the dynamic linker and | |
259 | all of it's structures are statically linked to the executable at | |
260 | link time. Thus the symbol for the address we are looking for has | |
261 | already been added to the minimal symbol table for the executable's | |
262 | objfile at the time the symbol file's symbols were read, and all we | |
263 | have to do is look it up there. Note that we explicitly do NOT want | |
264 | to find the copies in the shared library. | |
265 | ||
266 | The SVR4 version is much more complicated because the dynamic linker | |
267 | and it's structures are located in the shared C library, which gets | |
268 | run as the executable's "interpreter" by the kernel. We have to go | |
269 | to a lot more work to discover the address of DEBUG_BASE. Because | |
270 | of this complexity, we cache the value we find and return that value | |
271 | on subsequent invocations. Note there is no copy in the executable | |
272 | symbol tables. | |
273 | ||
274 | Irix 5 is basically like SunOS. | |
275 | ||
276 | Note that we can assume nothing about the process state at the time | |
277 | we need to find this address. We may be stopped on the first instruc- | |
278 | tion of the interpreter (C shared library), the first instruction of | |
279 | the executable itself, or somewhere else entirely (if we attached | |
7f86f058 | 280 | to the process for example). */ |
dabbe2c0 KB |
281 | |
282 | static CORE_ADDR | |
283 | locate_base (void) | |
284 | { | |
285 | struct minimal_symbol *msymbol; | |
286 | CORE_ADDR address = 0; | |
287 | ||
288 | msymbol = lookup_minimal_symbol (DEBUG_BASE, NULL, symfile_objfile); | |
289 | if ((msymbol != NULL) && (SYMBOL_VALUE_ADDRESS (msymbol) != 0)) | |
290 | { | |
291 | address = SYMBOL_VALUE_ADDRESS (msymbol); | |
292 | } | |
293 | return (address); | |
294 | } | |
295 | ||
7f86f058 | 296 | /* Remove the "mapping changed" breakpoint. |
dabbe2c0 KB |
297 | |
298 | Removes the breakpoint that gets hit when the dynamic linker | |
7f86f058 | 299 | completes a mapping change. */ |
dabbe2c0 KB |
300 | |
301 | static int | |
302 | disable_break (void) | |
303 | { | |
304 | int status = 1; | |
305 | ||
dabbe2c0 | 306 | /* Note that breakpoint address and original contents are in our address |
c378eb4e | 307 | space, so we just need to write the original contents back. */ |
dabbe2c0 | 308 | |
a6d9a66e | 309 | if (deprecated_remove_raw_breakpoint (target_gdbarch, base_breakpoint) != 0) |
dabbe2c0 KB |
310 | { |
311 | status = 0; | |
312 | } | |
313 | ||
8181d85f DJ |
314 | base_breakpoint = NULL; |
315 | ||
9185ddce JB |
316 | /* Note that it is possible that we have stopped at a location that |
317 | is different from the location where we inserted our breakpoint. | |
318 | On mips-irix, we can actually land in __dbx_init(), so we should | |
319 | not check the PC against our breakpoint address here. See procfs.c | |
320 | for more details. */ | |
dabbe2c0 KB |
321 | |
322 | return (status); | |
323 | } | |
324 | ||
7f86f058 | 325 | /* Arrange for dynamic linker to hit breakpoint. |
dabbe2c0 KB |
326 | |
327 | This functions inserts a breakpoint at the entry point of the | |
7f86f058 | 328 | main executable, where all shared libraries are mapped in. */ |
dabbe2c0 KB |
329 | |
330 | static int | |
331 | enable_break (void) | |
332 | { | |
6c95b8df | 333 | if (symfile_objfile != NULL && has_stack_frames ()) |
dabbe2c0 | 334 | { |
6c95b8df PA |
335 | struct frame_info *frame = get_current_frame (); |
336 | struct address_space *aspace = get_frame_address_space (frame); | |
abd0a5fa | 337 | CORE_ADDR entry_point; |
6c95b8df | 338 | |
abd0a5fa JK |
339 | if (!entry_point_address_query (&entry_point)) |
340 | return 0; | |
341 | ||
342 | base_breakpoint = deprecated_insert_raw_breakpoint (target_gdbarch, | |
343 | aspace, entry_point); | |
8181d85f DJ |
344 | |
345 | if (base_breakpoint != NULL) | |
346 | return 1; | |
dabbe2c0 KB |
347 | } |
348 | ||
349 | return 0; | |
350 | } | |
351 | ||
7f86f058 | 352 | /* Implement the "create_inferior_hook" target_solib_ops method. |
dabbe2c0 KB |
353 | |
354 | For SunOS executables, this first instruction is typically the | |
355 | one at "_start", or a similar text label, regardless of whether | |
356 | the executable is statically or dynamically linked. The runtime | |
357 | startup code takes care of dynamically linking in any shared | |
358 | libraries, once gdb allows the inferior to continue. | |
359 | ||
360 | For SVR4 executables, this first instruction is either the first | |
361 | instruction in the dynamic linker (for dynamically linked | |
362 | executables) or the instruction at "start" for statically linked | |
363 | executables. For dynamically linked executables, the system | |
364 | first exec's /lib/libc.so.N, which contains the dynamic linker, | |
365 | and starts it running. The dynamic linker maps in any needed | |
366 | shared libraries, maps in the actual user executable, and then | |
367 | jumps to "start" in the user executable. | |
368 | ||
369 | For both SunOS shared libraries, and SVR4 shared libraries, we | |
370 | can arrange to cooperate with the dynamic linker to discover the | |
371 | names of shared libraries that are dynamically linked, and the | |
372 | base addresses to which they are linked. | |
373 | ||
374 | This function is responsible for discovering those names and | |
375 | addresses, and saving sufficient information about them to allow | |
376 | their symbols to be read at a later time. | |
377 | ||
378 | FIXME | |
379 | ||
380 | Between enable_break() and disable_break(), this code does not | |
381 | properly handle hitting breakpoints which the user might have | |
382 | set in the startup code or in the dynamic linker itself. Proper | |
383 | handling will probably have to wait until the implementation is | |
384 | changed to use the "breakpoint handler function" method. | |
385 | ||
7f86f058 | 386 | Also, what if child has exit()ed? Must exit loop somehow. */ |
dabbe2c0 KB |
387 | |
388 | static void | |
268a4a75 | 389 | irix_solib_create_inferior_hook (int from_tty) |
dabbe2c0 | 390 | { |
d6b48e9c | 391 | struct inferior *inf; |
2020b7ab PA |
392 | struct thread_info *tp; |
393 | ||
b2391021 JB |
394 | inf = current_inferior (); |
395 | ||
396 | /* If we are attaching to the inferior, the shared libraries | |
397 | have already been mapped, so nothing more to do. */ | |
398 | if (inf->attach_flag) | |
399 | return; | |
400 | ||
11377e68 JB |
401 | /* Likewise when debugging from a core file, the shared libraries |
402 | have already been mapped, so nothing more to do. */ | |
403 | if (!target_can_run (¤t_target)) | |
404 | return; | |
405 | ||
dabbe2c0 KB |
406 | if (!enable_break ()) |
407 | { | |
8a3fe4f8 | 408 | warning (_("shared library handler failed to enable breakpoint")); |
dabbe2c0 KB |
409 | return; |
410 | } | |
411 | ||
412 | /* Now run the target. It will eventually hit the breakpoint, at | |
413 | which point all of the libraries will have been mapped in and we | |
414 | can go groveling around in the dynamic linker structures to find | |
c378eb4e | 415 | out what we need to know about them. */ |
dabbe2c0 | 416 | |
2020b7ab | 417 | tp = inferior_thread (); |
d6b48e9c | 418 | |
dabbe2c0 | 419 | clear_proceed_status (); |
d6b48e9c | 420 | |
16c381f0 JK |
421 | inf->control.stop_soon = STOP_QUIETLY; |
422 | tp->suspend.stop_signal = TARGET_SIGNAL_0; | |
d6b48e9c | 423 | |
dabbe2c0 KB |
424 | do |
425 | { | |
16c381f0 | 426 | target_resume (pid_to_ptid (-1), 0, tp->suspend.stop_signal); |
e4c8541f | 427 | wait_for_inferior (); |
dabbe2c0 | 428 | } |
16c381f0 | 429 | while (tp->suspend.stop_signal != TARGET_SIGNAL_TRAP); |
dabbe2c0 KB |
430 | |
431 | /* We are now either at the "mapping complete" breakpoint (or somewhere | |
432 | else, a condition we aren't prepared to deal with anyway), so adjust | |
433 | the PC as necessary after a breakpoint, disable the breakpoint, and | |
c378eb4e | 434 | add any shared libraries that were mapped in. */ |
dabbe2c0 KB |
435 | |
436 | if (!disable_break ()) | |
437 | { | |
8a3fe4f8 | 438 | warning (_("shared library handler failed to disable breakpoint")); |
dabbe2c0 KB |
439 | } |
440 | ||
441 | /* solib_add will call reinit_frame_cache. | |
442 | But we are stopped in the startup code and we might not have symbols | |
443 | for the startup code, so heuristic_proc_start could be called | |
444 | and will put out an annoying warning. | |
c0236d92 | 445 | Delaying the resetting of stop_soon until after symbol loading |
dabbe2c0 KB |
446 | suppresses the warning. */ |
447 | solib_add ((char *) 0, 0, (struct target_ops *) 0, auto_solib_add); | |
16c381f0 | 448 | inf->control.stop_soon = NO_STOP_QUIETLY; |
dabbe2c0 KB |
449 | } |
450 | ||
7f86f058 | 451 | /* Implement the "current_sos" target_so_ops method. */ |
dabbe2c0 KB |
452 | |
453 | static struct so_list * | |
454 | irix_current_sos (void) | |
455 | { | |
e17a4113 UW |
456 | enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch); |
457 | int addr_size = gdbarch_addr_bit (target_gdbarch) / TARGET_CHAR_BIT; | |
dabbe2c0 KB |
458 | CORE_ADDR lma; |
459 | char addr_buf[8]; | |
460 | struct so_list *head = 0; | |
461 | struct so_list **link_ptr = &head; | |
462 | int is_first = 1; | |
463 | struct lm_info lm; | |
464 | ||
465 | /* Make sure we've looked up the inferior's dynamic linker's base | |
466 | structure. */ | |
467 | if (!debug_base) | |
468 | { | |
469 | debug_base = locate_base (); | |
470 | ||
471 | /* If we can't find the dynamic linker's base structure, this | |
472 | must not be a dynamically linked executable. Hmm. */ | |
473 | if (!debug_base) | |
474 | return 0; | |
475 | } | |
476 | ||
e17a4113 UW |
477 | read_memory (debug_base, addr_buf, addr_size); |
478 | lma = extract_mips_address (addr_buf, addr_size, byte_order); | |
dabbe2c0 KB |
479 | |
480 | while (lma) | |
481 | { | |
482 | lm = fetch_lm_info (lma); | |
483 | if (!is_first) | |
484 | { | |
485 | int errcode; | |
486 | char *name_buf; | |
487 | int name_size; | |
488 | struct so_list *new | |
489 | = (struct so_list *) xmalloc (sizeof (struct so_list)); | |
490 | struct cleanup *old_chain = make_cleanup (xfree, new); | |
491 | ||
492 | memset (new, 0, sizeof (*new)); | |
493 | ||
494 | new->lm_info = xmalloc (sizeof (struct lm_info)); | |
495 | make_cleanup (xfree, new->lm_info); | |
496 | ||
497 | *new->lm_info = lm; | |
498 | ||
499 | /* Extract this shared object's name. */ | |
500 | name_size = lm.pathname_len; | |
501 | if (name_size == 0) | |
502 | name_size = SO_NAME_MAX_PATH_SIZE - 1; | |
503 | ||
504 | if (name_size >= SO_NAME_MAX_PATH_SIZE) | |
505 | { | |
506 | name_size = SO_NAME_MAX_PATH_SIZE - 1; | |
8f7e195f JB |
507 | warning (_("current_sos: truncating name of " |
508 | "%d characters to only %d characters"), | |
3e43a32a | 509 | lm.pathname_len, name_size); |
dabbe2c0 KB |
510 | } |
511 | ||
512 | target_read_string (lm.pathname_addr, &name_buf, | |
513 | name_size, &errcode); | |
514 | if (errcode != 0) | |
8a3fe4f8 | 515 | warning (_("Can't read pathname for load map: %s."), |
dabbe2c0 | 516 | safe_strerror (errcode)); |
dabbe2c0 KB |
517 | else |
518 | { | |
519 | strncpy (new->so_name, name_buf, name_size); | |
520 | new->so_name[name_size] = '\0'; | |
521 | xfree (name_buf); | |
522 | strcpy (new->so_original_name, new->so_name); | |
523 | } | |
524 | ||
525 | new->next = 0; | |
526 | *link_ptr = new; | |
527 | link_ptr = &new->next; | |
528 | ||
529 | discard_cleanups (old_chain); | |
530 | } | |
531 | is_first = 0; | |
532 | lma = lm.next; | |
533 | } | |
534 | ||
535 | return head; | |
536 | } | |
537 | ||
7f86f058 | 538 | /* Implement the "open_symbol_file_object" target_so_ops method. |
dabbe2c0 | 539 | |
7f86f058 PA |
540 | If no open symbol file, attempt to locate and open the main symbol |
541 | file. On IRIX, this is the first link map entry. If its name is | |
542 | here, we can open it. Useful when attaching to a process without | |
543 | first loading its symbol file. */ | |
dabbe2c0 KB |
544 | |
545 | static int | |
546 | irix_open_symbol_file_object (void *from_ttyp) | |
547 | { | |
e17a4113 UW |
548 | enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch); |
549 | int addr_size = gdbarch_addr_bit (target_gdbarch) / TARGET_CHAR_BIT; | |
dabbe2c0 KB |
550 | CORE_ADDR lma; |
551 | char addr_buf[8]; | |
552 | struct lm_info lm; | |
553 | struct cleanup *cleanups; | |
554 | int errcode; | |
555 | int from_tty = *(int *) from_ttyp; | |
556 | char *filename; | |
557 | ||
558 | if (symfile_objfile) | |
9e2f0ad4 | 559 | if (!query (_("Attempt to reload symbols from process? "))) |
dabbe2c0 KB |
560 | return 0; |
561 | ||
562 | if ((debug_base = locate_base ()) == 0) | |
563 | return 0; /* failed somehow... */ | |
564 | ||
565 | /* First link map member should be the executable. */ | |
e17a4113 UW |
566 | read_memory (debug_base, addr_buf, addr_size); |
567 | lma = extract_mips_address (addr_buf, addr_size, byte_order); | |
dabbe2c0 KB |
568 | if (lma == 0) |
569 | return 0; /* failed somehow... */ | |
570 | ||
571 | lm = fetch_lm_info (lma); | |
572 | ||
573 | if (lm.pathname_addr == 0) | |
574 | return 0; /* No filename. */ | |
575 | ||
576 | /* Now fetch the filename from target memory. */ | |
577 | target_read_string (lm.pathname_addr, &filename, SO_NAME_MAX_PATH_SIZE - 1, | |
578 | &errcode); | |
579 | ||
580 | if (errcode) | |
581 | { | |
8a3fe4f8 | 582 | warning (_("failed to read exec filename from attached file: %s"), |
dabbe2c0 KB |
583 | safe_strerror (errcode)); |
584 | return 0; | |
585 | } | |
586 | ||
587 | cleanups = make_cleanup (xfree, filename); | |
588 | /* Have a pathname: read the symbol file. */ | |
589 | symbol_file_add_main (filename, from_tty); | |
590 | ||
591 | do_cleanups (cleanups); | |
592 | ||
593 | return 1; | |
594 | } | |
595 | ||
7f86f058 | 596 | /* Implement the "special_symbol_handling" target_so_ops method. |
dabbe2c0 | 597 | |
7f86f058 | 598 | For IRIX, there's nothing to do. */ |
dabbe2c0 KB |
599 | |
600 | static void | |
601 | irix_special_symbol_handling (void) | |
602 | { | |
603 | } | |
604 | ||
605 | /* Using the solist entry SO, relocate the addresses in SEC. */ | |
606 | ||
607 | static void | |
608 | irix_relocate_section_addresses (struct so_list *so, | |
0542c86d | 609 | struct target_section *sec) |
dabbe2c0 KB |
610 | { |
611 | sec->addr += so->lm_info->reloc_offset; | |
612 | sec->endaddr += so->lm_info->reloc_offset; | |
613 | } | |
614 | ||
615 | /* Free the lm_info struct. */ | |
616 | ||
617 | static void | |
618 | irix_free_so (struct so_list *so) | |
619 | { | |
620 | xfree (so->lm_info); | |
621 | } | |
622 | ||
623 | /* Clear backend specific state. */ | |
624 | ||
625 | static void | |
626 | irix_clear_solib (void) | |
627 | { | |
628 | debug_base = 0; | |
629 | } | |
630 | ||
631 | /* Return 1 if PC lies in the dynamic symbol resolution code of the | |
632 | run time loader. */ | |
633 | static int | |
634 | irix_in_dynsym_resolve_code (CORE_ADDR pc) | |
635 | { | |
636 | return 0; | |
637 | } | |
638 | ||
734598d9 | 639 | struct target_so_ops irix_so_ops; |
dabbe2c0 | 640 | |
63807e1d PA |
641 | /* Provide a prototype to silence -Wmissing-prototypes. */ |
642 | extern initialize_file_ftype _initialize_irix_solib; | |
643 | ||
dabbe2c0 KB |
644 | void |
645 | _initialize_irix_solib (void) | |
646 | { | |
647 | irix_so_ops.relocate_section_addresses = irix_relocate_section_addresses; | |
648 | irix_so_ops.free_so = irix_free_so; | |
649 | irix_so_ops.clear_solib = irix_clear_solib; | |
650 | irix_so_ops.solib_create_inferior_hook = irix_solib_create_inferior_hook; | |
651 | irix_so_ops.special_symbol_handling = irix_special_symbol_handling; | |
652 | irix_so_ops.current_sos = irix_current_sos; | |
653 | irix_so_ops.open_symbol_file_object = irix_open_symbol_file_object; | |
654 | irix_so_ops.in_dynsym_resolve_code = irix_in_dynsym_resolve_code; | |
831a0c44 | 655 | irix_so_ops.bfd_open = solib_bfd_open; |
dabbe2c0 | 656 | } |