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 PA |
27 | |
28 | /* This function is suitable for architectures that don't | |
29 | extend/override the standard siginfo structure. */ | |
30 | ||
31 | struct type * | |
32 | linux_get_siginfo_type (struct gdbarch *gdbarch) | |
33 | { | |
34 | struct type *int_type, *uint_type, *long_type, *void_ptr_type; | |
35 | struct type *uid_type, *pid_type; | |
36 | struct type *sigval_type, *clock_type; | |
37 | struct type *siginfo_type, *sifields_type; | |
38 | struct type *type; | |
39 | ||
e9bb382b UW |
40 | int_type = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch), |
41 | 0, "int"); | |
42 | uint_type = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch), | |
43 | 1, "unsigned int"); | |
44 | long_type = arch_integer_type (gdbarch, gdbarch_long_bit (gdbarch), | |
45 | 0, "long"); | |
4aa995e1 PA |
46 | void_ptr_type = lookup_pointer_type (builtin_type (gdbarch)->builtin_void); |
47 | ||
48 | /* sival_t */ | |
e9bb382b | 49 | sigval_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_UNION); |
4aa995e1 PA |
50 | TYPE_NAME (sigval_type) = xstrdup ("sigval_t"); |
51 | append_composite_type_field (sigval_type, "sival_int", int_type); | |
52 | append_composite_type_field (sigval_type, "sival_ptr", void_ptr_type); | |
53 | ||
54 | /* __pid_t */ | |
e9bb382b UW |
55 | pid_type = arch_type (gdbarch, TYPE_CODE_TYPEDEF, TYPE_LENGTH (int_type), |
56 | xstrdup ("__pid_t")); | |
4aa995e1 | 57 | TYPE_TARGET_TYPE (pid_type) = int_type; |
e9bb382b | 58 | TYPE_TARGET_STUB (pid_type) = 1; |
4aa995e1 PA |
59 | |
60 | /* __uid_t */ | |
e9bb382b UW |
61 | uid_type = arch_type (gdbarch, TYPE_CODE_TYPEDEF, TYPE_LENGTH (uint_type), |
62 | xstrdup ("__uid_t")); | |
4aa995e1 | 63 | TYPE_TARGET_TYPE (uid_type) = uint_type; |
e9bb382b | 64 | TYPE_TARGET_STUB (uid_type) = 1; |
4aa995e1 PA |
65 | |
66 | /* __clock_t */ | |
e9bb382b UW |
67 | clock_type = arch_type (gdbarch, TYPE_CODE_TYPEDEF, TYPE_LENGTH (long_type), |
68 | xstrdup ("__clock_t")); | |
4aa995e1 | 69 | TYPE_TARGET_TYPE (clock_type) = long_type; |
e9bb382b | 70 | TYPE_TARGET_STUB (clock_type) = 1; |
4aa995e1 PA |
71 | |
72 | /* _sifields */ | |
e9bb382b | 73 | sifields_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_UNION); |
4aa995e1 PA |
74 | |
75 | { | |
76 | const int si_max_size = 128; | |
77 | int si_pad_size; | |
78 | int size_of_int = gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT; | |
79 | ||
80 | /* _pad */ | |
81 | if (gdbarch_ptr_bit (gdbarch) == 64) | |
82 | si_pad_size = (si_max_size / size_of_int) - 4; | |
83 | else | |
84 | si_pad_size = (si_max_size / size_of_int) - 3; | |
85 | append_composite_type_field (sifields_type, "_pad", | |
86 | init_vector_type (int_type, si_pad_size)); | |
87 | } | |
88 | ||
89 | /* _kill */ | |
e9bb382b | 90 | type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT); |
4aa995e1 PA |
91 | append_composite_type_field (type, "si_pid", pid_type); |
92 | append_composite_type_field (type, "si_uid", uid_type); | |
93 | append_composite_type_field (sifields_type, "_kill", type); | |
94 | ||
95 | /* _timer */ | |
e9bb382b | 96 | type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT); |
4aa995e1 PA |
97 | append_composite_type_field (type, "si_tid", int_type); |
98 | append_composite_type_field (type, "si_overrun", int_type); | |
99 | append_composite_type_field (type, "si_sigval", sigval_type); | |
100 | append_composite_type_field (sifields_type, "_timer", type); | |
101 | ||
102 | /* _rt */ | |
e9bb382b | 103 | type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT); |
4aa995e1 PA |
104 | append_composite_type_field (type, "si_pid", pid_type); |
105 | append_composite_type_field (type, "si_uid", uid_type); | |
106 | append_composite_type_field (type, "si_sigval", sigval_type); | |
107 | append_composite_type_field (sifields_type, "_rt", type); | |
108 | ||
109 | /* _sigchld */ | |
e9bb382b | 110 | type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT); |
4aa995e1 PA |
111 | append_composite_type_field (type, "si_pid", pid_type); |
112 | append_composite_type_field (type, "si_uid", uid_type); | |
113 | append_composite_type_field (type, "si_status", int_type); | |
114 | append_composite_type_field (type, "si_utime", clock_type); | |
115 | append_composite_type_field (type, "si_stime", clock_type); | |
116 | append_composite_type_field (sifields_type, "_sigchld", type); | |
117 | ||
118 | /* _sigfault */ | |
e9bb382b | 119 | type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT); |
4aa995e1 PA |
120 | append_composite_type_field (type, "si_addr", void_ptr_type); |
121 | append_composite_type_field (sifields_type, "_sigfault", type); | |
122 | ||
123 | /* _sigpoll */ | |
e9bb382b | 124 | type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT); |
4aa995e1 PA |
125 | append_composite_type_field (type, "si_band", long_type); |
126 | append_composite_type_field (type, "si_fd", int_type); | |
127 | append_composite_type_field (sifields_type, "_sigpoll", type); | |
128 | ||
129 | /* struct siginfo */ | |
e9bb382b | 130 | siginfo_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT); |
4aa995e1 PA |
131 | TYPE_NAME (siginfo_type) = xstrdup ("siginfo"); |
132 | append_composite_type_field (siginfo_type, "si_signo", int_type); | |
133 | append_composite_type_field (siginfo_type, "si_errno", int_type); | |
134 | append_composite_type_field (siginfo_type, "si_code", int_type); | |
135 | append_composite_type_field_aligned (siginfo_type, | |
136 | "_sifields", sifields_type, | |
137 | TYPE_LENGTH (long_type)); | |
138 | ||
139 | return siginfo_type; | |
140 | } | |
6b3ae818 | 141 | |
6c95b8df PA |
142 | int |
143 | linux_has_shared_address_space (void) | |
144 | { | |
145 | /* Determine whether we are running on uClinux or normal Linux | |
146 | kernel. */ | |
147 | CORE_ADDR dummy; | |
148 | int target_is_uclinux; | |
149 | ||
150 | target_is_uclinux | |
151 | = (target_auxv_search (¤t_target, AT_NULL, &dummy) > 0 | |
152 | && target_auxv_search (¤t_target, AT_PAGESZ, &dummy) == 0); | |
153 | ||
154 | return target_is_uclinux; | |
155 | } | |
a5ee0f0c PA |
156 | |
157 | /* This is how we want PTIDs from core files to be printed. */ | |
158 | ||
159 | static char * | |
160 | linux_core_pid_to_str (struct gdbarch *gdbarch, ptid_t ptid) | |
161 | { | |
162 | static char buf[80]; | |
163 | ||
164 | if (ptid_get_lwp (ptid) != 0) | |
165 | { | |
166 | snprintf (buf, sizeof (buf), "LWP %ld", ptid_get_lwp (ptid)); | |
167 | return buf; | |
168 | } | |
169 | ||
170 | return normal_pid_to_str (ptid); | |
171 | } | |
172 | ||
173 | /* To be called from the various GDB_OSABI_LINUX handlers for the | |
174 | various GNU/Linux architectures and machine types. */ | |
175 | ||
176 | void | |
177 | linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) | |
178 | { | |
179 | set_gdbarch_core_pid_to_str (gdbarch, linux_core_pid_to_str); | |
180 | } |