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