Commit | Line | Data |
---|---|---|
4aa995e1 PA |
1 | /* Target-dependent code for GNU/Linux, architecture independent. |
2 | ||
4c38e0a4 | 3 | Copyright (C) 2009, 2010 Free Software Foundation, Inc. |
4aa995e1 PA |
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 3 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, see <http://www.gnu.org/licenses/>. */ | |
19 | ||
20 | #include "defs.h" | |
21 | #include "gdbtypes.h" | |
2c0b251b | 22 | #include "linux-tdep.h" |
6c95b8df PA |
23 | #include "auxv.h" |
24 | #include "target.h" | |
6c95b8df | 25 | #include "elf/common.h" |
a5ee0f0c | 26 | #include "inferior.h" |
4aa995e1 | 27 | |
06253dd3 JK |
28 | static struct gdbarch_data *linux_gdbarch_data_handle; |
29 | ||
30 | struct linux_gdbarch_data | |
31 | { | |
32 | struct type *siginfo_type; | |
33 | }; | |
34 | ||
35 | static void * | |
36 | init_linux_gdbarch_data (struct gdbarch *gdbarch) | |
37 | { | |
38 | return GDBARCH_OBSTACK_ZALLOC (gdbarch, struct linux_gdbarch_data); | |
39 | } | |
40 | ||
41 | static struct linux_gdbarch_data * | |
42 | get_linux_gdbarch_data (struct gdbarch *gdbarch) | |
43 | { | |
44 | return gdbarch_data (gdbarch, linux_gdbarch_data_handle); | |
45 | } | |
46 | ||
4aa995e1 PA |
47 | /* This function is suitable for architectures that don't |
48 | extend/override the standard siginfo structure. */ | |
49 | ||
50 | struct type * | |
51 | linux_get_siginfo_type (struct gdbarch *gdbarch) | |
52 | { | |
06253dd3 | 53 | struct linux_gdbarch_data *linux_gdbarch_data; |
4aa995e1 PA |
54 | struct type *int_type, *uint_type, *long_type, *void_ptr_type; |
55 | struct type *uid_type, *pid_type; | |
56 | struct type *sigval_type, *clock_type; | |
57 | struct type *siginfo_type, *sifields_type; | |
58 | struct type *type; | |
59 | ||
06253dd3 JK |
60 | linux_gdbarch_data = get_linux_gdbarch_data (gdbarch); |
61 | if (linux_gdbarch_data->siginfo_type != NULL) | |
62 | return linux_gdbarch_data->siginfo_type; | |
63 | ||
e9bb382b UW |
64 | int_type = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch), |
65 | 0, "int"); | |
66 | uint_type = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch), | |
67 | 1, "unsigned int"); | |
68 | long_type = arch_integer_type (gdbarch, gdbarch_long_bit (gdbarch), | |
69 | 0, "long"); | |
4aa995e1 PA |
70 | void_ptr_type = lookup_pointer_type (builtin_type (gdbarch)->builtin_void); |
71 | ||
72 | /* sival_t */ | |
e9bb382b | 73 | sigval_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_UNION); |
4aa995e1 PA |
74 | TYPE_NAME (sigval_type) = xstrdup ("sigval_t"); |
75 | append_composite_type_field (sigval_type, "sival_int", int_type); | |
76 | append_composite_type_field (sigval_type, "sival_ptr", void_ptr_type); | |
77 | ||
78 | /* __pid_t */ | |
e9bb382b UW |
79 | pid_type = arch_type (gdbarch, TYPE_CODE_TYPEDEF, TYPE_LENGTH (int_type), |
80 | xstrdup ("__pid_t")); | |
4aa995e1 | 81 | TYPE_TARGET_TYPE (pid_type) = int_type; |
e9bb382b | 82 | TYPE_TARGET_STUB (pid_type) = 1; |
4aa995e1 PA |
83 | |
84 | /* __uid_t */ | |
e9bb382b UW |
85 | uid_type = arch_type (gdbarch, TYPE_CODE_TYPEDEF, TYPE_LENGTH (uint_type), |
86 | xstrdup ("__uid_t")); | |
4aa995e1 | 87 | TYPE_TARGET_TYPE (uid_type) = uint_type; |
e9bb382b | 88 | TYPE_TARGET_STUB (uid_type) = 1; |
4aa995e1 PA |
89 | |
90 | /* __clock_t */ | |
e9bb382b UW |
91 | clock_type = arch_type (gdbarch, TYPE_CODE_TYPEDEF, TYPE_LENGTH (long_type), |
92 | xstrdup ("__clock_t")); | |
4aa995e1 | 93 | TYPE_TARGET_TYPE (clock_type) = long_type; |
e9bb382b | 94 | TYPE_TARGET_STUB (clock_type) = 1; |
4aa995e1 PA |
95 | |
96 | /* _sifields */ | |
e9bb382b | 97 | sifields_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_UNION); |
4aa995e1 PA |
98 | |
99 | { | |
100 | const int si_max_size = 128; | |
101 | int si_pad_size; | |
102 | int size_of_int = gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT; | |
103 | ||
104 | /* _pad */ | |
105 | if (gdbarch_ptr_bit (gdbarch) == 64) | |
106 | si_pad_size = (si_max_size / size_of_int) - 4; | |
107 | else | |
108 | si_pad_size = (si_max_size / size_of_int) - 3; | |
109 | append_composite_type_field (sifields_type, "_pad", | |
110 | init_vector_type (int_type, si_pad_size)); | |
111 | } | |
112 | ||
113 | /* _kill */ | |
e9bb382b | 114 | type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT); |
4aa995e1 PA |
115 | append_composite_type_field (type, "si_pid", pid_type); |
116 | append_composite_type_field (type, "si_uid", uid_type); | |
117 | append_composite_type_field (sifields_type, "_kill", type); | |
118 | ||
119 | /* _timer */ | |
e9bb382b | 120 | type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT); |
4aa995e1 PA |
121 | append_composite_type_field (type, "si_tid", int_type); |
122 | append_composite_type_field (type, "si_overrun", int_type); | |
123 | append_composite_type_field (type, "si_sigval", sigval_type); | |
124 | append_composite_type_field (sifields_type, "_timer", type); | |
125 | ||
126 | /* _rt */ | |
e9bb382b | 127 | type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT); |
4aa995e1 PA |
128 | append_composite_type_field (type, "si_pid", pid_type); |
129 | append_composite_type_field (type, "si_uid", uid_type); | |
130 | append_composite_type_field (type, "si_sigval", sigval_type); | |
131 | append_composite_type_field (sifields_type, "_rt", type); | |
132 | ||
133 | /* _sigchld */ | |
e9bb382b | 134 | type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT); |
4aa995e1 PA |
135 | append_composite_type_field (type, "si_pid", pid_type); |
136 | append_composite_type_field (type, "si_uid", uid_type); | |
137 | append_composite_type_field (type, "si_status", int_type); | |
138 | append_composite_type_field (type, "si_utime", clock_type); | |
139 | append_composite_type_field (type, "si_stime", clock_type); | |
140 | append_composite_type_field (sifields_type, "_sigchld", type); | |
141 | ||
142 | /* _sigfault */ | |
e9bb382b | 143 | type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT); |
4aa995e1 PA |
144 | append_composite_type_field (type, "si_addr", void_ptr_type); |
145 | append_composite_type_field (sifields_type, "_sigfault", type); | |
146 | ||
147 | /* _sigpoll */ | |
e9bb382b | 148 | type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT); |
4aa995e1 PA |
149 | append_composite_type_field (type, "si_band", long_type); |
150 | append_composite_type_field (type, "si_fd", int_type); | |
151 | append_composite_type_field (sifields_type, "_sigpoll", type); | |
152 | ||
153 | /* struct siginfo */ | |
e9bb382b | 154 | siginfo_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT); |
4aa995e1 PA |
155 | TYPE_NAME (siginfo_type) = xstrdup ("siginfo"); |
156 | append_composite_type_field (siginfo_type, "si_signo", int_type); | |
157 | append_composite_type_field (siginfo_type, "si_errno", int_type); | |
158 | append_composite_type_field (siginfo_type, "si_code", int_type); | |
159 | append_composite_type_field_aligned (siginfo_type, | |
160 | "_sifields", sifields_type, | |
161 | TYPE_LENGTH (long_type)); | |
162 | ||
06253dd3 JK |
163 | linux_gdbarch_data->siginfo_type = siginfo_type; |
164 | ||
4aa995e1 PA |
165 | return siginfo_type; |
166 | } | |
6b3ae818 | 167 | |
6c95b8df PA |
168 | int |
169 | linux_has_shared_address_space (void) | |
170 | { | |
171 | /* Determine whether we are running on uClinux or normal Linux | |
172 | kernel. */ | |
173 | CORE_ADDR dummy; | |
174 | int target_is_uclinux; | |
175 | ||
176 | target_is_uclinux | |
177 | = (target_auxv_search (¤t_target, AT_NULL, &dummy) > 0 | |
178 | && target_auxv_search (¤t_target, AT_PAGESZ, &dummy) == 0); | |
179 | ||
180 | return target_is_uclinux; | |
181 | } | |
a5ee0f0c PA |
182 | |
183 | /* This is how we want PTIDs from core files to be printed. */ | |
184 | ||
185 | static char * | |
186 | linux_core_pid_to_str (struct gdbarch *gdbarch, ptid_t ptid) | |
187 | { | |
188 | static char buf[80]; | |
189 | ||
190 | if (ptid_get_lwp (ptid) != 0) | |
191 | { | |
192 | snprintf (buf, sizeof (buf), "LWP %ld", ptid_get_lwp (ptid)); | |
193 | return buf; | |
194 | } | |
195 | ||
196 | return normal_pid_to_str (ptid); | |
197 | } | |
198 | ||
199 | /* To be called from the various GDB_OSABI_LINUX handlers for the | |
200 | various GNU/Linux architectures and machine types. */ | |
201 | ||
202 | void | |
203 | linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) | |
204 | { | |
205 | set_gdbarch_core_pid_to_str (gdbarch, linux_core_pid_to_str); | |
206 | } | |
06253dd3 JK |
207 | |
208 | void | |
209 | _initialize_linux_tdep (void) | |
210 | { | |
211 | linux_gdbarch_data_handle = | |
212 | gdbarch_data_register_post_init (init_linux_gdbarch_data); | |
213 | } |