1 /* Provide legacy r_debug and link_map support for SVR4-like native targets.
3 Copyright (C) 2000, 2001, 2006, 2007 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
24 #include "solib-svr4.h"
29 /* nlist.h needs to be included before link.h on some older *BSD systems. */
35 /* Fetch (and possibly build) an appropriate link_map_offsets structure
36 for native targets using struct definitions from link.h. */
38 static struct link_map_offsets *
39 legacy_svr4_fetch_link_map_offsets (void)
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;
49 #define offsetof(TYPE, MEMBER) ((unsigned long) &((TYPE *)0)->MEMBER)
51 #define fieldsize(TYPE, MEMBER) (sizeof (((TYPE *)0)->MEMBER))
57 #ifdef HAVE_STRUCT_LINK_MAP_WITH_L_MEMBERS
58 lmo.r_version_offset = offsetof (struct r_debug, r_version);
59 lmo.r_version_size = fieldsize (struct r_debug, r_version);
60 lmo.r_map_offset = offsetof (struct r_debug, r_map);
61 lmo.r_ldsomap_offset = -1;
63 lmo.link_map_size = sizeof (struct link_map);
65 lmo.l_addr_offset = offsetof (struct link_map, l_addr);
66 lmo.l_next_offset = offsetof (struct link_map, l_next);
67 lmo.l_ld_offset = offsetof (struct link_map, l_ld);
68 lmo.l_prev_offset = offsetof (struct link_map, l_prev);
69 lmo.l_name_offset = offsetof (struct link_map, l_name);
70 #else /* !defined(HAVE_STRUCT_LINK_MAP_WITH_L_MEMBERS) */
71 #ifdef HAVE_STRUCT_LINK_MAP_WITH_LM_MEMBERS
72 lmo.link_map_size = sizeof (struct link_map);
74 lmo.l_addr_offset = offsetof (struct link_map, lm_addr);
75 lmo.l_next_offset = offsetof (struct link_map, lm_next);
76 /* FIXME: Is this the right field name, or is it available at all? */
77 lmo.l_ld_offset = offsetof (struct link_map, lm_ld);
78 lmo.l_name_offset = offsetof (struct link_map, lm_name);
79 #else /* !defined(HAVE_STRUCT_LINK_MAP_WITH_LM_MEMBERS) */
80 #if HAVE_STRUCT_SO_MAP_WITH_SOM_MEMBERS
81 lmo.link_map_size = sizeof (struct so_map);
83 lmo.l_addr_offset = offsetof (struct so_map, som_addr);
84 lmo.l_next_offset = offsetof (struct so_map, som_next);
85 lmo.l_name_offset = offsetof (struct so_map, som_path);
86 /* FIXME: Is the address of the dynamic table available? */
88 #endif /* HAVE_STRUCT_SO_MAP_WITH_SOM_MEMBERS */
89 #endif /* HAVE_STRUCT_LINK_MAP_WITH_LM_MEMBERS */
90 #endif /* HAVE_STRUCT_LINK_MAP_WITH_L_MEMBERS */
93 #if defined (HAVE_STRUCT_LINK_MAP32)
98 lmo32.r_version_offset = offsetof (struct r_debug32, r_version);
99 lmo32.r_version_size = fieldsize (struct r_debug32, r_version);
100 lmo32.r_map_offset = offsetof (struct r_debug32, r_map);
101 lmo32.r_ldsomap_offset = -1;
103 lmo32.link_map_size = sizeof (struct link_map32);
105 lmo32.l_addr_offset = offsetof (struct link_map32, l_addr);
106 lmo32.l_next_offset = offsetof (struct link_map32, l_next);
107 lmo32.l_prev_offset = offsetof (struct link_map32, l_prev);
108 lmo32.l_name_offset = offsetof (struct link_map32, l_name);
110 #endif /* defined (HAVE_STRUCT_LINK_MAP32) */
112 #if defined (HAVE_STRUCT_LINK_MAP32)
113 if (exec_bfd != NULL)
115 if (bfd_get_arch_size (exec_bfd) == 32)
118 if (gdbarch_ptr_bit (current_gdbarch) == 32)
124 #endif /* HAVE_LINK_H */
126 extern initialize_file_ftype _initialize_svr4_lm; /* -Wmissing-prototypes */
129 _initialize_svr4_lm (void)
132 legacy_svr4_fetch_link_map_offsets_hook = legacy_svr4_fetch_link_map_offsets;
133 #endif /* HAVE_LINK_H */