Commit | Line | Data |
---|---|---|
419b8bfb RC |
1 | /* Handle PA64 shared libraries for GDB, the GNU Debugger. |
2 | ||
28e7fd62 | 3 | Copyright (C) 2004-2013 Free Software Foundation, Inc. |
419b8bfb RC |
4 | |
5 | This file is part of GDB. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 9 | the Free Software Foundation; either version 3 of the License, or |
419b8bfb RC |
10 | (at your option) any later version. |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
c378eb4e MS |
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
19 | ||
20 | /* HP in their infinite stupidity choose not to use standard ELF dynamic | |
419b8bfb RC |
21 | linker interfaces. They also choose not to make their ELF dymamic |
22 | linker interfaces compatible with the SOM dynamic linker. The | |
23 | net result is we can not use either of the existing somsolib.c or | |
24 | solib.c. What a crock. | |
25 | ||
26 | Even more disgusting. This file depends on functions provided only | |
27 | in certain PA64 libraries. Thus this file is supposed to only be | |
28 | used native. When will HP ever learn that they need to provide the | |
29 | same functionality in all their libraries! */ | |
30 | ||
31 | #include "defs.h" | |
419b8bfb RC |
32 | #include "symtab.h" |
33 | #include "bfd.h" | |
34 | #include "symfile.h" | |
35 | #include "objfiles.h" | |
36 | #include "gdbcore.h" | |
37 | #include "target.h" | |
38 | #include "inferior.h" | |
fb14de7b | 39 | #include "regcache.h" |
92107356 | 40 | #include "gdb_bfd.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 | ||
c378eb4e | 63 | /* When adding fields, be sure to clear them in _initialize_pa64_solib. */ |
419b8bfb RC |
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 | ||
2021ad3a PM |
79 | static int read_dynamic_info (asection *dyninfo_sect, |
80 | dld_cache_t *dld_cache_p); | |
419b8bfb RC |
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 | ||
c378eb4e | 169 | /* Read in the dld load module descriptor. */ |
419b8bfb RC |
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. | |
c378eb4e | 209 | In particular, DT_HP_DLD_FLAGS. */ |
419b8bfb RC |
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 | { | |
c378eb4e | 227 | /* Set dld_flags_addr and dld_flags in *dld_cache_p. */ |
419b8bfb RC |
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 | { | |
3e43a32a MS |
234 | error (_("Error while reading in " |
235 | ".dynamic section of the program.")); | |
419b8bfb RC |
236 | } |
237 | } | |
238 | else if (dyn_tag == DT_HP_LOAD_MAP) | |
239 | { | |
240 | /* Dld will place the address of the load map at load_map_addr | |
241 | after it starts running. */ | |
242 | if (target_read_memory (entry_addr + offsetof(Elf64_Dyn, | |
243 | d_un.d_ptr), | |
244 | (char*) &dld_cache_p->load_map_addr, | |
245 | sizeof (dld_cache_p->load_map_addr)) | |
246 | != 0) | |
247 | { | |
3e43a32a MS |
248 | error (_("Error while reading in " |
249 | ".dynamic section of the program.")); | |
419b8bfb RC |
250 | } |
251 | } | |
252 | else | |
253 | { | |
c378eb4e | 254 | /* Tag is not of interest. */ |
419b8bfb RC |
255 | } |
256 | } | |
257 | ||
c378eb4e | 258 | /* Record other information and set is_valid to 1. */ |
419b8bfb RC |
259 | dld_cache_p->dyninfo_sect = dyninfo_sect; |
260 | ||
261 | /* Verify that we read in required info. These fields are re-set to zero | |
262 | in pa64_solib_restart. */ | |
263 | ||
264 | if (dld_cache_p->dld_flags_addr != 0 && dld_cache_p->load_map_addr != 0) | |
265 | dld_cache_p->is_valid = 1; | |
266 | else | |
267 | return 0; | |
268 | ||
269 | return 1; | |
270 | } | |
271 | ||
cb457ae2 | 272 | /* Helper function for gdb_bfd_lookup_symbol_from_symtab. */ |
419b8bfb | 273 | |
cb457ae2 YQ |
274 | static int |
275 | cmp_name (asymbol *sym, void *data) | |
419b8bfb | 276 | { |
cb457ae2 | 277 | return (strcmp (sym->name, (const char *) data) == 0); |
419b8bfb RC |
278 | } |
279 | ||
419b8bfb RC |
280 | /* This hook gets called just before the first instruction in the |
281 | inferior process is executed. | |
282 | ||
283 | This is our opportunity to set magic flags in the inferior so | |
284 | that GDB can be notified when a shared library is mapped in and | |
285 | to tell the dynamic linker that a private copy of the library is | |
286 | needed (so GDB can set breakpoints in the library). | |
287 | ||
7be67755 DA |
288 | We need to set DT_HP_DEBUG_CALLBACK to indicate that we want the |
289 | dynamic linker to call the breakpoint routine for significant events. | |
290 | We used to set DT_HP_DEBUG_PRIVATE to indicate that shared libraries | |
291 | should be mapped private. However, this flag can be set using | |
292 | "chatr +dbg enable". Not setting DT_HP_DEBUG_PRIVATE allows debugging | |
293 | with shared libraries mapped shareable. */ | |
419b8bfb RC |
294 | |
295 | static void | |
268a4a75 | 296 | pa64_solib_create_inferior_hook (int from_tty) |
419b8bfb RC |
297 | { |
298 | struct minimal_symbol *msymbol; | |
299 | unsigned int dld_flags, status; | |
300 | asection *shlib_info, *interp_sect; | |
301 | char buf[4]; | |
302 | struct objfile *objfile; | |
303 | CORE_ADDR anaddr; | |
304 | ||
419b8bfb RC |
305 | if (symfile_objfile == NULL) |
306 | return; | |
307 | ||
308 | /* First see if the objfile was dynamically linked. */ | |
309 | shlib_info = bfd_get_section_by_name (symfile_objfile->obfd, ".dynamic"); | |
310 | if (!shlib_info) | |
311 | return; | |
312 | ||
313 | /* It's got a .dynamic section, make sure it's not empty. */ | |
314 | if (bfd_section_size (symfile_objfile->obfd, shlib_info) == 0) | |
315 | return; | |
316 | ||
317 | /* Read in the .dynamic section. */ | |
318 | if (! read_dynamic_info (shlib_info, &dld_cache)) | |
8a3fe4f8 | 319 | error (_("Unable to read the .dynamic section.")); |
419b8bfb | 320 | |
7be67755 DA |
321 | /* If the libraries were not mapped private, warn the user. */ |
322 | if ((dld_cache.dld_flags & DT_HP_DEBUG_PRIVATE) == 0) | |
323 | warning | |
ac74f770 MS |
324 | (_("\ |
325 | Private mapping of shared library text was not specified\n\ | |
326 | by the executable; setting a breakpoint in a shared library which\n\ | |
327 | is not privately mapped will not work. See the HP-UX 11i v3 chatr\n\ | |
328 | manpage for methods to privately map shared library text.")); | |
7be67755 | 329 | |
419b8bfb | 330 | /* Turn on the flags we care about. */ |
419b8bfb RC |
331 | dld_cache.dld_flags |= DT_HP_DEBUG_CALLBACK; |
332 | status = target_write_memory (dld_cache.dld_flags_addr, | |
333 | (char *) &dld_cache.dld_flags, | |
334 | sizeof (dld_cache.dld_flags)); | |
335 | if (status != 0) | |
8a3fe4f8 | 336 | error (_("Unable to modify dynamic linker flags.")); |
419b8bfb RC |
337 | |
338 | /* Now we have to create a shared library breakpoint in the dynamic | |
339 | linker. This can be somewhat tricky since the symbol is inside | |
340 | the dynamic linker (for which we do not have symbols or a base | |
341 | load address! Luckily I wrote this code for solib.c years ago. */ | |
342 | interp_sect = bfd_get_section_by_name (exec_bfd, ".interp"); | |
343 | if (interp_sect) | |
344 | { | |
345 | unsigned int interp_sect_size; | |
346 | char *buf; | |
347 | CORE_ADDR load_addr; | |
348 | bfd *tmp_bfd; | |
349 | CORE_ADDR sym_addr = 0; | |
350 | ||
351 | /* Read the contents of the .interp section into a local buffer; | |
352 | the contents specify the dynamic linker this program uses. */ | |
353 | interp_sect_size = bfd_section_size (exec_bfd, interp_sect); | |
354 | buf = alloca (interp_sect_size); | |
355 | bfd_get_section_contents (exec_bfd, interp_sect, | |
356 | buf, 0, interp_sect_size); | |
357 | ||
358 | /* Now we need to figure out where the dynamic linker was | |
359 | loaded so that we can load its symbols and place a breakpoint | |
360 | in the dynamic linker itself. | |
361 | ||
362 | This address is stored on the stack. However, I've been unable | |
363 | to find any magic formula to find it for Solaris (appears to | |
364 | be trivial on GNU/Linux). Therefore, we have to try an alternate | |
365 | mechanism to find the dynamic linker's base address. */ | |
1c00ec6b | 366 | tmp_bfd = gdb_bfd_open (buf, gnutarget, -1); |
419b8bfb RC |
367 | if (tmp_bfd == NULL) |
368 | return; | |
369 | ||
370 | /* Make sure the dynamic linker's really a useful object. */ | |
371 | if (!bfd_check_format (tmp_bfd, bfd_object)) | |
372 | { | |
3e43a32a MS |
373 | warning (_("Unable to grok dynamic linker %s as an object file"), |
374 | buf); | |
cbb099e8 | 375 | gdb_bfd_unref (tmp_bfd); |
419b8bfb RC |
376 | return; |
377 | } | |
378 | ||
379 | /* We find the dynamic linker's base address by examining the | |
380 | current pc (which point at the entry point for the dynamic | |
c378eb4e | 381 | linker) and subtracting the offset of the entry point. |
419b8bfb RC |
382 | |
383 | Also note the breakpoint is the second instruction in the | |
384 | routine. */ | |
fb14de7b UW |
385 | load_addr = regcache_read_pc (get_current_regcache ()) |
386 | - tmp_bfd->start_address; | |
e009ee71 TT |
387 | sym_addr = gdb_bfd_lookup_symbol_from_symtab (tmp_bfd, cmp_name, |
388 | "__dld_break"); | |
419b8bfb RC |
389 | sym_addr = load_addr + sym_addr + 4; |
390 | ||
391 | /* Create the shared library breakpoint. */ | |
392 | { | |
393 | struct breakpoint *b | |
f5656ead | 394 | = create_solib_event_breakpoint (target_gdbarch (), sym_addr); |
419b8bfb RC |
395 | |
396 | /* The breakpoint is actually hard-coded into the dynamic linker, | |
397 | so we don't need to actually insert a breakpoint instruction | |
398 | there. In fact, the dynamic linker's code is immutable, even to | |
399 | ttrace, so we shouldn't even try to do that. For cases like | |
400 | this, we have "permanent" breakpoints. */ | |
401 | make_breakpoint_permanent (b); | |
402 | } | |
403 | ||
404 | /* We're done with the temporary bfd. */ | |
cbb099e8 | 405 | gdb_bfd_unref (tmp_bfd); |
419b8bfb RC |
406 | } |
407 | } | |
408 | ||
409 | static void | |
410 | pa64_special_symbol_handling (void) | |
411 | { | |
412 | } | |
413 | ||
414 | static struct so_list * | |
415 | pa64_current_sos (void) | |
416 | { | |
417 | struct so_list *head = 0; | |
418 | struct so_list **link_ptr = &head; | |
419 | int dll_index; | |
420 | ||
421 | /* Read in the load map pointer if we have not done so already. */ | |
422 | if (! dld_cache.have_read_dld_descriptor) | |
423 | if (! read_dld_descriptor ()) | |
424 | return NULL; | |
425 | ||
45851e00 | 426 | for (dll_index = -1; ; dll_index++) |
419b8bfb RC |
427 | { |
428 | struct load_module_desc dll_desc; | |
429 | char *dll_path; | |
430 | struct so_list *new; | |
431 | struct cleanup *old_chain; | |
432 | ||
45851e00 RC |
433 | if (dll_index == 0) |
434 | continue; | |
435 | ||
419b8bfb RC |
436 | /* Read in the load module descriptor. */ |
437 | if (dlgetmodinfo (dll_index, &dll_desc, sizeof (dll_desc), | |
438 | pa64_target_read_memory, 0, dld_cache.load_map) | |
439 | == 0) | |
440 | break; | |
441 | ||
442 | /* Get the name of the shared library. */ | |
443 | dll_path = (char *)dlgetname (&dll_desc, sizeof (dll_desc), | |
444 | pa64_target_read_memory, | |
445 | 0, dld_cache.load_map); | |
446 | ||
419b8bfb RC |
447 | new = (struct so_list *) xmalloc (sizeof (struct so_list)); |
448 | memset (new, 0, sizeof (struct so_list)); | |
449 | new->lm_info = (struct lm_info *) xmalloc (sizeof (struct lm_info)); | |
450 | memset (new->lm_info, 0, sizeof (struct lm_info)); | |
451 | ||
452 | strncpy (new->so_name, dll_path, SO_NAME_MAX_PATH_SIZE - 1); | |
453 | new->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0'; | |
454 | strcpy (new->so_original_name, new->so_name); | |
455 | ||
456 | memcpy (&new->lm_info->desc, &dll_desc, sizeof (dll_desc)); | |
457 | ||
458 | #ifdef SOLIB_PA64_DBG | |
459 | { | |
460 | struct load_module_desc *d = &new->lm_info->desc; | |
433759f7 | 461 | |
419b8bfb RC |
462 | printf ("\n+ library \"%s\" is described at index %d\n", new->so_name, |
463 | dll_index); | |
2244ba2e PM |
464 | printf (" text_base = %s\n", hex_string (d->text_base)); |
465 | printf (" text_size = %s\n", hex_string (d->text_size)); | |
466 | printf (" data_base = %s\n", hex_string (d->data_base)); | |
467 | printf (" data_size = %s\n", hex_string (d->data_size)); | |
468 | printf (" unwind_base = %s\n", hex_string (d->unwind_base)); | |
469 | printf (" linkage_ptr = %s\n", hex_string (d->linkage_ptr)); | |
470 | printf (" phdr_base = %s\n", hex_string (d->phdr_base)); | |
471 | printf (" tls_size = %s\n", hex_string (d->tls_size)); | |
472 | printf (" tls_start_addr = %s\n", hex_string (d->tls_start_addr)); | |
473 | printf (" unwind_size = %s\n", hex_string (d->unwind_size)); | |
474 | printf (" tls_index = %s\n", hex_string (d->tls_index)); | |
419b8bfb RC |
475 | } |
476 | #endif | |
477 | ||
478 | /* Link the new object onto the list. */ | |
479 | new->next = NULL; | |
480 | *link_ptr = new; | |
481 | link_ptr = &new->next; | |
482 | } | |
483 | ||
484 | return head; | |
485 | } | |
486 | ||
487 | static int | |
488 | pa64_open_symbol_file_object (void *from_ttyp) | |
489 | { | |
490 | int from_tty = *(int *)from_ttyp; | |
491 | char buf[4]; | |
492 | struct load_module_desc dll_desc; | |
493 | char *dll_path; | |
494 | ||
495 | if (symfile_objfile) | |
9e2f0ad4 | 496 | if (!query (_("Attempt to reload symbols from process? "))) |
419b8bfb RC |
497 | return 0; |
498 | ||
499 | /* Read in the load map pointer if we have not done so already. */ | |
500 | if (! dld_cache.have_read_dld_descriptor) | |
501 | if (! read_dld_descriptor ()) | |
502 | return 0; | |
503 | ||
504 | /* Read in the load module descriptor. */ | |
505 | if (dlgetmodinfo (0, &dll_desc, sizeof (dll_desc), | |
506 | pa64_target_read_memory, 0, dld_cache.load_map) == 0) | |
507 | return 0; | |
508 | ||
509 | /* Get the name of the shared library. */ | |
510 | dll_path = (char *)dlgetname (&dll_desc, sizeof (dll_desc), | |
511 | pa64_target_read_memory, | |
512 | 0, dld_cache.load_map); | |
513 | ||
514 | /* Have a pathname: read the symbol file. */ | |
515 | symbol_file_add_main (dll_path, from_tty); | |
516 | ||
517 | return 1; | |
518 | } | |
519 | ||
520 | /* Return nonzero if PC is an address inside the dynamic linker. */ | |
521 | static int | |
522 | pa64_in_dynsym_resolve_code (CORE_ADDR pc) | |
523 | { | |
524 | asection *shlib_info; | |
525 | ||
526 | if (symfile_objfile == NULL) | |
527 | return 0; | |
528 | ||
529 | if (!dld_cache.have_read_dld_descriptor) | |
530 | if (!read_dld_descriptor ()) | |
531 | return 0; | |
532 | ||
533 | return (pc >= dld_cache.dld_desc.text_base | |
534 | && pc < dld_cache.dld_desc.text_base + dld_cache.dld_desc.text_size); | |
535 | } | |
536 | ||
537 | ||
538 | /* Return the GOT value for the shared library in which ADDR belongs. If | |
539 | ADDR isn't in any known shared library, return zero. */ | |
540 | ||
541 | static CORE_ADDR | |
542 | pa64_solib_get_got_by_pc (CORE_ADDR addr) | |
543 | { | |
544 | struct so_list *so_list = master_so_list (); | |
545 | CORE_ADDR got_value = 0; | |
546 | ||
547 | while (so_list) | |
548 | { | |
549 | if (so_list->lm_info->desc.text_base <= addr | |
550 | && ((so_list->lm_info->desc.text_base | |
551 | + so_list->lm_info->desc.text_size) | |
552 | > addr)) | |
45851e00 | 553 | { |
419b8bfb | 554 | got_value = so_list->lm_info->desc.linkage_ptr; |
45851e00 | 555 | break; |
419b8bfb RC |
556 | } |
557 | so_list = so_list->next; | |
558 | } | |
559 | return got_value; | |
560 | } | |
561 | ||
562 | /* Get some HPUX-specific data from a shared lib. */ | |
563 | static CORE_ADDR | |
564 | pa64_solib_thread_start_addr (struct so_list *so) | |
565 | { | |
566 | return so->lm_info->desc.tls_start_addr; | |
567 | } | |
568 | ||
569 | ||
570 | /* Return the address of the handle of the shared library in which ADDR | |
45851e00 | 571 | belongs. If ADDR isn't in any known shared library, return zero. */ |
419b8bfb RC |
572 | |
573 | static CORE_ADDR | |
574 | pa64_solib_get_solib_by_pc (CORE_ADDR addr) | |
575 | { | |
576 | struct so_list *so_list = master_so_list (); | |
577 | CORE_ADDR retval = 0; | |
578 | ||
579 | while (so_list) | |
580 | { | |
581 | if (so_list->lm_info->desc.text_base <= addr | |
582 | && ((so_list->lm_info->desc.text_base | |
583 | + so_list->lm_info->desc.text_size) | |
584 | > addr)) | |
585 | { | |
586 | retval = so_list->lm_info->desc_addr; | |
587 | break; | |
588 | } | |
589 | so_list = so_list->next; | |
590 | } | |
591 | return retval; | |
592 | } | |
593 | ||
c378eb4e | 594 | /* pa64 libraries do not seem to set the section offsets in a standard (i.e. |
45851e00 RC |
595 | SVr4) way; the text section offset stored in the file doesn't correspond |
596 | to the place where the library is actually loaded into memory. Instead, | |
597 | we rely on the dll descriptor to tell us where things were loaded. */ | |
598 | static CORE_ADDR | |
599 | pa64_solib_get_text_base (struct objfile *objfile) | |
600 | { | |
601 | struct so_list *so; | |
602 | ||
603 | for (so = master_so_list (); so; so = so->next) | |
604 | if (so->objfile == objfile) | |
605 | return so->lm_info->desc.text_base; | |
606 | ||
607 | return 0; | |
608 | } | |
609 | ||
419b8bfb RC |
610 | static struct target_so_ops pa64_so_ops; |
611 | ||
612 | extern initialize_file_ftype _initialize_pa64_solib; /* -Wmissing-prototypes */ | |
613 | ||
614 | void | |
615 | _initialize_pa64_solib (void) | |
616 | { | |
617 | pa64_so_ops.relocate_section_addresses = pa64_relocate_section_addresses; | |
618 | pa64_so_ops.free_so = pa64_free_so; | |
619 | pa64_so_ops.clear_solib = pa64_clear_solib; | |
620 | pa64_so_ops.solib_create_inferior_hook = pa64_solib_create_inferior_hook; | |
621 | pa64_so_ops.special_symbol_handling = pa64_special_symbol_handling; | |
622 | pa64_so_ops.current_sos = pa64_current_sos; | |
623 | pa64_so_ops.open_symbol_file_object = pa64_open_symbol_file_object; | |
624 | pa64_so_ops.in_dynsym_resolve_code = pa64_in_dynsym_resolve_code; | |
831a0c44 | 625 | pa64_so_ops.bfd_open = solib_bfd_open; |
419b8bfb RC |
626 | |
627 | memset (&dld_cache, 0, sizeof (dld_cache)); | |
628 | } | |
629 | ||
d542061a | 630 | void pa64_solib_select (struct gdbarch *gdbarch) |
419b8bfb | 631 | { |
d542061a | 632 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
419b8bfb | 633 | |
433759f7 | 634 | set_solib_ops (gdbarch, &pa64_so_ops); |
419b8bfb RC |
635 | tdep->solib_thread_start_addr = pa64_solib_thread_start_addr; |
636 | tdep->solib_get_got_by_pc = pa64_solib_get_got_by_pc; | |
637 | tdep->solib_get_solib_by_pc = pa64_solib_get_solib_by_pc; | |
45851e00 | 638 | tdep->solib_get_text_base = pa64_solib_get_text_base; |
419b8bfb RC |
639 | } |
640 | ||
d542061a | 641 | #else /* HAVE_ELF_HP_H */ |
419b8bfb RC |
642 | |
643 | extern initialize_file_ftype _initialize_pa64_solib; /* -Wmissing-prototypes */ | |
644 | ||
645 | void | |
646 | _initialize_pa64_solib (void) | |
647 | { | |
648 | } | |
649 | ||
d542061a | 650 | void pa64_solib_select (struct gdbarch *gdbarch) |
419b8bfb RC |
651 | { |
652 | /* For a SOM-only target, there is no pa64 solib support. This is needed | |
653 | for hppa-hpux-tdep.c to build. */ | |
8a3fe4f8 | 654 | error (_("Cannot select pa64 solib support for this configuration.")); |
419b8bfb RC |
655 | } |
656 | #endif |