aboutsummaryrefslogtreecommitdiff
path: root/gdb/solib-legacy.c
blob: d876802d35f935108410503685b1f12f02339c55 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/* Provide legacy r_debug and link_map support for SVR4-like native targets.

   Copyright (C) 2000, 2001, 2006, 2007 Free Software Foundation, Inc.

   This file is part of GDB.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.  */

#include "defs.h"
#include "gdbcore.h"
#include "solib-svr4.h"

#ifdef HAVE_LINK_H

#ifdef HAVE_NLIST_H
/* nlist.h needs to be included before link.h on some older *BSD systems. */
#include <nlist.h>
#endif

#include <link.h>

/* Fetch (and possibly build) an appropriate link_map_offsets structure
   for native targets using struct definitions from link.h.  */

static struct link_map_offsets *
legacy_svr4_fetch_link_map_offsets (void)
{
  static struct link_map_offsets lmo;
  static struct link_map_offsets *lmp = 0;
#if defined (HAVE_STRUCT_LINK_MAP32)
  static struct link_map_offsets lmo32;
  static struct link_map_offsets *lmp32 = 0;
#endif

#ifndef offsetof
#define offsetof(TYPE, MEMBER) ((unsigned long) &((TYPE *)0)->MEMBER)
#endif
#define fieldsize(TYPE, MEMBER) (sizeof (((TYPE *)0)->MEMBER))

  if (lmp == 0)
    {
      lmp = &lmo;

#ifdef HAVE_STRUCT_LINK_MAP_WITH_L_MEMBERS
      lmo.r_version_offset = offsetof (struct r_debug, r_version);
      lmo.r_version_size = fieldsize (struct r_debug, r_version);
      lmo.r_map_offset = offsetof (struct r_debug, r_map);
      lmo.r_ldsomap_offset = -1;

      lmo.link_map_size = sizeof (struct link_map);

      lmo.l_addr_offset = offsetof (struct link_map, l_addr);
      lmo.l_addr_size = fieldsize (struct link_map, l_addr);

      lmo.l_next_offset = offsetof (struct link_map, l_next);
      lmo.l_next_size = fieldsize (struct link_map, l_next);

      lmo.l_ld_offset = offsetof (struct link_map, l_ld);
      lmo.l_ld_size = fieldsize (struct link_map, l_ld);

      lmo.l_prev_offset = offsetof (struct link_map, l_prev);
      lmo.l_prev_size = fieldsize (struct link_map, l_prev);

      lmo.l_name_offset = offsetof (struct link_map, l_name);
      lmo.l_name_size = fieldsize (struct link_map, l_name);
#else /* !defined(HAVE_STRUCT_LINK_MAP_WITH_L_MEMBERS) */
#ifdef HAVE_STRUCT_LINK_MAP_WITH_LM_MEMBERS
      lmo.link_map_size = sizeof (struct link_map);

      lmo.l_addr_offset = offsetof (struct link_map, lm_addr);
      lmo.l_addr_size = fieldsize (struct link_map, lm_addr);

      lmo.l_next_offset = offsetof (struct link_map, lm_next);
      lmo.l_next_size = fieldsize (struct link_map, lm_next);

      /* FIXME: Is this the right field name, or is it available at all?  */
      lmo.l_ld_offset = offsetof (struct link_map, lm_ld);
      lmo.l_ld_size = fieldsize (struct link_map, lm_ld);

      lmo.l_name_offset = offsetof (struct link_map, lm_name);
      lmo.l_name_size = fieldsize (struct link_map, lm_name);
#else /* !defined(HAVE_STRUCT_LINK_MAP_WITH_LM_MEMBERS) */
#if HAVE_STRUCT_SO_MAP_WITH_SOM_MEMBERS
      lmo.link_map_size = sizeof (struct so_map);

      lmo.l_addr_offset = offsetof (struct so_map, som_addr);
      lmo.l_addr_size = fieldsize (struct so_map, som_addr);

      lmo.l_next_offset = offsetof (struct so_map, som_next);
      lmo.l_next_size = fieldsize (struct so_map, som_next);

      lmo.l_name_offset = offsetof (struct so_map, som_path);
      lmo.l_name_size = fieldsize (struct so_map, som_path);

      /* FIXME: Is the address of the dynamic table available?  */
      lmo.l_ld_offset = 0;
      lmo.l_ld_size = 0;
#endif /* HAVE_STRUCT_SO_MAP_WITH_SOM_MEMBERS */
#endif /* HAVE_STRUCT_LINK_MAP_WITH_LM_MEMBERS */
#endif /* HAVE_STRUCT_LINK_MAP_WITH_L_MEMBERS */
    }

#if defined (HAVE_STRUCT_LINK_MAP32)
  if (lmp32 == 0)
    {
      lmp32 = &lmo32;

      lmo32.r_version_offset = offsetof (struct r_debug32, r_version);
      lmo32.r_version_size = fieldsize (struct r_debug32, r_version);
      lmo32.r_map_offset = offsetof (struct r_debug32, r_map);
      lmo32.r_ldsomap_offset = -1;

      lmo32.link_map_size = sizeof (struct link_map32);

      lmo32.l_addr_offset = offsetof (struct link_map32, l_addr);
      lmo32.l_addr_size = fieldsize (struct link_map32, l_addr);

      lmo32.l_next_offset = offsetof (struct link_map32, l_next);
      lmo32.l_next_size = fieldsize (struct link_map32, l_next);

      lmo32.l_prev_offset = offsetof (struct link_map32, l_prev);
      lmo32.l_prev_size = fieldsize (struct link_map32, l_prev);

      lmo32.l_name_offset = offsetof (struct link_map32, l_name);
      lmo32.l_name_size = fieldsize (struct link_map32, l_name);
    }
#endif /* defined (HAVE_STRUCT_LINK_MAP32) */

#if defined (HAVE_STRUCT_LINK_MAP32)
  if (exec_bfd != NULL)
    {
      if (bfd_get_arch_size (exec_bfd) == 32)
	return lmp32;
    }
  if (TARGET_PTR_BIT == 32)
    return lmp32;
#endif
  return lmp;
}

#endif /* HAVE_LINK_H */

extern initialize_file_ftype _initialize_svr4_lm; /* -Wmissing-prototypes */

void
_initialize_svr4_lm (void)
{
#ifdef HAVE_LINK_H
  legacy_svr4_fetch_link_map_offsets_hook = legacy_svr4_fetch_link_map_offsets;
#endif /* HAVE_LINK_H */
}