1 /* Provide legacy r_debug and link_map support for SVR4-like native targets.
3 Copyright (C) 2000, 2001, 2006
4 Free Software Foundation, Inc.
6 This file is part of GDB.
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.
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.
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
20 Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
25 #include "solib-svr4.h"
30 /* nlist.h needs to be included before link.h on some older *BSD systems. */
36 /* Fetch (and possibly build) an appropriate link_map_offsets structure
37 for native targets using struct definitions from link.h. */
39 static struct link_map_offsets
*
40 legacy_svr4_fetch_link_map_offsets (void)
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;
50 #define offsetof(TYPE, MEMBER) ((unsigned long) &((TYPE *)0)->MEMBER)
52 #define fieldsize(TYPE, MEMBER) (sizeof (((TYPE *)0)->MEMBER))
58 #ifdef HAVE_STRUCT_LINK_MAP_WITH_L_MEMBERS
59 lmo
.r_version_offset
= offsetof (struct r_debug
, r_version
);
60 lmo
.r_version_size
= fieldsize (struct r_debug
, r_version
);
61 lmo
.r_map_offset
= offsetof (struct r_debug
, r_map
);
62 lmo
.r_ldsomap_offset
= -1;
64 lmo
.link_map_size
= sizeof (struct link_map
);
66 lmo
.l_addr_offset
= offsetof (struct link_map
, l_addr
);
67 lmo
.l_addr_size
= fieldsize (struct link_map
, l_addr
);
69 lmo
.l_next_offset
= offsetof (struct link_map
, l_next
);
70 lmo
.l_next_size
= fieldsize (struct link_map
, l_next
);
72 lmo
.l_prev_offset
= offsetof (struct link_map
, l_prev
);
73 lmo
.l_prev_size
= fieldsize (struct link_map
, l_prev
);
75 lmo
.l_name_offset
= offsetof (struct link_map
, l_name
);
76 lmo
.l_name_size
= fieldsize (struct link_map
, l_name
);
77 #else /* !defined(HAVE_STRUCT_LINK_MAP_WITH_L_MEMBERS) */
78 #ifdef HAVE_STRUCT_LINK_MAP_WITH_LM_MEMBERS
79 lmo
.link_map_size
= sizeof (struct link_map
);
81 lmo
.l_addr_offset
= offsetof (struct link_map
, lm_addr
);
82 lmo
.l_addr_size
= fieldsize (struct link_map
, lm_addr
);
84 lmo
.l_next_offset
= offsetof (struct link_map
, lm_next
);
85 lmo
.l_next_size
= fieldsize (struct link_map
, lm_next
);
87 lmo
.l_name_offset
= offsetof (struct link_map
, lm_name
);
88 lmo
.l_name_size
= fieldsize (struct link_map
, lm_name
);
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
);
93 lmo
.l_addr_offset
= offsetof (struct so_map
, som_addr
);
94 lmo
.l_addr_size
= fieldsize (struct so_map
, som_addr
);
96 lmo
.l_next_offset
= offsetof (struct so_map
, som_next
);
97 lmo
.l_next_size
= fieldsize (struct so_map
, som_next
);
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 */
106 #if defined (HAVE_STRUCT_LINK_MAP32)
111 lmo32
.r_version_offset
= offsetof (struct r_debug32
, r_version
);
112 lmo32
.r_version_size
= fieldsize (struct r_debug32
, r_version
);
113 lmo32
.r_map_offset
= offsetof (struct r_debug32
, r_map
);
114 lmo32
.r_ldsomap_offset
= -1;
116 lmo32
.link_map_size
= sizeof (struct link_map32
);
118 lmo32
.l_addr_offset
= offsetof (struct link_map32
, l_addr
);
119 lmo32
.l_addr_size
= fieldsize (struct link_map32
, l_addr
);
121 lmo32
.l_next_offset
= offsetof (struct link_map32
, l_next
);
122 lmo32
.l_next_size
= fieldsize (struct link_map32
, l_next
);
124 lmo32
.l_prev_offset
= offsetof (struct link_map32
, l_prev
);
125 lmo32
.l_prev_size
= fieldsize (struct link_map32
, l_prev
);
127 lmo32
.l_name_offset
= offsetof (struct link_map32
, l_name
);
128 lmo32
.l_name_size
= fieldsize (struct link_map32
, l_name
);
130 #endif /* defined (HAVE_STRUCT_LINK_MAP32) */
132 #if defined (HAVE_STRUCT_LINK_MAP32)
133 if (exec_bfd
!= NULL
)
135 if (bfd_get_arch_size (exec_bfd
) == 32)
138 if (TARGET_PTR_BIT
== 32)
144 #endif /* HAVE_LINK_H */
146 extern initialize_file_ftype _initialize_svr4_lm
; /* -Wmissing-prototypes */
149 _initialize_svr4_lm (void)
152 legacy_svr4_fetch_link_map_offsets_hook
= legacy_svr4_fetch_link_map_offsets
;
153 #endif /* HAVE_LINK_H */