*** empty log message ***
[deliverable/binutils-gdb.git] / gdb / solib-legacy.c
CommitLineData
21479ded 1/* Provide legacy r_debug and link_map support for SVR4-like native targets.
e4cd0d6a
MK
2
3 Copyright (C) 2000, 2001, 2006
21479ded
KB
4 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 2 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, write to the Free Software
197e01b6
EZ
20 Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
21479ded 22
21479ded
KB
23#include "defs.h"
24#include "gdbcore.h"
25#include "solib-svr4.h"
26
27#ifdef HAVE_LINK_H
486363b6
KB
28
29#ifdef HAVE_NLIST_H
30/* nlist.h needs to be included before link.h on some older *BSD systems. */
31#include <nlist.h>
32#endif
33
21479ded
KB
34#include <link.h>
35
36/* Fetch (and possibly build) an appropriate link_map_offsets structure
37 for native targets using struct definitions from link.h. */
38
39static struct link_map_offsets *
40legacy_svr4_fetch_link_map_offsets (void)
41{
42 static struct link_map_offsets lmo;
43 static struct link_map_offsets *lmp = 0;
44#if defined (HAVE_STRUCT_LINK_MAP32)
45 static struct link_map_offsets lmo32;
46 static struct link_map_offsets *lmp32 = 0;
47#endif
48
49#ifndef offsetof
50#define offsetof(TYPE, MEMBER) ((unsigned long) &((TYPE *)0)->MEMBER)
51#endif
52#define fieldsize(TYPE, MEMBER) (sizeof (((TYPE *)0)->MEMBER))
53
54 if (lmp == 0)
55 {
56 lmp = &lmo;
57
d45fe813 58#ifdef HAVE_STRUCT_LINK_MAP_WITH_L_MEMBERS
e4cd0d6a
MK
59 lmo.r_version_offset = offsetof (struct r_debug, r_version);
60 lmo.r_version_size = fieldsize (struct r_debug, r_version);
21479ded 61 lmo.r_map_offset = offsetof (struct r_debug, r_map);
e4cd0d6a 62 lmo.r_ldsomap_offset = -1;
21479ded
KB
63
64 lmo.link_map_size = sizeof (struct link_map);
65
66 lmo.l_addr_offset = offsetof (struct link_map, l_addr);
67 lmo.l_addr_size = fieldsize (struct link_map, l_addr);
68
69 lmo.l_next_offset = offsetof (struct link_map, l_next);
70 lmo.l_next_size = fieldsize (struct link_map, l_next);
71
cc10cae3
AO
72 lmo.l_ld_offset = offsetof (struct link_map, l_ld);
73 lmo.l_ld_size = fieldsize (struct link_map, l_ld);
74
21479ded
KB
75 lmo.l_prev_offset = offsetof (struct link_map, l_prev);
76 lmo.l_prev_size = fieldsize (struct link_map, l_prev);
77
78 lmo.l_name_offset = offsetof (struct link_map, l_name);
79 lmo.l_name_size = fieldsize (struct link_map, l_name);
d45fe813
KB
80#else /* !defined(HAVE_STRUCT_LINK_MAP_WITH_L_MEMBERS) */
81#ifdef HAVE_STRUCT_LINK_MAP_WITH_LM_MEMBERS
21479ded
KB
82 lmo.link_map_size = sizeof (struct link_map);
83
84 lmo.l_addr_offset = offsetof (struct link_map, lm_addr);
85 lmo.l_addr_size = fieldsize (struct link_map, lm_addr);
86
87 lmo.l_next_offset = offsetof (struct link_map, lm_next);
88 lmo.l_next_size = fieldsize (struct link_map, lm_next);
89
cc10cae3
AO
90 /* FIXME: Is this the right field name, or is it available at all? */
91 lmo.l_ld_offset = offsetof (struct link_map, lm_ld);
92 lmo.l_ld_size = fieldsize (struct link_map, lm_ld);
93
21479ded
KB
94 lmo.l_name_offset = offsetof (struct link_map, lm_name);
95 lmo.l_name_size = fieldsize (struct link_map, lm_name);
d45fe813
KB
96#else /* !defined(HAVE_STRUCT_LINK_MAP_WITH_LM_MEMBERS) */
97#if HAVE_STRUCT_SO_MAP_WITH_SOM_MEMBERS
98 lmo.link_map_size = sizeof (struct so_map);
99
100 lmo.l_addr_offset = offsetof (struct so_map, som_addr);
101 lmo.l_addr_size = fieldsize (struct so_map, som_addr);
102
103 lmo.l_next_offset = offsetof (struct so_map, som_next);
104 lmo.l_next_size = fieldsize (struct so_map, som_next);
105
106 lmo.l_name_offset = offsetof (struct so_map, som_path);
107 lmo.l_name_size = fieldsize (struct so_map, som_path);
cc10cae3
AO
108
109 /* FIXME: Is the address of the dynamic table available? */
110 lmo.l_ld_offset = 0;
111 lmo.l_ld_size = 0;
d45fe813
KB
112#endif /* HAVE_STRUCT_SO_MAP_WITH_SOM_MEMBERS */
113#endif /* HAVE_STRUCT_LINK_MAP_WITH_LM_MEMBERS */
114#endif /* HAVE_STRUCT_LINK_MAP_WITH_L_MEMBERS */
21479ded
KB
115 }
116
117#if defined (HAVE_STRUCT_LINK_MAP32)
118 if (lmp32 == 0)
119 {
120 lmp32 = &lmo32;
121
e4cd0d6a
MK
122 lmo32.r_version_offset = offsetof (struct r_debug32, r_version);
123 lmo32.r_version_size = fieldsize (struct r_debug32, r_version);
21479ded 124 lmo32.r_map_offset = offsetof (struct r_debug32, r_map);
e4cd0d6a 125 lmo32.r_ldsomap_offset = -1;
21479ded
KB
126
127 lmo32.link_map_size = sizeof (struct link_map32);
128
129 lmo32.l_addr_offset = offsetof (struct link_map32, l_addr);
130 lmo32.l_addr_size = fieldsize (struct link_map32, l_addr);
131
132 lmo32.l_next_offset = offsetof (struct link_map32, l_next);
133 lmo32.l_next_size = fieldsize (struct link_map32, l_next);
134
135 lmo32.l_prev_offset = offsetof (struct link_map32, l_prev);
136 lmo32.l_prev_size = fieldsize (struct link_map32, l_prev);
137
138 lmo32.l_name_offset = offsetof (struct link_map32, l_name);
139 lmo32.l_name_size = fieldsize (struct link_map32, l_name);
140 }
141#endif /* defined (HAVE_STRUCT_LINK_MAP32) */
142
143#if defined (HAVE_STRUCT_LINK_MAP32)
d0e1d48e
MS
144 if (exec_bfd != NULL)
145 {
146 if (bfd_get_arch_size (exec_bfd) == 32)
147 return lmp32;
148 }
78b29b40 149 if (TARGET_PTR_BIT == 32)
21479ded 150 return lmp32;
21479ded 151#endif
78b29b40 152 return lmp;
21479ded
KB
153}
154
155#endif /* HAVE_LINK_H */
156
a78f21af
AC
157extern initialize_file_ftype _initialize_svr4_lm; /* -Wmissing-prototypes */
158
21479ded
KB
159void
160_initialize_svr4_lm (void)
161{
162#ifdef HAVE_LINK_H
163 legacy_svr4_fetch_link_map_offsets_hook = legacy_svr4_fetch_link_map_offsets;
164#endif /* HAVE_LINK_H */
165}
This page took 0.671082 seconds and 4 git commands to generate.