Commit | Line | Data |
---|---|---|
53a5351d | 1 | /* Handle HP ELF shared libraries for GDB, the GNU Debugger. |
c5f10366 | 2 | |
8b92e4d5 | 3 | Copyright 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, |
4646aa9d | 4 | Inc. |
53a5351d JM |
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 | |
10 | the Free Software Foundation; either version 2 of the License, or | |
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 | |
19 | along with this program; if not, write to the Free Software | |
20 | Foundation, Inc., 59 Temple Place - Suite 330, | |
21 | Boston, MA 02111-1307, USA. | |
22 | ||
23 | HP in their infinite stupidity choose not to use standard ELF dynamic | |
24 | linker interfaces. They also choose not to make their ELF dymamic | |
25 | linker interfaces compatible with the SOM dynamic linker. The | |
26 | net result is we can not use either of the existing somsolib.c or | |
27 | solib.c. What a crock. | |
28 | ||
29 | Even more disgusting. This file depends on functions provided only | |
30 | in certain PA64 libraries. Thus this file is supposed to only be | |
31 | used native. When will HP ever learn that they need to provide the | |
32 | same functionality in all their libraries! */ | |
33 | ||
34 | #include <dlfcn.h> | |
35 | #include <elf.h> | |
36 | #include <elf_hp.h> | |
37 | ||
38 | #include "defs.h" | |
39 | ||
40 | #include "frame.h" | |
41 | #include "bfd.h" | |
42 | #include "libhppa.h" | |
43 | #include "gdbcore.h" | |
44 | #include "symtab.h" | |
45 | #include "breakpoint.h" | |
46 | #include "symfile.h" | |
47 | #include "objfiles.h" | |
48 | #include "inferior.h" | |
49 | #include "gdb-stabs.h" | |
50 | #include "gdb_stat.h" | |
51 | #include "gdbcmd.h" | |
53a5351d | 52 | #include "language.h" |
4e052eda | 53 | #include "regcache.h" |
4646aa9d | 54 | #include "exec.h" |
7c46b9fb | 55 | #include "hppa-tdep.h" |
53a5351d JM |
56 | |
57 | #include <fcntl.h> | |
58 | ||
59 | #ifndef O_BINARY | |
60 | #define O_BINARY 0 | |
61 | #endif | |
62 | ||
a14ed312 | 63 | static CORE_ADDR bfd_lookup_symbol (bfd *, char *); |
53a5351d | 64 | /* This lives in hppa-tdep.c. */ |
a14ed312 | 65 | extern struct unwind_table_entry *find_unwind_entry (CORE_ADDR pc); |
53a5351d JM |
66 | |
67 | /* These ought to be defined in some public interface, but aren't. They | |
68 | identify dynamic linker events. */ | |
69 | #define DLD_CB_LOAD 1 | |
70 | #define DLD_CB_UNLOAD 0 | |
71 | ||
72 | /* A structure to keep track of all the known shared objects. */ | |
73 | struct so_list | |
74 | { | |
75 | bfd *abfd; | |
76 | char *name; | |
77 | struct so_list *next; | |
78 | struct objfile *objfile; | |
79 | CORE_ADDR pa64_solib_desc_addr; | |
80 | struct load_module_desc pa64_solib_desc; | |
81 | struct section_table *sections; | |
82 | struct section_table *sections_end; | |
2a3750c5 | 83 | int loaded; |
53a5351d JM |
84 | }; |
85 | ||
86 | static struct so_list *so_list_head; | |
87 | ||
88 | /* This is the cumulative size in bytes of the symbol tables of all | |
89 | shared objects on the so_list_head list. (When we say size, here | |
90 | we mean of the information before it is brought into memory and | |
91 | potentially expanded by GDB.) When adding a new shlib, this value | |
b7209cb4 FF |
92 | is compared against a threshold size, held by auto_solib_limit (in |
93 | megabytes). If adding symbols for the new shlib would cause the | |
94 | total size to exceed the threshold, then the new shlib's symbols | |
95 | are not loaded. */ | |
53a5351d JM |
96 | static LONGEST pa64_solib_total_st_size; |
97 | ||
98 | /* When the threshold is reached for any shlib, we refuse to add | |
99 | symbols for subsequent shlibs, even if those shlibs' symbols would | |
b7209cb4 | 100 | be small enough to fit under the threshold. Although this may |
53a5351d | 101 | result in one, early large shlib preventing the loading of later, |
b7209cb4 | 102 | smaller shlibs' symbols, it allows us to issue one informational |
53a5351d JM |
103 | message. The alternative, to issue a message for each shlib whose |
104 | symbols aren't loaded, could be a big annoyance where the threshold | |
b7209cb4 | 105 | is exceeded due to a very large number of shlibs. */ |
53a5351d JM |
106 | static int pa64_solib_st_size_threshold_exceeded; |
107 | ||
108 | /* When adding fields, be sure to clear them in _initialize_pa64_solib. */ | |
109 | typedef struct | |
110 | { | |
111 | CORE_ADDR dld_flags_addr; | |
c5f10366 | 112 | LONGEST dld_flags; |
7be0c536 | 113 | struct bfd_section *dyninfo_sect; |
2a3750c5 JB |
114 | int have_read_dld_descriptor; |
115 | int is_valid; | |
53a5351d JM |
116 | CORE_ADDR load_map; |
117 | CORE_ADDR load_map_addr; | |
118 | struct load_module_desc dld_desc; | |
119 | } | |
120 | dld_cache_t; | |
121 | ||
122 | static dld_cache_t dld_cache; | |
123 | ||
a14ed312 | 124 | static void pa64_sharedlibrary_info_command (char *, int); |
53a5351d | 125 | |
a14ed312 | 126 | static void pa64_solib_sharedlibrary_command (char *, int); |
53a5351d | 127 | |
a14ed312 | 128 | static void *pa64_target_read_memory (void *, CORE_ADDR, size_t, int); |
53a5351d | 129 | |
2a3750c5 | 130 | static int read_dld_descriptor (struct target_ops *, int readsyms); |
53a5351d | 131 | |
2a3750c5 | 132 | static int read_dynamic_info (asection *, dld_cache_t *); |
53a5351d | 133 | |
2a3750c5 | 134 | static void add_to_solist (int, char *, int, struct load_module_desc *, |
a14ed312 | 135 | CORE_ADDR, struct target_ops *); |
53a5351d JM |
136 | |
137 | /* When examining the shared library for debugging information we have to | |
138 | look for HP debug symbols, stabs and dwarf2 debug symbols. */ | |
139 | static char *pa64_debug_section_names[] = { | |
140 | ".debug_header", ".debug_gntt", ".debug_lntt", ".debug_slt", ".debug_vt", | |
141 | ".stabs", ".stabstr", ".debug_info", ".debug_abbrev", ".debug_aranges", | |
142 | ".debug_macinfo", ".debug_line", ".debug_loc", ".debug_pubnames", | |
143 | ".debug_str", NULL | |
144 | }; | |
145 | ||
146 | /* Return a ballbark figure for the amount of memory GDB will need to | |
147 | allocate to read in the debug symbols from FILENAME. */ | |
148 | static LONGEST | |
fba45db2 | 149 | pa64_solib_sizeof_symbol_table (char *filename) |
53a5351d JM |
150 | { |
151 | bfd *abfd; | |
152 | int i; | |
153 | int desc; | |
154 | char *absolute_name; | |
155 | LONGEST st_size = (LONGEST) 0; | |
156 | asection *sect; | |
157 | ||
158 | /* We believe that filename was handed to us by the dynamic linker, and | |
159 | is therefore always an absolute path. */ | |
014d698b EZ |
160 | desc = openp (getenv ("PATH"), OPF_TRY_CWD_FIRST, filename, |
161 | O_RDONLY | O_BINARY, 0, &absolute_name); | |
53a5351d JM |
162 | if (desc < 0) |
163 | { | |
164 | perror_with_name (filename); | |
165 | } | |
166 | filename = absolute_name; | |
167 | ||
168 | abfd = bfd_fdopenr (filename, gnutarget, desc); | |
169 | if (!abfd) | |
170 | { | |
171 | close (desc); | |
b8c9b27d | 172 | make_cleanup (xfree, filename); |
8a3fe4f8 | 173 | error (_("\"%s\": can't open to read symbols: %s."), filename, |
53a5351d JM |
174 | bfd_errmsg (bfd_get_error ())); |
175 | } | |
176 | ||
177 | if (!bfd_check_format (abfd, bfd_object)) | |
178 | { | |
179 | bfd_close (abfd); | |
b8c9b27d | 180 | make_cleanup (xfree, filename); |
8a3fe4f8 | 181 | error (_("\"%s\": can't read symbols: %s."), filename, |
53a5351d JM |
182 | bfd_errmsg (bfd_get_error ())); |
183 | } | |
184 | ||
185 | /* Sum the sizes of the various sections that compose debug info. */ | |
186 | for (i = 0; pa64_debug_section_names[i] != NULL; i++) | |
187 | { | |
188 | asection *sect; | |
189 | ||
190 | sect = bfd_get_section_by_name (abfd, pa64_debug_section_names[i]); | |
191 | if (sect) | |
192 | st_size += (LONGEST)bfd_section_size (abfd, sect); | |
193 | } | |
194 | ||
195 | bfd_close (abfd); | |
b8c9b27d | 196 | xfree (filename); |
53a5351d JM |
197 | |
198 | /* Unfortunately, just summing the sizes of various debug info | |
199 | sections isn't a very accurate measurement of how much heap | |
200 | space the debugger will need to hold them. It also doesn't | |
201 | account for space needed by linker (aka "minimal") symbols. | |
202 | ||
203 | Anecdotal evidence suggests that just summing the sizes of | |
204 | debug-info-related sections understates the heap space needed | |
205 | to represent it internally by about an order of magnitude. | |
206 | ||
207 | Since it's not exactly brain surgery we're doing here, rather | |
208 | than attempt to more accurately measure the size of a shlib's | |
209 | symbol table in GDB's heap, we'll just apply a 10x fudge- | |
210 | factor to the debug info sections' size-sum. No, this doesn't | |
211 | account for minimal symbols in non-debuggable shlibs. But it | |
212 | all roughly washes out in the end. */ | |
213 | return st_size * (LONGEST) 10; | |
214 | } | |
215 | ||
216 | /* Add a shared library to the objfile list and load its symbols into | |
217 | GDB's symbol table. */ | |
218 | static void | |
fba45db2 KB |
219 | pa64_solib_add_solib_objfile (struct so_list *so, char *name, int from_tty, |
220 | CORE_ADDR text_addr) | |
53a5351d JM |
221 | { |
222 | bfd *tmp_bfd; | |
223 | asection *sec; | |
7c46b9fb | 224 | struct hppa_objfile_private *obj_private; |
a39a16c4 MM |
225 | struct section_addr_info *section_addrs; |
226 | struct cleanup *my_cleanups; | |
53a5351d JM |
227 | |
228 | /* We need the BFD so that we can look at its sections. We open up the | |
229 | file temporarily, then close it when we are done. */ | |
230 | tmp_bfd = bfd_openr (name, gnutarget); | |
231 | if (tmp_bfd == NULL) | |
232 | { | |
233 | perror_with_name (name); | |
234 | return; | |
235 | } | |
236 | ||
237 | if (!bfd_check_format (tmp_bfd, bfd_object)) | |
238 | { | |
239 | bfd_close (tmp_bfd); | |
8a3fe4f8 | 240 | error (_("\"%s\" is not an object file: %s"), name, |
53a5351d JM |
241 | bfd_errmsg (bfd_get_error ())); |
242 | } | |
243 | ||
244 | ||
245 | /* Undo some braindamage from symfile.c. | |
246 | ||
247 | First, symfile.c will subtract the VMA of the first .text section | |
248 | in the shared library that it finds. Undo that. */ | |
249 | sec = bfd_get_section_by_name (tmp_bfd, ".text"); | |
250 | text_addr += bfd_section_vma (tmp_bfd, sec); | |
251 | ||
252 | /* Now find the true lowest section in the shared library. */ | |
253 | sec = NULL; | |
c5f10366 | 254 | bfd_map_over_sections (tmp_bfd, find_lowest_section, &sec); |
53a5351d JM |
255 | |
256 | if (sec) | |
257 | { | |
258 | /* Subtract out the VMA of the lowest section. */ | |
259 | text_addr -= bfd_section_vma (tmp_bfd, sec); | |
260 | ||
261 | /* ??? Add back in the filepos of that lowest section. */ | |
262 | text_addr += sec->filepos; | |
263 | } | |
264 | ||
a39a16c4 MM |
265 | section_addrs = alloc_section_addr_info (bfd_count_sections (tmp_bfd)); |
266 | my_cleanups = make_cleanup (xfree, section_addrs); | |
267 | ||
53a5351d JM |
268 | /* We are done with the temporary bfd. Get rid of it and make sure |
269 | nobody else can us it. */ | |
270 | bfd_close (tmp_bfd); | |
271 | tmp_bfd = NULL; | |
272 | ||
273 | /* Now let the generic code load up symbols for this library. */ | |
a39a16c4 MM |
274 | section_addrs->other[0].addr = text_addr; |
275 | section_addrs->other[0].name = ".text"; | |
276 | so->objfile = symbol_file_add (name, from_tty, section_addrs, 0, OBJF_SHARED); | |
53a5351d JM |
277 | so->abfd = so->objfile->obfd; |
278 | ||
279 | /* Mark this as a shared library and save private data. */ | |
280 | so->objfile->flags |= OBJF_SHARED; | |
281 | ||
7c46b9fb RC |
282 | obj_private = (struct hppa_objfile_private *) |
283 | objfile_data (so->objfile, hppa_objfile_priv_data); | |
284 | if (obj_private == NULL) | |
53a5351d | 285 | { |
7c46b9fb | 286 | obj_private = (struct hppa_objfile_private *) |
8b92e4d5 | 287 | obstack_alloc (&so->objfile->objfile_obstack, |
7c46b9fb RC |
288 | sizeof (struct hppa_objfile_private)); |
289 | set_objfile_data (so->objfile, hppa_objfile_priv_data, obj_private); | |
53a5351d JM |
290 | obj_private->unwind_info = NULL; |
291 | obj_private->so_info = NULL; | |
53a5351d JM |
292 | } |
293 | ||
53a5351d JM |
294 | obj_private->so_info = so; |
295 | obj_private->dp = so->pa64_solib_desc.linkage_ptr; | |
a39a16c4 | 296 | do_cleanups (my_cleanups); |
53a5351d JM |
297 | } |
298 | ||
299 | /* Load debugging information for a shared library. TARGET may be | |
300 | NULL if we are not attaching to a process or reading a core file. */ | |
301 | ||
302 | static void | |
fba45db2 KB |
303 | pa64_solib_load_symbols (struct so_list *so, char *name, int from_tty, |
304 | CORE_ADDR text_addr, struct target_ops *target) | |
53a5351d JM |
305 | { |
306 | struct section_table *p; | |
307 | asection *sec; | |
308 | int status; | |
309 | char buf[4]; | |
310 | CORE_ADDR presumed_data_start; | |
311 | ||
312 | if (text_addr == 0) | |
313 | text_addr = so->pa64_solib_desc.text_base; | |
314 | ||
315 | pa64_solib_add_solib_objfile (so, name, from_tty, text_addr); | |
316 | ||
317 | /* Now we need to build a section table for this library since | |
318 | we might be debugging a core file from a dynamically linked | |
319 | executable in which the libraries were not privately mapped. */ | |
320 | if (build_section_table (so->abfd, | |
321 | &so->sections, | |
322 | &so->sections_end)) | |
323 | { | |
8a3fe4f8 | 324 | error (_("Unable to build section table for shared library\n.")); |
53a5351d JM |
325 | return; |
326 | } | |
327 | ||
f0a58b0b | 328 | (so->objfile->section_offsets)->offsets[SECT_OFF_TEXT (so->objfile)] |
53a5351d | 329 | = so->pa64_solib_desc.text_base; |
f0a58b0b | 330 | (so->objfile->section_offsets)->offsets[SECT_OFF_DATA (so->objfile)] |
53a5351d JM |
331 | = so->pa64_solib_desc.data_base; |
332 | ||
333 | /* Relocate all the sections based on where they got loaded. */ | |
334 | for (p = so->sections; p < so->sections_end; p++) | |
335 | { | |
336 | if (p->the_bfd_section->flags & SEC_CODE) | |
337 | { | |
b8fbeb18 EZ |
338 | p->addr += ANOFFSET (so->objfile->section_offsets, SECT_OFF_TEXT (so->objfile)); |
339 | p->endaddr += ANOFFSET (so->objfile->section_offsets, SECT_OFF_TEXT (so->objfile)); | |
53a5351d JM |
340 | } |
341 | else if (p->the_bfd_section->flags & SEC_DATA) | |
342 | { | |
b8fbeb18 EZ |
343 | p->addr += ANOFFSET (so->objfile->section_offsets, SECT_OFF_DATA (so->objfile)); |
344 | p->endaddr += ANOFFSET (so->objfile->section_offsets, SECT_OFF_DATA (so->objfile)); | |
53a5351d JM |
345 | } |
346 | } | |
347 | ||
348 | /* Now see if we need to map in the text and data for this shared | |
349 | library (for example debugging a core file which does not use | |
350 | private shared libraries.). | |
351 | ||
352 | Carefully peek at the first text address in the library. If the | |
353 | read succeeds, then the libraries were privately mapped and were | |
354 | included in the core dump file. | |
355 | ||
356 | If the peek failed, then the libraries were not privately mapped | |
357 | and are not in the core file, we'll have to read them in ourselves. */ | |
358 | status = target_read_memory (text_addr, buf, 4); | |
359 | if (status != 0) | |
360 | { | |
6426a772 JM |
361 | int new, old; |
362 | ||
53a5351d | 363 | new = so->sections_end - so->sections; |
53a5351d | 364 | |
6426a772 JM |
365 | old = target_resize_to_sections (target, new); |
366 | ||
53a5351d JM |
367 | /* Copy over the old data before it gets clobbered. */ |
368 | memcpy ((char *) (target->to_sections + old), | |
369 | so->sections, | |
370 | ((sizeof (struct section_table)) * new)); | |
371 | } | |
372 | } | |
373 | ||
374 | ||
375 | /* Add symbols from shared libraries into the symtab list, unless the | |
b7209cb4 | 376 | size threshold specified by auto_solib_limit (in megabytes) would |
53a5351d JM |
377 | be exceeded. */ |
378 | ||
379 | void | |
990f9fe3 | 380 | pa64_solib_add (char *arg_string, int from_tty, struct target_ops *target, int readsyms) |
53a5351d JM |
381 | { |
382 | struct minimal_symbol *msymbol; | |
383 | CORE_ADDR addr; | |
384 | asection *shlib_info; | |
385 | int status; | |
386 | unsigned int dld_flags; | |
387 | char buf[4], *re_err; | |
388 | int threshold_warning_given = 0; | |
389 | int dll_index; | |
390 | struct load_module_desc dll_desc; | |
391 | char *dll_path; | |
392 | ||
393 | /* First validate our arguments. */ | |
394 | if ((re_err = re_comp (arg_string ? arg_string : ".")) != NULL) | |
395 | { | |
8a3fe4f8 | 396 | error (_("Invalid regexp: %s"), re_err); |
53a5351d JM |
397 | } |
398 | ||
399 | /* If we're debugging a core file, or have attached to a running | |
400 | process, then pa64_solib_create_inferior_hook will not have been | |
401 | called. | |
402 | ||
403 | We need to first determine if we're dealing with a dynamically | |
404 | linked executable. If not, then return without an error or warning. | |
405 | ||
beda9597 MS |
406 | We also need to examine __dld_flags to determine if the shared |
407 | library list is valid and to determine if the libraries have been | |
408 | privately mapped. */ | |
53a5351d JM |
409 | if (symfile_objfile == NULL) |
410 | return; | |
411 | ||
412 | /* First see if the objfile was dynamically linked. */ | |
413 | shlib_info = bfd_get_section_by_name (symfile_objfile->obfd, ".dynamic"); | |
414 | if (!shlib_info) | |
415 | return; | |
416 | ||
417 | /* It's got a .dynamic section, make sure it's not empty. */ | |
418 | if (bfd_section_size (symfile_objfile->obfd, shlib_info) == 0) | |
419 | return; | |
420 | ||
421 | /* Read in the load map pointer if we have not done so already. */ | |
422 | if (! dld_cache.have_read_dld_descriptor) | |
990f9fe3 | 423 | if (! read_dld_descriptor (target, readsyms)) |
53a5351d JM |
424 | return; |
425 | ||
426 | /* If the libraries were not mapped private, warn the user. */ | |
427 | if ((dld_cache.dld_flags & DT_HP_DEBUG_PRIVATE) == 0) | |
8a3fe4f8 AC |
428 | warning (_("\ |
429 | The shared libraries were not privately mapped; setting a\n\ | |
430 | breakpoint in a shared library will not work until you rerun the program.")); | |
53a5351d JM |
431 | |
432 | /* For each shaerd library, add it to the shared library list. */ | |
433 | for (dll_index = 1; ; dll_index++) | |
434 | { | |
435 | /* Read in the load module descriptor. */ | |
436 | if (dlgetmodinfo (dll_index, &dll_desc, sizeof (dll_desc), | |
437 | pa64_target_read_memory, 0, dld_cache.load_map) | |
438 | == 0) | |
439 | return; | |
440 | ||
441 | /* Get the name of the shared library. */ | |
442 | dll_path = (char *)dlgetname (&dll_desc, sizeof (dll_desc), | |
443 | pa64_target_read_memory, | |
444 | 0, dld_cache.load_map); | |
445 | ||
446 | if (!dll_path) | |
8a3fe4f8 | 447 | error (_("pa64_solib_add, unable to read shared library path.")); |
53a5351d | 448 | |
990f9fe3 | 449 | add_to_solist (from_tty, dll_path, readsyms, &dll_desc, 0, target); |
53a5351d JM |
450 | } |
451 | } | |
452 | ||
453 | ||
454 | /* This hook gets called just before the first instruction in the | |
455 | inferior process is executed. | |
456 | ||
457 | This is our opportunity to set magic flags in the inferior so | |
458 | that GDB can be notified when a shared library is mapped in and | |
459 | to tell the dynamic linker that a private copy of the library is | |
460 | needed (so GDB can set breakpoints in the library). | |
461 | ||
462 | We need to set two flag bits in this routine. | |
463 | ||
464 | DT_HP_DEBUG_PRIVATE to indicate that shared libraries should be | |
465 | mapped private. | |
466 | ||
beda9597 MS |
467 | DT_HP_DEBUG_CALLBACK to indicate that we want the dynamic linker |
468 | to call the breakpoint routine for significant events. */ | |
53a5351d JM |
469 | |
470 | void | |
fba45db2 | 471 | pa64_solib_create_inferior_hook (void) |
53a5351d JM |
472 | { |
473 | struct minimal_symbol *msymbol; | |
474 | unsigned int dld_flags, status; | |
475 | asection *shlib_info, *interp_sect; | |
476 | char buf[4]; | |
477 | struct objfile *objfile; | |
478 | CORE_ADDR anaddr; | |
479 | ||
480 | /* First, remove all the solib event breakpoints. Their addresses | |
481 | may have changed since the last time we ran the program. */ | |
482 | remove_solib_event_breakpoints (); | |
483 | ||
484 | if (symfile_objfile == NULL) | |
485 | return; | |
486 | ||
487 | /* First see if the objfile was dynamically linked. */ | |
488 | shlib_info = bfd_get_section_by_name (symfile_objfile->obfd, ".dynamic"); | |
489 | if (!shlib_info) | |
490 | return; | |
491 | ||
492 | /* It's got a .dynamic section, make sure it's not empty. */ | |
493 | if (bfd_section_size (symfile_objfile->obfd, shlib_info) == 0) | |
494 | return; | |
495 | ||
53a5351d JM |
496 | /* Read in the .dynamic section. */ |
497 | if (! read_dynamic_info (shlib_info, &dld_cache)) | |
8a3fe4f8 | 498 | error (_("Unable to read the .dynamic section.")); |
53a5351d JM |
499 | |
500 | /* Turn on the flags we care about. */ | |
501 | dld_cache.dld_flags |= DT_HP_DEBUG_PRIVATE; | |
53a5351d | 502 | dld_cache.dld_flags |= DT_HP_DEBUG_CALLBACK; |
53a5351d JM |
503 | status = target_write_memory (dld_cache.dld_flags_addr, |
504 | (char *) &dld_cache.dld_flags, | |
505 | sizeof (dld_cache.dld_flags)); | |
506 | if (status != 0) | |
8a3fe4f8 | 507 | error (_("Unable to modify dynamic linker flags.")); |
53a5351d JM |
508 | |
509 | /* Now we have to create a shared library breakpoint in the dynamic | |
510 | linker. This can be somewhat tricky since the symbol is inside | |
511 | the dynamic linker (for which we do not have symbols or a base | |
512 | load address! Luckily I wrote this code for solib.c years ago. */ | |
513 | interp_sect = bfd_get_section_by_name (exec_bfd, ".interp"); | |
514 | if (interp_sect) | |
515 | { | |
516 | unsigned int interp_sect_size; | |
517 | char *buf; | |
518 | CORE_ADDR load_addr; | |
519 | bfd *tmp_bfd; | |
520 | CORE_ADDR sym_addr = 0; | |
521 | ||
522 | /* Read the contents of the .interp section into a local buffer; | |
523 | the contents specify the dynamic linker this program uses. */ | |
524 | interp_sect_size = bfd_section_size (exec_bfd, interp_sect); | |
525 | buf = alloca (interp_sect_size); | |
526 | bfd_get_section_contents (exec_bfd, interp_sect, | |
527 | buf, 0, interp_sect_size); | |
528 | ||
529 | /* Now we need to figure out where the dynamic linker was | |
530 | loaded so that we can load its symbols and place a breakpoint | |
531 | in the dynamic linker itself. | |
532 | ||
533 | This address is stored on the stack. However, I've been unable | |
534 | to find any magic formula to find it for Solaris (appears to | |
535 | be trivial on GNU/Linux). Therefore, we have to try an alternate | |
536 | mechanism to find the dynamic linker's base address. */ | |
537 | tmp_bfd = bfd_openr (buf, gnutarget); | |
538 | if (tmp_bfd == NULL) | |
539 | goto get_out; | |
540 | ||
541 | /* Make sure the dynamic linker's really a useful object. */ | |
542 | if (!bfd_check_format (tmp_bfd, bfd_object)) | |
543 | { | |
8a3fe4f8 | 544 | warning (_("Unable to grok dynamic linker %s as an object file"), buf); |
53a5351d JM |
545 | bfd_close (tmp_bfd); |
546 | goto get_out; | |
547 | } | |
548 | ||
549 | /* We find the dynamic linker's base address by examining the | |
550 | current pc (which point at the entry point for the dynamic | |
551 | linker) and subtracting the offset of the entry point. | |
552 | ||
553 | Also note the breakpoint is the second instruction in the | |
554 | routine. */ | |
555 | load_addr = read_pc () - tmp_bfd->start_address; | |
556 | sym_addr = bfd_lookup_symbol (tmp_bfd, "__dld_break"); | |
557 | sym_addr = load_addr + sym_addr + 4; | |
558 | ||
559 | /* Create the shared library breakpoint. */ | |
c2c6d25f JM |
560 | { |
561 | struct breakpoint *b | |
562 | = create_solib_event_breakpoint (sym_addr); | |
563 | ||
564 | /* The breakpoint is actually hard-coded into the dynamic linker, | |
565 | so we don't need to actually insert a breakpoint instruction | |
566 | there. In fact, the dynamic linker's code is immutable, even to | |
567 | ttrace, so we shouldn't even try to do that. For cases like | |
568 | this, we have "permanent" breakpoints. */ | |
569 | make_breakpoint_permanent (b); | |
570 | } | |
53a5351d JM |
571 | |
572 | /* We're done with the temporary bfd. */ | |
573 | bfd_close (tmp_bfd); | |
574 | } | |
575 | ||
576 | get_out: | |
577 | /* Wipe out all knowledge of old shared libraries since their | |
578 | mapping can change from one exec to another! */ | |
579 | while (so_list_head) | |
580 | { | |
581 | struct so_list *temp; | |
582 | ||
583 | temp = so_list_head; | |
b8c9b27d | 584 | xfree (so_list_head); |
53a5351d JM |
585 | so_list_head = temp->next; |
586 | } | |
587 | clear_symtab_users (); | |
588 | } | |
589 | ||
590 | /* This operation removes the "hook" between GDB and the dynamic linker, | |
591 | which causes the dld to notify GDB of shared library events. | |
592 | ||
593 | After this operation completes, the dld will no longer notify GDB of | |
594 | shared library events. To resume notifications, GDB must call | |
595 | pa64_solib_create_inferior_hook. | |
596 | ||
beda9597 MS |
597 | This operation does not remove any knowledge of shared libraries |
598 | of which GDB may already have been notified. */ | |
53a5351d JM |
599 | |
600 | void | |
fba45db2 | 601 | pa64_solib_remove_inferior_hook (int pid) |
53a5351d JM |
602 | { |
603 | /* Turn off the DT_HP_DEBUG_CALLBACK bit in the dynamic linker flags. */ | |
604 | dld_cache.dld_flags &= ~DT_HP_DEBUG_CALLBACK; | |
605 | target_write_memory (dld_cache.dld_flags_addr, | |
606 | (char *)&dld_cache.dld_flags, | |
607 | sizeof (dld_cache.dld_flags)); | |
608 | } | |
609 | ||
610 | /* This function creates a breakpoint on the dynamic linker hook, which | |
611 | is called when e.g., a shl_load or shl_unload call is made. This | |
612 | breakpoint will only trigger when a shl_load call is made. | |
613 | ||
614 | If filename is NULL, then loads of any dll will be caught. Else, | |
615 | only loads of the file whose pathname is the string contained by | |
616 | filename will be caught. | |
617 | ||
618 | Undefined behaviour is guaranteed if this function is called before | |
619 | pa64_solib_create_inferior_hook. */ | |
620 | ||
621 | void | |
fba45db2 KB |
622 | pa64_solib_create_catch_load_hook (int pid, int tempflag, char *filename, |
623 | char *cond_string) | |
53a5351d JM |
624 | { |
625 | create_solib_load_event_breakpoint ("", tempflag, filename, cond_string); | |
626 | } | |
627 | ||
628 | /* This function creates a breakpoint on the dynamic linker hook, which | |
629 | is called when e.g., a shl_load or shl_unload call is made. This | |
630 | breakpoint will only trigger when a shl_unload call is made. | |
631 | ||
632 | If filename is NULL, then unloads of any dll will be caught. Else, | |
633 | only unloads of the file whose pathname is the string contained by | |
634 | filename will be caught. | |
635 | ||
636 | Undefined behaviour is guaranteed if this function is called before | |
637 | pa64_solib_create_inferior_hook. */ | |
638 | ||
639 | void | |
fba45db2 KB |
640 | pa64_solib_create_catch_unload_hook (int pid, int tempflag, char *filename, |
641 | char *cond_string) | |
53a5351d JM |
642 | { |
643 | create_solib_unload_event_breakpoint ("", tempflag, filename, cond_string); | |
644 | } | |
645 | ||
646 | /* Return nonzero if the dynamic linker has reproted that a library | |
647 | has been loaded. */ | |
648 | ||
649 | int | |
fba45db2 | 650 | pa64_solib_have_load_event (int pid) |
53a5351d JM |
651 | { |
652 | CORE_ADDR event_kind; | |
653 | ||
34f75cc1 | 654 | event_kind = read_register (HPPA_ARG0_REGNUM); |
53a5351d JM |
655 | return (event_kind == DLD_CB_LOAD); |
656 | } | |
657 | ||
658 | /* Return nonzero if the dynamic linker has reproted that a library | |
659 | has been unloaded. */ | |
660 | int | |
fba45db2 | 661 | pa64_solib_have_unload_event (int pid) |
53a5351d JM |
662 | { |
663 | CORE_ADDR event_kind; | |
664 | ||
34f75cc1 | 665 | event_kind = read_register (HPPA_ARG0_REGNUM); |
53a5351d JM |
666 | return (event_kind == DLD_CB_UNLOAD); |
667 | } | |
668 | ||
669 | /* Return a pointer to a string indicating the pathname of the most | |
670 | recently loaded library. | |
671 | ||
672 | The caller is reposible for copying the string before the inferior is | |
673 | restarted. */ | |
674 | ||
675 | char * | |
fba45db2 | 676 | pa64_solib_loaded_library_pathname (int pid) |
53a5351d JM |
677 | { |
678 | static char dll_path[MAXPATHLEN]; | |
34f75cc1 | 679 | CORE_ADDR dll_path_addr = read_register (HPPA_ARG3_REGNUM); |
53a5351d JM |
680 | read_memory_string (dll_path_addr, dll_path, MAXPATHLEN); |
681 | return dll_path; | |
682 | } | |
683 | ||
684 | /* Return a pointer to a string indicating the pathname of the most | |
685 | recently unloaded library. | |
686 | ||
687 | The caller is reposible for copying the string before the inferior is | |
688 | restarted. */ | |
689 | ||
690 | char * | |
fba45db2 | 691 | pa64_solib_unloaded_library_pathname (int pid) |
53a5351d JM |
692 | { |
693 | static char dll_path[MAXPATHLEN]; | |
34f75cc1 | 694 | CORE_ADDR dll_path_addr = read_register (HPPA_ARG3_REGNUM); |
53a5351d JM |
695 | read_memory_string (dll_path_addr, dll_path, MAXPATHLEN); |
696 | return dll_path; | |
697 | } | |
698 | ||
699 | /* Return nonzero if PC is an address inside the dynamic linker. */ | |
700 | ||
701 | int | |
fba45db2 | 702 | pa64_solib_in_dynamic_linker (int pid, CORE_ADDR pc) |
53a5351d JM |
703 | { |
704 | asection *shlib_info; | |
705 | ||
706 | if (symfile_objfile == NULL) | |
707 | return 0; | |
708 | ||
709 | if (!dld_cache.have_read_dld_descriptor) | |
990f9fe3 | 710 | if (!read_dld_descriptor (¤t_target, auto_solib_add)) |
53a5351d JM |
711 | return 0; |
712 | ||
713 | return (pc >= dld_cache.dld_desc.text_base | |
714 | && pc < dld_cache.dld_desc.text_base + dld_cache.dld_desc.text_size); | |
715 | } | |
716 | ||
717 | ||
718 | /* Return the GOT value for the shared library in which ADDR belongs. If | |
719 | ADDR isn't in any known shared library, return zero. */ | |
720 | ||
721 | CORE_ADDR | |
fba45db2 | 722 | pa64_solib_get_got_by_pc (CORE_ADDR addr) |
53a5351d JM |
723 | { |
724 | struct so_list *so_list = so_list_head; | |
725 | CORE_ADDR got_value = 0; | |
726 | ||
727 | while (so_list) | |
728 | { | |
729 | if (so_list->pa64_solib_desc.text_base <= addr | |
730 | && ((so_list->pa64_solib_desc.text_base | |
731 | + so_list->pa64_solib_desc.text_size) | |
732 | > addr)) | |
733 | { | |
734 | got_value = so_list->pa64_solib_desc.linkage_ptr; | |
735 | break; | |
736 | } | |
737 | so_list = so_list->next; | |
738 | } | |
739 | return got_value; | |
740 | } | |
741 | ||
742 | /* Return the address of the handle of the shared library in which ADDR | |
743 | belongs. If ADDR isn't in any known shared library, return zero. | |
744 | ||
745 | This function is used in hppa_fix_call_dummy in hppa-tdep.c. */ | |
746 | ||
747 | CORE_ADDR | |
fba45db2 | 748 | pa64_solib_get_solib_by_pc (CORE_ADDR addr) |
53a5351d JM |
749 | { |
750 | struct so_list *so_list = so_list_head; | |
751 | CORE_ADDR retval = 0; | |
752 | ||
753 | while (so_list) | |
754 | { | |
755 | if (so_list->pa64_solib_desc.text_base <= addr | |
756 | && ((so_list->pa64_solib_desc.text_base | |
757 | + so_list->pa64_solib_desc.text_size) | |
758 | > addr)) | |
759 | { | |
760 | retval = so_list->pa64_solib_desc_addr; | |
761 | break; | |
762 | } | |
763 | so_list = so_list->next; | |
764 | } | |
765 | return retval; | |
766 | } | |
767 | ||
768 | /* Dump information about all the currently loaded shared libraries. */ | |
769 | ||
770 | static void | |
fba45db2 | 771 | pa64_sharedlibrary_info_command (char *ignore, int from_tty) |
53a5351d JM |
772 | { |
773 | struct so_list *so_list = so_list_head; | |
774 | ||
775 | if (exec_bfd == NULL) | |
776 | { | |
4ce44c66 | 777 | printf_unfiltered ("No executable file.\n"); |
53a5351d JM |
778 | return; |
779 | } | |
780 | ||
781 | if (so_list == NULL) | |
782 | { | |
783 | printf_unfiltered ("No shared libraries loaded at this time.\n"); | |
784 | return; | |
785 | } | |
786 | ||
787 | printf_unfiltered ("Shared Object Libraries\n"); | |
c2c6d25f JM |
788 | printf_unfiltered (" %-19s%-19s%-19s%-19s\n", |
789 | " text start", " text end", | |
790 | " data start", " data end"); | |
53a5351d JM |
791 | while (so_list) |
792 | { | |
793 | unsigned int flags; | |
794 | ||
795 | printf_unfiltered ("%s", so_list->name); | |
796 | if (so_list->objfile == NULL) | |
797 | printf_unfiltered (" (symbols not loaded)"); | |
798 | if (so_list->loaded == 0) | |
799 | printf_unfiltered (" (shared library unloaded)"); | |
800 | printf_unfiltered (" %-18s", | |
bb599908 | 801 | hex_string_custom (so_list->pa64_solib_desc.linkage_ptr, 16)); |
53a5351d JM |
802 | printf_unfiltered ("\n"); |
803 | printf_unfiltered ("%-18s", | |
bb599908 | 804 | hex_string_custom (so_list->pa64_solib_desc.text_base, 16)); |
53a5351d | 805 | printf_unfiltered (" %-18s", |
bb599908 PH |
806 | hex_string_custom ((so_list->pa64_solib_desc.text_base |
807 | + so_list->pa64_solib_desc.text_size), 16)); | |
53a5351d | 808 | printf_unfiltered (" %-18s", |
bb599908 | 809 | hex_string_custom (so_list->pa64_solib_desc.data_base, 16)); |
53a5351d | 810 | printf_unfiltered (" %-18s\n", |
bb599908 PH |
811 | hex_string_custom ((so_list->pa64_solib_desc.data_base |
812 | + so_list->pa64_solib_desc.data_size), 16)); | |
53a5351d JM |
813 | so_list = so_list->next; |
814 | } | |
815 | } | |
816 | ||
817 | /* Load up one or more shared libraries as directed by the user. */ | |
818 | ||
819 | static void | |
fba45db2 | 820 | pa64_solib_sharedlibrary_command (char *args, int from_tty) |
53a5351d JM |
821 | { |
822 | dont_repeat (); | |
990f9fe3 | 823 | pa64_solib_add (args, from_tty, (struct target_ops *) 0, 1); |
53a5351d JM |
824 | } |
825 | ||
826 | /* Return the name of the shared library containing ADDR or NULL if ADDR | |
827 | is not contained in any known shared library. */ | |
828 | ||
829 | char * | |
fba45db2 | 830 | pa64_solib_address (CORE_ADDR addr) |
53a5351d JM |
831 | { |
832 | struct so_list *so = so_list_head; | |
833 | ||
834 | while (so) | |
835 | { | |
836 | /* Is this address within this shlib's text range? If so, | |
837 | return the shlib's name. */ | |
838 | if (addr >= so->pa64_solib_desc.text_base | |
839 | && addr < (so->pa64_solib_desc.text_base | |
840 | | so->pa64_solib_desc.text_size)) | |
841 | return so->name; | |
842 | ||
843 | /* Nope, keep looking... */ | |
844 | so = so->next; | |
845 | } | |
846 | ||
847 | /* No, we couldn't prove that the address is within a shlib. */ | |
848 | return NULL; | |
849 | } | |
850 | ||
851 | /* We are killing the inferior and restarting the program. */ | |
852 | ||
853 | void | |
fba45db2 | 854 | pa64_solib_restart (void) |
53a5351d JM |
855 | { |
856 | struct so_list *sl = so_list_head; | |
857 | ||
858 | /* Before the shlib info vanishes, use it to disable any breakpoints | |
859 | that may still be active in those shlibs. */ | |
860 | disable_breakpoints_in_shlibs (0); | |
861 | ||
862 | /* Discard all the shlib descriptors. */ | |
863 | while (sl) | |
864 | { | |
865 | struct so_list *next_sl = sl->next; | |
b8c9b27d | 866 | xfree (sl); |
53a5351d JM |
867 | sl = next_sl; |
868 | } | |
869 | so_list_head = NULL; | |
870 | ||
871 | pa64_solib_total_st_size = (LONGEST) 0; | |
872 | pa64_solib_st_size_threshold_exceeded = 0; | |
873 | ||
874 | dld_cache.is_valid = 0; | |
875 | dld_cache.have_read_dld_descriptor = 0; | |
876 | dld_cache.dld_flags_addr = 0; | |
877 | dld_cache.load_map = 0; | |
878 | dld_cache.load_map_addr = 0; | |
879 | dld_cache.dld_desc.data_base = 0; | |
880 | dld_cache.dld_flags = 0; | |
881 | dld_cache.dyninfo_sect = 0; | |
882 | } | |
883 | ||
884 | void | |
fba45db2 | 885 | _initialize_pa64_solib (void) |
53a5351d JM |
886 | { |
887 | add_com ("sharedlibrary", class_files, pa64_solib_sharedlibrary_command, | |
1bedd215 | 888 | _("Load shared object library symbols for files matching REGEXP.")); |
53a5351d | 889 | add_info ("sharedlibrary", pa64_sharedlibrary_info_command, |
1bedd215 | 890 | _("Status of loaded shared object libraries.")); |
b7209cb4 | 891 | |
5bf193a2 AC |
892 | add_setshow_boolean_cmd ("auto-solib-add", class_support, |
893 | &auto_solib_add, _("\ | |
894 | Set autoloading of shared library symbols."), _("\ | |
895 | Show autoloading of shared library symbols."), _("\ | |
b7209cb4 FF |
896 | If \"on\", symbols from all shared object libraries will be loaded\n\ |
897 | automatically when the inferior begins execution, when the dynamic linker\n\ | |
898 | informs gdb that a new library has been loaded, or when attaching to the\n\ | |
5bf193a2 AC |
899 | inferior. Otherwise, symbols must be loaded manually, using `sharedlibrary'."), |
900 | NULL, | |
901 | NULL, /* FIXME: i18n: */ | |
902 | &setlist, &showlist); | |
b7209cb4 | 903 | |
85c07804 AC |
904 | add_setshow_zinteger_cmd ("auto-solib-limit", class_support, |
905 | &auto_solib_limit, _("\ | |
906 | Set threshold (in Mb) for autoloading shared library symbols."), _("\ | |
907 | Show threshold (in Mb) for autoloading shared library symbols."), _("\ | |
b7209cb4 FF |
908 | When shared library autoloading is enabled, new libraries will be loaded\n\ |
909 | only until the total size of shared library symbols exceeds this\n\ | |
85c07804 AC |
910 | threshold in megabytes. Is ignored when using `sharedlibrary'."), |
911 | NULL, | |
912 | NULL, /* FIXME: i18n: */ | |
913 | &setlist, &showlist); | |
53a5351d | 914 | |
b7209cb4 FF |
915 | /* ??rehrauer: On HP-UX, the kernel parameter MAXDSIZ limits how |
916 | much data space a process can use. We ought to be reading | |
917 | MAXDSIZ and setting auto_solib_limit to some large fraction of | |
918 | that value. If not that, we maybe ought to be setting it smaller | |
919 | than the default for MAXDSIZ (that being 64Mb, I believe). | |
920 | However, [1] this threshold is only crudely approximated rather | |
921 | than actually measured, and [2] 50 Mbytes is too small for | |
922 | debugging gdb itself. Thus, the arbitrary 100 figure. */ | |
923 | auto_solib_limit = 100; /* Megabytes */ | |
53a5351d JM |
924 | |
925 | pa64_solib_restart (); | |
926 | } | |
927 | ||
928 | /* Get some HPUX-specific data from a shared lib. */ | |
929 | CORE_ADDR | |
b82f24bf | 930 | pa64_solib_thread_start_addr (struct so_list *so) |
53a5351d JM |
931 | { |
932 | return so->pa64_solib_desc.tls_start_addr; | |
933 | } | |
934 | ||
935 | /* Read the dynamic linker's internal shared library descriptor. | |
936 | ||
937 | This must happen after dld starts running, so we can't do it in | |
938 | read_dynamic_info. Record the fact that we have loaded the | |
939 | descriptor. If the library is archive bound, then return zero, else | |
940 | return nonzero. */ | |
941 | ||
2a3750c5 | 942 | static int |
990f9fe3 | 943 | read_dld_descriptor (struct target_ops *target, int readsyms) |
53a5351d JM |
944 | { |
945 | char *dll_path; | |
946 | asection *dyninfo_sect; | |
947 | ||
948 | /* If necessary call read_dynamic_info to extract the contents of the | |
949 | .dynamic section from the shared library. */ | |
950 | if (!dld_cache.is_valid) | |
951 | { | |
952 | if (symfile_objfile == NULL) | |
8a3fe4f8 | 953 | error (_("No object file symbols.")); |
53a5351d JM |
954 | |
955 | dyninfo_sect = bfd_get_section_by_name (symfile_objfile->obfd, | |
956 | ".dynamic"); | |
957 | if (!dyninfo_sect) | |
958 | { | |
959 | return 0; | |
960 | } | |
961 | ||
962 | if (!read_dynamic_info (dyninfo_sect, &dld_cache)) | |
8a3fe4f8 | 963 | error (_("Unable to read in .dynamic section information.")); |
53a5351d JM |
964 | } |
965 | ||
966 | /* Read the load map pointer. */ | |
967 | if (target_read_memory (dld_cache.load_map_addr, | |
968 | (char*) &dld_cache.load_map, | |
969 | sizeof(dld_cache.load_map)) | |
970 | != 0) | |
971 | { | |
8a3fe4f8 | 972 | error (_("Error while reading in load map pointer.")); |
53a5351d JM |
973 | } |
974 | ||
975 | /* Read in the dld load module descriptor */ | |
976 | if (dlgetmodinfo (-1, | |
977 | &dld_cache.dld_desc, | |
978 | sizeof(dld_cache.dld_desc), | |
979 | pa64_target_read_memory, | |
980 | 0, | |
981 | dld_cache.load_map) | |
982 | == 0) | |
983 | { | |
8a3fe4f8 | 984 | error (_("Error trying to get information about dynamic linker.")); |
53a5351d JM |
985 | } |
986 | ||
987 | /* Indicate that we have loaded the dld descriptor. */ | |
988 | dld_cache.have_read_dld_descriptor = 1; | |
989 | ||
990 | /* Add dld.sl to the list of known shared libraries so that we can | |
991 | do unwind, etc. | |
992 | ||
993 | ?!? This may not be correct. Consider of dld.sl contains symbols | |
994 | which are also referenced/defined by the user program or some user | |
995 | shared library. We need to make absolutely sure that we do not | |
996 | pollute the namespace from GDB's point of view. */ | |
997 | dll_path = dlgetname (&dld_cache.dld_desc, | |
998 | sizeof(dld_cache.dld_desc), | |
999 | pa64_target_read_memory, | |
1000 | 0, | |
1001 | dld_cache.load_map); | |
990f9fe3 | 1002 | add_to_solist(0, dll_path, readsyms, &dld_cache.dld_desc, 0, target); |
53a5351d JM |
1003 | |
1004 | return 1; | |
1005 | } | |
1006 | ||
1007 | /* Read the .dynamic section and extract the information of interest, | |
1008 | which is stored in dld_cache. The routine elf_locate_base in solib.c | |
1009 | was used as a model for this. */ | |
1010 | ||
2a3750c5 | 1011 | static int |
fba45db2 | 1012 | read_dynamic_info (asection *dyninfo_sect, dld_cache_t *dld_cache_p) |
53a5351d JM |
1013 | { |
1014 | char *buf; | |
1015 | char *bufend; | |
1016 | CORE_ADDR dyninfo_addr; | |
1017 | int dyninfo_sect_size; | |
1018 | CORE_ADDR entry_addr; | |
1019 | ||
1020 | /* Read in .dynamic section, silently ignore errors. */ | |
1021 | dyninfo_addr = bfd_section_vma (symfile_objfile->obfd, dyninfo_sect); | |
1022 | dyninfo_sect_size = bfd_section_size (exec_bfd, dyninfo_sect); | |
1023 | buf = alloca (dyninfo_sect_size); | |
1024 | if (target_read_memory (dyninfo_addr, buf, dyninfo_sect_size)) | |
1025 | return 0; | |
1026 | ||
1027 | /* Scan the .dynamic section and record the items of interest. | |
1028 | In particular, DT_HP_DLD_FLAGS */ | |
1029 | for (bufend = buf + dyninfo_sect_size, entry_addr = dyninfo_addr; | |
1030 | buf < bufend; | |
1031 | buf += sizeof (Elf64_Dyn), entry_addr += sizeof (Elf64_Dyn)) | |
1032 | { | |
1033 | Elf64_Dyn *x_dynp = (Elf64_Dyn*)buf; | |
1034 | Elf64_Sxword dyn_tag; | |
1035 | CORE_ADDR dyn_ptr; | |
35fc8285 | 1036 | char *pbuf; |
53a5351d | 1037 | |
35fc8285 | 1038 | pbuf = alloca (TARGET_PTR_BIT / HOST_CHAR_BIT); |
53a5351d JM |
1039 | dyn_tag = bfd_h_get_64 (symfile_objfile->obfd, |
1040 | (bfd_byte*) &x_dynp->d_tag); | |
1041 | ||
1042 | /* We can't use a switch here because dyn_tag is 64 bits and HP's | |
1043 | lame comiler does not handle 64bit items in switch statements. */ | |
1044 | if (dyn_tag == DT_NULL) | |
1045 | break; | |
1046 | else if (dyn_tag == DT_HP_DLD_FLAGS) | |
1047 | { | |
1048 | /* Set dld_flags_addr and dld_flags in *dld_cache_p */ | |
1049 | dld_cache_p->dld_flags_addr = entry_addr + offsetof(Elf64_Dyn, d_un); | |
1050 | if (target_read_memory (dld_cache_p->dld_flags_addr, | |
1051 | (char*) &dld_cache_p->dld_flags, | |
1052 | sizeof(dld_cache_p->dld_flags)) | |
1053 | != 0) | |
1054 | { | |
8a3fe4f8 | 1055 | error (_("Error while reading in .dynamic section of the program.")); |
53a5351d JM |
1056 | } |
1057 | } | |
1058 | else if (dyn_tag == DT_HP_LOAD_MAP) | |
1059 | { | |
1060 | /* Dld will place the address of the load map at load_map_addr | |
1061 | after it starts running. */ | |
1062 | if (target_read_memory (entry_addr + offsetof(Elf64_Dyn, | |
1063 | d_un.d_ptr), | |
1064 | (char*) &dld_cache_p->load_map_addr, | |
1065 | sizeof(dld_cache_p->load_map_addr)) | |
1066 | != 0) | |
1067 | { | |
8a3fe4f8 | 1068 | error (_("Error while reading in .dynamic section of the program.")); |
53a5351d JM |
1069 | } |
1070 | } | |
1071 | else | |
1072 | { | |
1073 | /* tag is not of interest */ | |
1074 | } | |
1075 | } | |
1076 | ||
1077 | /* Record other information and set is_valid to 1. */ | |
1078 | dld_cache_p->dyninfo_sect = dyninfo_sect; | |
1079 | ||
1080 | /* Verify that we read in required info. These fields are re-set to zero | |
1081 | in pa64_solib_restart. */ | |
1082 | ||
1083 | if (dld_cache_p->dld_flags_addr != 0 && dld_cache_p->load_map_addr != 0) | |
1084 | dld_cache_p->is_valid = 1; | |
1085 | else | |
1086 | return 0; | |
1087 | ||
1088 | return 1; | |
1089 | } | |
1090 | ||
1091 | /* Wrapper for target_read_memory to make dlgetmodinfo happy. */ | |
1092 | ||
1093 | static void * | |
fba45db2 | 1094 | pa64_target_read_memory (void *buffer, CORE_ADDR ptr, size_t bufsiz, int ident) |
53a5351d JM |
1095 | { |
1096 | if (target_read_memory (ptr, buffer, bufsiz) != 0) | |
1097 | return 0; | |
1098 | return buffer; | |
1099 | } | |
1100 | ||
1101 | /* Called from handle_dynlink_load_event and pa64_solib_add to add | |
1102 | a shared library to so_list_head list and possibly to read in the | |
1103 | debug information for the library. | |
1104 | ||
1105 | If load_module_desc_p is NULL, then the load module descriptor must | |
1106 | be read from the inferior process at the address load_module_desc_addr. */ | |
1107 | ||
1108 | static void | |
2a3750c5 | 1109 | add_to_solist (int from_tty, char *dll_path, int readsyms, |
fba45db2 KB |
1110 | struct load_module_desc *load_module_desc_p, |
1111 | CORE_ADDR load_module_desc_addr, struct target_ops *target) | |
53a5351d JM |
1112 | { |
1113 | struct so_list *new_so, *so_list_tail; | |
1114 | int pa64_solib_st_size_threshhold_exceeded; | |
1115 | LONGEST st_size; | |
1116 | ||
1117 | if (symfile_objfile == NULL) | |
1118 | return; | |
1119 | ||
1120 | so_list_tail = so_list_head; | |
1121 | /* Find the end of the list of shared objects. */ | |
1122 | while (so_list_tail && so_list_tail->next) | |
1123 | { | |
1124 | if (strcmp (so_list_tail->name, dll_path) == 0) | |
1125 | return; | |
1126 | so_list_tail = so_list_tail->next; | |
1127 | } | |
1128 | ||
1129 | if (so_list_tail && strcmp (so_list_tail->name, dll_path) == 0) | |
1130 | return; | |
1131 | ||
1132 | /* Add the shared library to the so_list_head list */ | |
1133 | new_so = (struct so_list *) xmalloc (sizeof (struct so_list)); | |
1134 | memset ((char *)new_so, 0, sizeof (struct so_list)); | |
1135 | if (so_list_head == NULL) | |
1136 | { | |
1137 | so_list_head = new_so; | |
1138 | so_list_tail = new_so; | |
1139 | } | |
1140 | else | |
1141 | { | |
1142 | so_list_tail->next = new_so; | |
1143 | so_list_tail = new_so; | |
1144 | } | |
1145 | ||
1146 | /* Initialize the new_so */ | |
1147 | if (load_module_desc_p) | |
1148 | { | |
1149 | new_so->pa64_solib_desc = *load_module_desc_p; | |
1150 | } | |
1151 | else | |
1152 | { | |
1153 | if (target_read_memory (load_module_desc_addr, | |
1154 | (char*) &new_so->pa64_solib_desc, | |
1155 | sizeof(struct load_module_desc)) | |
1156 | != 0) | |
1157 | { | |
8a3fe4f8 | 1158 | error (_("Error while reading in dynamic library %s"), dll_path); |
53a5351d JM |
1159 | } |
1160 | } | |
1161 | ||
1162 | new_so->pa64_solib_desc_addr = load_module_desc_addr; | |
1163 | new_so->loaded = 1; | |
1164 | new_so->name = obsavestring (dll_path, strlen(dll_path), | |
4a146b47 | 1165 | &symfile_objfile->objfile_obstack); |
53a5351d JM |
1166 | |
1167 | /* If we are not going to load the library, tell the user if we | |
1168 | haven't already and return. */ | |
1169 | ||
1170 | st_size = pa64_solib_sizeof_symbol_table (dll_path); | |
1171 | pa64_solib_st_size_threshhold_exceeded = | |
1172 | !from_tty | |
990f9fe3 | 1173 | && readsyms |
53a5351d | 1174 | && ( (st_size + pa64_solib_total_st_size) |
c3c057c8 | 1175 | > (auto_solib_limit * (LONGEST) (1024 * 1024))); |
53a5351d JM |
1176 | if (pa64_solib_st_size_threshhold_exceeded) |
1177 | { | |
1178 | pa64_solib_add_solib_objfile (new_so, dll_path, from_tty, 1); | |
1179 | return; | |
1180 | } | |
1181 | ||
1182 | /* Now read in debug info. */ | |
1183 | pa64_solib_total_st_size += st_size; | |
1184 | ||
1185 | /* This fills in new_so->objfile, among others. */ | |
1186 | pa64_solib_load_symbols (new_so, | |
1187 | dll_path, | |
1188 | from_tty, | |
b57d7d21 JL |
1189 | 0, |
1190 | target); | |
53a5351d JM |
1191 | return; |
1192 | } | |
1193 | ||
1194 | ||
1195 | /* | |
1196 | LOCAL FUNCTION | |
1197 | ||
1198 | bfd_lookup_symbol -- lookup the value for a specific symbol | |
1199 | ||
1200 | SYNOPSIS | |
1201 | ||
1202 | CORE_ADDR bfd_lookup_symbol (bfd *abfd, char *symname) | |
1203 | ||
1204 | DESCRIPTION | |
1205 | ||
1206 | An expensive way to lookup the value of a single symbol for | |
1207 | bfd's that are only temporary anyway. This is used by the | |
1208 | shared library support to find the address of the debugger | |
1209 | interface structures in the shared library. | |
1210 | ||
1211 | Note that 0 is specifically allowed as an error return (no | |
1212 | such symbol). | |
1213 | */ | |
1214 | ||
1215 | static CORE_ADDR | |
fba45db2 | 1216 | bfd_lookup_symbol (bfd *abfd, char *symname) |
53a5351d JM |
1217 | { |
1218 | unsigned int storage_needed; | |
1219 | asymbol *sym; | |
1220 | asymbol **symbol_table; | |
1221 | unsigned int number_of_symbols; | |
1222 | unsigned int i; | |
1223 | struct cleanup *back_to; | |
1224 | CORE_ADDR symaddr = 0; | |
1225 | ||
1226 | storage_needed = bfd_get_symtab_upper_bound (abfd); | |
1227 | ||
1228 | if (storage_needed > 0) | |
1229 | { | |
1230 | symbol_table = (asymbol **) xmalloc (storage_needed); | |
c5f10366 | 1231 | back_to = make_cleanup (xfree, symbol_table); |
53a5351d JM |
1232 | number_of_symbols = bfd_canonicalize_symtab (abfd, symbol_table); |
1233 | ||
1234 | for (i = 0; i < number_of_symbols; i++) | |
1235 | { | |
1236 | sym = *symbol_table++; | |
c5f10366 | 1237 | if (strcmp (sym->name, symname) == 0) |
53a5351d JM |
1238 | { |
1239 | /* Bfd symbols are section relative. */ | |
1240 | symaddr = sym->value + sym->section->vma; | |
1241 | break; | |
1242 | } | |
1243 | } | |
1244 | do_cleanups (back_to); | |
1245 | } | |
1246 | return (symaddr); | |
1247 | } | |
1248 |