Remove a.out NetBSD and OpenBSD hosts
[deliverable/binutils-gdb.git] / gdb / solib-sunos.c
CommitLineData
ab31aa69 1/* Handle SunOS shared libraries for GDB, the GNU Debugger.
8dcef9cf 2
28e7fd62 3 Copyright (C) 1990-2013 Free Software Foundation, Inc.
ab31aa69
KB
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
ab31aa69
KB
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/>. */
ab31aa69
KB
19
20#include "defs.h"
21
22#include <sys/types.h>
23#include <signal.h>
24#include "gdb_string.h"
ab31aa69
KB
25#include <fcntl.h>
26
8dcef9cf 27/* SunOS shared libs need the nlist structure. */
ab31aa69
KB
28#include <a.out.h>
29#include <link.h>
30
31#include "symtab.h"
32#include "bfd.h"
33#include "symfile.h"
34#include "objfiles.h"
35#include "gdbcore.h"
36#include "inferior.h"
2020b7ab 37#include "gdbthread.h"
ab31aa69 38#include "solist.h"
03cc47f7
MK
39#include "bcache.h"
40#include "regcache.h"
ab31aa69 41
8dcef9cf
MK
42/* The shared library implementation found on BSD a.out systems is
43 very similar to the SunOS implementation. However, the data
44 structures defined in <link.h> are named very differently. Make up
45 for those differences here. */
46
47#ifdef HAVE_STRUCT_SO_MAP_WITH_SOM_MEMBERS
48
49/* FIXME: Temporary until the equivalent defines have been removed
50 from all nm-*bsd*.h files. */
51#ifndef link_dynamic
52
53/* Map `struct link_map' and its members. */
54#define link_map so_map
55#define lm_addr som_addr
56#define lm_name som_path
57#define lm_next som_next
58
59/* Map `struct link_dynamic_2' and its members. */
60#define link_dynamic_2 section_dispatch_table
61#define ld_loaded sdt_loaded
62
63/* Map `struct rtc_symb' and its members. */
64#define rtc_symb rt_symbol
65#define rtc_sp rt_sp
66#define rtc_next rt_next
67
68/* Map `struct ld_debug' and its members. */
69#define ld_debug so_debug
70#define ldd_in_debugger dd_in_debugger
71#define ldd_bp_addr dd_bpt_addr
72#define ldd_bp_inst dd_bpt_shadow
73#define ldd_cp dd_cc
74
75/* Map `struct link_dynamic' and its members. */
76#define link_dynamic _dynamic
77#define ld_version d_version
78#define ldd d_debug
79#define ld_un d_un
80#define ld_2 d_sdt
81
82#endif
83
84#endif
85
c378eb4e 86/* Link map info to include in an allocated so_list entry. */
ab31aa69
KB
87
88struct lm_info
89 {
90 /* Pointer to copy of link map from inferior. The type is char *
91 rather than void *, so that we may use byte offsets to find the
92 various fields without the need for a cast. */
93 char *lm;
94 };
95
96
c378eb4e 97/* Symbols which are used to locate the base of the link map structures. */
ab31aa69
KB
98
99static char *debug_base_symbols[] =
100{
101 "_DYNAMIC",
102 "_DYNAMIC__MGC",
103 NULL
104};
105
106static char *main_name_list[] =
107{
108 "main_$main",
109 NULL
110};
111
ae0167b9
AC
112/* Macro to extract an address from a solib structure. When GDB is
113 configured for some 32-bit targets (e.g. Solaris 2.7 sparc), BFD is
114 configured to handle 64-bit targets, so CORE_ADDR is 64 bits. We
115 have to extract only the significant bits of addresses to get the
116 right address when accessing the core file BFD.
117
118 Assume that the address is unsigned. */
ab31aa69
KB
119
120#define SOLIB_EXTRACT_ADDRESS(MEMBER) \
e17a4113 121 extract_unsigned_integer (&(MEMBER), sizeof (MEMBER), \
f5656ead 122 gdbarch_byte_order (target_gdbarch ()))
ab31aa69
KB
123
124/* local data declarations */
125
126static struct link_dynamic dynamic_copy;
127static struct link_dynamic_2 ld_2_copy;
128static struct ld_debug debug_copy;
129static CORE_ADDR debug_addr;
130static CORE_ADDR flag_addr;
131
132#ifndef offsetof
133#define offsetof(TYPE, MEMBER) ((unsigned long) &((TYPE *)0)->MEMBER)
134#endif
135#define fieldsize(TYPE, MEMBER) (sizeof (((TYPE *)0)->MEMBER))
136
137/* link map access functions */
138
139static CORE_ADDR
b23518f0 140lm_addr (struct so_list *so)
ab31aa69 141{
f5656ead 142 enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
ab31aa69
KB
143 int lm_addr_offset = offsetof (struct link_map, lm_addr);
144 int lm_addr_size = fieldsize (struct link_map, lm_addr);
145
146 return (CORE_ADDR) extract_signed_integer (so->lm_info->lm + lm_addr_offset,
e17a4113 147 lm_addr_size, byte_order);
ab31aa69
KB
148}
149
150static CORE_ADDR
b23518f0 151lm_next (struct so_list *so)
ab31aa69 152{
f5656ead 153 enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
ab31aa69
KB
154 int lm_next_offset = offsetof (struct link_map, lm_next);
155 int lm_next_size = fieldsize (struct link_map, lm_next);
156
ae0167b9
AC
157 /* Assume that the address is unsigned. */
158 return extract_unsigned_integer (so->lm_info->lm + lm_next_offset,
e17a4113 159 lm_next_size, byte_order);
ab31aa69
KB
160}
161
162static CORE_ADDR
b23518f0 163lm_name (struct so_list *so)
ab31aa69 164{
f5656ead 165 enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
ab31aa69
KB
166 int lm_name_offset = offsetof (struct link_map, lm_name);
167 int lm_name_size = fieldsize (struct link_map, lm_name);
168
ae0167b9
AC
169 /* Assume that the address is unsigned. */
170 return extract_unsigned_integer (so->lm_info->lm + lm_name_offset,
e17a4113 171 lm_name_size, byte_order);
ab31aa69
KB
172}
173
c378eb4e 174static CORE_ADDR debug_base; /* Base of dynamic linker structures. */
ab31aa69
KB
175
176/* Local function prototypes */
177
178static int match_main (char *);
179
180/* Allocate the runtime common object file. */
181
182static void
183allocate_rt_common_objfile (void)
184{
185 struct objfile *objfile;
186 struct objfile *last_one;
187
188 objfile = (struct objfile *) xmalloc (sizeof (struct objfile));
189 memset (objfile, 0, sizeof (struct objfile));
5068b8e8 190 objfile->psymbol_cache = psymbol_bcache_init ();
191 objfile->macro_cache = bcache_xmalloc (NULL, NULL);
192 objfile->filename_cache = bcache_xmalloc (NULL, NULL);
1ab21617 193 obstack_init (&objfile->objfile_obstack);
982526a1 194 objfile->name = xstrdup ("rt_common");
ab31aa69 195
c378eb4e 196 /* Add this file onto the tail of the linked list of other such files. */
ab31aa69
KB
197
198 objfile->next = NULL;
199 if (object_files == NULL)
200 object_files = objfile;
201 else
202 {
203 for (last_one = object_files;
204 last_one->next;
205 last_one = last_one->next);
206 last_one->next = objfile;
207 }
208
209 rt_common_objfile = objfile;
210}
211
212/* Read all dynamically loaded common symbol definitions from the inferior
213 and put them into the minimal symbol table for the runtime common
214 objfile. */
215
216static void
217solib_add_common_symbols (CORE_ADDR rtc_symp)
218{
219 struct rtc_symb inferior_rtc_symb;
220 struct nlist inferior_rtc_nlist;
221 int len;
222 char *name;
223
224 /* Remove any runtime common symbols from previous runs. */
225
226 if (rt_common_objfile != NULL && rt_common_objfile->minimal_symbol_count)
227 {
4a146b47 228 obstack_free (&rt_common_objfile->objfile_obstack, 0);
1ab21617 229 obstack_init (&rt_common_objfile->objfile_obstack);
ab31aa69
KB
230 rt_common_objfile->minimal_symbol_count = 0;
231 rt_common_objfile->msymbols = NULL;
15831452 232 terminate_minimal_symbol_table (rt_common_objfile);
ab31aa69
KB
233 }
234
235 init_minimal_symbol_collection ();
236 make_cleanup_discard_minimal_symbols ();
237
238 while (rtc_symp)
239 {
240 read_memory (rtc_symp,
241 (char *) &inferior_rtc_symb,
242 sizeof (inferior_rtc_symb));
243 read_memory (SOLIB_EXTRACT_ADDRESS (inferior_rtc_symb.rtc_sp),
244 (char *) &inferior_rtc_nlist,
245 sizeof (inferior_rtc_nlist));
246 if (inferior_rtc_nlist.n_type == N_COMM)
247 {
248 /* FIXME: The length of the symbol name is not available, but in the
249 current implementation the common symbol is allocated immediately
c378eb4e 250 behind the name of the symbol. */
ab31aa69
KB
251 len = inferior_rtc_nlist.n_value - inferior_rtc_nlist.n_un.n_strx;
252
253 name = xmalloc (len);
254 read_memory (SOLIB_EXTRACT_ADDRESS (inferior_rtc_nlist.n_un.n_name),
255 name, len);
256
c378eb4e 257 /* Allocate the runtime common objfile if necessary. */
ab31aa69
KB
258 if (rt_common_objfile == NULL)
259 allocate_rt_common_objfile ();
260
261 prim_record_minimal_symbol (name, inferior_rtc_nlist.n_value,
262 mst_bss, rt_common_objfile);
263 xfree (name);
264 }
265 rtc_symp = SOLIB_EXTRACT_ADDRESS (inferior_rtc_symb.rtc_next);
266 }
267
268 /* Install any minimal symbols that have been collected as the current
269 minimal symbols for the runtime common objfile. */
270
271 install_minimal_symbols (rt_common_objfile);
272}
273
274
7f86f058 275/* Locate the base address of dynamic linker structs.
ab31aa69
KB
276
277 For both the SunOS and SVR4 shared library implementations, if the
278 inferior executable has been linked dynamically, there is a single
279 address somewhere in the inferior's data space which is the key to
280 locating all of the dynamic linker's runtime structures. This
281 address is the value of the debug base symbol. The job of this
282 function is to find and return that address, or to return 0 if there
283 is no such address (the executable is statically linked for example).
284
285 For SunOS, the job is almost trivial, since the dynamic linker and
286 all of it's structures are statically linked to the executable at
287 link time. Thus the symbol for the address we are looking for has
288 already been added to the minimal symbol table for the executable's
289 objfile at the time the symbol file's symbols were read, and all we
290 have to do is look it up there. Note that we explicitly do NOT want
291 to find the copies in the shared library.
292
293 The SVR4 version is a bit more complicated because the address
294 is contained somewhere in the dynamic info section. We have to go
295 to a lot more work to discover the address of the debug base symbol.
296 Because of this complexity, we cache the value we find and return that
297 value on subsequent invocations. Note there is no copy in the
7f86f058 298 executable symbol tables. */
ab31aa69
KB
299
300static CORE_ADDR
301locate_base (void)
302{
303 struct minimal_symbol *msymbol;
304 CORE_ADDR address = 0;
305 char **symbolp;
306
307 /* For SunOS, we want to limit the search for the debug base symbol to the
308 executable being debugged, since there is a duplicate named symbol in the
c378eb4e 309 shared library. We don't want the shared library versions. */
ab31aa69
KB
310
311 for (symbolp = debug_base_symbols; *symbolp != NULL; symbolp++)
312 {
313 msymbol = lookup_minimal_symbol (*symbolp, NULL, symfile_objfile);
314 if ((msymbol != NULL) && (SYMBOL_VALUE_ADDRESS (msymbol) != 0))
315 {
316 address = SYMBOL_VALUE_ADDRESS (msymbol);
317 return (address);
318 }
319 }
320 return (0);
321}
322
7f86f058 323/* Locate first member in dynamic linker's map.
ab31aa69
KB
324
325 Find the first element in the inferior's dynamic link map, and
326 return its address in the inferior. This function doesn't copy the
327 link map entry itself into our address space; current_sos actually
328 does the reading. */
329
330static CORE_ADDR
331first_link_map_member (void)
332{
333 CORE_ADDR lm = 0;
334
335 read_memory (debug_base, (char *) &dynamic_copy, sizeof (dynamic_copy));
336 if (dynamic_copy.ld_version >= 2)
337 {
338 /* It is a version that we can deal with, so read in the secondary
c378eb4e 339 structure and find the address of the link map list from it. */
ab31aa69
KB
340 read_memory (SOLIB_EXTRACT_ADDRESS (dynamic_copy.ld_un.ld_2),
341 (char *) &ld_2_copy, sizeof (struct link_dynamic_2));
342 lm = SOLIB_EXTRACT_ADDRESS (ld_2_copy.ld_loaded);
343 }
344 return (lm);
345}
346
347static int
348open_symbol_file_object (void *from_ttyp)
349{
350 return 1;
351}
352
353
7f86f058 354/* Implement the "current_sos" target_so_ops method. */
ab31aa69
KB
355
356static struct so_list *
357sunos_current_sos (void)
358{
359 CORE_ADDR lm;
360 struct so_list *head = 0;
361 struct so_list **link_ptr = &head;
362 int errcode;
363 char *buffer;
364
365 /* Make sure we've looked up the inferior's dynamic linker's base
366 structure. */
367 if (! debug_base)
368 {
369 debug_base = locate_base ();
370
371 /* If we can't find the dynamic linker's base structure, this
372 must not be a dynamically linked executable. Hmm. */
373 if (! debug_base)
374 return 0;
375 }
376
377 /* Walk the inferior's link map list, and build our list of
378 `struct so_list' nodes. */
379 lm = first_link_map_member ();
380 while (lm)
381 {
382 struct so_list *new
383 = (struct so_list *) xmalloc (sizeof (struct so_list));
384 struct cleanup *old_chain = make_cleanup (xfree, new);
385
386 memset (new, 0, sizeof (*new));
387
388 new->lm_info = xmalloc (sizeof (struct lm_info));
389 make_cleanup (xfree, new->lm_info);
390
391 new->lm_info->lm = xmalloc (sizeof (struct link_map));
392 make_cleanup (xfree, new->lm_info->lm);
393 memset (new->lm_info->lm, 0, sizeof (struct link_map));
394
395 read_memory (lm, new->lm_info->lm, sizeof (struct link_map));
396
b23518f0 397 lm = lm_next (new);
ab31aa69
KB
398
399 /* Extract this shared object's name. */
b23518f0 400 target_read_string (lm_name (new), &buffer,
ab31aa69
KB
401 SO_NAME_MAX_PATH_SIZE - 1, &errcode);
402 if (errcode != 0)
8a3fe4f8
AC
403 warning (_("Can't read pathname for load map: %s."),
404 safe_strerror (errcode));
ab31aa69
KB
405 else
406 {
407 strncpy (new->so_name, buffer, SO_NAME_MAX_PATH_SIZE - 1);
408 new->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
409 xfree (buffer);
410 strcpy (new->so_original_name, new->so_name);
411 }
412
413 /* If this entry has no name, or its name matches the name
414 for the main executable, don't include it in the list. */
415 if (! new->so_name[0]
416 || match_main (new->so_name))
417 free_so (new);
418 else
419 {
420 new->next = 0;
421 *link_ptr = new;
422 link_ptr = &new->next;
423 }
424
425 discard_cleanups (old_chain);
426 }
427
428 return head;
429}
430
431
432/* On some systems, the only way to recognize the link map entry for
433 the main executable file is by looking at its name. Return
434 non-zero iff SONAME matches one of the known main executable names. */
435
436static int
437match_main (char *soname)
438{
439 char **mainp;
440
441 for (mainp = main_name_list; *mainp != NULL; mainp++)
442 {
443 if (strcmp (soname, *mainp) == 0)
444 return (1);
445 }
446
447 return (0);
448}
449
450
451static int
452sunos_in_dynsym_resolve_code (CORE_ADDR pc)
453{
454 return 0;
455}
456
7f86f058 457/* Remove the "mapping changed" breakpoint.
ab31aa69
KB
458
459 Removes the breakpoint that gets hit when the dynamic linker
7f86f058 460 completes a mapping change. */
ab31aa69
KB
461
462static int
463disable_break (void)
464{
c378eb4e 465 CORE_ADDR breakpoint_addr; /* Address where end bkpt is set. */
ab31aa69
KB
466
467 int in_debugger = 0;
468
469 /* Read the debugger structure from the inferior to retrieve the
470 address of the breakpoint and the original contents of the
471 breakpoint address. Remove the breakpoint by writing the original
c378eb4e 472 contents back. */
ab31aa69
KB
473
474 read_memory (debug_addr, (char *) &debug_copy, sizeof (debug_copy));
475
c378eb4e 476 /* Set `in_debugger' to zero now. */
ab31aa69
KB
477
478 write_memory (flag_addr, (char *) &in_debugger, sizeof (in_debugger));
479
480 breakpoint_addr = SOLIB_EXTRACT_ADDRESS (debug_copy.ldd_bp_addr);
481 write_memory (breakpoint_addr, (char *) &debug_copy.ldd_bp_inst,
482 sizeof (debug_copy.ldd_bp_inst));
483
484 /* For the SVR4 version, we always know the breakpoint address. For the
485 SunOS version we don't know it until the above code is executed.
c378eb4e 486 Grumble if we are stopped anywhere besides the breakpoint address. */
ab31aa69
KB
487
488 if (stop_pc != breakpoint_addr)
489 {
3e43a32a
MS
490 warning (_("stopped at unknown breakpoint "
491 "while handling shared libraries"));
ab31aa69
KB
492 }
493
494 return 1;
495}
496
7f86f058 497/* Arrange for dynamic linker to hit breakpoint.
ab31aa69
KB
498
499 Both the SunOS and the SVR4 dynamic linkers have, as part of their
500 debugger interface, support for arranging for the inferior to hit
501 a breakpoint after mapping in the shared libraries. This function
502 enables that breakpoint.
503
504 For SunOS, there is a special flag location (in_debugger) which we
505 set to 1. When the dynamic linker sees this flag set, it will set
506 a breakpoint at a location known only to itself, after saving the
507 original contents of that place and the breakpoint address itself,
508 in it's own internal structures. When we resume the inferior, it
509 will eventually take a SIGTRAP when it runs into the breakpoint.
510 We handle this (in a different place) by restoring the contents of
511 the breakpointed location (which is only known after it stops),
512 chasing around to locate the shared libraries that have been
513 loaded, then resuming.
514
515 For SVR4, the debugger interface structure contains a member (r_brk)
516 which is statically initialized at the time the shared library is
517 built, to the offset of a function (_r_debug_state) which is guaran-
518 teed to be called once before mapping in a library, and again when
519 the mapping is complete. At the time we are examining this member,
520 it contains only the unrelocated offset of the function, so we have
521 to do our own relocation. Later, when the dynamic linker actually
522 runs, it relocates r_brk to be the actual address of _r_debug_state().
523
524 The debugger interface structure also contains an enumeration which
525 is set to either RT_ADD or RT_DELETE prior to changing the mapping,
7f86f058
PA
526 depending upon whether or not the library is being mapped or
527 unmapped, and then set to RT_CONSISTENT after the library is
528 mapped/unmapped. */
ab31aa69
KB
529
530static int
531enable_break (void)
532{
533 int success = 0;
534 int j;
535 int in_debugger;
536
c378eb4e 537 /* Get link_dynamic structure. */
ab31aa69
KB
538
539 j = target_read_memory (debug_base, (char *) &dynamic_copy,
540 sizeof (dynamic_copy));
541 if (j)
542 {
543 /* unreadable */
544 return (0);
545 }
546
c378eb4e 547 /* Calc address of debugger interface structure. */
ab31aa69
KB
548
549 debug_addr = SOLIB_EXTRACT_ADDRESS (dynamic_copy.ldd);
550
c378eb4e 551 /* Calc address of `in_debugger' member of debugger interface structure. */
ab31aa69
KB
552
553 flag_addr = debug_addr + (CORE_ADDR) ((char *) &debug_copy.ldd_in_debugger -
554 (char *) &debug_copy);
555
556 /* Write a value of 1 to this member. */
557
558 in_debugger = 1;
559 write_memory (flag_addr, (char *) &in_debugger, sizeof (in_debugger));
560 success = 1;
561
562 return (success);
563}
564
7f86f058 565/* Implement the "special_symbol_handling" target_so_ops method.
ab31aa69
KB
566
567 For SunOS4, this consists of grunging around in the dynamic
568 linkers structures to find symbol definitions for "common" symbols
569 and adding them to the minimal symbol table for the runtime common
7f86f058 570 objfile. */
ab31aa69
KB
571
572static void
573sunos_special_symbol_handling (void)
574{
575 int j;
576
577 if (debug_addr == 0)
578 {
c378eb4e 579 /* Get link_dynamic structure. */
ab31aa69
KB
580
581 j = target_read_memory (debug_base, (char *) &dynamic_copy,
582 sizeof (dynamic_copy));
583 if (j)
584 {
585 /* unreadable */
586 return;
587 }
588
c378eb4e 589 /* Calc address of debugger interface structure. */
ab31aa69
KB
590 /* FIXME, this needs work for cross-debugging of core files
591 (byteorder, size, alignment, etc). */
592
593 debug_addr = SOLIB_EXTRACT_ADDRESS (dynamic_copy.ldd);
594 }
595
596 /* Read the debugger structure from the inferior, just to make sure
c378eb4e 597 we have a current copy. */
ab31aa69
KB
598
599 j = target_read_memory (debug_addr, (char *) &debug_copy,
600 sizeof (debug_copy));
601 if (j)
602 return; /* unreadable */
603
c378eb4e 604 /* Get common symbol definitions for the loaded object. */
ab31aa69
KB
605
606 if (debug_copy.ldd_cp)
607 {
608 solib_add_common_symbols (SOLIB_EXTRACT_ADDRESS (debug_copy.ldd_cp));
609 }
610}
611
7f86f058 612/* Implement the "create_inferior_hook" target_solib_ops method.
ab31aa69
KB
613
614 For SunOS executables, this first instruction is typically the
615 one at "_start", or a similar text label, regardless of whether
616 the executable is statically or dynamically linked. The runtime
617 startup code takes care of dynamically linking in any shared
618 libraries, once gdb allows the inferior to continue.
619
7f86f058
PA
620 We can arrange to cooperate with the dynamic linker to discover the
621 names of shared libraries that are dynamically linked, and the base
622 addresses to which they are linked.
ab31aa69
KB
623
624 This function is responsible for discovering those names and
625 addresses, and saving sufficient information about them to allow
626 their symbols to be read at a later time.
627
628 FIXME
629
630 Between enable_break() and disable_break(), this code does not
631 properly handle hitting breakpoints which the user might have
632 set in the startup code or in the dynamic linker itself. Proper
633 handling will probably have to wait until the implementation is
634 changed to use the "breakpoint handler function" method.
635
7f86f058 636 Also, what if child has exit()ed? Must exit loop somehow. */
ab31aa69
KB
637
638static void
268a4a75 639sunos_solib_create_inferior_hook (int from_tty)
ab31aa69 640{
2020b7ab 641 struct thread_info *tp;
d6b48e9c 642 struct inferior *inf;
2020b7ab 643
ab31aa69
KB
644 if ((debug_base = locate_base ()) == 0)
645 {
c378eb4e 646 /* Can't find the symbol or the executable is statically linked. */
ab31aa69
KB
647 return;
648 }
649
650 if (!enable_break ())
651 {
8a3fe4f8 652 warning (_("shared library handler failed to enable breakpoint"));
ab31aa69
KB
653 return;
654 }
655
656 /* SCO and SunOS need the loop below, other systems should be using the
657 special shared library breakpoints and the shared library breakpoint
658 service routine.
659
660 Now run the target. It will eventually hit the breakpoint, at
661 which point all of the libraries will have been mapped in and we
662 can go groveling around in the dynamic linker structures to find
c378eb4e 663 out what we need to know about them. */
ab31aa69 664
d6b48e9c 665 inf = current_inferior ();
2020b7ab 666 tp = inferior_thread ();
d6b48e9c 667
ab31aa69 668 clear_proceed_status ();
d6b48e9c 669
16c381f0 670 inf->control.stop_soon = STOP_QUIETLY;
a493e3e2 671 tp->suspend.stop_signal = GDB_SIGNAL_0;
ab31aa69
KB
672 do
673 {
16c381f0 674 target_resume (pid_to_ptid (-1), 0, tp->suspend.stop_signal);
e4c8541f 675 wait_for_inferior ();
ab31aa69 676 }
a493e3e2 677 while (tp->suspend.stop_signal != GDB_SIGNAL_TRAP);
16c381f0 678 inf->control.stop_soon = NO_STOP_QUIETLY;
ab31aa69
KB
679
680 /* We are now either at the "mapping complete" breakpoint (or somewhere
681 else, a condition we aren't prepared to deal with anyway), so adjust
682 the PC as necessary after a breakpoint, disable the breakpoint, and
b4397864
UW
683 add any shared libraries that were mapped in.
684
685 Note that adjust_pc_after_break did not perform any PC adjustment,
686 as the breakpoint the inferior just hit was not inserted by GDB,
687 but by the dynamic loader itself, and is therefore not found on
688 the GDB software break point list. Thus we have to adjust the
689 PC here. */
ab31aa69 690
f5656ead 691 if (gdbarch_decr_pc_after_break (target_gdbarch ()))
ab31aa69 692 {
f5656ead 693 stop_pc -= gdbarch_decr_pc_after_break (target_gdbarch ());
fb14de7b 694 regcache_write_pc (get_current_regcache (), stop_pc);
ab31aa69
KB
695 }
696
697 if (!disable_break ())
698 {
8a3fe4f8 699 warning (_("shared library handler failed to disable breakpoint"));
ab31aa69
KB
700 }
701
990f9fe3 702 solib_add ((char *) 0, 0, (struct target_ops *) 0, auto_solib_add);
ab31aa69
KB
703}
704
705static void
706sunos_clear_solib (void)
707{
708 debug_base = 0;
709}
710
711static void
712sunos_free_so (struct so_list *so)
713{
714 xfree (so->lm_info->lm);
715 xfree (so->lm_info);
716}
717
718static void
719sunos_relocate_section_addresses (struct so_list *so,
0542c86d 720 struct target_section *sec)
ab31aa69 721{
b23518f0
PM
722 sec->addr += lm_addr (so);
723 sec->endaddr += lm_addr (so);
ab31aa69
KB
724}
725
726static struct target_so_ops sunos_so_ops;
727
728void
729_initialize_sunos_solib (void)
730{
731 sunos_so_ops.relocate_section_addresses = sunos_relocate_section_addresses;
732 sunos_so_ops.free_so = sunos_free_so;
733 sunos_so_ops.clear_solib = sunos_clear_solib;
734 sunos_so_ops.solib_create_inferior_hook = sunos_solib_create_inferior_hook;
735 sunos_so_ops.special_symbol_handling = sunos_special_symbol_handling;
736 sunos_so_ops.current_sos = sunos_current_sos;
737 sunos_so_ops.open_symbol_file_object = open_symbol_file_object;
738 sunos_so_ops.in_dynsym_resolve_code = sunos_in_dynsym_resolve_code;
831a0c44 739 sunos_so_ops.bfd_open = solib_bfd_open;
ab31aa69 740
c378eb4e 741 /* FIXME: Don't do this here. *_gdbarch_init() should set so_ops. */
ab31aa69
KB
742 current_target_so_ops = &sunos_so_ops;
743}
This page took 1.678556 seconds and 4 git commands to generate.