Conditionally include nlist.h in solib-legacy.c for older *BSD systems.
[deliverable/binutils-gdb.git] / gdb / solib-legacy.c
CommitLineData
21479ded
KB
1/* Provide legacy r_debug and link_map support for SVR4-like native targets.
2 Copyright 2000, 2001
3 Free Software Foundation, Inc.
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
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
21
22#define _SYSCALL32 /* for Sparc64 cross Sparc32 */
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
21479ded
KB
59 lmo.r_debug_size = sizeof (struct r_debug);
60
61 lmo.r_map_offset = offsetof (struct r_debug, r_map);
62 lmo.r_map_size = fieldsize (struct r_debug, r_map);
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
72 lmo.l_prev_offset = offsetof (struct link_map, l_prev);
73 lmo.l_prev_size = fieldsize (struct link_map, l_prev);
74
75 lmo.l_name_offset = offsetof (struct link_map, l_name);
76 lmo.l_name_size = fieldsize (struct link_map, l_name);
d45fe813
KB
77#else /* !defined(HAVE_STRUCT_LINK_MAP_WITH_L_MEMBERS) */
78#ifdef HAVE_STRUCT_LINK_MAP_WITH_LM_MEMBERS
21479ded
KB
79 lmo.link_map_size = sizeof (struct link_map);
80
81 lmo.l_addr_offset = offsetof (struct link_map, lm_addr);
82 lmo.l_addr_size = fieldsize (struct link_map, lm_addr);
83
84 lmo.l_next_offset = offsetof (struct link_map, lm_next);
85 lmo.l_next_size = fieldsize (struct link_map, lm_next);
86
87 lmo.l_name_offset = offsetof (struct link_map, lm_name);
88 lmo.l_name_size = fieldsize (struct link_map, lm_name);
d45fe813
KB
89#else /* !defined(HAVE_STRUCT_LINK_MAP_WITH_LM_MEMBERS) */
90#if HAVE_STRUCT_SO_MAP_WITH_SOM_MEMBERS
91 lmo.link_map_size = sizeof (struct so_map);
92
93 lmo.l_addr_offset = offsetof (struct so_map, som_addr);
94 lmo.l_addr_size = fieldsize (struct so_map, som_addr);
95
96 lmo.l_next_offset = offsetof (struct so_map, som_next);
97 lmo.l_next_size = fieldsize (struct so_map, som_next);
98
99 lmo.l_name_offset = offsetof (struct so_map, som_path);
100 lmo.l_name_size = fieldsize (struct so_map, som_path);
101#endif /* HAVE_STRUCT_SO_MAP_WITH_SOM_MEMBERS */
102#endif /* HAVE_STRUCT_LINK_MAP_WITH_LM_MEMBERS */
103#endif /* HAVE_STRUCT_LINK_MAP_WITH_L_MEMBERS */
21479ded
KB
104 }
105
106#if defined (HAVE_STRUCT_LINK_MAP32)
107 if (lmp32 == 0)
108 {
109 lmp32 = &lmo32;
110
111 lmo32.r_debug_size = sizeof (struct r_debug32);
112
113 lmo32.r_map_offset = offsetof (struct r_debug32, r_map);
114 lmo32.r_map_size = fieldsize (struct r_debug32, r_map);
115
116 lmo32.link_map_size = sizeof (struct link_map32);
117
118 lmo32.l_addr_offset = offsetof (struct link_map32, l_addr);
119 lmo32.l_addr_size = fieldsize (struct link_map32, l_addr);
120
121 lmo32.l_next_offset = offsetof (struct link_map32, l_next);
122 lmo32.l_next_size = fieldsize (struct link_map32, l_next);
123
124 lmo32.l_prev_offset = offsetof (struct link_map32, l_prev);
125 lmo32.l_prev_size = fieldsize (struct link_map32, l_prev);
126
127 lmo32.l_name_offset = offsetof (struct link_map32, l_name);
128 lmo32.l_name_size = fieldsize (struct link_map32, l_name);
129 }
130#endif /* defined (HAVE_STRUCT_LINK_MAP32) */
131
132#if defined (HAVE_STRUCT_LINK_MAP32)
133 if (bfd_get_arch_size (exec_bfd) == 32)
134 return lmp32;
135 else
136#endif
137 return lmp;
138}
139
140#endif /* HAVE_LINK_H */
141
142void
143_initialize_svr4_lm (void)
144{
145#ifdef HAVE_LINK_H
146 legacy_svr4_fetch_link_map_offsets_hook = legacy_svr4_fetch_link_map_offsets;
147#endif /* HAVE_LINK_H */
148}
This page took 0.03319 seconds and 4 git commands to generate.