]>
Commit | Line | Data |
---|---|---|
419b8bfb RC |
1 | /* Handle PA64 shared libraries for GDB, the GNU Debugger. |
2 | ||
7b6bb8da JB |
3 | Copyright (C) 2004, 2007, 2008, 2009, 2010, 2011 |
4 | Free Software Foundation, Inc. | |
419b8bfb RC |
5 | |
6 | This file is part of GDB. | |
7 | ||
8 | This program is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 10 | the Free Software Foundation; either version 3 of the License, or |
419b8bfb RC |
11 | (at your option) any later version. |
12 | ||
13 | This program is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
a9762ec7 | 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
419b8bfb RC |
20 | |
21 | HP in their infinite stupidity choose not to use standard ELF dynamic | |
22 | linker interfaces. They also choose not to make their ELF dymamic | |
23 | linker interfaces compatible with the SOM dynamic linker. The | |
24 | net result is we can not use either of the existing somsolib.c or | |
25 | solib.c. What a crock. | |
26 | ||
27 | Even more disgusting. This file depends on functions provided only | |
28 | in certain PA64 libraries. Thus this file is supposed to only be | |
29 | used native. When will HP ever learn that they need to provide the | |
30 | same functionality in all their libraries! */ | |
31 | ||
32 | #include "defs.h" | |
419b8bfb RC |
33 | #include "symtab.h" |
34 | #include "bfd.h" | |
35 | #include "symfile.h" | |
36 | #include "objfiles.h" | |
37 | #include "gdbcore.h" | |
38 | #include "target.h" | |
39 | #include "inferior.h" | |
fb14de7b | 40 | #include "regcache.h" |
419b8bfb RC |
41 | |
42 | #include "hppa-tdep.h" | |
43 | #include "solist.h" | |
d542061a | 44 | #include "solib.h" |
419b8bfb RC |
45 | #include "solib-pa64.h" |
46 | ||
47 | #undef SOLIB_PA64_DBG | |
48 | ||
d542061a UW |
49 | /* We can build this file only when running natively on 64-bit HP/UX. |
50 | We check for that by checking for the elf_hp.h header file. */ | |
fb6d93b2 | 51 | #if defined(HAVE_ELF_HP_H) && defined(__LP64__) |
419b8bfb | 52 | |
d0ac9ef8 MK |
53 | /* FIXME: kettenis/20041213: These includes should be eliminated. */ |
54 | #include <dlfcn.h> | |
55 | #include <elf.h> | |
56 | #include <elf_hp.h> | |
57 | ||
419b8bfb RC |
58 | struct lm_info { |
59 | struct load_module_desc desc; | |
60 | CORE_ADDR desc_addr; | |
61 | }; | |
62 | ||
63 | /* When adding fields, be sure to clear them in _initialize_pa64_solib. */ | |
64 | typedef struct | |
65 | { | |
66 | CORE_ADDR dld_flags_addr; | |
67 | LONGEST dld_flags; | |
68 | struct bfd_section *dyninfo_sect; | |
69 | int have_read_dld_descriptor; | |
70 | int is_valid; | |
71 | CORE_ADDR load_map; | |
72 | CORE_ADDR load_map_addr; | |
73 | struct load_module_desc dld_desc; | |
74 | } | |
75 | dld_cache_t; | |
76 | ||
77 | static dld_cache_t dld_cache; | |
78 | ||
79 | static int | |
80 | read_dynamic_info (asection *dyninfo_sect, dld_cache_t *dld_cache_p); | |
81 | ||
82 | static void | |
83 | pa64_relocate_section_addresses (struct so_list *so, | |
0542c86d | 84 | struct target_section *sec) |
419b8bfb | 85 | { |
45851e00 RC |
86 | asection *asec = sec->the_bfd_section; |
87 | CORE_ADDR load_offset; | |
88 | ||
89 | /* Relocate all the sections based on where they got loaded. */ | |
90 | ||
91 | load_offset = bfd_section_vma (so->abfd, asec) - asec->filepos; | |
92 | ||
93 | if (asec->flags & SEC_CODE) | |
94 | { | |
95 | sec->addr += so->lm_info->desc.text_base - load_offset; | |
96 | sec->endaddr += so->lm_info->desc.text_base - load_offset; | |
97 | } | |
98 | else if (asec->flags & SEC_DATA) | |
99 | { | |
100 | sec->addr += so->lm_info->desc.data_base - load_offset; | |
101 | sec->endaddr += so->lm_info->desc.data_base - load_offset; | |
102 | } | |
419b8bfb RC |
103 | } |
104 | ||
105 | static void | |
106 | pa64_free_so (struct so_list *so) | |
107 | { | |
108 | xfree (so->lm_info); | |
109 | } | |
110 | ||
111 | static void | |
112 | pa64_clear_solib (void) | |
113 | { | |
114 | } | |
115 | ||
116 | /* Wrapper for target_read_memory for dlgetmodinfo. */ | |
117 | ||
118 | static void * | |
119 | pa64_target_read_memory (void *buffer, CORE_ADDR ptr, size_t bufsiz, int ident) | |
120 | { | |
121 | if (target_read_memory (ptr, buffer, bufsiz) != 0) | |
122 | return 0; | |
123 | return buffer; | |
124 | } | |
125 | ||
126 | /* Read the dynamic linker's internal shared library descriptor. | |
127 | ||
128 | This must happen after dld starts running, so we can't do it in | |
129 | read_dynamic_info. Record the fact that we have loaded the | |
6536cc32 DA |
130 | descriptor. If the library is archive bound or the load map |
131 | hasn't been setup, then return zero; else return nonzero. */ | |
419b8bfb RC |
132 | |
133 | static int | |
134 | read_dld_descriptor (void) | |
135 | { | |
136 | char *dll_path; | |
137 | asection *dyninfo_sect; | |
138 | ||
139 | /* If necessary call read_dynamic_info to extract the contents of the | |
140 | .dynamic section from the shared library. */ | |
141 | if (!dld_cache.is_valid) | |
142 | { | |
143 | if (symfile_objfile == NULL) | |
8a3fe4f8 | 144 | error (_("No object file symbols.")); |
419b8bfb RC |
145 | |
146 | dyninfo_sect = bfd_get_section_by_name (symfile_objfile->obfd, | |
147 | ".dynamic"); | |
148 | if (!dyninfo_sect) | |
149 | { | |
150 | return 0; | |
151 | } | |
152 | ||
153 | if (!read_dynamic_info (dyninfo_sect, &dld_cache)) | |
8a3fe4f8 | 154 | error (_("Unable to read in .dynamic section information.")); |
419b8bfb RC |
155 | } |
156 | ||
157 | /* Read the load map pointer. */ | |
158 | if (target_read_memory (dld_cache.load_map_addr, | |
159 | (char *) &dld_cache.load_map, | |
160 | sizeof (dld_cache.load_map)) | |
161 | != 0) | |
162 | { | |
8a3fe4f8 | 163 | error (_("Error while reading in load map pointer.")); |
419b8bfb RC |
164 | } |
165 | ||
6536cc32 DA |
166 | if (!dld_cache.load_map) |
167 | return 0; | |
168 | ||
419b8bfb RC |
169 | /* Read in the dld load module descriptor */ |
170 | if (dlgetmodinfo (-1, | |
171 | &dld_cache.dld_desc, | |
172 | sizeof (dld_cache.dld_desc), | |
173 | pa64_target_read_memory, | |
174 | 0, | |
175 | dld_cache.load_map) | |
176 | == 0) | |
177 | { | |
8a3fe4f8 | 178 | error (_("Error trying to get information about dynamic linker.")); |
419b8bfb RC |
179 | } |
180 | ||
181 | /* Indicate that we have loaded the dld descriptor. */ | |
182 | dld_cache.have_read_dld_descriptor = 1; | |
183 | ||
184 | return 1; | |
185 | } | |
186 | ||
187 | ||
188 | /* Read the .dynamic section and extract the information of interest, | |
189 | which is stored in dld_cache. The routine elf_locate_base in solib.c | |
190 | was used as a model for this. */ | |
191 | ||
192 | static int | |
193 | read_dynamic_info (asection *dyninfo_sect, dld_cache_t *dld_cache_p) | |
194 | { | |
195 | char *buf; | |
196 | char *bufend; | |
197 | CORE_ADDR dyninfo_addr; | |
198 | int dyninfo_sect_size; | |
199 | CORE_ADDR entry_addr; | |
200 | ||
201 | /* Read in .dynamic section, silently ignore errors. */ | |
202 | dyninfo_addr = bfd_section_vma (symfile_objfile->obfd, dyninfo_sect); | |
203 | dyninfo_sect_size = bfd_section_size (exec_bfd, dyninfo_sect); | |
204 | buf = alloca (dyninfo_sect_size); | |
205 | if (target_read_memory (dyninfo_addr, buf, dyninfo_sect_size)) | |
206 | return 0; | |
207 | ||
208 | /* Scan the .dynamic section and record the items of interest. | |
209 | In particular, DT_HP_DLD_FLAGS */ | |
210 | for (bufend = buf + dyninfo_sect_size, entry_addr = dyninfo_addr; | |
211 | buf < bufend; | |
212 | buf += sizeof (Elf64_Dyn), entry_addr += sizeof (Elf64_Dyn)) | |
213 | { | |
214 | Elf64_Dyn *x_dynp = (Elf64_Dyn*)buf; | |
215 | Elf64_Sxword dyn_tag; | |
216 | CORE_ADDR dyn_ptr; | |
419b8bfb | 217 | |
419b8bfb RC |
218 | dyn_tag = bfd_h_get_64 (symfile_objfile->obfd, |
219 | (bfd_byte*) &x_dynp->d_tag); | |
220 | ||
221 | /* We can't use a switch here because dyn_tag is 64 bits and HP's | |
222 | lame comiler does not handle 64bit items in switch statements. */ | |
223 | if (dyn_tag == DT_NULL) | |
224 | break; | |
225 | else if (dyn_tag == DT_HP_DLD_FLAGS) | |
226 | { | |
227 | /* Set dld_flags_addr and dld_flags in *dld_cache_p */ | |
228 | dld_cache_p->dld_flags_addr = entry_addr + offsetof(Elf64_Dyn, d_un); | |
229 | if (target_read_memory (dld_cache_p->dld_flags_addr, | |
230 | (char*) &dld_cache_p->dld_flags, | |
231 | sizeof (dld_cache_p->dld_flags)) | |
232 | != 0) | |
233 | { | |
8a3fe4f8 | 234 | error (_("Error while reading in .dynamic section of the program.")); |
419b8bfb RC |
235 | } |
236 | } | |
237 | else if (dyn_tag == DT_HP_LOAD_MAP) | |
238 | { | |
239 | /* Dld will place the address of the load map at load_map_addr | |
240 | after it starts running. */ | |
241 | if (target_read_memory (entry_addr + offsetof(Elf64_Dyn, | |
242 | d_un.d_ptr), | |
243 | (char*) &dld_cache_p->load_map_addr, | |
244 | sizeof (dld_cache_p->load_map_addr)) | |
245 | != 0) | |
246 | { | |
8a3fe4f8 | 247 | error (_("Error while reading in .dynamic section of the program.")); |
419b8bfb RC |
248 | } |
249 | } | |
250 | else | |
251 | { | |
252 | /* tag is not of interest */ | |
253 | } | |
254 | } | |
255 | ||
256 | /* Record other information and set is_valid to 1. */ | |
257 | dld_cache_p->dyninfo_sect = dyninfo_sect; | |
258 | ||
259 | /* Verify that we read in required info. These fields are re-set to zero | |
260 | in pa64_solib_restart. */ | |
261 | ||
262 | if (dld_cache_p->dld_flags_addr != 0 && dld_cache_p->load_map_addr != 0) | |
263 | dld_cache_p->is_valid = 1; | |
264 | else | |
265 | return 0; | |
266 | ||
267 | return 1; | |
268 | } | |
269 | ||
270 | /* | |
271 | bfd_lookup_symbol -- lookup the value for a specific symbol | |
272 | ||
273 | An expensive way to lookup the value of a single symbol for | |
274 | bfd's that are only temporary anyway. This is used by the | |
275 | shared library support to find the address of the debugger | |
276 | interface structures in the shared library. | |
277 | ||
278 | Note that 0 is specifically allowed as an error return (no | |
279 | such symbol). | |
280 | */ | |
281 | ||
282 | static CORE_ADDR | |
283 | bfd_lookup_symbol (bfd *abfd, char *symname) | |
284 | { | |
285 | unsigned int storage_needed; | |
286 | asymbol *sym; | |
287 | asymbol **symbol_table; | |
288 | unsigned int number_of_symbols; | |
289 | unsigned int i; | |
290 | struct cleanup *back_to; | |
291 | CORE_ADDR symaddr = 0; | |
292 | ||
293 | storage_needed = bfd_get_symtab_upper_bound (abfd); | |
294 | ||
295 | if (storage_needed > 0) | |
296 | { | |
297 | symbol_table = (asymbol **) xmalloc (storage_needed); | |
298 | back_to = make_cleanup (xfree, symbol_table); | |
299 | number_of_symbols = bfd_canonicalize_symtab (abfd, symbol_table); | |
300 | ||
301 | for (i = 0; i < number_of_symbols; i++) | |
302 | { | |
303 | sym = *symbol_table++; | |
304 | if (strcmp (sym->name, symname) == 0) | |
305 | { | |
306 | /* Bfd symbols are section relative. */ | |
307 | symaddr = sym->value + sym->section->vma; | |
308 | break; | |
309 | } | |
310 | } | |
311 | do_cleanups (back_to); | |
312 | } | |
313 | return (symaddr); | |
314 | } | |
315 | ||
316 | ||
317 | /* This hook gets called just before the first instruction in the | |
318 | inferior process is executed. | |
319 | ||
320 | This is our opportunity to set magic flags in the inferior so | |
321 | that GDB can be notified when a shared library is mapped in and | |
322 | to tell the dynamic linker that a private copy of the library is | |
323 | needed (so GDB can set breakpoints in the library). | |
324 | ||
7be67755 DA |
325 | We need to set DT_HP_DEBUG_CALLBACK to indicate that we want the |
326 | dynamic linker to call the breakpoint routine for significant events. | |
327 | We used to set DT_HP_DEBUG_PRIVATE to indicate that shared libraries | |
328 | should be mapped private. However, this flag can be set using | |
329 | "chatr +dbg enable". Not setting DT_HP_DEBUG_PRIVATE allows debugging | |
330 | with shared libraries mapped shareable. */ | |
419b8bfb RC |
331 | |
332 | static void | |
268a4a75 | 333 | pa64_solib_create_inferior_hook (int from_tty) |
419b8bfb RC |
334 | { |
335 | struct minimal_symbol *msymbol; | |
336 | unsigned int dld_flags, status; | |
337 | asection *shlib_info, *interp_sect; | |
338 | char buf[4]; | |
339 | struct objfile *objfile; | |
340 | CORE_ADDR anaddr; | |
341 | ||
419b8bfb RC |
342 | if (symfile_objfile == NULL) |
343 | return; | |
344 | ||
345 | /* First see if the objfile was dynamically linked. */ | |
346 | shlib_info = bfd_get_section_by_name (symfile_objfile->obfd, ".dynamic"); | |
347 | if (!shlib_info) | |
348 | return; | |
349 | ||
350 | /* It's got a .dynamic section, make sure it's not empty. */ | |
351 | if (bfd_section_size (symfile_objfile->obfd, shlib_info) == 0) | |
352 | return; | |
353 | ||
354 | /* Read in the .dynamic section. */ | |
355 | if (! read_dynamic_info (shlib_info, &dld_cache)) | |
8a3fe4f8 | 356 | error (_("Unable to read the .dynamic section.")); |
419b8bfb | 357 | |
7be67755 DA |
358 | /* If the libraries were not mapped private, warn the user. */ |
359 | if ((dld_cache.dld_flags & DT_HP_DEBUG_PRIVATE) == 0) | |
360 | warning | |
361 | (_("Private mapping of shared library text was not specified\n" | |
362 | "by the executable; setting a breakpoint in a shared library which\n" | |
363 | "is not privately mapped will not work. See the HP-UX 11i v3 chatr\n" | |
364 | "manpage for methods to privately map shared library text.")); | |
365 | ||
419b8bfb | 366 | /* Turn on the flags we care about. */ |
419b8bfb RC |
367 | dld_cache.dld_flags |= DT_HP_DEBUG_CALLBACK; |
368 | status = target_write_memory (dld_cache.dld_flags_addr, | |
369 | (char *) &dld_cache.dld_flags, | |
370 | sizeof (dld_cache.dld_flags)); | |
371 | if (status != 0) | |
8a3fe4f8 | 372 | error (_("Unable to modify dynamic linker flags.")); |
419b8bfb RC |
373 | |
374 | /* Now we have to create a shared library breakpoint in the dynamic | |
375 | linker. This can be somewhat tricky since the symbol is inside | |
376 | the dynamic linker (for which we do not have symbols or a base | |
377 | load address! Luckily I wrote this code for solib.c years ago. */ | |
378 | interp_sect = bfd_get_section_by_name (exec_bfd, ".interp"); | |
379 | if (interp_sect) | |
380 | { | |
381 | unsigned int interp_sect_size; | |
382 | char *buf; | |
383 | CORE_ADDR load_addr; | |
384 | bfd *tmp_bfd; | |
385 | CORE_ADDR sym_addr = 0; | |
386 | ||
387 | /* Read the contents of the .interp section into a local buffer; | |
388 | the contents specify the dynamic linker this program uses. */ | |
389 | interp_sect_size = bfd_section_size (exec_bfd, interp_sect); | |
390 | buf = alloca (interp_sect_size); | |
391 | bfd_get_section_contents (exec_bfd, interp_sect, | |
392 | buf, 0, interp_sect_size); | |
393 | ||
394 | /* Now we need to figure out where the dynamic linker was | |
395 | loaded so that we can load its symbols and place a breakpoint | |
396 | in the dynamic linker itself. | |
397 | ||
398 | This address is stored on the stack. However, I've been unable | |
399 | to find any magic formula to find it for Solaris (appears to | |
400 | be trivial on GNU/Linux). Therefore, we have to try an alternate | |
401 | mechanism to find the dynamic linker's base address. */ | |
402 | tmp_bfd = bfd_openr (buf, gnutarget); | |
403 | if (tmp_bfd == NULL) | |
404 | return; | |
405 | ||
406 | /* Make sure the dynamic linker's really a useful object. */ | |
407 | if (!bfd_check_format (tmp_bfd, bfd_object)) | |
408 | { | |
8a3fe4f8 | 409 | warning (_("Unable to grok dynamic linker %s as an object file"), buf); |
419b8bfb RC |
410 | bfd_close (tmp_bfd); |
411 | return; | |
412 | } | |
413 | ||
414 | /* We find the dynamic linker's base address by examining the | |
415 | current pc (which point at the entry point for the dynamic | |
416 | linker) and subtracting the offset of the entry point. | |
417 | ||
418 | Also note the breakpoint is the second instruction in the | |
419 | routine. */ | |
fb14de7b UW |
420 | load_addr = regcache_read_pc (get_current_regcache ()) |
421 | - tmp_bfd->start_address; | |
419b8bfb RC |
422 | sym_addr = bfd_lookup_symbol (tmp_bfd, "__dld_break"); |
423 | sym_addr = load_addr + sym_addr + 4; | |
424 | ||
425 | /* Create the shared library breakpoint. */ | |
426 | { | |
427 | struct breakpoint *b | |
a6d9a66e | 428 | = create_solib_event_breakpoint (target_gdbarch, sym_addr); |
419b8bfb RC |
429 | |
430 | /* The breakpoint is actually hard-coded into the dynamic linker, | |
431 | so we don't need to actually insert a breakpoint instruction | |
432 | there. In fact, the dynamic linker's code is immutable, even to | |
433 | ttrace, so we shouldn't even try to do that. For cases like | |
434 | this, we have "permanent" breakpoints. */ | |
435 | make_breakpoint_permanent (b); | |
436 | } | |
437 | ||
438 | /* We're done with the temporary bfd. */ | |
439 | bfd_close (tmp_bfd); | |
440 | } | |
441 | } | |
442 | ||
443 | static void | |
444 | pa64_special_symbol_handling (void) | |
445 | { | |
446 | } | |
447 | ||
448 | static struct so_list * | |
449 | pa64_current_sos (void) | |
450 | { | |
451 | struct so_list *head = 0; | |
452 | struct so_list **link_ptr = &head; | |
453 | int dll_index; | |
454 | ||
455 | /* Read in the load map pointer if we have not done so already. */ | |
456 | if (! dld_cache.have_read_dld_descriptor) | |
457 | if (! read_dld_descriptor ()) | |
458 | return NULL; | |
459 | ||
45851e00 | 460 | for (dll_index = -1; ; dll_index++) |
419b8bfb RC |
461 | { |
462 | struct load_module_desc dll_desc; | |
463 | char *dll_path; | |
464 | struct so_list *new; | |
465 | struct cleanup *old_chain; | |
466 | ||
45851e00 RC |
467 | if (dll_index == 0) |
468 | continue; | |
469 | ||
419b8bfb RC |
470 | /* Read in the load module descriptor. */ |
471 | if (dlgetmodinfo (dll_index, &dll_desc, sizeof (dll_desc), | |
472 | pa64_target_read_memory, 0, dld_cache.load_map) | |
473 | == 0) | |
474 | break; | |
475 | ||
476 | /* Get the name of the shared library. */ | |
477 | dll_path = (char *)dlgetname (&dll_desc, sizeof (dll_desc), | |
478 | pa64_target_read_memory, | |
479 | 0, dld_cache.load_map); | |
480 | ||
419b8bfb RC |
481 | new = (struct so_list *) xmalloc (sizeof (struct so_list)); |
482 | memset (new, 0, sizeof (struct so_list)); | |
483 | new->lm_info = (struct lm_info *) xmalloc (sizeof (struct lm_info)); | |
484 | memset (new->lm_info, 0, sizeof (struct lm_info)); | |
485 | ||
486 | strncpy (new->so_name, dll_path, SO_NAME_MAX_PATH_SIZE - 1); | |
487 | new->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0'; | |
488 | strcpy (new->so_original_name, new->so_name); | |
489 | ||
490 | memcpy (&new->lm_info->desc, &dll_desc, sizeof (dll_desc)); | |
491 | ||
492 | #ifdef SOLIB_PA64_DBG | |
493 | { | |
494 | struct load_module_desc *d = &new->lm_info->desc; | |
433759f7 | 495 | |
419b8bfb RC |
496 | printf ("\n+ library \"%s\" is described at index %d\n", new->so_name, |
497 | dll_index); | |
2244ba2e PM |
498 | printf (" text_base = %s\n", hex_string (d->text_base)); |
499 | printf (" text_size = %s\n", hex_string (d->text_size)); | |
500 | printf (" data_base = %s\n", hex_string (d->data_base)); | |
501 | printf (" data_size = %s\n", hex_string (d->data_size)); | |
502 | printf (" unwind_base = %s\n", hex_string (d->unwind_base)); | |
503 | printf (" linkage_ptr = %s\n", hex_string (d->linkage_ptr)); | |
504 | printf (" phdr_base = %s\n", hex_string (d->phdr_base)); | |
505 | printf (" tls_size = %s\n", hex_string (d->tls_size)); | |
506 | printf (" tls_start_addr = %s\n", hex_string (d->tls_start_addr)); | |
507 | printf (" unwind_size = %s\n", hex_string (d->unwind_size)); | |
508 | printf (" tls_index = %s\n", hex_string (d->tls_index)); | |
419b8bfb RC |
509 | } |
510 | #endif | |
511 | ||
512 | /* Link the new object onto the list. */ | |
513 | new->next = NULL; | |
514 | *link_ptr = new; | |
515 | link_ptr = &new->next; | |
516 | } | |
517 | ||
518 | return head; | |
519 | } | |
520 | ||
521 | static int | |
522 | pa64_open_symbol_file_object (void *from_ttyp) | |
523 | { | |
524 | int from_tty = *(int *)from_ttyp; | |
525 | char buf[4]; | |
526 | struct load_module_desc dll_desc; | |
527 | char *dll_path; | |
528 | ||
529 | if (symfile_objfile) | |
9e2f0ad4 | 530 | if (!query (_("Attempt to reload symbols from process? "))) |
419b8bfb RC |
531 | return 0; |
532 | ||
533 | /* Read in the load map pointer if we have not done so already. */ | |
534 | if (! dld_cache.have_read_dld_descriptor) | |
535 | if (! read_dld_descriptor ()) | |
536 | return 0; | |
537 | ||
538 | /* Read in the load module descriptor. */ | |
539 | if (dlgetmodinfo (0, &dll_desc, sizeof (dll_desc), | |
540 | pa64_target_read_memory, 0, dld_cache.load_map) == 0) | |
541 | return 0; | |
542 | ||
543 | /* Get the name of the shared library. */ | |
544 | dll_path = (char *)dlgetname (&dll_desc, sizeof (dll_desc), | |
545 | pa64_target_read_memory, | |
546 | 0, dld_cache.load_map); | |
547 | ||
548 | /* Have a pathname: read the symbol file. */ | |
549 | symbol_file_add_main (dll_path, from_tty); | |
550 | ||
551 | return 1; | |
552 | } | |
553 | ||
554 | /* Return nonzero if PC is an address inside the dynamic linker. */ | |
555 | static int | |
556 | pa64_in_dynsym_resolve_code (CORE_ADDR pc) | |
557 | { | |
558 | asection *shlib_info; | |
559 | ||
560 | if (symfile_objfile == NULL) | |
561 | return 0; | |
562 | ||
563 | if (!dld_cache.have_read_dld_descriptor) | |
564 | if (!read_dld_descriptor ()) | |
565 | return 0; | |
566 | ||
567 | return (pc >= dld_cache.dld_desc.text_base | |
568 | && pc < dld_cache.dld_desc.text_base + dld_cache.dld_desc.text_size); | |
569 | } | |
570 | ||
571 | ||
572 | /* Return the GOT value for the shared library in which ADDR belongs. If | |
573 | ADDR isn't in any known shared library, return zero. */ | |
574 | ||
575 | static CORE_ADDR | |
576 | pa64_solib_get_got_by_pc (CORE_ADDR addr) | |
577 | { | |
578 | struct so_list *so_list = master_so_list (); | |
579 | CORE_ADDR got_value = 0; | |
580 | ||
581 | while (so_list) | |
582 | { | |
583 | if (so_list->lm_info->desc.text_base <= addr | |
584 | && ((so_list->lm_info->desc.text_base | |
585 | + so_list->lm_info->desc.text_size) | |
586 | > addr)) | |
45851e00 | 587 | { |
419b8bfb | 588 | got_value = so_list->lm_info->desc.linkage_ptr; |
45851e00 | 589 | break; |
419b8bfb RC |
590 | } |
591 | so_list = so_list->next; | |
592 | } | |
593 | return got_value; | |
594 | } | |
595 | ||
596 | /* Get some HPUX-specific data from a shared lib. */ | |
597 | static CORE_ADDR | |
598 | pa64_solib_thread_start_addr (struct so_list *so) | |
599 | { | |
600 | return so->lm_info->desc.tls_start_addr; | |
601 | } | |
602 | ||
603 | ||
604 | /* Return the address of the handle of the shared library in which ADDR | |
45851e00 | 605 | belongs. If ADDR isn't in any known shared library, return zero. */ |
419b8bfb RC |
606 | |
607 | static CORE_ADDR | |
608 | pa64_solib_get_solib_by_pc (CORE_ADDR addr) | |
609 | { | |
610 | struct so_list *so_list = master_so_list (); | |
611 | CORE_ADDR retval = 0; | |
612 | ||
613 | while (so_list) | |
614 | { | |
615 | if (so_list->lm_info->desc.text_base <= addr | |
616 | && ((so_list->lm_info->desc.text_base | |
617 | + so_list->lm_info->desc.text_size) | |
618 | > addr)) | |
619 | { | |
620 | retval = so_list->lm_info->desc_addr; | |
621 | break; | |
622 | } | |
623 | so_list = so_list->next; | |
624 | } | |
625 | return retval; | |
626 | } | |
627 | ||
45851e00 RC |
628 | /* pa64 libraries do not seem to set the section offsets in a standard (i.e. |
629 | SVr4) way; the text section offset stored in the file doesn't correspond | |
630 | to the place where the library is actually loaded into memory. Instead, | |
631 | we rely on the dll descriptor to tell us where things were loaded. */ | |
632 | static CORE_ADDR | |
633 | pa64_solib_get_text_base (struct objfile *objfile) | |
634 | { | |
635 | struct so_list *so; | |
636 | ||
637 | for (so = master_so_list (); so; so = so->next) | |
638 | if (so->objfile == objfile) | |
639 | return so->lm_info->desc.text_base; | |
640 | ||
641 | return 0; | |
642 | } | |
643 | ||
419b8bfb RC |
644 | static struct target_so_ops pa64_so_ops; |
645 | ||
646 | extern initialize_file_ftype _initialize_pa64_solib; /* -Wmissing-prototypes */ | |
647 | ||
648 | void | |
649 | _initialize_pa64_solib (void) | |
650 | { | |
651 | pa64_so_ops.relocate_section_addresses = pa64_relocate_section_addresses; | |
652 | pa64_so_ops.free_so = pa64_free_so; | |
653 | pa64_so_ops.clear_solib = pa64_clear_solib; | |
654 | pa64_so_ops.solib_create_inferior_hook = pa64_solib_create_inferior_hook; | |
655 | pa64_so_ops.special_symbol_handling = pa64_special_symbol_handling; | |
656 | pa64_so_ops.current_sos = pa64_current_sos; | |
657 | pa64_so_ops.open_symbol_file_object = pa64_open_symbol_file_object; | |
658 | pa64_so_ops.in_dynsym_resolve_code = pa64_in_dynsym_resolve_code; | |
831a0c44 | 659 | pa64_so_ops.bfd_open = solib_bfd_open; |
419b8bfb RC |
660 | |
661 | memset (&dld_cache, 0, sizeof (dld_cache)); | |
662 | } | |
663 | ||
d542061a | 664 | void pa64_solib_select (struct gdbarch *gdbarch) |
419b8bfb | 665 | { |
d542061a | 666 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
419b8bfb | 667 | |
433759f7 | 668 | set_solib_ops (gdbarch, &pa64_so_ops); |
419b8bfb RC |
669 | tdep->solib_thread_start_addr = pa64_solib_thread_start_addr; |
670 | tdep->solib_get_got_by_pc = pa64_solib_get_got_by_pc; | |
671 | tdep->solib_get_solib_by_pc = pa64_solib_get_solib_by_pc; | |
45851e00 | 672 | tdep->solib_get_text_base = pa64_solib_get_text_base; |
419b8bfb RC |
673 | } |
674 | ||
d542061a | 675 | #else /* HAVE_ELF_HP_H */ |
419b8bfb RC |
676 | |
677 | extern initialize_file_ftype _initialize_pa64_solib; /* -Wmissing-prototypes */ | |
678 | ||
679 | void | |
680 | _initialize_pa64_solib (void) | |
681 | { | |
682 | } | |
683 | ||
d542061a | 684 | void pa64_solib_select (struct gdbarch *gdbarch) |
419b8bfb RC |
685 | { |
686 | /* For a SOM-only target, there is no pa64 solib support. This is needed | |
687 | for hppa-hpux-tdep.c to build. */ | |
8a3fe4f8 | 688 | error (_("Cannot select pa64 solib support for this configuration.")); |
419b8bfb RC |
689 | } |
690 | #endif |