Update
[gdb.git] / gdb / solib-som.c
blob247ada36645ac601f50666f7c822b08917a8c05c
1 /* Handle SOM shared libraries.
3 Copyright (C) 2004, 2005, 2007, 2008 Free Software Foundation, Inc.
5 This file is part of GDB.
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
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
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.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #include "defs.h"
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"
29 #include "hppa-tdep.h"
30 #include "solist.h"
31 #include "solib.h"
33 #undef SOLIB_SOM_DBG
35 /* These ought to be defined in some public interface, but aren't. They
36 define the meaning of the various bits in the distinguished __dld_flags
37 variable that is declared in every debuggable a.out on HP-UX, and that
38 is shared between the debugger and the dynamic linker.
40 #define DLD_FLAGS_MAPPRIVATE 0x1
41 #define DLD_FLAGS_HOOKVALID 0x2
42 #define DLD_FLAGS_LISTVALID 0x4
43 #define DLD_FLAGS_BOR_ENABLE 0x8
45 struct lm_info
47 /* Version of this structure (it is expected to change again in hpux10). */
48 unsigned char struct_version;
50 /* Binding mode for this library. */
51 unsigned char bind_mode;
53 /* Version of this library. */
54 short library_version;
56 /* Start of text address,
57 link-time text location (length of text area),
58 end of text address. */
59 CORE_ADDR text_addr;
60 CORE_ADDR text_link_addr;
61 CORE_ADDR text_end;
63 /* Start of data, start of bss and end of data. */
64 CORE_ADDR data_start;
65 CORE_ADDR bss_start;
66 CORE_ADDR data_end;
68 /* Value of linkage pointer (%r19). */
69 CORE_ADDR got_value;
71 /* Address in target of offset from thread-local register of
72 start of this thread's data. I.e., the first thread-local
73 variable in this shared library starts at *(tsd_start_addr)
74 from that area pointed to by cr27 (mpsfu_hi).
76 We do the indirection as soon as we read it, so from then
77 on it's the offset itself. */
78 CORE_ADDR tsd_start_addr;
80 /* Address of the link map entry in the loader. */
81 CORE_ADDR lm_addr;
84 /* These addresses should be filled in by som_solib_create_inferior_hook.
85 They are also used elsewhere in this module.
87 typedef struct
89 CORE_ADDR address;
90 struct unwind_table_entry *unwind;
92 addr_and_unwind_t;
94 /* When adding fields, be sure to clear them in _initialize_som_solib. */
95 static struct
97 int is_valid;
98 addr_and_unwind_t hook;
99 addr_and_unwind_t hook_stub;
100 addr_and_unwind_t load;
101 addr_and_unwind_t load_stub;
102 addr_and_unwind_t unload;
103 addr_and_unwind_t unload2;
104 addr_and_unwind_t unload_stub;
106 dld_cache;
108 static void
109 som_relocate_section_addresses (struct so_list *so,
110 struct section_table *sec)
112 flagword aflag = bfd_get_section_flags(so->abfd, sec->the_bfd_section);
114 if (aflag & SEC_CODE)
116 sec->addr += so->lm_info->text_addr - so->lm_info->text_link_addr;
117 sec->endaddr += so->lm_info->text_addr - so->lm_info->text_link_addr;
119 else if (aflag & SEC_DATA)
121 sec->addr += so->lm_info->data_start;
122 sec->endaddr += so->lm_info->data_start;
124 else
128 /* This hook gets called just before the first instruction in the
129 inferior process is executed.
131 This is our opportunity to set magic flags in the inferior so
132 that GDB can be notified when a shared library is mapped in and
133 to tell the dynamic linker that a private copy of the library is
134 needed (so GDB can set breakpoints in the library).
136 __dld_flags is the location of the magic flags; as of this implementation
137 there are 3 flags of interest:
139 bit 0 when set indicates that private copies of the libraries are needed
140 bit 1 when set indicates that the callback hook routine is valid
141 bit 2 when set indicates that the dynamic linker should maintain the
142 __dld_list structure when loading/unloading libraries.
144 Note that shared libraries are not mapped in at this time, so we have
145 run the inferior until the libraries are mapped in. Typically this
146 means running until the "_start" is called. */
148 static void
149 som_solib_create_inferior_hook (void)
151 struct minimal_symbol *msymbol;
152 unsigned int dld_flags, status, have_endo;
153 asection *shlib_info;
154 char buf[4];
155 CORE_ADDR anaddr;
157 /* First, remove all the solib event breakpoints. Their addresses
158 may have changed since the last time we ran the program. */
159 remove_solib_event_breakpoints ();
161 if (symfile_objfile == NULL)
162 return;
164 /* First see if the objfile was dynamically linked. */
165 shlib_info = bfd_get_section_by_name (symfile_objfile->obfd, "$SHLIB_INFO$");
166 if (!shlib_info)
167 return;
169 /* It's got a $SHLIB_INFO$ section, make sure it's not empty. */
170 if (bfd_section_size (symfile_objfile->obfd, shlib_info) == 0)
171 return;
173 have_endo = 0;
174 /* Slam the pid of the process into __d_pid.
176 We used to warn when this failed, but that warning is only useful
177 on very old HP systems (hpux9 and older). The warnings are an
178 annoyance to users of modern systems and foul up the testsuite as
179 well. As a result, the warnings have been disabled. */
180 msymbol = lookup_minimal_symbol ("__d_pid", NULL, symfile_objfile);
181 if (msymbol == NULL)
182 goto keep_going;
184 anaddr = SYMBOL_VALUE_ADDRESS (msymbol);
185 store_unsigned_integer (buf, 4, PIDGET (inferior_ptid));
186 status = target_write_memory (anaddr, buf, 4);
187 if (status != 0)
189 warning (_("\
190 Unable to write __d_pid.\n\
191 Suggest linking with /opt/langtools/lib/end.o.\n\
192 GDB will be unable to track shl_load/shl_unload calls"));
193 goto keep_going;
196 /* Get the value of _DLD_HOOK (an export stub) and put it in __dld_hook;
197 This will force the dynamic linker to call __d_trap when significant
198 events occur.
200 Note that the above is the pre-HP-UX 9.0 behaviour. At 9.0 and above,
201 the dld provides an export stub named "__d_trap" as well as the
202 function named "__d_trap" itself, but doesn't provide "_DLD_HOOK".
203 We'll look first for the old flavor and then the new.
205 msymbol = lookup_minimal_symbol ("_DLD_HOOK", NULL, symfile_objfile);
206 if (msymbol == NULL)
207 msymbol = lookup_minimal_symbol ("__d_trap", NULL, symfile_objfile);
208 if (msymbol == NULL)
210 warning (_("\
211 Unable to find _DLD_HOOK symbol in object file.\n\
212 Suggest linking with /opt/langtools/lib/end.o.\n\
213 GDB will be unable to track shl_load/shl_unload calls"));
214 goto keep_going;
216 anaddr = SYMBOL_VALUE_ADDRESS (msymbol);
217 dld_cache.hook.address = anaddr;
219 /* Grrr, this might not be an export symbol! We have to find the
220 export stub. */
221 msymbol = hppa_lookup_stub_minimal_symbol (SYMBOL_LINKAGE_NAME (msymbol),
222 EXPORT);
223 if (msymbol != NULL)
225 anaddr = SYMBOL_VALUE (msymbol);
226 dld_cache.hook_stub.address = anaddr;
228 store_unsigned_integer (buf, 4, anaddr);
230 msymbol = lookup_minimal_symbol ("__dld_hook", NULL, symfile_objfile);
231 if (msymbol == NULL)
233 warning (_("\
234 Unable to find __dld_hook symbol in object file.\n\
235 Suggest linking with /opt/langtools/lib/end.o.\n\
236 GDB will be unable to track shl_load/shl_unload calls"));
237 goto keep_going;
239 anaddr = SYMBOL_VALUE_ADDRESS (msymbol);
240 status = target_write_memory (anaddr, buf, 4);
242 /* Now set a shlib_event breakpoint at __d_trap so we can track
243 significant shared library events. */
244 msymbol = lookup_minimal_symbol ("__d_trap", NULL, symfile_objfile);
245 if (msymbol == NULL)
247 warning (_("\
248 Unable to find __dld_d_trap symbol in object file.\n\
249 Suggest linking with /opt/langtools/lib/end.o.\n\
250 GDB will be unable to track shl_load/shl_unload calls"));
251 goto keep_going;
253 create_solib_event_breakpoint (SYMBOL_VALUE_ADDRESS (msymbol));
255 /* We have all the support usually found in end.o, so we can track
256 shl_load and shl_unload calls. */
257 have_endo = 1;
259 keep_going:
261 /* Get the address of __dld_flags, if no such symbol exists, then we can
262 not debug the shared code. */
263 msymbol = lookup_minimal_symbol ("__dld_flags", NULL, NULL);
264 if (msymbol == NULL)
266 error (_("Unable to find __dld_flags symbol in object file."));
269 anaddr = SYMBOL_VALUE_ADDRESS (msymbol);
271 /* Read the current contents. */
272 status = target_read_memory (anaddr, buf, 4);
273 if (status != 0)
274 error (_("Unable to read __dld_flags."));
275 dld_flags = extract_unsigned_integer (buf, 4);
277 /* Turn on the flags we care about. */
278 dld_flags |= DLD_FLAGS_MAPPRIVATE;
279 if (have_endo)
280 dld_flags |= DLD_FLAGS_HOOKVALID;
281 store_unsigned_integer (buf, 4, dld_flags);
282 status = target_write_memory (anaddr, buf, 4);
283 if (status != 0)
284 error (_("Unable to write __dld_flags."));
286 /* Now find the address of _start and set a breakpoint there.
287 We still need this code for two reasons:
289 * Not all sites have /opt/langtools/lib/end.o, so it's not always
290 possible to track the dynamic linker's events.
292 * At this time no events are triggered for shared libraries
293 loaded at startup time (what a crock). */
295 msymbol = lookup_minimal_symbol ("_start", NULL, symfile_objfile);
296 if (msymbol == NULL)
297 error (_("Unable to find _start symbol in object file."));
299 anaddr = SYMBOL_VALUE_ADDRESS (msymbol);
301 /* Make the breakpoint at "_start" a shared library event breakpoint. */
302 create_solib_event_breakpoint (anaddr);
304 clear_symtab_users ();
307 static void
308 som_special_symbol_handling (void)
312 static void
313 som_solib_desire_dynamic_linker_symbols (void)
315 struct objfile *objfile;
316 struct unwind_table_entry *u;
317 struct minimal_symbol *dld_msymbol;
319 /* Do we already know the value of these symbols? If so, then
320 we've no work to do.
322 (If you add clauses to this test, be sure to likewise update the
323 test within the loop.)
325 if (dld_cache.is_valid)
326 return;
328 ALL_OBJFILES (objfile)
330 dld_msymbol = lookup_minimal_symbol ("shl_load", NULL, objfile);
331 if (dld_msymbol != NULL)
333 dld_cache.load.address = SYMBOL_VALUE (dld_msymbol);
334 dld_cache.load.unwind = find_unwind_entry (dld_cache.load.address);
337 dld_msymbol = lookup_minimal_symbol_solib_trampoline ("shl_load",
338 objfile);
339 if (dld_msymbol != NULL)
341 if (SYMBOL_TYPE (dld_msymbol) == mst_solib_trampoline)
343 u = find_unwind_entry (SYMBOL_VALUE (dld_msymbol));
344 if ((u != NULL) && (u->stub_unwind.stub_type == EXPORT))
346 dld_cache.load_stub.address = SYMBOL_VALUE (dld_msymbol);
347 dld_cache.load_stub.unwind = u;
352 dld_msymbol = lookup_minimal_symbol ("shl_unload", NULL, objfile);
353 if (dld_msymbol != NULL)
355 dld_cache.unload.address = SYMBOL_VALUE (dld_msymbol);
356 dld_cache.unload.unwind = find_unwind_entry (dld_cache.unload.address);
358 /* ??rehrauer: I'm not sure exactly what this is, but it appears
359 that on some HPUX 10.x versions, there's two unwind regions to
360 cover the body of "shl_unload", the second being 4 bytes past
361 the end of the first. This is a large hack to handle that
362 case, but since I don't seem to have any legitimate way to
363 look for this thing via the symbol table...
365 if (dld_cache.unload.unwind != NULL)
367 u = find_unwind_entry (dld_cache.unload.unwind->region_end + 4);
368 if (u != NULL)
370 dld_cache.unload2.address = u->region_start;
371 dld_cache.unload2.unwind = u;
376 dld_msymbol = lookup_minimal_symbol_solib_trampoline ("shl_unload",
377 objfile);
378 if (dld_msymbol != NULL)
380 if (SYMBOL_TYPE (dld_msymbol) == mst_solib_trampoline)
382 u = find_unwind_entry (SYMBOL_VALUE (dld_msymbol));
383 if ((u != NULL) && (u->stub_unwind.stub_type == EXPORT))
385 dld_cache.unload_stub.address = SYMBOL_VALUE (dld_msymbol);
386 dld_cache.unload_stub.unwind = u;
391 /* Did we find everything we were looking for? If so, stop. */
392 if ((dld_cache.load.address != 0)
393 && (dld_cache.load_stub.address != 0)
394 && (dld_cache.unload.address != 0)
395 && (dld_cache.unload_stub.address != 0))
397 dld_cache.is_valid = 1;
398 break;
402 dld_cache.hook.unwind = find_unwind_entry (dld_cache.hook.address);
403 dld_cache.hook_stub.unwind = find_unwind_entry (dld_cache.hook_stub.address);
405 /* We're prepared not to find some of these symbols, which is why
406 this function is a "desire" operation, and not a "require".
410 static int
411 som_in_dynsym_resolve_code (CORE_ADDR pc)
413 struct unwind_table_entry *u_pc;
415 /* Are we in the dld itself?
417 ??rehrauer: Large hack -- We'll assume that any address in a
418 shared text region is the dld's text. This would obviously
419 fall down if the user attached to a process, whose shlibs
420 weren't mapped to a (writeable) private region. However, in
421 that case the debugger probably isn't able to set the fundamental
422 breakpoint in the dld callback anyways, so this hack should be
423 safe.
425 if ((pc & (CORE_ADDR) 0xc0000000) == (CORE_ADDR) 0xc0000000)
426 return 1;
428 /* Cache the address of some symbols that are part of the dynamic
429 linker, if not already known.
431 som_solib_desire_dynamic_linker_symbols ();
433 /* Are we in the dld callback? Or its export stub? */
434 u_pc = find_unwind_entry (pc);
435 if (u_pc == NULL)
436 return 0;
438 if ((u_pc == dld_cache.hook.unwind) || (u_pc == dld_cache.hook_stub.unwind))
439 return 1;
441 /* Or the interface of the dld (i.e., "shl_load" or friends)? */
442 if ((u_pc == dld_cache.load.unwind)
443 || (u_pc == dld_cache.unload.unwind)
444 || (u_pc == dld_cache.unload2.unwind)
445 || (u_pc == dld_cache.load_stub.unwind)
446 || (u_pc == dld_cache.unload_stub.unwind))
447 return 1;
449 /* Apparently this address isn't part of the dld's text. */
450 return 0;
453 static void
454 som_clear_solib (void)
458 struct dld_list {
459 char name[4];
460 char info[4];
461 char text_addr[4];
462 char text_link_addr[4];
463 char text_end[4];
464 char data_start[4];
465 char bss_start[4];
466 char data_end[4];
467 char got_value[4];
468 char next[4];
469 char tsd_start_addr_ptr[4];
472 static CORE_ADDR
473 link_map_start (void)
475 struct minimal_symbol *sym;
476 CORE_ADDR addr;
477 char buf[4];
478 unsigned int dld_flags;
480 sym = lookup_minimal_symbol ("__dld_flags", NULL, NULL);
481 if (!sym)
482 error (_("Unable to find __dld_flags symbol in object file."));
483 addr = SYMBOL_VALUE_ADDRESS (sym);
484 read_memory (addr, buf, 4);
485 dld_flags = extract_unsigned_integer (buf, 4);
486 if ((dld_flags & DLD_FLAGS_LISTVALID) == 0)
487 error (_("__dld_list is not valid according to __dld_flags."));
489 /* If the libraries were not mapped private, warn the user. */
490 if ((dld_flags & DLD_FLAGS_MAPPRIVATE) == 0)
491 warning (_("The shared libraries were not privately mapped; setting a\n"
492 "breakpoint in a shared library will not work until you rerun the "
493 "program.\n"));
495 sym = lookup_minimal_symbol ("__dld_list", NULL, NULL);
496 if (!sym)
498 /* Older crt0.o files (hpux8) don't have __dld_list as a symbol,
499 but the data is still available if you know where to look. */
500 sym = lookup_minimal_symbol ("__dld_flags", NULL, NULL);
501 if (!sym)
503 error (_("Unable to find dynamic library list."));
504 return 0;
506 addr = SYMBOL_VALUE_ADDRESS (sym) - 8;
508 else
509 addr = SYMBOL_VALUE_ADDRESS (sym);
511 read_memory (addr, buf, 4);
512 addr = extract_unsigned_integer (buf, 4);
513 if (addr == 0)
514 return 0;
516 read_memory (addr, buf, 4);
517 return extract_unsigned_integer (buf, 4);
520 /* Does this so's name match the main binary? */
521 static int
522 match_main (const char *name)
524 return strcmp (name, symfile_objfile->name) == 0;
527 static struct so_list *
528 som_current_sos (void)
530 CORE_ADDR lm;
531 struct so_list *head = 0;
532 struct so_list **link_ptr = &head;
534 for (lm = link_map_start (); lm; )
536 char *namebuf;
537 CORE_ADDR addr;
538 struct so_list *new;
539 struct cleanup *old_chain;
540 int errcode;
541 struct dld_list dbuf;
542 char tsdbuf[4];
544 new = (struct so_list *) xmalloc (sizeof (struct so_list));
545 old_chain = make_cleanup (xfree, new);
547 memset (new, 0, sizeof (*new));
548 new->lm_info = xmalloc (sizeof (struct lm_info));
549 make_cleanup (xfree, new->lm_info);
551 read_memory (lm, (gdb_byte *)&dbuf, sizeof (struct dld_list));
553 addr = extract_unsigned_integer ((gdb_byte *)&dbuf.name,
554 sizeof (dbuf.name));
555 target_read_string (addr, &namebuf, SO_NAME_MAX_PATH_SIZE - 1, &errcode);
556 if (errcode != 0)
557 warning (_("Can't read pathname for load map: %s."),
558 safe_strerror (errcode));
559 else
561 strncpy (new->so_name, namebuf, SO_NAME_MAX_PATH_SIZE - 1);
562 new->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
563 xfree (namebuf);
564 strcpy (new->so_original_name, new->so_name);
567 if (new->so_name[0] && !match_main (new->so_name))
569 struct lm_info *lmi = new->lm_info;
570 unsigned int tmp;
572 lmi->lm_addr = lm;
574 #define EXTRACT(_fld) \
575 extract_unsigned_integer ((gdb_byte *)&dbuf._fld, sizeof (dbuf._fld));
577 lmi->text_addr = EXTRACT (text_addr);
578 tmp = EXTRACT (info);
579 lmi->library_version = (tmp >> 16) & 0xffff;
580 lmi->bind_mode = (tmp >> 8) & 0xff;
581 lmi->struct_version = tmp & 0xff;
582 lmi->text_link_addr = EXTRACT (text_link_addr);
583 lmi->text_end = EXTRACT (text_end);
584 lmi->data_start = EXTRACT (data_start);
585 lmi->bss_start = EXTRACT (bss_start);
586 lmi->data_end = EXTRACT (data_end);
587 lmi->got_value = EXTRACT (got_value);
588 tmp = EXTRACT (tsd_start_addr_ptr);
589 read_memory (tmp, tsdbuf, 4);
590 lmi->tsd_start_addr = extract_unsigned_integer (tsdbuf, 4);
592 #ifdef SOLIB_SOM_DBG
593 printf ("\n+ library \"%s\" is described at 0x%s\n", new->so_name,
594 paddr_nz (lm));
595 printf (" 'version' is %d\n", new->lm_info->struct_version);
596 printf (" 'bind_mode' is %d\n", new->lm_info->bind_mode);
597 printf (" 'library_version' is %d\n",
598 new->lm_info->library_version);
599 printf (" 'text_addr' is 0x%s\n",
600 paddr_nz (new->lm_info->text_addr));
601 printf (" 'text_link_addr' is 0x%s\n",
602 paddr_nz (new->lm_info->text_link_addr));
603 printf (" 'text_end' is 0x%s\n",
604 paddr_nz (new->lm_info->text_end));
605 printf (" 'data_start' is 0x%s\n",
606 paddr_nz (new->lm_info->data_start));
607 printf (" 'bss_start' is 0x%s\n",
608 paddr_nz (new->lm_info->bss_start));
609 printf (" 'data_end' is 0x%s\n",
610 paddr_nz (new->lm_info->data_end));
611 printf (" 'got_value' is %s\n",
612 paddr_nz (new->lm_info->got_value));
613 printf (" 'tsd_start_addr' is 0x%s\n",
614 paddr_nz (new->lm_info->tsd_start_addr));
615 #endif
617 new->addr_low = lmi->text_addr;
618 new->addr_high = lmi->text_end;
620 /* Link the new object onto the list. */
621 new->next = NULL;
622 *link_ptr = new;
623 link_ptr = &new->next;
625 else
627 free_so (new);
630 lm = EXTRACT (next);
631 discard_cleanups (old_chain);
632 #undef EXTRACT
635 /* TODO: The original somsolib code has logic to detect and eliminate
636 duplicate entries. Do we need that? */
638 return head;
641 static int
642 som_open_symbol_file_object (void *from_ttyp)
644 CORE_ADDR lm, l_name;
645 char *filename;
646 int errcode;
647 int from_tty = *(int *)from_ttyp;
648 char buf[4];
650 if (symfile_objfile)
651 if (!query ("Attempt to reload symbols from process? "))
652 return 0;
654 /* First link map member should be the executable. */
655 if ((lm = link_map_start ()) == 0)
656 return 0; /* failed somehow... */
658 /* Read address of name from target memory to GDB. */
659 read_memory (lm + offsetof (struct dld_list, name), buf, 4);
661 /* Convert the address to host format. Assume that the address is
662 unsigned. */
663 l_name = extract_unsigned_integer (buf, 4);
665 if (l_name == 0)
666 return 0; /* No filename. */
668 /* Now fetch the filename from target memory. */
669 target_read_string (l_name, &filename, SO_NAME_MAX_PATH_SIZE - 1, &errcode);
671 if (errcode)
673 warning (_("failed to read exec filename from attached file: %s"),
674 safe_strerror (errcode));
675 return 0;
678 make_cleanup (xfree, filename);
679 /* Have a pathname: read the symbol file. */
680 symbol_file_add_main (filename, from_tty);
682 return 1;
685 static void
686 som_free_so (struct so_list *so)
688 xfree (so->lm_info);
691 static CORE_ADDR
692 som_solib_thread_start_addr (struct so_list *so)
694 return so->lm_info->tsd_start_addr;
697 /* Return the GOT value for the shared library in which ADDR belongs. If
698 ADDR isn't in any known shared library, return zero. */
700 static CORE_ADDR
701 som_solib_get_got_by_pc (CORE_ADDR addr)
703 struct so_list *so_list = master_so_list ();
704 CORE_ADDR got_value = 0;
706 while (so_list)
708 if (so_list->lm_info->text_addr <= addr
709 && so_list->lm_info->text_end > addr)
711 got_value = so_list->lm_info->got_value;
712 break;
714 so_list = so_list->next;
716 return got_value;
719 /* Return the address of the handle of the shared library in which ADDR belongs.
720 If ADDR isn't in any known shared library, return zero. */
721 /* this function is used in initialize_hp_cxx_exception_support in
722 hppa-hpux-tdep.c */
724 static CORE_ADDR
725 som_solib_get_solib_by_pc (CORE_ADDR addr)
727 struct so_list *so_list = master_so_list ();
729 while (so_list)
731 if (so_list->lm_info->text_addr <= addr
732 && so_list->lm_info->text_end > addr)
734 break;
736 so_list = so_list->next;
738 if (so_list)
739 return so_list->lm_info->lm_addr;
740 else
741 return 0;
745 static struct target_so_ops som_so_ops;
747 extern initialize_file_ftype _initialize_som_solib; /* -Wmissing-prototypes */
749 void
750 _initialize_som_solib (void)
752 som_so_ops.relocate_section_addresses = som_relocate_section_addresses;
753 som_so_ops.free_so = som_free_so;
754 som_so_ops.clear_solib = som_clear_solib;
755 som_so_ops.solib_create_inferior_hook = som_solib_create_inferior_hook;
756 som_so_ops.special_symbol_handling = som_special_symbol_handling;
757 som_so_ops.current_sos = som_current_sos;
758 som_so_ops.open_symbol_file_object = som_open_symbol_file_object;
759 som_so_ops.in_dynsym_resolve_code = som_in_dynsym_resolve_code;
762 void som_solib_select (struct gdbarch *gdbarch)
764 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
765 set_solib_ops (gdbarch, &som_so_ops);
767 tdep->solib_thread_start_addr = som_solib_thread_start_addr;
768 tdep->solib_get_got_by_pc = som_solib_get_got_by_pc;
769 tdep->solib_get_solib_by_pc = som_solib_get_solib_by_pc;
772 /* The rest of these functions are not part of the solib interface; they
773 are used by somread.c or hppa-hpux-tdep.c */
776 som_solib_section_offsets (struct objfile *objfile,
777 struct section_offsets *offsets)
779 struct so_list *so_list = master_so_list ();
781 while (so_list)
783 /* Oh what a pain! We need the offsets before so_list->objfile
784 is valid. The BFDs will never match. Make a best guess. */
785 if (strstr (objfile->name, so_list->so_name))
787 asection *private_section;
789 /* The text offset is easy. */
790 offsets->offsets[SECT_OFF_TEXT (objfile)]
791 = (so_list->lm_info->text_addr
792 - so_list->lm_info->text_link_addr);
793 offsets->offsets[SECT_OFF_RODATA (objfile)]
794 = ANOFFSET (offsets, SECT_OFF_TEXT (objfile));
796 /* We should look at presumed_dp in the SOM header, but
797 that's not easily available. This should be OK though. */
798 private_section = bfd_get_section_by_name (objfile->obfd,
799 "$PRIVATE$");
800 if (!private_section)
802 warning (_("Unable to find $PRIVATE$ in shared library!"));
803 offsets->offsets[SECT_OFF_DATA (objfile)] = 0;
804 offsets->offsets[SECT_OFF_BSS (objfile)] = 0;
805 return 1;
807 offsets->offsets[SECT_OFF_DATA (objfile)]
808 = (so_list->lm_info->data_start - private_section->vma);
809 offsets->offsets[SECT_OFF_BSS (objfile)]
810 = ANOFFSET (offsets, SECT_OFF_DATA (objfile));
811 return 1;
813 so_list = so_list->next;
815 return 0;