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