2011-01-07 Michael Snyder <msnyder@vmware.com>
[deliverable/binutils-gdb.git] / gdb / solib-som.c
CommitLineData
fbdbf38b 1/* Handle SOM shared libraries.
419b8bfb 2
7b6bb8da 3 Copyright (C) 2004, 2005, 2007, 2008, 2009, 2010, 2011
4c38e0a4 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#include "defs.h"
419b8bfb
RC
22#include "symtab.h"
23#include "bfd.h"
24#include "symfile.h"
25#include "objfiles.h"
26#include "gdbcore.h"
27#include "target.h"
28#include "inferior.h"
29
30#include "hppa-tdep.h"
31#include "solist.h"
d542061a 32#include "solib.h"
63807e1d 33#include "solib-som.h"
419b8bfb 34
7be67755
DA
35#include <sys/utsname.h>
36#include <string.h>
37
419b8bfb
RC
38#undef SOLIB_SOM_DBG
39
40/* These ought to be defined in some public interface, but aren't. They
41 define the meaning of the various bits in the distinguished __dld_flags
42 variable that is declared in every debuggable a.out on HP-UX, and that
43 is shared between the debugger and the dynamic linker.
44 */
45#define DLD_FLAGS_MAPPRIVATE 0x1
46#define DLD_FLAGS_HOOKVALID 0x2
47#define DLD_FLAGS_LISTVALID 0x4
48#define DLD_FLAGS_BOR_ENABLE 0x8
49
50struct lm_info
51 {
3e43a32a
MS
52 /* Version of this structure (it is expected to change again in
53 hpux10). */
419b8bfb
RC
54 unsigned char struct_version;
55
56 /* Binding mode for this library. */
57 unsigned char bind_mode;
58
59 /* Version of this library. */
60 short library_version;
61
62 /* Start of text address,
63 link-time text location (length of text area),
64 end of text address. */
65 CORE_ADDR text_addr;
66 CORE_ADDR text_link_addr;
67 CORE_ADDR text_end;
68
69 /* Start of data, start of bss and end of data. */
70 CORE_ADDR data_start;
71 CORE_ADDR bss_start;
72 CORE_ADDR data_end;
73
74 /* Value of linkage pointer (%r19). */
75 CORE_ADDR got_value;
76
77 /* Address in target of offset from thread-local register of
78 start of this thread's data. I.e., the first thread-local
79 variable in this shared library starts at *(tsd_start_addr)
80 from that area pointed to by cr27 (mpsfu_hi).
81
82 We do the indirection as soon as we read it, so from then
83 on it's the offset itself. */
84 CORE_ADDR tsd_start_addr;
85
86 /* Address of the link map entry in the loader. */
87 CORE_ADDR lm_addr;
88 };
89
90/* These addresses should be filled in by som_solib_create_inferior_hook.
91 They are also used elsewhere in this module.
92 */
93typedef struct
94 {
95 CORE_ADDR address;
96 struct unwind_table_entry *unwind;
97 }
98addr_and_unwind_t;
99
100/* When adding fields, be sure to clear them in _initialize_som_solib. */
101static struct
102 {
103 int is_valid;
104 addr_and_unwind_t hook;
105 addr_and_unwind_t hook_stub;
106 addr_and_unwind_t load;
107 addr_and_unwind_t load_stub;
108 addr_and_unwind_t unload;
109 addr_and_unwind_t unload2;
110 addr_and_unwind_t unload_stub;
111 }
112dld_cache;
113
114static void
115som_relocate_section_addresses (struct so_list *so,
0542c86d 116 struct target_section *sec)
419b8bfb
RC
117{
118 flagword aflag = bfd_get_section_flags(so->abfd, sec->the_bfd_section);
119
419b8bfb
RC
120 if (aflag & SEC_CODE)
121 {
122 sec->addr += so->lm_info->text_addr - so->lm_info->text_link_addr;
123 sec->endaddr += so->lm_info->text_addr - so->lm_info->text_link_addr;
124 }
125 else if (aflag & SEC_DATA)
126 {
127 sec->addr += so->lm_info->data_start;
128 sec->endaddr += so->lm_info->data_start;
129 }
130 else
131 ;
132}
133
7be67755
DA
134/* Get HP-UX major release number. Returns zero if the
135 release is not known. */
136
137static int
138get_hpux_major_release (void)
139{
140 static int hpux_major_release = -1;
141
142 if (hpux_major_release == -1)
143 {
144 struct utsname x;
145 char *p;
146
147 uname (&x);
148 p = strchr (x.release, '.');
149 hpux_major_release = p ? atoi (p + 1) : 0;
150 }
151
152 return hpux_major_release;
153}
154
155/* DL header flag defines. */
156#define SHLIB_TEXT_PRIVATE_ENABLE 0x4000
157
158/* The DL header is documented in <shl.h>. We are only interested
159 in the flags field to determine whether the executable wants shared
160 libraries mapped private. */
161struct {
162 short junk[37];
163 short flags;
164} dl_header;
165
419b8bfb
RC
166/* This hook gets called just before the first instruction in the
167 inferior process is executed.
168
169 This is our opportunity to set magic flags in the inferior so
170 that GDB can be notified when a shared library is mapped in and
171 to tell the dynamic linker that a private copy of the library is
172 needed (so GDB can set breakpoints in the library).
173
174 __dld_flags is the location of the magic flags; as of this implementation
175 there are 3 flags of interest:
176
177 bit 0 when set indicates that private copies of the libraries are needed
178 bit 1 when set indicates that the callback hook routine is valid
179 bit 2 when set indicates that the dynamic linker should maintain the
180 __dld_list structure when loading/unloading libraries.
181
182 Note that shared libraries are not mapped in at this time, so we have
183 run the inferior until the libraries are mapped in. Typically this
184 means running until the "_start" is called. */
185
186static void
268a4a75 187som_solib_create_inferior_hook (int from_tty)
419b8bfb 188{
e17a4113 189 enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch);
419b8bfb
RC
190 struct minimal_symbol *msymbol;
191 unsigned int dld_flags, status, have_endo;
192 asection *shlib_info;
193 char buf[4];
419b8bfb
RC
194 CORE_ADDR anaddr;
195
419b8bfb
RC
196 if (symfile_objfile == NULL)
197 return;
198
199 /* First see if the objfile was dynamically linked. */
200 shlib_info = bfd_get_section_by_name (symfile_objfile->obfd, "$SHLIB_INFO$");
201 if (!shlib_info)
202 return;
203
204 /* It's got a $SHLIB_INFO$ section, make sure it's not empty. */
205 if (bfd_section_size (symfile_objfile->obfd, shlib_info) == 0)
206 return;
207
7be67755
DA
208 /* Read the DL header. */
209 bfd_get_section_contents (symfile_objfile->obfd, shlib_info,
210 (char *) &dl_header, 0, sizeof (dl_header));
211
419b8bfb
RC
212 have_endo = 0;
213 /* Slam the pid of the process into __d_pid.
214
215 We used to warn when this failed, but that warning is only useful
216 on very old HP systems (hpux9 and older). The warnings are an
217 annoyance to users of modern systems and foul up the testsuite as
218 well. As a result, the warnings have been disabled. */
219 msymbol = lookup_minimal_symbol ("__d_pid", NULL, symfile_objfile);
220 if (msymbol == NULL)
221 goto keep_going;
222
223 anaddr = SYMBOL_VALUE_ADDRESS (msymbol);
e17a4113 224 store_unsigned_integer (buf, 4, byte_order, PIDGET (inferior_ptid));
419b8bfb
RC
225 status = target_write_memory (anaddr, buf, 4);
226 if (status != 0)
227 {
ac74f770
MS
228 warning (_("\
229Unable to write __d_pid.\n\
230Suggest linking with /opt/langtools/lib/end.o.\n\
231GDB will be unable to track shl_load/shl_unload calls"));
419b8bfb
RC
232 goto keep_going;
233 }
234
235 /* Get the value of _DLD_HOOK (an export stub) and put it in __dld_hook;
236 This will force the dynamic linker to call __d_trap when significant
237 events occur.
238
239 Note that the above is the pre-HP-UX 9.0 behaviour. At 9.0 and above,
240 the dld provides an export stub named "__d_trap" as well as the
241 function named "__d_trap" itself, but doesn't provide "_DLD_HOOK".
242 We'll look first for the old flavor and then the new.
243 */
244 msymbol = lookup_minimal_symbol ("_DLD_HOOK", NULL, symfile_objfile);
245 if (msymbol == NULL)
246 msymbol = lookup_minimal_symbol ("__d_trap", NULL, symfile_objfile);
247 if (msymbol == NULL)
248 {
ac74f770
MS
249 warning (_("\
250Unable to find _DLD_HOOK symbol in object file.\n\
251Suggest linking with /opt/langtools/lib/end.o.\n\
252GDB will be unable to track shl_load/shl_unload calls"));
419b8bfb
RC
253 goto keep_going;
254 }
255 anaddr = SYMBOL_VALUE_ADDRESS (msymbol);
256 dld_cache.hook.address = anaddr;
257
258 /* Grrr, this might not be an export symbol! We have to find the
259 export stub. */
ff644745
JB
260 msymbol = hppa_lookup_stub_minimal_symbol (SYMBOL_LINKAGE_NAME (msymbol),
261 EXPORT);
262 if (msymbol != NULL)
263 {
264 anaddr = SYMBOL_VALUE (msymbol);
265 dld_cache.hook_stub.address = anaddr;
266 }
e17a4113 267 store_unsigned_integer (buf, 4, byte_order, anaddr);
419b8bfb
RC
268
269 msymbol = lookup_minimal_symbol ("__dld_hook", NULL, symfile_objfile);
270 if (msymbol == NULL)
271 {
ac74f770
MS
272 warning (_("\
273Unable to find __dld_hook symbol in object file.\n\
274Suggest linking with /opt/langtools/lib/end.o.\n\
275GDB will be unable to track shl_load/shl_unload calls"));
419b8bfb
RC
276 goto keep_going;
277 }
278 anaddr = SYMBOL_VALUE_ADDRESS (msymbol);
279 status = target_write_memory (anaddr, buf, 4);
280
281 /* Now set a shlib_event breakpoint at __d_trap so we can track
282 significant shared library events. */
283 msymbol = lookup_minimal_symbol ("__d_trap", NULL, symfile_objfile);
284 if (msymbol == NULL)
285 {
ac74f770
MS
286 warning (_("\
287Unable to find __dld_d_trap symbol in object file.\n\
288Suggest linking with /opt/langtools/lib/end.o.\n\
289GDB will be unable to track shl_load/shl_unload calls"));
419b8bfb
RC
290 goto keep_going;
291 }
a6d9a66e
UW
292 create_solib_event_breakpoint (target_gdbarch,
293 SYMBOL_VALUE_ADDRESS (msymbol));
419b8bfb
RC
294
295 /* We have all the support usually found in end.o, so we can track
296 shl_load and shl_unload calls. */
297 have_endo = 1;
298
299keep_going:
300
301 /* Get the address of __dld_flags, if no such symbol exists, then we can
302 not debug the shared code. */
303 msymbol = lookup_minimal_symbol ("__dld_flags", NULL, NULL);
304 if (msymbol == NULL)
305 {
8a3fe4f8 306 error (_("Unable to find __dld_flags symbol in object file."));
419b8bfb
RC
307 }
308
309 anaddr = SYMBOL_VALUE_ADDRESS (msymbol);
310
311 /* Read the current contents. */
312 status = target_read_memory (anaddr, buf, 4);
313 if (status != 0)
8a3fe4f8 314 error (_("Unable to read __dld_flags."));
e17a4113 315 dld_flags = extract_unsigned_integer (buf, 4, byte_order);
419b8bfb 316
7be67755
DA
317 /* If the libraries were not mapped private on HP-UX 11 and later, warn
318 the user. On HP-UX 10 and earlier, there is no easy way to specify
319 that shared libraries should be privately mapped. So, we just force
320 private mapping. */
321 if (get_hpux_major_release () >= 11
322 && (dl_header.flags & SHLIB_TEXT_PRIVATE_ENABLE) == 0
323 && (dld_flags & DLD_FLAGS_MAPPRIVATE) == 0)
324 warning
ac74f770
MS
325 (_("\
326Private mapping of shared library text was not specified\n\
327by the executable; setting a breakpoint in a shared library which\n\
328is not privately mapped will not work. See the HP-UX 11i v3 chatr\n\
329manpage for methods to privately map shared library text."));
7be67755 330
419b8bfb 331 /* Turn on the flags we care about. */
7be67755
DA
332 if (get_hpux_major_release () < 11)
333 dld_flags |= DLD_FLAGS_MAPPRIVATE;
419b8bfb
RC
334 if (have_endo)
335 dld_flags |= DLD_FLAGS_HOOKVALID;
e17a4113 336 store_unsigned_integer (buf, 4, byte_order, dld_flags);
419b8bfb
RC
337 status = target_write_memory (anaddr, buf, 4);
338 if (status != 0)
8a3fe4f8 339 error (_("Unable to write __dld_flags."));
419b8bfb
RC
340
341 /* Now find the address of _start and set a breakpoint there.
342 We still need this code for two reasons:
343
344 * Not all sites have /opt/langtools/lib/end.o, so it's not always
345 possible to track the dynamic linker's events.
346
347 * At this time no events are triggered for shared libraries
348 loaded at startup time (what a crock). */
349
350 msymbol = lookup_minimal_symbol ("_start", NULL, symfile_objfile);
351 if (msymbol == NULL)
8a3fe4f8 352 error (_("Unable to find _start symbol in object file."));
419b8bfb
RC
353
354 anaddr = SYMBOL_VALUE_ADDRESS (msymbol);
355
356 /* Make the breakpoint at "_start" a shared library event breakpoint. */
a6d9a66e 357 create_solib_event_breakpoint (target_gdbarch, anaddr);
419b8bfb 358
c1e56572 359 clear_symtab_users (0);
419b8bfb
RC
360}
361
419b8bfb
RC
362static void
363som_special_symbol_handling (void)
364{
365}
366
367static void
368som_solib_desire_dynamic_linker_symbols (void)
369{
370 struct objfile *objfile;
371 struct unwind_table_entry *u;
372 struct minimal_symbol *dld_msymbol;
373
374 /* Do we already know the value of these symbols? If so, then
375 we've no work to do.
376
377 (If you add clauses to this test, be sure to likewise update the
378 test within the loop.)
379 */
380 if (dld_cache.is_valid)
381 return;
382
383 ALL_OBJFILES (objfile)
384 {
385 dld_msymbol = lookup_minimal_symbol ("shl_load", NULL, objfile);
386 if (dld_msymbol != NULL)
387 {
388 dld_cache.load.address = SYMBOL_VALUE (dld_msymbol);
389 dld_cache.load.unwind = find_unwind_entry (dld_cache.load.address);
390 }
391
392 dld_msymbol = lookup_minimal_symbol_solib_trampoline ("shl_load",
393 objfile);
394 if (dld_msymbol != NULL)
395 {
712f90be 396 if (MSYMBOL_TYPE (dld_msymbol) == mst_solib_trampoline)
419b8bfb
RC
397 {
398 u = find_unwind_entry (SYMBOL_VALUE (dld_msymbol));
399 if ((u != NULL) && (u->stub_unwind.stub_type == EXPORT))
400 {
401 dld_cache.load_stub.address = SYMBOL_VALUE (dld_msymbol);
402 dld_cache.load_stub.unwind = u;
403 }
404 }
405 }
406
407 dld_msymbol = lookup_minimal_symbol ("shl_unload", NULL, objfile);
408 if (dld_msymbol != NULL)
409 {
410 dld_cache.unload.address = SYMBOL_VALUE (dld_msymbol);
411 dld_cache.unload.unwind = find_unwind_entry (dld_cache.unload.address);
412
413 /* ??rehrauer: I'm not sure exactly what this is, but it appears
414 that on some HPUX 10.x versions, there's two unwind regions to
415 cover the body of "shl_unload", the second being 4 bytes past
416 the end of the first. This is a large hack to handle that
417 case, but since I don't seem to have any legitimate way to
418 look for this thing via the symbol table...
419 */
420 if (dld_cache.unload.unwind != NULL)
421 {
422 u = find_unwind_entry (dld_cache.unload.unwind->region_end + 4);
423 if (u != NULL)
424 {
425 dld_cache.unload2.address = u->region_start;
426 dld_cache.unload2.unwind = u;
427 }
428 }
429 }
430
431 dld_msymbol = lookup_minimal_symbol_solib_trampoline ("shl_unload",
432 objfile);
433 if (dld_msymbol != NULL)
434 {
712f90be 435 if (MSYMBOL_TYPE (dld_msymbol) == mst_solib_trampoline)
419b8bfb
RC
436 {
437 u = find_unwind_entry (SYMBOL_VALUE (dld_msymbol));
438 if ((u != NULL) && (u->stub_unwind.stub_type == EXPORT))
439 {
440 dld_cache.unload_stub.address = SYMBOL_VALUE (dld_msymbol);
441 dld_cache.unload_stub.unwind = u;
442 }
443 }
444 }
445
446 /* Did we find everything we were looking for? If so, stop. */
447 if ((dld_cache.load.address != 0)
448 && (dld_cache.load_stub.address != 0)
449 && (dld_cache.unload.address != 0)
450 && (dld_cache.unload_stub.address != 0))
451 {
452 dld_cache.is_valid = 1;
453 break;
454 }
455 }
456
457 dld_cache.hook.unwind = find_unwind_entry (dld_cache.hook.address);
458 dld_cache.hook_stub.unwind = find_unwind_entry (dld_cache.hook_stub.address);
459
460 /* We're prepared not to find some of these symbols, which is why
461 this function is a "desire" operation, and not a "require".
462 */
463}
464
465static int
466som_in_dynsym_resolve_code (CORE_ADDR pc)
467{
468 struct unwind_table_entry *u_pc;
469
470 /* Are we in the dld itself?
471
472 ??rehrauer: Large hack -- We'll assume that any address in a
473 shared text region is the dld's text. This would obviously
474 fall down if the user attached to a process, whose shlibs
475 weren't mapped to a (writeable) private region. However, in
476 that case the debugger probably isn't able to set the fundamental
477 breakpoint in the dld callback anyways, so this hack should be
478 safe.
479 */
480 if ((pc & (CORE_ADDR) 0xc0000000) == (CORE_ADDR) 0xc0000000)
481 return 1;
482
483 /* Cache the address of some symbols that are part of the dynamic
484 linker, if not already known.
485 */
486 som_solib_desire_dynamic_linker_symbols ();
487
488 /* Are we in the dld callback? Or its export stub? */
489 u_pc = find_unwind_entry (pc);
490 if (u_pc == NULL)
491 return 0;
492
493 if ((u_pc == dld_cache.hook.unwind) || (u_pc == dld_cache.hook_stub.unwind))
494 return 1;
495
496 /* Or the interface of the dld (i.e., "shl_load" or friends)? */
497 if ((u_pc == dld_cache.load.unwind)
498 || (u_pc == dld_cache.unload.unwind)
499 || (u_pc == dld_cache.unload2.unwind)
500 || (u_pc == dld_cache.load_stub.unwind)
501 || (u_pc == dld_cache.unload_stub.unwind))
502 return 1;
503
504 /* Apparently this address isn't part of the dld's text. */
505 return 0;
506}
507
508static void
509som_clear_solib (void)
510{
511}
512
513struct dld_list {
514 char name[4];
515 char info[4];
516 char text_addr[4];
517 char text_link_addr[4];
518 char text_end[4];
519 char data_start[4];
520 char bss_start[4];
521 char data_end[4];
522 char got_value[4];
523 char next[4];
524 char tsd_start_addr_ptr[4];
525};
526
527static CORE_ADDR
528link_map_start (void)
529{
e17a4113 530 enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch);
419b8bfb
RC
531 struct minimal_symbol *sym;
532 CORE_ADDR addr;
533 char buf[4];
534 unsigned int dld_flags;
535
536 sym = lookup_minimal_symbol ("__dld_flags", NULL, NULL);
537 if (!sym)
8a3fe4f8 538 error (_("Unable to find __dld_flags symbol in object file."));
419b8bfb
RC
539 addr = SYMBOL_VALUE_ADDRESS (sym);
540 read_memory (addr, buf, 4);
e17a4113 541 dld_flags = extract_unsigned_integer (buf, 4, byte_order);
419b8bfb 542 if ((dld_flags & DLD_FLAGS_LISTVALID) == 0)
8a3fe4f8 543 error (_("__dld_list is not valid according to __dld_flags."));
419b8bfb 544
419b8bfb
RC
545 sym = lookup_minimal_symbol ("__dld_list", NULL, NULL);
546 if (!sym)
547 {
548 /* Older crt0.o files (hpux8) don't have __dld_list as a symbol,
549 but the data is still available if you know where to look. */
550 sym = lookup_minimal_symbol ("__dld_flags", NULL, NULL);
551 if (!sym)
552 {
8a3fe4f8 553 error (_("Unable to find dynamic library list."));
419b8bfb
RC
554 return 0;
555 }
556 addr = SYMBOL_VALUE_ADDRESS (sym) - 8;
557 }
558 else
559 addr = SYMBOL_VALUE_ADDRESS (sym);
560
561 read_memory (addr, buf, 4);
e17a4113 562 addr = extract_unsigned_integer (buf, 4, byte_order);
419b8bfb 563 if (addr == 0)
7fc4b1a1 564 return 0;
419b8bfb
RC
565
566 read_memory (addr, buf, 4);
e17a4113 567 return extract_unsigned_integer (buf, 4, byte_order);
419b8bfb
RC
568}
569
570/* Does this so's name match the main binary? */
571static int
572match_main (const char *name)
573{
574 return strcmp (name, symfile_objfile->name) == 0;
575}
576
577static struct so_list *
578som_current_sos (void)
579{
e17a4113 580 enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch);
419b8bfb
RC
581 CORE_ADDR lm;
582 struct so_list *head = 0;
583 struct so_list **link_ptr = &head;
584
585 for (lm = link_map_start (); lm; )
586 {
587 char *namebuf;
588 CORE_ADDR addr;
589 struct so_list *new;
590 struct cleanup *old_chain;
591 int errcode;
592 struct dld_list dbuf;
593 char tsdbuf[4];
594
595 new = (struct so_list *) xmalloc (sizeof (struct so_list));
596 old_chain = make_cleanup (xfree, new);
597
598 memset (new, 0, sizeof (*new));
599 new->lm_info = xmalloc (sizeof (struct lm_info));
600 make_cleanup (xfree, new->lm_info);
601
fbdbf38b 602 read_memory (lm, (gdb_byte *)&dbuf, sizeof (struct dld_list));
419b8bfb 603
fbdbf38b 604 addr = extract_unsigned_integer ((gdb_byte *)&dbuf.name,
e17a4113 605 sizeof (dbuf.name), byte_order);
419b8bfb
RC
606 target_read_string (addr, &namebuf, SO_NAME_MAX_PATH_SIZE - 1, &errcode);
607 if (errcode != 0)
8a3fe4f8
AC
608 warning (_("Can't read pathname for load map: %s."),
609 safe_strerror (errcode));
419b8bfb
RC
610 else
611 {
612 strncpy (new->so_name, namebuf, SO_NAME_MAX_PATH_SIZE - 1);
613 new->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
614 xfree (namebuf);
615 strcpy (new->so_original_name, new->so_name);
616 }
617
618 if (new->so_name[0] && !match_main (new->so_name))
619 {
620 struct lm_info *lmi = new->lm_info;
621 unsigned int tmp;
622
623 lmi->lm_addr = lm;
624
625#define EXTRACT(_fld) \
e17a4113
UW
626 extract_unsigned_integer ((gdb_byte *)&dbuf._fld, \
627 sizeof (dbuf._fld), byte_order);
419b8bfb
RC
628
629 lmi->text_addr = EXTRACT (text_addr);
630 tmp = EXTRACT (info);
631 lmi->library_version = (tmp >> 16) & 0xffff;
632 lmi->bind_mode = (tmp >> 8) & 0xff;
633 lmi->struct_version = tmp & 0xff;
634 lmi->text_link_addr = EXTRACT (text_link_addr);
635 lmi->text_end = EXTRACT (text_end);
636 lmi->data_start = EXTRACT (data_start);
637 lmi->bss_start = EXTRACT (bss_start);
638 lmi->data_end = EXTRACT (data_end);
639 lmi->got_value = EXTRACT (got_value);
640 tmp = EXTRACT (tsd_start_addr_ptr);
641 read_memory (tmp, tsdbuf, 4);
e17a4113
UW
642 lmi->tsd_start_addr
643 = extract_unsigned_integer (tsdbuf, 4, byte_order);
419b8bfb
RC
644
645#ifdef SOLIB_SOM_DBG
5af949e3
UW
646 printf ("\n+ library \"%s\" is described at %s\n", new->so_name,
647 paddress (target_gdbarch, lm));
419b8bfb
RC
648 printf (" 'version' is %d\n", new->lm_info->struct_version);
649 printf (" 'bind_mode' is %d\n", new->lm_info->bind_mode);
650 printf (" 'library_version' is %d\n",
651 new->lm_info->library_version);
5af949e3
UW
652 printf (" 'text_addr' is %s\n",
653 paddress (target_gdbarch, new->lm_info->text_addr));
654 printf (" 'text_link_addr' is %s\n",
655 paddress (target_gdbarch, new->lm_info->text_link_addr));
656 printf (" 'text_end' is %s\n",
657 paddress (target_gdbarch, new->lm_info->text_end));
658 printf (" 'data_start' is %s\n",
659 paddress (target_gdbarch, new->lm_info->data_start));
660 printf (" 'bss_start' is %s\n",
661 paddress (target_gdbarch, new->lm_info->bss_start));
662 printf (" 'data_end' is %s\n",
663 paddress (target_gdbarch, new->lm_info->data_end));
664 printf (" 'got_value' is %s\n",
665 paddress (target_gdbarch, new->lm_info->got_value));
666 printf (" 'tsd_start_addr' is %s\n",
667 paddress (target_gdbarch, new->lm_info->tsd_start_addr));
419b8bfb
RC
668#endif
669
cfa9d6d9
DJ
670 new->addr_low = lmi->text_addr;
671 new->addr_high = lmi->text_end;
672
419b8bfb
RC
673 /* Link the new object onto the list. */
674 new->next = NULL;
675 *link_ptr = new;
676 link_ptr = &new->next;
677 }
678 else
679 {
680 free_so (new);
681 }
682
683 lm = EXTRACT (next);
684 discard_cleanups (old_chain);
685#undef EXTRACT
686 }
687
688 /* TODO: The original somsolib code has logic to detect and eliminate
689 duplicate entries. Do we need that? */
690
691 return head;
692}
693
694static int
695som_open_symbol_file_object (void *from_ttyp)
696{
e17a4113 697 enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch);
419b8bfb
RC
698 CORE_ADDR lm, l_name;
699 char *filename;
700 int errcode;
701 int from_tty = *(int *)from_ttyp;
702 char buf[4];
703
704 if (symfile_objfile)
9e2f0ad4 705 if (!query (_("Attempt to reload symbols from process? ")))
419b8bfb
RC
706 return 0;
707
708 /* First link map member should be the executable. */
709 if ((lm = link_map_start ()) == 0)
710 return 0; /* failed somehow... */
711
712 /* Read address of name from target memory to GDB. */
713 read_memory (lm + offsetof (struct dld_list, name), buf, 4);
714
715 /* Convert the address to host format. Assume that the address is
716 unsigned. */
e17a4113 717 l_name = extract_unsigned_integer (buf, 4, byte_order);
419b8bfb
RC
718
719 if (l_name == 0)
720 return 0; /* No filename. */
721
722 /* Now fetch the filename from target memory. */
723 target_read_string (l_name, &filename, SO_NAME_MAX_PATH_SIZE - 1, &errcode);
724
725 if (errcode)
726 {
8a3fe4f8 727 warning (_("failed to read exec filename from attached file: %s"),
419b8bfb
RC
728 safe_strerror (errcode));
729 return 0;
730 }
731
732 make_cleanup (xfree, filename);
733 /* Have a pathname: read the symbol file. */
734 symbol_file_add_main (filename, from_tty);
735
736 return 1;
737}
738
739static void
740som_free_so (struct so_list *so)
741{
742 xfree (so->lm_info);
743}
744
745static CORE_ADDR
746som_solib_thread_start_addr (struct so_list *so)
747{
748 return so->lm_info->tsd_start_addr;
749}
750
751/* Return the GOT value for the shared library in which ADDR belongs. If
752 ADDR isn't in any known shared library, return zero. */
753
754static CORE_ADDR
755som_solib_get_got_by_pc (CORE_ADDR addr)
756{
757 struct so_list *so_list = master_so_list ();
758 CORE_ADDR got_value = 0;
759
760 while (so_list)
761 {
762 if (so_list->lm_info->text_addr <= addr
763 && so_list->lm_info->text_end > addr)
764 {
765 got_value = so_list->lm_info->got_value;
766 break;
767 }
768 so_list = so_list->next;
769 }
770 return got_value;
771}
772
3e43a32a
MS
773/* Return the address of the handle of the shared library in which
774 ADDR belongs. If ADDR isn't in any known shared library, return
775 zero. */
419b8bfb
RC
776/* this function is used in initialize_hp_cxx_exception_support in
777 hppa-hpux-tdep.c */
778
779static CORE_ADDR
780som_solib_get_solib_by_pc (CORE_ADDR addr)
781{
782 struct so_list *so_list = master_so_list ();
783
784 while (so_list)
785 {
786 if (so_list->lm_info->text_addr <= addr
787 && so_list->lm_info->text_end > addr)
788 {
789 break;
790 }
791 so_list = so_list->next;
792 }
793 if (so_list)
794 return so_list->lm_info->lm_addr;
795 else
796 return 0;
797}
798
799
800static struct target_so_ops som_so_ops;
801
802extern initialize_file_ftype _initialize_som_solib; /* -Wmissing-prototypes */
803
804void
805_initialize_som_solib (void)
806{
807 som_so_ops.relocate_section_addresses = som_relocate_section_addresses;
808 som_so_ops.free_so = som_free_so;
809 som_so_ops.clear_solib = som_clear_solib;
810 som_so_ops.solib_create_inferior_hook = som_solib_create_inferior_hook;
811 som_so_ops.special_symbol_handling = som_special_symbol_handling;
812 som_so_ops.current_sos = som_current_sos;
813 som_so_ops.open_symbol_file_object = som_open_symbol_file_object;
814 som_so_ops.in_dynsym_resolve_code = som_in_dynsym_resolve_code;
831a0c44 815 som_so_ops.bfd_open = solib_bfd_open;
419b8bfb
RC
816}
817
63807e1d
PA
818void
819som_solib_select (struct gdbarch *gdbarch)
419b8bfb 820{
d542061a 821 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
419b8bfb 822
433759f7 823 set_solib_ops (gdbarch, &som_so_ops);
419b8bfb
RC
824 tdep->solib_thread_start_addr = som_solib_thread_start_addr;
825 tdep->solib_get_got_by_pc = som_solib_get_got_by_pc;
826 tdep->solib_get_solib_by_pc = som_solib_get_solib_by_pc;
827}
828
829/* The rest of these functions are not part of the solib interface; they
830 are used by somread.c or hppa-hpux-tdep.c */
831
832int
833som_solib_section_offsets (struct objfile *objfile,
834 struct section_offsets *offsets)
835{
836 struct so_list *so_list = master_so_list ();
837
838 while (so_list)
839 {
840 /* Oh what a pain! We need the offsets before so_list->objfile
841 is valid. The BFDs will never match. Make a best guess. */
842 if (strstr (objfile->name, so_list->so_name))
843 {
844 asection *private_section;
845
846 /* The text offset is easy. */
847 offsets->offsets[SECT_OFF_TEXT (objfile)]
848 = (so_list->lm_info->text_addr
849 - so_list->lm_info->text_link_addr);
850 offsets->offsets[SECT_OFF_RODATA (objfile)]
851 = ANOFFSET (offsets, SECT_OFF_TEXT (objfile));
852
853 /* We should look at presumed_dp in the SOM header, but
854 that's not easily available. This should be OK though. */
855 private_section = bfd_get_section_by_name (objfile->obfd,
856 "$PRIVATE$");
857 if (!private_section)
858 {
8a3fe4f8 859 warning (_("Unable to find $PRIVATE$ in shared library!"));
419b8bfb
RC
860 offsets->offsets[SECT_OFF_DATA (objfile)] = 0;
861 offsets->offsets[SECT_OFF_BSS (objfile)] = 0;
862 return 1;
863 }
864 offsets->offsets[SECT_OFF_DATA (objfile)]
865 = (so_list->lm_info->data_start - private_section->vma);
866 offsets->offsets[SECT_OFF_BSS (objfile)]
867 = ANOFFSET (offsets, SECT_OFF_DATA (objfile));
868 return 1;
869 }
870 so_list = so_list->next;
871 }
872 return 0;
873}
This page took 0.621089 seconds and 4 git commands to generate.