OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gdb-6.8/] [gdb/] [solib-sunos.c] - Blame information for rev 853

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.