Cleanup solib-svr4.c by moving legacy code out to its own file.
[binutils-gdb.git] / gdb / solib-legacy.c
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
28 #include <link.h>
29
30 /* Fetch (and possibly build) an appropriate link_map_offsets structure
31 for native targets using struct definitions from link.h. */
32
33 static struct link_map_offsets *
34 legacy_svr4_fetch_link_map_offsets (void)
35 {
36 static struct link_map_offsets lmo;
37 static struct link_map_offsets *lmp = 0;
38 #if defined (HAVE_STRUCT_LINK_MAP32)
39 static struct link_map_offsets lmo32;
40 static struct link_map_offsets *lmp32 = 0;
41 #endif
42
43 #ifndef offsetof
44 #define offsetof(TYPE, MEMBER) ((unsigned long) &((TYPE *)0)->MEMBER)
45 #endif
46 #define fieldsize(TYPE, MEMBER) (sizeof (((TYPE *)0)->MEMBER))
47
48 if (lmp == 0)
49 {
50 lmp = &lmo;
51
52 #ifdef SVR4_SHARED_LIBS
53 lmo.r_debug_size = sizeof (struct r_debug);
54
55 lmo.r_map_offset = offsetof (struct r_debug, r_map);
56 lmo.r_map_size = fieldsize (struct r_debug, r_map);
57
58 lmo.link_map_size = sizeof (struct link_map);
59
60 lmo.l_addr_offset = offsetof (struct link_map, l_addr);
61 lmo.l_addr_size = fieldsize (struct link_map, l_addr);
62
63 lmo.l_next_offset = offsetof (struct link_map, l_next);
64 lmo.l_next_size = fieldsize (struct link_map, l_next);
65
66 lmo.l_prev_offset = offsetof (struct link_map, l_prev);
67 lmo.l_prev_size = fieldsize (struct link_map, l_prev);
68
69 lmo.l_name_offset = offsetof (struct link_map, l_name);
70 lmo.l_name_size = fieldsize (struct link_map, l_name);
71 #else /* !SVR4_SHARED_LIBS */
72 lmo.link_map_size = sizeof (struct link_map);
73
74 lmo.l_addr_offset = offsetof (struct link_map, lm_addr);
75 lmo.l_addr_size = fieldsize (struct link_map, lm_addr);
76
77 lmo.l_next_offset = offsetof (struct link_map, lm_next);
78 lmo.l_next_size = fieldsize (struct link_map, lm_next);
79
80 lmo.l_name_offset = offsetof (struct link_map, lm_name);
81 lmo.l_name_size = fieldsize (struct link_map, lm_name);
82 #endif /* SVR4_SHARED_LIBS */
83 }
84
85 #if defined (HAVE_STRUCT_LINK_MAP32)
86 if (lmp32 == 0)
87 {
88 lmp32 = &lmo32;
89
90 lmo32.r_debug_size = sizeof (struct r_debug32);
91
92 lmo32.r_map_offset = offsetof (struct r_debug32, r_map);
93 lmo32.r_map_size = fieldsize (struct r_debug32, r_map);
94
95 lmo32.link_map_size = sizeof (struct link_map32);
96
97 lmo32.l_addr_offset = offsetof (struct link_map32, l_addr);
98 lmo32.l_addr_size = fieldsize (struct link_map32, l_addr);
99
100 lmo32.l_next_offset = offsetof (struct link_map32, l_next);
101 lmo32.l_next_size = fieldsize (struct link_map32, l_next);
102
103 lmo32.l_prev_offset = offsetof (struct link_map32, l_prev);
104 lmo32.l_prev_size = fieldsize (struct link_map32, l_prev);
105
106 lmo32.l_name_offset = offsetof (struct link_map32, l_name);
107 lmo32.l_name_size = fieldsize (struct link_map32, l_name);
108 }
109 #endif /* defined (HAVE_STRUCT_LINK_MAP32) */
110
111 #if defined (HAVE_STRUCT_LINK_MAP32)
112 if (bfd_get_arch_size (exec_bfd) == 32)
113 return lmp32;
114 else
115 #endif
116 return lmp;
117 }
118
119 #endif /* HAVE_LINK_H */
120
121 void
122 _initialize_svr4_lm (void)
123 {
124 #ifdef HAVE_LINK_H
125 legacy_svr4_fetch_link_map_offsets_hook = legacy_svr4_fetch_link_map_offsets;
126 #endif /* HAVE_LINK_H */
127 }