Commit | Line | Data |
---|---|---|
a904c024 AA |
1 | /* Target-dependent code for FreeBSD, architecture-independent. |
2 | ||
3666a048 | 3 | Copyright (C) 2002-2021 Free Software Foundation, Inc. |
a904c024 AA |
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" | |
82372b2f | 21 | #include "auxv.h" |
a904c024 AA |
22 | #include "gdbcore.h" |
23 | #include "inferior.h" | |
ed810cc7 | 24 | #include "objfiles.h" |
a904c024 AA |
25 | #include "regcache.h" |
26 | #include "regset.h" | |
4de283e4 TT |
27 | #include "gdbthread.h" |
28 | #include "objfiles.h" | |
e6cdd38e | 29 | #include "xml-syscall.h" |
4de283e4 TT |
30 | #include <sys/socket.h> |
31 | #include <arpa/inet.h> | |
32 | ||
33 | #include "elf-bfd.h" | |
34 | #include "fbsd-tdep.h" | |
82a1fd3a | 35 | #include "gcore.h" |
a904c024 | 36 | |
e61667ef RS |
37 | /* This enum is derived from FreeBSD's <sys/signal.h>. */ |
38 | ||
39 | enum | |
40 | { | |
41 | FREEBSD_SIGHUP = 1, | |
42 | FREEBSD_SIGINT = 2, | |
43 | FREEBSD_SIGQUIT = 3, | |
44 | FREEBSD_SIGILL = 4, | |
45 | FREEBSD_SIGTRAP = 5, | |
46 | FREEBSD_SIGABRT = 6, | |
47 | FREEBSD_SIGEMT = 7, | |
48 | FREEBSD_SIGFPE = 8, | |
49 | FREEBSD_SIGKILL = 9, | |
50 | FREEBSD_SIGBUS = 10, | |
51 | FREEBSD_SIGSEGV = 11, | |
52 | FREEBSD_SIGSYS = 12, | |
53 | FREEBSD_SIGPIPE = 13, | |
54 | FREEBSD_SIGALRM = 14, | |
55 | FREEBSD_SIGTERM = 15, | |
56 | FREEBSD_SIGURG = 16, | |
57 | FREEBSD_SIGSTOP = 17, | |
58 | FREEBSD_SIGTSTP = 18, | |
59 | FREEBSD_SIGCONT = 19, | |
60 | FREEBSD_SIGCHLD = 20, | |
61 | FREEBSD_SIGTTIN = 21, | |
62 | FREEBSD_SIGTTOU = 22, | |
63 | FREEBSD_SIGIO = 23, | |
64 | FREEBSD_SIGXCPU = 24, | |
65 | FREEBSD_SIGXFSZ = 25, | |
66 | FREEBSD_SIGVTALRM = 26, | |
67 | FREEBSD_SIGPROF = 27, | |
68 | FREEBSD_SIGWINCH = 28, | |
69 | FREEBSD_SIGINFO = 29, | |
70 | FREEBSD_SIGUSR1 = 30, | |
71 | FREEBSD_SIGUSR2 = 31, | |
72 | FREEBSD_SIGTHR = 32, | |
73 | FREEBSD_SIGLIBRT = 33, | |
74 | FREEBSD_SIGRTMIN = 65, | |
75 | FREEBSD_SIGRTMAX = 126, | |
76 | }; | |
a904c024 | 77 | |
4b654465 JB |
78 | /* FreeBSD kernels 12.0 and later include a copy of the |
79 | 'ptrace_lwpinfo' structure returned by the PT_LWPINFO ptrace | |
80 | operation in an ELF core note (NT_FREEBSD_PTLWPINFO) for each LWP. | |
81 | The constants below define the offset of field members and flags in | |
82 | this structure used by methods in this file. Note that the | |
83 | 'ptrace_lwpinfo' struct in the note is preceded by a 4 byte integer | |
84 | containing the size of the structure. */ | |
85 | ||
86 | #define LWPINFO_OFFSET 0x4 | |
87 | ||
88 | /* Offsets in ptrace_lwpinfo. */ | |
89 | #define LWPINFO_PL_FLAGS 0x8 | |
90 | #define LWPINFO64_PL_SIGINFO 0x30 | |
91 | #define LWPINFO32_PL_SIGINFO 0x2c | |
92 | ||
93 | /* Flags in pl_flags. */ | |
94 | #define PL_FLAG_SI 0x20 /* siginfo is valid */ | |
95 | ||
96 | /* Sizes of siginfo_t. */ | |
97 | #define SIZE64_SIGINFO_T 80 | |
98 | #define SIZE32_SIGINFO_T 64 | |
99 | ||
d2176225 JB |
100 | /* Offsets in data structure used in NT_FREEBSD_PROCSTAT_VMMAP core |
101 | dump notes. See <sys/user.h> for the definition of struct | |
102 | kinfo_vmentry. This data structure should have the same layout on | |
57c2a98a JB |
103 | all architectures. |
104 | ||
105 | Note that FreeBSD 7.0 used an older version of this structure | |
85102364 | 106 | (struct kinfo_vmentry), but the NT_FREEBSD_PROCSTAT_VMMAP core |
57c2a98a JB |
107 | dump note wasn't introduced until FreeBSD 9.2. As a result, the |
108 | core dump note has always used the 7.1 and later structure | |
109 | format. */ | |
d2176225 JB |
110 | |
111 | #define KVE_STRUCTSIZE 0x0 | |
112 | #define KVE_START 0x8 | |
113 | #define KVE_END 0x10 | |
114 | #define KVE_OFFSET 0x18 | |
115 | #define KVE_FLAGS 0x2c | |
906b4aac | 116 | #define KVE_PROTECTION 0x38 |
d2176225 JB |
117 | #define KVE_PATH 0x88 |
118 | ||
119 | /* Flags in the 'kve_protection' field in struct kinfo_vmentry. These | |
120 | match the KVME_PROT_* constants in <sys/user.h>. */ | |
121 | ||
122 | #define KINFO_VME_PROT_READ 0x00000001 | |
123 | #define KINFO_VME_PROT_WRITE 0x00000002 | |
124 | #define KINFO_VME_PROT_EXEC 0x00000004 | |
125 | ||
126 | /* Flags in the 'kve_flags' field in struct kinfo_vmentry. These | |
127 | match the KVME_FLAG_* constants in <sys/user.h>. */ | |
128 | ||
129 | #define KINFO_VME_FLAG_COW 0x00000001 | |
130 | #define KINFO_VME_FLAG_NEEDS_COPY 0x00000002 | |
131 | #define KINFO_VME_FLAG_NOCOREDUMP 0x00000004 | |
132 | #define KINFO_VME_FLAG_SUPER 0x00000008 | |
133 | #define KINFO_VME_FLAG_GROWS_UP 0x00000010 | |
134 | #define KINFO_VME_FLAG_GROWS_DOWN 0x00000020 | |
135 | ||
136 | /* Offsets in data structure used in NT_FREEBSD_PROCSTAT_FILES core | |
137 | dump notes. See <sys/user.h> for the definition of struct | |
138 | kinfo_file. This data structure should have the same layout on all | |
57c2a98a JB |
139 | architectures. |
140 | ||
141 | Note that FreeBSD 7.0 used an older version of this structure | |
142 | (struct kinfo_ofile), but the NT_FREEBSD_PROCSTAT_FILES core dump | |
143 | note wasn't introduced until FreeBSD 9.2. As a result, the core | |
144 | dump note has always used the 7.1 and later structure format. */ | |
d2176225 JB |
145 | |
146 | #define KF_STRUCTSIZE 0x0 | |
147 | #define KF_TYPE 0x4 | |
148 | #define KF_FD 0x8 | |
57c2a98a JB |
149 | #define KF_FLAGS 0x10 |
150 | #define KF_OFFSET 0x18 | |
151 | #define KF_VNODE_TYPE 0x20 | |
152 | #define KF_SOCK_DOMAIN 0x24 | |
153 | #define KF_SOCK_TYPE 0x28 | |
154 | #define KF_SOCK_PROTOCOL 0x2c | |
155 | #define KF_SA_LOCAL 0x30 | |
156 | #define KF_SA_PEER 0xb0 | |
d2176225 JB |
157 | #define KF_PATH 0x170 |
158 | ||
159 | /* Constants for the 'kf_type' field in struct kinfo_file. These | |
160 | match the KF_TYPE_* constants in <sys/user.h>. */ | |
161 | ||
162 | #define KINFO_FILE_TYPE_VNODE 1 | |
57c2a98a JB |
163 | #define KINFO_FILE_TYPE_SOCKET 2 |
164 | #define KINFO_FILE_TYPE_PIPE 3 | |
165 | #define KINFO_FILE_TYPE_FIFO 4 | |
166 | #define KINFO_FILE_TYPE_KQUEUE 5 | |
167 | #define KINFO_FILE_TYPE_CRYPTO 6 | |
168 | #define KINFO_FILE_TYPE_MQUEUE 7 | |
169 | #define KINFO_FILE_TYPE_SHM 8 | |
170 | #define KINFO_FILE_TYPE_SEM 9 | |
171 | #define KINFO_FILE_TYPE_PTS 10 | |
172 | #define KINFO_FILE_TYPE_PROCDESC 11 | |
d2176225 JB |
173 | |
174 | /* Special values for the 'kf_fd' field in struct kinfo_file. These | |
175 | match the KF_FD_TYPE_* constants in <sys/user.h>. */ | |
176 | ||
177 | #define KINFO_FILE_FD_TYPE_CWD -1 | |
57c2a98a JB |
178 | #define KINFO_FILE_FD_TYPE_ROOT -2 |
179 | #define KINFO_FILE_FD_TYPE_JAIL -3 | |
180 | #define KINFO_FILE_FD_TYPE_TRACE -4 | |
d2176225 | 181 | #define KINFO_FILE_FD_TYPE_TEXT -5 |
57c2a98a JB |
182 | #define KINFO_FILE_FD_TYPE_CTTY -6 |
183 | ||
184 | /* Flags in the 'kf_flags' field in struct kinfo_file. These match | |
185 | the KF_FLAG_* constants in <sys/user.h>. */ | |
186 | ||
187 | #define KINFO_FILE_FLAG_READ 0x00000001 | |
188 | #define KINFO_FILE_FLAG_WRITE 0x00000002 | |
189 | #define KINFO_FILE_FLAG_APPEND 0x00000004 | |
190 | #define KINFO_FILE_FLAG_ASYNC 0x00000008 | |
191 | #define KINFO_FILE_FLAG_FSYNC 0x00000010 | |
192 | #define KINFO_FILE_FLAG_NONBLOCK 0x00000020 | |
193 | #define KINFO_FILE_FLAG_DIRECT 0x00000040 | |
194 | #define KINFO_FILE_FLAG_HASLOCK 0x00000080 | |
195 | #define KINFO_FILE_FLAG_EXEC 0x00004000 | |
196 | ||
197 | /* Constants for the 'kf_vnode_type' field in struct kinfo_file. | |
198 | These match the KF_VTYPE_* constants in <sys/user.h>. */ | |
199 | ||
200 | #define KINFO_FILE_VTYPE_VREG 1 | |
201 | #define KINFO_FILE_VTYPE_VDIR 2 | |
202 | #define KINFO_FILE_VTYPE_VCHR 4 | |
203 | #define KINFO_FILE_VTYPE_VLNK 5 | |
204 | #define KINFO_FILE_VTYPE_VSOCK 6 | |
205 | #define KINFO_FILE_VTYPE_VFIFO 7 | |
206 | ||
207 | /* Constants for socket address families. These match AF_* constants | |
208 | in <sys/socket.h>. */ | |
209 | ||
210 | #define FBSD_AF_UNIX 1 | |
211 | #define FBSD_AF_INET 2 | |
212 | #define FBSD_AF_INET6 28 | |
213 | ||
214 | /* Constants for socket types. These match SOCK_* constants in | |
215 | <sys/socket.h>. */ | |
216 | ||
217 | #define FBSD_SOCK_STREAM 1 | |
218 | #define FBSD_SOCK_DGRAM 2 | |
219 | #define FBSD_SOCK_SEQPACKET 5 | |
220 | ||
221 | /* Constants for IP protocols. These match IPPROTO_* constants in | |
222 | <netinet/in.h>. */ | |
223 | ||
224 | #define FBSD_IPPROTO_ICMP 1 | |
225 | #define FBSD_IPPROTO_TCP 6 | |
226 | #define FBSD_IPPROTO_UDP 17 | |
227 | #define FBSD_IPPROTO_SCTP 132 | |
228 | ||
229 | /* Socket address structures. These have the same layout on all | |
230 | FreeBSD architectures. In addition, multibyte fields such as IP | |
231 | addresses are always stored in network byte order. */ | |
232 | ||
233 | struct fbsd_sockaddr_in | |
234 | { | |
235 | uint8_t sin_len; | |
236 | uint8_t sin_family; | |
237 | uint8_t sin_port[2]; | |
238 | uint8_t sin_addr[4]; | |
239 | char sin_zero[8]; | |
240 | }; | |
241 | ||
242 | struct fbsd_sockaddr_in6 | |
243 | { | |
244 | uint8_t sin6_len; | |
245 | uint8_t sin6_family; | |
246 | uint8_t sin6_port[2]; | |
247 | uint32_t sin6_flowinfo; | |
248 | uint8_t sin6_addr[16]; | |
249 | uint32_t sin6_scope_id; | |
250 | }; | |
251 | ||
252 | struct fbsd_sockaddr_un | |
253 | { | |
254 | uint8_t sun_len; | |
255 | uint8_t sun_family; | |
256 | char sun_path[104]; | |
257 | }; | |
d2176225 JB |
258 | |
259 | /* Number of 32-bit words in a signal set. This matches _SIG_WORDS in | |
260 | <sys/_sigset.h> and is the same value on all architectures. */ | |
261 | ||
262 | #define SIG_WORDS 4 | |
263 | ||
264 | /* Offsets in data structure used in NT_FREEBSD_PROCSTAT_PROC core | |
265 | dump notes. See <sys/user.h> for the definition of struct | |
266 | kinfo_proc. This data structure has different layouts on different | |
267 | architectures mostly due to ILP32 vs LP64. However, FreeBSD/i386 | |
268 | uses a 32-bit time_t while all other architectures use a 64-bit | |
269 | time_t. | |
270 | ||
271 | The core dump note actually contains one kinfo_proc structure for | |
272 | each thread, but all of the process-wide data can be obtained from | |
273 | the first structure. One result of this note's format is that some | |
274 | of the process-wide status available in the native target method | |
275 | from the kern.proc.pid.<pid> sysctl such as ki_stat and ki_siglist | |
276 | is not available from a core dump. Instead, the per-thread data | |
277 | structures contain the value of these fields for individual | |
278 | threads. */ | |
279 | ||
280 | struct kinfo_proc_layout | |
281 | { | |
282 | /* Offsets of struct kinfo_proc members. */ | |
283 | int ki_layout; | |
284 | int ki_pid; | |
285 | int ki_ppid; | |
286 | int ki_pgid; | |
287 | int ki_tpgid; | |
288 | int ki_sid; | |
289 | int ki_tdev_freebsd11; | |
290 | int ki_sigignore; | |
291 | int ki_sigcatch; | |
292 | int ki_uid; | |
293 | int ki_ruid; | |
294 | int ki_svuid; | |
295 | int ki_rgid; | |
296 | int ki_svgid; | |
297 | int ki_ngroups; | |
298 | int ki_groups; | |
299 | int ki_size; | |
300 | int ki_rssize; | |
301 | int ki_tsize; | |
302 | int ki_dsize; | |
303 | int ki_ssize; | |
304 | int ki_start; | |
305 | int ki_nice; | |
306 | int ki_comm; | |
307 | int ki_tdev; | |
308 | int ki_rusage; | |
309 | int ki_rusage_ch; | |
310 | ||
311 | /* Offsets of struct rusage members. */ | |
312 | int ru_utime; | |
313 | int ru_stime; | |
314 | int ru_maxrss; | |
315 | int ru_minflt; | |
316 | int ru_majflt; | |
317 | }; | |
318 | ||
319 | const struct kinfo_proc_layout kinfo_proc_layout_32 = | |
320 | { | |
321 | .ki_layout = 0x4, | |
322 | .ki_pid = 0x28, | |
323 | .ki_ppid = 0x2c, | |
324 | .ki_pgid = 0x30, | |
325 | .ki_tpgid = 0x34, | |
326 | .ki_sid = 0x38, | |
327 | .ki_tdev_freebsd11 = 0x44, | |
328 | .ki_sigignore = 0x68, | |
329 | .ki_sigcatch = 0x78, | |
330 | .ki_uid = 0x88, | |
331 | .ki_ruid = 0x8c, | |
332 | .ki_svuid = 0x90, | |
333 | .ki_rgid = 0x94, | |
334 | .ki_svgid = 0x98, | |
335 | .ki_ngroups = 0x9c, | |
336 | .ki_groups = 0xa0, | |
337 | .ki_size = 0xe0, | |
338 | .ki_rssize = 0xe4, | |
339 | .ki_tsize = 0xec, | |
340 | .ki_dsize = 0xf0, | |
341 | .ki_ssize = 0xf4, | |
342 | .ki_start = 0x118, | |
343 | .ki_nice = 0x145, | |
344 | .ki_comm = 0x17f, | |
345 | .ki_tdev = 0x1f0, | |
346 | .ki_rusage = 0x220, | |
347 | .ki_rusage_ch = 0x278, | |
348 | ||
349 | .ru_utime = 0x0, | |
350 | .ru_stime = 0x10, | |
351 | .ru_maxrss = 0x20, | |
352 | .ru_minflt = 0x30, | |
353 | .ru_majflt = 0x34, | |
354 | }; | |
355 | ||
356 | const struct kinfo_proc_layout kinfo_proc_layout_i386 = | |
357 | { | |
358 | .ki_layout = 0x4, | |
359 | .ki_pid = 0x28, | |
360 | .ki_ppid = 0x2c, | |
361 | .ki_pgid = 0x30, | |
362 | .ki_tpgid = 0x34, | |
363 | .ki_sid = 0x38, | |
364 | .ki_tdev_freebsd11 = 0x44, | |
365 | .ki_sigignore = 0x68, | |
366 | .ki_sigcatch = 0x78, | |
367 | .ki_uid = 0x88, | |
368 | .ki_ruid = 0x8c, | |
369 | .ki_svuid = 0x90, | |
370 | .ki_rgid = 0x94, | |
371 | .ki_svgid = 0x98, | |
372 | .ki_ngroups = 0x9c, | |
373 | .ki_groups = 0xa0, | |
374 | .ki_size = 0xe0, | |
375 | .ki_rssize = 0xe4, | |
376 | .ki_tsize = 0xec, | |
377 | .ki_dsize = 0xf0, | |
378 | .ki_ssize = 0xf4, | |
379 | .ki_start = 0x118, | |
380 | .ki_nice = 0x135, | |
381 | .ki_comm = 0x16f, | |
382 | .ki_tdev = 0x1e0, | |
383 | .ki_rusage = 0x210, | |
384 | .ki_rusage_ch = 0x258, | |
385 | ||
386 | .ru_utime = 0x0, | |
387 | .ru_stime = 0x8, | |
388 | .ru_maxrss = 0x10, | |
389 | .ru_minflt = 0x20, | |
390 | .ru_majflt = 0x24, | |
391 | }; | |
392 | ||
393 | const struct kinfo_proc_layout kinfo_proc_layout_64 = | |
394 | { | |
395 | .ki_layout = 0x4, | |
396 | .ki_pid = 0x48, | |
397 | .ki_ppid = 0x4c, | |
398 | .ki_pgid = 0x50, | |
399 | .ki_tpgid = 0x54, | |
400 | .ki_sid = 0x58, | |
401 | .ki_tdev_freebsd11 = 0x64, | |
402 | .ki_sigignore = 0x88, | |
403 | .ki_sigcatch = 0x98, | |
404 | .ki_uid = 0xa8, | |
405 | .ki_ruid = 0xac, | |
406 | .ki_svuid = 0xb0, | |
407 | .ki_rgid = 0xb4, | |
408 | .ki_svgid = 0xb8, | |
409 | .ki_ngroups = 0xbc, | |
410 | .ki_groups = 0xc0, | |
411 | .ki_size = 0x100, | |
412 | .ki_rssize = 0x108, | |
413 | .ki_tsize = 0x118, | |
414 | .ki_dsize = 0x120, | |
415 | .ki_ssize = 0x128, | |
416 | .ki_start = 0x150, | |
417 | .ki_nice = 0x185, | |
418 | .ki_comm = 0x1bf, | |
419 | .ki_tdev = 0x230, | |
420 | .ki_rusage = 0x260, | |
421 | .ki_rusage_ch = 0x2f0, | |
422 | ||
423 | .ru_utime = 0x0, | |
424 | .ru_stime = 0x10, | |
425 | .ru_maxrss = 0x20, | |
426 | .ru_minflt = 0x40, | |
427 | .ru_majflt = 0x48, | |
428 | }; | |
429 | ||
762c974a JB |
430 | static struct gdbarch_data *fbsd_gdbarch_data_handle; |
431 | ||
432 | struct fbsd_gdbarch_data | |
433 | { | |
434 | struct type *siginfo_type; | |
435 | }; | |
436 | ||
437 | static void * | |
438 | init_fbsd_gdbarch_data (struct gdbarch *gdbarch) | |
439 | { | |
440 | return GDBARCH_OBSTACK_ZALLOC (gdbarch, struct fbsd_gdbarch_data); | |
441 | } | |
442 | ||
443 | static struct fbsd_gdbarch_data * | |
444 | get_fbsd_gdbarch_data (struct gdbarch *gdbarch) | |
445 | { | |
446 | return ((struct fbsd_gdbarch_data *) | |
447 | gdbarch_data (gdbarch, fbsd_gdbarch_data_handle)); | |
448 | } | |
449 | ||
945f3901 JB |
450 | struct fbsd_pspace_data |
451 | { | |
452 | /* Offsets in the runtime linker's 'Obj_Entry' structure. */ | |
d4e05d2f TT |
453 | LONGEST off_linkmap = 0; |
454 | LONGEST off_tlsindex = 0; | |
455 | bool rtld_offsets_valid = false; | |
945f3901 JB |
456 | }; |
457 | ||
d4e05d2f TT |
458 | /* Per-program-space data for FreeBSD architectures. */ |
459 | static const struct program_space_key<fbsd_pspace_data> | |
460 | fbsd_pspace_data_handle; | |
461 | ||
945f3901 JB |
462 | static struct fbsd_pspace_data * |
463 | get_fbsd_pspace_data (struct program_space *pspace) | |
464 | { | |
465 | struct fbsd_pspace_data *data; | |
466 | ||
d4e05d2f | 467 | data = fbsd_pspace_data_handle.get (pspace); |
945f3901 | 468 | if (data == NULL) |
d4e05d2f | 469 | data = fbsd_pspace_data_handle.emplace (pspace); |
945f3901 JB |
470 | |
471 | return data; | |
472 | } | |
473 | ||
79117428 JB |
474 | /* This is how we want PTIDs from core files to be printed. */ |
475 | ||
a068643d | 476 | static std::string |
79117428 JB |
477 | fbsd_core_pid_to_str (struct gdbarch *gdbarch, ptid_t ptid) |
478 | { | |
e38504b3 | 479 | if (ptid.lwp () != 0) |
a068643d | 480 | return string_printf ("LWP %ld", ptid.lwp ()); |
79117428 JB |
481 | |
482 | return normal_pid_to_str (ptid); | |
483 | } | |
484 | ||
485 | /* Extract the name assigned to a thread from a core. Returns the | |
486 | string in a static buffer. */ | |
487 | ||
488 | static const char * | |
489 | fbsd_core_thread_name (struct gdbarch *gdbarch, struct thread_info *thr) | |
490 | { | |
491 | static char buf[80]; | |
492 | struct bfd_section *section; | |
493 | bfd_size_type size; | |
79117428 | 494 | |
e38504b3 | 495 | if (thr->ptid.lwp () != 0) |
79117428 JB |
496 | { |
497 | /* FreeBSD includes a NT_FREEBSD_THRMISC note for each thread | |
498 | whose contents are defined by a "struct thrmisc" declared in | |
499 | <sys/procfs.h> on FreeBSD. The per-thread name is stored as | |
500 | a null-terminated string as the first member of the | |
501 | structure. Rather than define the full structure here, just | |
502 | extract the null-terminated name from the start of the | |
503 | note. */ | |
2af9fc44 JB |
504 | thread_section_name section_name (".thrmisc", thr->ptid); |
505 | ||
506 | section = bfd_get_section_by_name (core_bfd, section_name.c_str ()); | |
fd361982 | 507 | if (section != NULL && bfd_section_size (section) > 0) |
79117428 JB |
508 | { |
509 | /* Truncate the name if it is longer than "buf". */ | |
fd361982 | 510 | size = bfd_section_size (section); |
79117428 JB |
511 | if (size > sizeof buf - 1) |
512 | size = sizeof buf - 1; | |
513 | if (bfd_get_section_contents (core_bfd, section, buf, (file_ptr) 0, | |
514 | size) | |
515 | && buf[0] != '\0') | |
516 | { | |
517 | buf[size] = '\0'; | |
518 | ||
519 | /* Note that each thread will report the process command | |
520 | as its thread name instead of an empty name if a name | |
521 | has not been set explicitly. Return a NULL name in | |
522 | that case. */ | |
523 | if (strcmp (buf, elf_tdata (core_bfd)->core->program) != 0) | |
524 | return buf; | |
525 | } | |
526 | } | |
527 | } | |
528 | ||
529 | return NULL; | |
530 | } | |
531 | ||
4b654465 JB |
532 | /* Implement the "core_xfer_siginfo" gdbarch method. */ |
533 | ||
534 | static LONGEST | |
535 | fbsd_core_xfer_siginfo (struct gdbarch *gdbarch, gdb_byte *readbuf, | |
536 | ULONGEST offset, ULONGEST len) | |
537 | { | |
538 | size_t siginfo_size; | |
539 | ||
a181c0bf | 540 | if (gdbarch_long_bit (gdbarch) == 32) |
4b654465 JB |
541 | siginfo_size = SIZE32_SIGINFO_T; |
542 | else | |
543 | siginfo_size = SIZE64_SIGINFO_T; | |
544 | if (offset > siginfo_size) | |
545 | return -1; | |
546 | ||
547 | thread_section_name section_name (".note.freebsdcore.lwpinfo", inferior_ptid); | |
548 | asection *section = bfd_get_section_by_name (core_bfd, section_name.c_str ()); | |
549 | if (section == NULL) | |
550 | return -1; | |
551 | ||
552 | gdb_byte buf[4]; | |
553 | if (!bfd_get_section_contents (core_bfd, section, buf, | |
554 | LWPINFO_OFFSET + LWPINFO_PL_FLAGS, 4)) | |
555 | return -1; | |
556 | ||
557 | int pl_flags = extract_signed_integer (buf, 4, gdbarch_byte_order (gdbarch)); | |
558 | if (!(pl_flags & PL_FLAG_SI)) | |
559 | return -1; | |
560 | ||
561 | if (offset + len > siginfo_size) | |
562 | len = siginfo_size - offset; | |
563 | ||
564 | ULONGEST siginfo_offset; | |
a181c0bf | 565 | if (gdbarch_long_bit (gdbarch) == 32) |
4b654465 JB |
566 | siginfo_offset = LWPINFO_OFFSET + LWPINFO32_PL_SIGINFO; |
567 | else | |
568 | siginfo_offset = LWPINFO_OFFSET + LWPINFO64_PL_SIGINFO; | |
569 | ||
570 | if (!bfd_get_section_contents (core_bfd, section, readbuf, | |
571 | siginfo_offset + offset, len)) | |
572 | return -1; | |
573 | ||
574 | return len; | |
575 | } | |
576 | ||
a904c024 AA |
577 | static int |
578 | find_signalled_thread (struct thread_info *info, void *data) | |
579 | { | |
580 | if (info->suspend.stop_signal != GDB_SIGNAL_0 | |
e99b03dc | 581 | && info->ptid.pid () == inferior_ptid.pid ()) |
a904c024 AA |
582 | return 1; |
583 | ||
584 | return 0; | |
585 | } | |
586 | ||
739ab2e9 SS |
587 | /* Return a byte_vector containing the contents of a core dump note |
588 | for the target object of type OBJECT. If STRUCTSIZE is non-zero, | |
589 | the data is prefixed with a 32-bit integer size to match the format | |
590 | used in FreeBSD NT_PROCSTAT_* notes. */ | |
591 | ||
592 | static gdb::optional<gdb::byte_vector> | |
593 | fbsd_make_note_desc (enum target_object object, uint32_t structsize) | |
594 | { | |
595 | gdb::optional<gdb::byte_vector> buf = | |
596 | target_read_alloc (current_top_target (), object, NULL); | |
597 | if (!buf || buf->empty ()) | |
598 | return {}; | |
599 | ||
600 | if (structsize == 0) | |
601 | return buf; | |
602 | ||
603 | gdb::byte_vector desc (sizeof (structsize) + buf->size ()); | |
604 | memcpy (desc.data (), &structsize, sizeof (structsize)); | |
605 | memcpy (desc.data () + sizeof (structsize), buf->data (), buf->size ()); | |
606 | return desc; | |
607 | } | |
608 | ||
a904c024 AA |
609 | /* Create appropriate note sections for a corefile, returning them in |
610 | allocated memory. */ | |
611 | ||
c21f37a8 | 612 | static gdb::unique_xmalloc_ptr<char> |
a904c024 AA |
613 | fbsd_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size) |
614 | { | |
c21f37a8 | 615 | gdb::unique_xmalloc_ptr<char> note_data; |
a904c024 | 616 | Elf_Internal_Ehdr *i_ehdrp; |
08036331 | 617 | struct thread_info *curr_thr, *signalled_thr; |
a904c024 AA |
618 | |
619 | /* Put a "FreeBSD" label in the ELF header. */ | |
620 | i_ehdrp = elf_elfheader (obfd); | |
621 | i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_FREEBSD; | |
622 | ||
623 | gdb_assert (gdbarch_iterate_over_regset_sections_p (gdbarch)); | |
624 | ||
a904c024 AA |
625 | if (get_exec_file (0)) |
626 | { | |
627 | const char *fname = lbasename (get_exec_file (0)); | |
0afbabf0 | 628 | std::string psargs = fname; |
a904c024 | 629 | |
0afbabf0 JB |
630 | const char *infargs = get_inferior_args (); |
631 | if (infargs != NULL) | |
632 | psargs = psargs + " " + infargs; | |
a904c024 | 633 | |
c21f37a8 SM |
634 | note_data.reset (elfcore_write_prpsinfo (obfd, note_data.release (), |
635 | note_size, fname, | |
636 | psargs.c_str ())); | |
a904c024 AA |
637 | } |
638 | ||
20a0aab3 | 639 | /* Thread register information. */ |
a70b8144 | 640 | try |
20a0aab3 JB |
641 | { |
642 | update_thread_list (); | |
643 | } | |
230d2906 | 644 | catch (const gdb_exception_error &e) |
20a0aab3 JB |
645 | { |
646 | exception_print (gdb_stderr, e); | |
647 | } | |
20a0aab3 JB |
648 | |
649 | /* Like the kernel, prefer dumping the signalled thread first. | |
650 | "First thread" is what tools use to infer the signalled thread. | |
651 | In case there's more than one signalled thread, prefer the | |
652 | current thread, if it is signalled. */ | |
653 | curr_thr = inferior_thread (); | |
654 | if (curr_thr->suspend.stop_signal != GDB_SIGNAL_0) | |
655 | signalled_thr = curr_thr; | |
656 | else | |
657 | { | |
658 | signalled_thr = iterate_over_threads (find_signalled_thread, NULL); | |
659 | if (signalled_thr == NULL) | |
660 | signalled_thr = curr_thr; | |
661 | } | |
662 | ||
82a1fd3a AB |
663 | gcore_build_thread_register_notes (gdbarch, signalled_thr, |
664 | signalled_thr->suspend.stop_signal, | |
665 | obfd, ¬e_data, note_size); | |
08036331 | 666 | for (thread_info *thr : current_inferior ()->non_exited_threads ()) |
20a0aab3 JB |
667 | { |
668 | if (thr == signalled_thr) | |
669 | continue; | |
20a0aab3 | 670 | |
82a1fd3a AB |
671 | gcore_build_thread_register_notes (gdbarch, thr, |
672 | signalled_thr->suspend.stop_signal, | |
673 | obfd, ¬e_data, note_size); | |
20a0aab3 JB |
674 | } |
675 | ||
739ab2e9 SS |
676 | /* Auxiliary vector. */ |
677 | uint32_t structsize = gdbarch_ptr_bit (gdbarch) / 4; /* Elf_Auxinfo */ | |
678 | gdb::optional<gdb::byte_vector> note_desc = | |
679 | fbsd_make_note_desc (TARGET_OBJECT_AUXV, structsize); | |
680 | if (note_desc && !note_desc->empty ()) | |
681 | { | |
c21f37a8 SM |
682 | note_data.reset (elfcore_write_note (obfd, note_data.release (), |
683 | note_size, "FreeBSD", | |
684 | NT_FREEBSD_PROCSTAT_AUXV, | |
685 | note_desc->data (), | |
686 | note_desc->size ())); | |
739ab2e9 SS |
687 | if (!note_data) |
688 | return NULL; | |
689 | } | |
690 | ||
691 | /* Virtual memory mappings. */ | |
692 | note_desc = fbsd_make_note_desc (TARGET_OBJECT_FREEBSD_VMMAP, 0); | |
693 | if (note_desc && !note_desc->empty ()) | |
694 | { | |
c21f37a8 SM |
695 | note_data.reset (elfcore_write_note (obfd, note_data.release (), |
696 | note_size, "FreeBSD", | |
697 | NT_FREEBSD_PROCSTAT_VMMAP, | |
698 | note_desc->data (), | |
699 | note_desc->size ())); | |
739ab2e9 SS |
700 | if (!note_data) |
701 | return NULL; | |
702 | } | |
703 | ||
704 | note_desc = fbsd_make_note_desc (TARGET_OBJECT_FREEBSD_PS_STRINGS, 0); | |
705 | if (note_desc && !note_desc->empty ()) | |
706 | { | |
c21f37a8 SM |
707 | note_data.reset (elfcore_write_note (obfd, note_data.release (), |
708 | note_size, "FreeBSD", | |
709 | NT_FREEBSD_PROCSTAT_PSSTRINGS, | |
710 | note_desc->data (), | |
711 | note_desc->size ())); | |
739ab2e9 SS |
712 | if (!note_data) |
713 | return NULL; | |
714 | } | |
715 | ||
a904c024 AA |
716 | return note_data; |
717 | } | |
718 | ||
57c2a98a JB |
719 | /* Helper function to generate the file descriptor description for a |
720 | single open file in 'info proc files'. */ | |
721 | ||
722 | static const char * | |
723 | fbsd_file_fd (int kf_fd) | |
724 | { | |
725 | switch (kf_fd) | |
726 | { | |
727 | case KINFO_FILE_FD_TYPE_CWD: | |
728 | return "cwd"; | |
729 | case KINFO_FILE_FD_TYPE_ROOT: | |
730 | return "root"; | |
731 | case KINFO_FILE_FD_TYPE_JAIL: | |
732 | return "jail"; | |
733 | case KINFO_FILE_FD_TYPE_TRACE: | |
734 | return "trace"; | |
735 | case KINFO_FILE_FD_TYPE_TEXT: | |
736 | return "text"; | |
737 | case KINFO_FILE_FD_TYPE_CTTY: | |
738 | return "ctty"; | |
739 | default: | |
740 | return int_string (kf_fd, 10, 1, 0, 0); | |
741 | } | |
742 | } | |
743 | ||
744 | /* Helper function to generate the file type for a single open file in | |
745 | 'info proc files'. */ | |
746 | ||
747 | static const char * | |
748 | fbsd_file_type (int kf_type, int kf_vnode_type) | |
749 | { | |
750 | switch (kf_type) | |
751 | { | |
752 | case KINFO_FILE_TYPE_VNODE: | |
753 | switch (kf_vnode_type) | |
754 | { | |
755 | case KINFO_FILE_VTYPE_VREG: | |
756 | return "file"; | |
757 | case KINFO_FILE_VTYPE_VDIR: | |
758 | return "dir"; | |
759 | case KINFO_FILE_VTYPE_VCHR: | |
760 | return "chr"; | |
761 | case KINFO_FILE_VTYPE_VLNK: | |
762 | return "link"; | |
763 | case KINFO_FILE_VTYPE_VSOCK: | |
764 | return "socket"; | |
765 | case KINFO_FILE_VTYPE_VFIFO: | |
766 | return "fifo"; | |
767 | default: | |
768 | { | |
769 | char *str = get_print_cell (); | |
770 | ||
771 | xsnprintf (str, PRINT_CELL_SIZE, "vn:%d", kf_vnode_type); | |
772 | return str; | |
773 | } | |
774 | } | |
775 | case KINFO_FILE_TYPE_SOCKET: | |
776 | return "socket"; | |
777 | case KINFO_FILE_TYPE_PIPE: | |
778 | return "pipe"; | |
779 | case KINFO_FILE_TYPE_FIFO: | |
780 | return "fifo"; | |
781 | case KINFO_FILE_TYPE_KQUEUE: | |
782 | return "kqueue"; | |
783 | case KINFO_FILE_TYPE_CRYPTO: | |
784 | return "crypto"; | |
785 | case KINFO_FILE_TYPE_MQUEUE: | |
786 | return "mqueue"; | |
787 | case KINFO_FILE_TYPE_SHM: | |
788 | return "shm"; | |
789 | case KINFO_FILE_TYPE_SEM: | |
790 | return "sem"; | |
791 | case KINFO_FILE_TYPE_PTS: | |
792 | return "pts"; | |
793 | case KINFO_FILE_TYPE_PROCDESC: | |
794 | return "proc"; | |
795 | default: | |
796 | return int_string (kf_type, 10, 1, 0, 0); | |
797 | } | |
798 | } | |
799 | ||
800 | /* Helper function to generate the file flags for a single open file in | |
801 | 'info proc files'. */ | |
802 | ||
803 | static const char * | |
804 | fbsd_file_flags (int kf_flags) | |
805 | { | |
806 | static char file_flags[10]; | |
807 | ||
808 | file_flags[0] = (kf_flags & KINFO_FILE_FLAG_READ) ? 'r' : '-'; | |
809 | file_flags[1] = (kf_flags & KINFO_FILE_FLAG_WRITE) ? 'w' : '-'; | |
810 | file_flags[2] = (kf_flags & KINFO_FILE_FLAG_EXEC) ? 'x' : '-'; | |
811 | file_flags[3] = (kf_flags & KINFO_FILE_FLAG_APPEND) ? 'a' : '-'; | |
812 | file_flags[4] = (kf_flags & KINFO_FILE_FLAG_ASYNC) ? 's' : '-'; | |
813 | file_flags[5] = (kf_flags & KINFO_FILE_FLAG_FSYNC) ? 'f' : '-'; | |
814 | file_flags[6] = (kf_flags & KINFO_FILE_FLAG_NONBLOCK) ? 'n' : '-'; | |
815 | file_flags[7] = (kf_flags & KINFO_FILE_FLAG_DIRECT) ? 'd' : '-'; | |
816 | file_flags[8] = (kf_flags & KINFO_FILE_FLAG_HASLOCK) ? 'l' : '-'; | |
817 | file_flags[9] = '\0'; | |
818 | ||
819 | return file_flags; | |
820 | } | |
821 | ||
822 | /* Helper function to generate the name of an IP protocol. */ | |
823 | ||
824 | static const char * | |
825 | fbsd_ipproto (int protocol) | |
826 | { | |
827 | switch (protocol) | |
828 | { | |
829 | case FBSD_IPPROTO_ICMP: | |
830 | return "icmp"; | |
831 | case FBSD_IPPROTO_TCP: | |
832 | return "tcp"; | |
833 | case FBSD_IPPROTO_UDP: | |
834 | return "udp"; | |
835 | case FBSD_IPPROTO_SCTP: | |
836 | return "sctp"; | |
837 | default: | |
838 | { | |
839 | char *str = get_print_cell (); | |
840 | ||
841 | xsnprintf (str, PRINT_CELL_SIZE, "ip<%d>", protocol); | |
842 | return str; | |
843 | } | |
844 | } | |
845 | } | |
846 | ||
847 | /* Helper function to print out an IPv4 socket address. */ | |
848 | ||
849 | static void | |
850 | fbsd_print_sockaddr_in (const void *sockaddr) | |
851 | { | |
852 | const struct fbsd_sockaddr_in *sin = | |
853 | reinterpret_cast<const struct fbsd_sockaddr_in *> (sockaddr); | |
854 | char buf[INET_ADDRSTRLEN]; | |
855 | ||
07147793 | 856 | if (inet_ntop (AF_INET, sin->sin_addr, buf, sizeof buf) == nullptr) |
57c2a98a JB |
857 | error (_("Failed to format IPv4 address")); |
858 | printf_filtered ("%s:%u", buf, | |
859 | (sin->sin_port[0] << 8) | sin->sin_port[1]); | |
860 | } | |
861 | ||
862 | /* Helper function to print out an IPv6 socket address. */ | |
863 | ||
864 | static void | |
865 | fbsd_print_sockaddr_in6 (const void *sockaddr) | |
866 | { | |
867 | const struct fbsd_sockaddr_in6 *sin6 = | |
868 | reinterpret_cast<const struct fbsd_sockaddr_in6 *> (sockaddr); | |
869 | char buf[INET6_ADDRSTRLEN]; | |
870 | ||
07147793 | 871 | if (inet_ntop (AF_INET6, sin6->sin6_addr, buf, sizeof buf) == nullptr) |
57c2a98a JB |
872 | error (_("Failed to format IPv6 address")); |
873 | printf_filtered ("%s.%u", buf, | |
874 | (sin6->sin6_port[0] << 8) | sin6->sin6_port[1]); | |
875 | } | |
876 | ||
877 | /* See fbsd-tdep.h. */ | |
878 | ||
879 | void | |
880 | fbsd_info_proc_files_header () | |
881 | { | |
882 | printf_filtered (_("Open files:\n\n")); | |
883 | printf_filtered (" %6s %6s %10s %9s %s\n", | |
884 | "FD", "Type", "Offset", "Flags ", "Name"); | |
885 | } | |
886 | ||
887 | /* See fbsd-tdep.h. */ | |
888 | ||
889 | void | |
890 | fbsd_info_proc_files_entry (int kf_type, int kf_fd, int kf_flags, | |
891 | LONGEST kf_offset, int kf_vnode_type, | |
892 | int kf_sock_domain, int kf_sock_type, | |
893 | int kf_sock_protocol, const void *kf_sa_local, | |
894 | const void *kf_sa_peer, const void *kf_path) | |
895 | { | |
896 | printf_filtered (" %6s %6s %10s %8s ", | |
897 | fbsd_file_fd (kf_fd), | |
898 | fbsd_file_type (kf_type, kf_vnode_type), | |
899 | kf_offset > -1 ? hex_string (kf_offset) : "-", | |
900 | fbsd_file_flags (kf_flags)); | |
901 | if (kf_type == KINFO_FILE_TYPE_SOCKET) | |
902 | { | |
903 | switch (kf_sock_domain) | |
904 | { | |
905 | case FBSD_AF_UNIX: | |
906 | { | |
907 | switch (kf_sock_type) | |
908 | { | |
909 | case FBSD_SOCK_STREAM: | |
910 | printf_filtered ("unix stream:"); | |
911 | break; | |
912 | case FBSD_SOCK_DGRAM: | |
913 | printf_filtered ("unix dgram:"); | |
914 | break; | |
915 | case FBSD_SOCK_SEQPACKET: | |
916 | printf_filtered ("unix seqpacket:"); | |
917 | break; | |
918 | default: | |
919 | printf_filtered ("unix <%d>:", kf_sock_type); | |
920 | break; | |
921 | } | |
922 | ||
923 | /* For local sockets, print out the first non-nul path | |
924 | rather than both paths. */ | |
aa989b27 | 925 | const struct fbsd_sockaddr_un *saddr_un |
57c2a98a | 926 | = reinterpret_cast<const struct fbsd_sockaddr_un *> (kf_sa_local); |
aa989b27 CB |
927 | if (saddr_un->sun_path[0] == 0) |
928 | saddr_un = reinterpret_cast<const struct fbsd_sockaddr_un *> | |
57c2a98a | 929 | (kf_sa_peer); |
aa989b27 | 930 | printf_filtered ("%s", saddr_un->sun_path); |
57c2a98a JB |
931 | break; |
932 | } | |
933 | case FBSD_AF_INET: | |
934 | printf_filtered ("%s4 ", fbsd_ipproto (kf_sock_protocol)); | |
935 | fbsd_print_sockaddr_in (kf_sa_local); | |
936 | printf_filtered (" -> "); | |
937 | fbsd_print_sockaddr_in (kf_sa_peer); | |
938 | break; | |
939 | case FBSD_AF_INET6: | |
940 | printf_filtered ("%s6 ", fbsd_ipproto (kf_sock_protocol)); | |
941 | fbsd_print_sockaddr_in6 (kf_sa_local); | |
942 | printf_filtered (" -> "); | |
943 | fbsd_print_sockaddr_in6 (kf_sa_peer); | |
944 | break; | |
945 | } | |
946 | } | |
947 | else | |
948 | printf_filtered ("%s", reinterpret_cast<const char *> (kf_path)); | |
949 | printf_filtered ("\n"); | |
950 | } | |
951 | ||
952 | /* Implement "info proc files" for a corefile. */ | |
953 | ||
954 | static void | |
955 | fbsd_core_info_proc_files (struct gdbarch *gdbarch) | |
956 | { | |
957 | asection *section | |
958 | = bfd_get_section_by_name (core_bfd, ".note.freebsdcore.files"); | |
959 | if (section == NULL) | |
960 | { | |
961 | warning (_("unable to find open files in core file")); | |
962 | return; | |
963 | } | |
964 | ||
fd361982 | 965 | size_t note_size = bfd_section_size (section); |
57c2a98a JB |
966 | if (note_size < 4) |
967 | error (_("malformed core note - too short for header")); | |
968 | ||
969 | gdb::def_vector<unsigned char> contents (note_size); | |
970 | if (!bfd_get_section_contents (core_bfd, section, contents.data (), | |
971 | 0, note_size)) | |
972 | error (_("could not get core note contents")); | |
973 | ||
974 | unsigned char *descdata = contents.data (); | |
975 | unsigned char *descend = descdata + note_size; | |
976 | ||
977 | /* Skip over the structure size. */ | |
978 | descdata += 4; | |
979 | ||
980 | fbsd_info_proc_files_header (); | |
981 | ||
982 | while (descdata + KF_PATH < descend) | |
983 | { | |
984 | ULONGEST structsize = bfd_get_32 (core_bfd, descdata + KF_STRUCTSIZE); | |
985 | if (structsize < KF_PATH) | |
986 | error (_("malformed core note - file structure too small")); | |
987 | ||
988 | LONGEST type = bfd_get_signed_32 (core_bfd, descdata + KF_TYPE); | |
989 | LONGEST fd = bfd_get_signed_32 (core_bfd, descdata + KF_FD); | |
990 | LONGEST flags = bfd_get_signed_32 (core_bfd, descdata + KF_FLAGS); | |
991 | LONGEST offset = bfd_get_signed_64 (core_bfd, descdata + KF_OFFSET); | |
992 | LONGEST vnode_type = bfd_get_signed_32 (core_bfd, | |
993 | descdata + KF_VNODE_TYPE); | |
994 | LONGEST sock_domain = bfd_get_signed_32 (core_bfd, | |
995 | descdata + KF_SOCK_DOMAIN); | |
996 | LONGEST sock_type = bfd_get_signed_32 (core_bfd, descdata + KF_SOCK_TYPE); | |
997 | LONGEST sock_protocol = bfd_get_signed_32 (core_bfd, | |
998 | descdata + KF_SOCK_PROTOCOL); | |
999 | fbsd_info_proc_files_entry (type, fd, flags, offset, vnode_type, | |
1000 | sock_domain, sock_type, sock_protocol, | |
1001 | descdata + KF_SA_LOCAL, descdata + KF_SA_PEER, | |
1002 | descdata + KF_PATH); | |
1003 | ||
1004 | descdata += structsize; | |
1005 | } | |
1006 | } | |
1007 | ||
d2176225 JB |
1008 | /* Helper function to generate mappings flags for a single VM map |
1009 | entry in 'info proc mappings'. */ | |
1010 | ||
6f3b1098 | 1011 | static const char * |
d2176225 JB |
1012 | fbsd_vm_map_entry_flags (int kve_flags, int kve_protection) |
1013 | { | |
1014 | static char vm_flags[9]; | |
1015 | ||
1016 | vm_flags[0] = (kve_protection & KINFO_VME_PROT_READ) ? 'r' : '-'; | |
1017 | vm_flags[1] = (kve_protection & KINFO_VME_PROT_WRITE) ? 'w' : '-'; | |
1018 | vm_flags[2] = (kve_protection & KINFO_VME_PROT_EXEC) ? 'x' : '-'; | |
1019 | vm_flags[3] = ' '; | |
1020 | vm_flags[4] = (kve_flags & KINFO_VME_FLAG_COW) ? 'C' : '-'; | |
1021 | vm_flags[5] = (kve_flags & KINFO_VME_FLAG_NEEDS_COPY) ? 'N' : '-'; | |
1022 | vm_flags[6] = (kve_flags & KINFO_VME_FLAG_SUPER) ? 'S' : '-'; | |
1023 | vm_flags[7] = (kve_flags & KINFO_VME_FLAG_GROWS_UP) ? 'U' | |
1024 | : (kve_flags & KINFO_VME_FLAG_GROWS_DOWN) ? 'D' : '-'; | |
1025 | vm_flags[8] = '\0'; | |
1026 | ||
1027 | return vm_flags; | |
1028 | } | |
1029 | ||
6f3b1098 JB |
1030 | /* See fbsd-tdep.h. */ |
1031 | ||
1032 | void | |
1033 | fbsd_info_proc_mappings_header (int addr_bit) | |
1034 | { | |
1035 | printf_filtered (_("Mapped address spaces:\n\n")); | |
1036 | if (addr_bit == 64) | |
1037 | { | |
1038 | printf_filtered (" %18s %18s %10s %10s %9s %s\n", | |
1039 | "Start Addr", | |
1040 | " End Addr", | |
1041 | " Size", " Offset", "Flags ", "File"); | |
1042 | } | |
1043 | else | |
1044 | { | |
1045 | printf_filtered ("\t%10s %10s %10s %10s %9s %s\n", | |
1046 | "Start Addr", | |
1047 | " End Addr", | |
1048 | " Size", " Offset", "Flags ", "File"); | |
1049 | } | |
1050 | } | |
1051 | ||
1052 | /* See fbsd-tdep.h. */ | |
1053 | ||
1054 | void | |
1055 | fbsd_info_proc_mappings_entry (int addr_bit, ULONGEST kve_start, | |
1056 | ULONGEST kve_end, ULONGEST kve_offset, | |
1057 | int kve_flags, int kve_protection, | |
1058 | const void *kve_path) | |
1059 | { | |
1060 | if (addr_bit == 64) | |
1061 | { | |
1062 | printf_filtered (" %18s %18s %10s %10s %9s %s\n", | |
1063 | hex_string (kve_start), | |
1064 | hex_string (kve_end), | |
1065 | hex_string (kve_end - kve_start), | |
1066 | hex_string (kve_offset), | |
1067 | fbsd_vm_map_entry_flags (kve_flags, kve_protection), | |
1068 | reinterpret_cast<const char *> (kve_path)); | |
1069 | } | |
1070 | else | |
1071 | { | |
1072 | printf_filtered ("\t%10s %10s %10s %10s %9s %s\n", | |
1073 | hex_string (kve_start), | |
1074 | hex_string (kve_end), | |
1075 | hex_string (kve_end - kve_start), | |
1076 | hex_string (kve_offset), | |
1077 | fbsd_vm_map_entry_flags (kve_flags, kve_protection), | |
1078 | reinterpret_cast<const char *> (kve_path)); | |
1079 | } | |
1080 | } | |
1081 | ||
d2176225 JB |
1082 | /* Implement "info proc mappings" for a corefile. */ |
1083 | ||
1084 | static void | |
1085 | fbsd_core_info_proc_mappings (struct gdbarch *gdbarch) | |
1086 | { | |
1087 | asection *section; | |
1088 | unsigned char *descdata, *descend; | |
1089 | size_t note_size; | |
1090 | ||
1091 | section = bfd_get_section_by_name (core_bfd, ".note.freebsdcore.vmmap"); | |
1092 | if (section == NULL) | |
1093 | { | |
1094 | warning (_("unable to find mappings in core file")); | |
1095 | return; | |
1096 | } | |
1097 | ||
fd361982 | 1098 | note_size = bfd_section_size (section); |
d2176225 JB |
1099 | if (note_size < 4) |
1100 | error (_("malformed core note - too short for header")); | |
1101 | ||
1102 | gdb::def_vector<unsigned char> contents (note_size); | |
1103 | if (!bfd_get_section_contents (core_bfd, section, contents.data (), | |
1104 | 0, note_size)) | |
1105 | error (_("could not get core note contents")); | |
1106 | ||
1107 | descdata = contents.data (); | |
1108 | descend = descdata + note_size; | |
1109 | ||
1110 | /* Skip over the structure size. */ | |
1111 | descdata += 4; | |
1112 | ||
6f3b1098 | 1113 | fbsd_info_proc_mappings_header (gdbarch_addr_bit (gdbarch)); |
d2176225 JB |
1114 | while (descdata + KVE_PATH < descend) |
1115 | { | |
6f3b1098 | 1116 | ULONGEST structsize = bfd_get_32 (core_bfd, descdata + KVE_STRUCTSIZE); |
d2176225 JB |
1117 | if (structsize < KVE_PATH) |
1118 | error (_("malformed core note - vmmap entry too small")); | |
1119 | ||
6f3b1098 JB |
1120 | ULONGEST start = bfd_get_64 (core_bfd, descdata + KVE_START); |
1121 | ULONGEST end = bfd_get_64 (core_bfd, descdata + KVE_END); | |
1122 | ULONGEST offset = bfd_get_64 (core_bfd, descdata + KVE_OFFSET); | |
1123 | LONGEST flags = bfd_get_signed_32 (core_bfd, descdata + KVE_FLAGS); | |
1124 | LONGEST prot = bfd_get_signed_32 (core_bfd, descdata + KVE_PROTECTION); | |
1125 | fbsd_info_proc_mappings_entry (gdbarch_addr_bit (gdbarch), start, end, | |
1126 | offset, flags, prot, descdata + KVE_PATH); | |
d2176225 JB |
1127 | |
1128 | descdata += structsize; | |
1129 | } | |
1130 | } | |
1131 | ||
1132 | /* Fetch the pathname of a vnode for a single file descriptor from the | |
1133 | file table core note. */ | |
1134 | ||
1135 | static gdb::unique_xmalloc_ptr<char> | |
1136 | fbsd_core_vnode_path (struct gdbarch *gdbarch, int fd) | |
1137 | { | |
1138 | asection *section; | |
1139 | unsigned char *descdata, *descend; | |
1140 | size_t note_size; | |
1141 | ||
1142 | section = bfd_get_section_by_name (core_bfd, ".note.freebsdcore.files"); | |
1143 | if (section == NULL) | |
1144 | return nullptr; | |
1145 | ||
fd361982 | 1146 | note_size = bfd_section_size (section); |
d2176225 JB |
1147 | if (note_size < 4) |
1148 | error (_("malformed core note - too short for header")); | |
1149 | ||
1150 | gdb::def_vector<unsigned char> contents (note_size); | |
1151 | if (!bfd_get_section_contents (core_bfd, section, contents.data (), | |
1152 | 0, note_size)) | |
1153 | error (_("could not get core note contents")); | |
1154 | ||
1155 | descdata = contents.data (); | |
1156 | descend = descdata + note_size; | |
1157 | ||
1158 | /* Skip over the structure size. */ | |
1159 | descdata += 4; | |
1160 | ||
9f235e09 | 1161 | while (descdata + KF_PATH < descend) |
d2176225 JB |
1162 | { |
1163 | ULONGEST structsize; | |
1164 | ||
1165 | structsize = bfd_get_32 (core_bfd, descdata + KF_STRUCTSIZE); | |
9f235e09 JB |
1166 | if (structsize < KF_PATH) |
1167 | error (_("malformed core note - file structure too small")); | |
d2176225 JB |
1168 | |
1169 | if (bfd_get_32 (core_bfd, descdata + KF_TYPE) == KINFO_FILE_TYPE_VNODE | |
1170 | && bfd_get_signed_32 (core_bfd, descdata + KF_FD) == fd) | |
1171 | { | |
1172 | char *path = (char *) descdata + KF_PATH; | |
b02f78f9 | 1173 | return make_unique_xstrdup (path); |
d2176225 JB |
1174 | } |
1175 | ||
1176 | descdata += structsize; | |
1177 | } | |
1178 | return nullptr; | |
1179 | } | |
1180 | ||
1181 | /* Helper function to read a struct timeval. */ | |
1182 | ||
1183 | static void | |
1184 | fbsd_core_fetch_timeval (struct gdbarch *gdbarch, unsigned char *data, | |
1185 | LONGEST &sec, ULONGEST &usec) | |
1186 | { | |
1187 | if (gdbarch_addr_bit (gdbarch) == 64) | |
1188 | { | |
1189 | sec = bfd_get_signed_64 (core_bfd, data); | |
1190 | usec = bfd_get_64 (core_bfd, data + 8); | |
1191 | } | |
1192 | else if (bfd_get_arch (core_bfd) == bfd_arch_i386) | |
1193 | { | |
1194 | sec = bfd_get_signed_32 (core_bfd, data); | |
1195 | usec = bfd_get_32 (core_bfd, data + 4); | |
1196 | } | |
1197 | else | |
1198 | { | |
1199 | sec = bfd_get_signed_64 (core_bfd, data); | |
1200 | usec = bfd_get_32 (core_bfd, data + 8); | |
1201 | } | |
1202 | } | |
1203 | ||
1204 | /* Print out the contents of a signal set. */ | |
1205 | ||
1206 | static void | |
1207 | fbsd_print_sigset (const char *descr, unsigned char *sigset) | |
1208 | { | |
1209 | printf_filtered ("%s: ", descr); | |
1210 | for (int i = 0; i < SIG_WORDS; i++) | |
1211 | printf_filtered ("%08x ", | |
1212 | (unsigned int) bfd_get_32 (core_bfd, sigset + i * 4)); | |
1213 | printf_filtered ("\n"); | |
1214 | } | |
1215 | ||
1216 | /* Implement "info proc status" for a corefile. */ | |
1217 | ||
1218 | static void | |
1219 | fbsd_core_info_proc_status (struct gdbarch *gdbarch) | |
1220 | { | |
1221 | const struct kinfo_proc_layout *kp; | |
1222 | asection *section; | |
d2176225 JB |
1223 | unsigned char *descdata; |
1224 | int addr_bit, long_bit; | |
1225 | size_t note_size; | |
1226 | ULONGEST value; | |
1227 | LONGEST sec; | |
1228 | ||
1229 | section = bfd_get_section_by_name (core_bfd, ".note.freebsdcore.proc"); | |
1230 | if (section == NULL) | |
1231 | { | |
1232 | warning (_("unable to find process info in core file")); | |
1233 | return; | |
1234 | } | |
1235 | ||
1236 | addr_bit = gdbarch_addr_bit (gdbarch); | |
1237 | if (addr_bit == 64) | |
1238 | kp = &kinfo_proc_layout_64; | |
1239 | else if (bfd_get_arch (core_bfd) == bfd_arch_i386) | |
1240 | kp = &kinfo_proc_layout_i386; | |
1241 | else | |
1242 | kp = &kinfo_proc_layout_32; | |
1243 | long_bit = gdbarch_long_bit (gdbarch); | |
1244 | ||
1245 | /* | |
1246 | * Ensure that the note is large enough for all of the fields fetched | |
1247 | * by this function. In particular, the note must contain the 32-bit | |
1248 | * structure size, then it must be long enough to access the last | |
1249 | * field used (ki_rusage_ch.ru_majflt) which is the size of a long. | |
1250 | */ | |
fd361982 | 1251 | note_size = bfd_section_size (section); |
d2176225 JB |
1252 | if (note_size < (4 + kp->ki_rusage_ch + kp->ru_majflt |
1253 | + long_bit / TARGET_CHAR_BIT)) | |
1254 | error (_("malformed core note - too short")); | |
1255 | ||
1256 | gdb::def_vector<unsigned char> contents (note_size); | |
1257 | if (!bfd_get_section_contents (core_bfd, section, contents.data (), | |
1258 | 0, note_size)) | |
1259 | error (_("could not get core note contents")); | |
1260 | ||
1261 | descdata = contents.data (); | |
1262 | ||
1263 | /* Skip over the structure size. */ | |
1264 | descdata += 4; | |
1265 | ||
1266 | /* Verify 'ki_layout' is 0. */ | |
1267 | if (bfd_get_32 (core_bfd, descdata + kp->ki_layout) != 0) | |
1268 | { | |
1269 | warning (_("unsupported process information in core file")); | |
1270 | return; | |
1271 | } | |
1272 | ||
1273 | printf_filtered ("Name: %.19s\n", descdata + kp->ki_comm); | |
1274 | printf_filtered ("Process ID: %s\n", | |
1275 | pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_pid))); | |
1276 | printf_filtered ("Parent process: %s\n", | |
1277 | pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_ppid))); | |
1278 | printf_filtered ("Process group: %s\n", | |
1279 | pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_pgid))); | |
1280 | printf_filtered ("Session id: %s\n", | |
1281 | pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_sid))); | |
1282 | ||
1283 | /* FreeBSD 12.0 and later store a 64-bit dev_t at 'ki_tdev'. Older | |
1284 | kernels store a 32-bit dev_t at 'ki_tdev_freebsd11'. In older | |
1285 | kernels the 64-bit 'ki_tdev' field is in a reserved section of | |
1286 | the structure that is cleared to zero. Assume that a zero value | |
1287 | in ki_tdev indicates a core dump from an older kernel and use the | |
1288 | value in 'ki_tdev_freebsd11' instead. */ | |
1289 | value = bfd_get_64 (core_bfd, descdata + kp->ki_tdev); | |
1290 | if (value == 0) | |
1291 | value = bfd_get_32 (core_bfd, descdata + kp->ki_tdev_freebsd11); | |
1292 | printf_filtered ("TTY: %s\n", pulongest (value)); | |
1293 | printf_filtered ("TTY owner process group: %s\n", | |
1294 | pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_tpgid))); | |
1295 | printf_filtered ("User IDs (real, effective, saved): %s %s %s\n", | |
1296 | pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_ruid)), | |
1297 | pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_uid)), | |
1298 | pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_svuid))); | |
1299 | printf_filtered ("Group IDs (real, effective, saved): %s %s %s\n", | |
1300 | pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_rgid)), | |
1301 | pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_groups)), | |
1302 | pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_svgid))); | |
1303 | printf_filtered ("Groups: "); | |
1304 | uint16_t ngroups = bfd_get_16 (core_bfd, descdata + kp->ki_ngroups); | |
1305 | for (int i = 0; i < ngroups; i++) | |
1306 | printf_filtered ("%s ", | |
1307 | pulongest (bfd_get_32 (core_bfd, | |
1308 | descdata + kp->ki_groups + i * 4))); | |
1309 | printf_filtered ("\n"); | |
1310 | value = bfd_get (long_bit, core_bfd, | |
1311 | descdata + kp->ki_rusage + kp->ru_minflt); | |
1312 | printf_filtered ("Minor faults (no memory page): %s\n", pulongest (value)); | |
1313 | value = bfd_get (long_bit, core_bfd, | |
1314 | descdata + kp->ki_rusage_ch + kp->ru_minflt); | |
1315 | printf_filtered ("Minor faults, children: %s\n", pulongest (value)); | |
1316 | value = bfd_get (long_bit, core_bfd, | |
1317 | descdata + kp->ki_rusage + kp->ru_majflt); | |
1318 | printf_filtered ("Major faults (memory page faults): %s\n", | |
1319 | pulongest (value)); | |
1320 | value = bfd_get (long_bit, core_bfd, | |
1321 | descdata + kp->ki_rusage_ch + kp->ru_majflt); | |
1322 | printf_filtered ("Major faults, children: %s\n", pulongest (value)); | |
1323 | fbsd_core_fetch_timeval (gdbarch, | |
1324 | descdata + kp->ki_rusage + kp->ru_utime, | |
1325 | sec, value); | |
1326 | printf_filtered ("utime: %s.%06d\n", plongest (sec), (int) value); | |
1327 | fbsd_core_fetch_timeval (gdbarch, | |
1328 | descdata + kp->ki_rusage + kp->ru_stime, | |
1329 | sec, value); | |
1330 | printf_filtered ("stime: %s.%06d\n", plongest (sec), (int) value); | |
1331 | fbsd_core_fetch_timeval (gdbarch, | |
1332 | descdata + kp->ki_rusage_ch + kp->ru_utime, | |
1333 | sec, value); | |
1334 | printf_filtered ("utime, children: %s.%06d\n", plongest (sec), (int) value); | |
1335 | fbsd_core_fetch_timeval (gdbarch, | |
1336 | descdata + kp->ki_rusage_ch + kp->ru_stime, | |
1337 | sec, value); | |
1338 | printf_filtered ("stime, children: %s.%06d\n", plongest (sec), (int) value); | |
1339 | printf_filtered ("'nice' value: %d\n", | |
aac4760f | 1340 | (int) bfd_get_signed_8 (core_bfd, descdata + kp->ki_nice)); |
d2176225 JB |
1341 | fbsd_core_fetch_timeval (gdbarch, descdata + kp->ki_start, sec, value); |
1342 | printf_filtered ("Start time: %s.%06d\n", plongest (sec), (int) value); | |
1343 | printf_filtered ("Virtual memory size: %s kB\n", | |
1344 | pulongest (bfd_get (addr_bit, core_bfd, | |
1345 | descdata + kp->ki_size) / 1024)); | |
1346 | printf_filtered ("Data size: %s pages\n", | |
1347 | pulongest (bfd_get (addr_bit, core_bfd, | |
1348 | descdata + kp->ki_dsize))); | |
1349 | printf_filtered ("Stack size: %s pages\n", | |
1350 | pulongest (bfd_get (addr_bit, core_bfd, | |
1351 | descdata + kp->ki_ssize))); | |
1352 | printf_filtered ("Text size: %s pages\n", | |
1353 | pulongest (bfd_get (addr_bit, core_bfd, | |
1354 | descdata + kp->ki_tsize))); | |
1355 | printf_filtered ("Resident set size: %s pages\n", | |
1356 | pulongest (bfd_get (addr_bit, core_bfd, | |
1357 | descdata + kp->ki_rssize))); | |
1358 | printf_filtered ("Maximum RSS: %s pages\n", | |
1359 | pulongest (bfd_get (long_bit, core_bfd, | |
1360 | descdata + kp->ki_rusage | |
1361 | + kp->ru_maxrss))); | |
1362 | fbsd_print_sigset ("Ignored Signals", descdata + kp->ki_sigignore); | |
1363 | fbsd_print_sigset ("Caught Signals", descdata + kp->ki_sigcatch); | |
1364 | } | |
1365 | ||
1366 | /* Implement the "core_info_proc" gdbarch method. */ | |
1367 | ||
1368 | static void | |
1369 | fbsd_core_info_proc (struct gdbarch *gdbarch, const char *args, | |
1370 | enum info_proc_what what) | |
1371 | { | |
1372 | bool do_cmdline = false; | |
1373 | bool do_cwd = false; | |
1374 | bool do_exe = false; | |
57c2a98a | 1375 | bool do_files = false; |
d2176225 JB |
1376 | bool do_mappings = false; |
1377 | bool do_status = false; | |
1378 | int pid; | |
1379 | ||
1380 | switch (what) | |
1381 | { | |
1382 | case IP_MINIMAL: | |
1383 | do_cmdline = true; | |
1384 | do_cwd = true; | |
1385 | do_exe = true; | |
1386 | break; | |
1387 | case IP_MAPPINGS: | |
1388 | do_mappings = true; | |
1389 | break; | |
1390 | case IP_STATUS: | |
1391 | case IP_STAT: | |
1392 | do_status = true; | |
1393 | break; | |
1394 | case IP_CMDLINE: | |
1395 | do_cmdline = true; | |
1396 | break; | |
1397 | case IP_EXE: | |
1398 | do_exe = true; | |
1399 | break; | |
1400 | case IP_CWD: | |
1401 | do_cwd = true; | |
1402 | break; | |
57c2a98a JB |
1403 | case IP_FILES: |
1404 | do_files = true; | |
1405 | break; | |
d2176225 JB |
1406 | case IP_ALL: |
1407 | do_cmdline = true; | |
1408 | do_cwd = true; | |
1409 | do_exe = true; | |
57c2a98a | 1410 | do_files = true; |
d2176225 JB |
1411 | do_mappings = true; |
1412 | do_status = true; | |
1413 | break; | |
1414 | default: | |
1415 | return; | |
1416 | } | |
1417 | ||
1418 | pid = bfd_core_file_pid (core_bfd); | |
1419 | if (pid != 0) | |
1420 | printf_filtered (_("process %d\n"), pid); | |
1421 | ||
1422 | if (do_cmdline) | |
1423 | { | |
1424 | const char *cmdline; | |
1425 | ||
1426 | cmdline = bfd_core_file_failing_command (core_bfd); | |
1427 | if (cmdline) | |
1428 | printf_filtered ("cmdline = '%s'\n", cmdline); | |
1429 | else | |
1430 | warning (_("Command line unavailable")); | |
1431 | } | |
1432 | if (do_cwd) | |
1433 | { | |
1434 | gdb::unique_xmalloc_ptr<char> cwd = | |
1435 | fbsd_core_vnode_path (gdbarch, KINFO_FILE_FD_TYPE_CWD); | |
1436 | if (cwd) | |
1437 | printf_filtered ("cwd = '%s'\n", cwd.get ()); | |
1438 | else | |
1439 | warning (_("unable to read current working directory")); | |
1440 | } | |
1441 | if (do_exe) | |
1442 | { | |
1443 | gdb::unique_xmalloc_ptr<char> exe = | |
1444 | fbsd_core_vnode_path (gdbarch, KINFO_FILE_FD_TYPE_TEXT); | |
1445 | if (exe) | |
1446 | printf_filtered ("exe = '%s'\n", exe.get ()); | |
1447 | else | |
1448 | warning (_("unable to read executable path name")); | |
1449 | } | |
57c2a98a JB |
1450 | if (do_files) |
1451 | fbsd_core_info_proc_files (gdbarch); | |
d2176225 JB |
1452 | if (do_mappings) |
1453 | fbsd_core_info_proc_mappings (gdbarch); | |
1454 | if (do_status) | |
1455 | fbsd_core_info_proc_status (gdbarch); | |
1456 | } | |
1457 | ||
82372b2f JB |
1458 | /* Print descriptions of FreeBSD-specific AUXV entries to FILE. */ |
1459 | ||
1460 | static void | |
1461 | fbsd_print_auxv_entry (struct gdbarch *gdbarch, struct ui_file *file, | |
1462 | CORE_ADDR type, CORE_ADDR val) | |
1463 | { | |
fd2b4de5 JB |
1464 | const char *name = "???"; |
1465 | const char *description = ""; | |
1466 | enum auxv_format format = AUXV_FORMAT_HEX; | |
82372b2f JB |
1467 | |
1468 | switch (type) | |
1469 | { | |
fd2b4de5 JB |
1470 | case AT_NULL: |
1471 | case AT_IGNORE: | |
1472 | case AT_EXECFD: | |
1473 | case AT_PHDR: | |
1474 | case AT_PHENT: | |
1475 | case AT_PHNUM: | |
1476 | case AT_PAGESZ: | |
1477 | case AT_BASE: | |
1478 | case AT_FLAGS: | |
1479 | case AT_ENTRY: | |
1480 | case AT_NOTELF: | |
1481 | case AT_UID: | |
1482 | case AT_EUID: | |
1483 | case AT_GID: | |
1484 | case AT_EGID: | |
1485 | default_print_auxv_entry (gdbarch, file, type, val); | |
1486 | return; | |
82372b2f JB |
1487 | #define _TAGNAME(tag) #tag |
1488 | #define TAGNAME(tag) _TAGNAME(AT_##tag) | |
1489 | #define TAG(tag, text, kind) \ | |
1490 | case AT_FREEBSD_##tag: name = TAGNAME(tag); description = text; format = kind; break | |
1491 | TAG (EXECPATH, _("Executable path"), AUXV_FORMAT_STR); | |
1492 | TAG (CANARY, _("Canary for SSP"), AUXV_FORMAT_HEX); | |
1493 | TAG (CANARYLEN, ("Length of the SSP canary"), AUXV_FORMAT_DEC); | |
1494 | TAG (OSRELDATE, _("OSRELDATE"), AUXV_FORMAT_DEC); | |
1495 | TAG (NCPUS, _("Number of CPUs"), AUXV_FORMAT_DEC); | |
1496 | TAG (PAGESIZES, _("Pagesizes"), AUXV_FORMAT_HEX); | |
1497 | TAG (PAGESIZESLEN, _("Number of pagesizes"), AUXV_FORMAT_DEC); | |
1498 | TAG (TIMEKEEP, _("Pointer to timehands"), AUXV_FORMAT_HEX); | |
1499 | TAG (STACKPROT, _("Initial stack protection"), AUXV_FORMAT_HEX); | |
12c4bd7f JB |
1500 | TAG (EHDRFLAGS, _("ELF header e_flags"), AUXV_FORMAT_HEX); |
1501 | TAG (HWCAP, _("Machine-dependent CPU capability hints"), AUXV_FORMAT_HEX); | |
d7ded98f | 1502 | TAG (HWCAP2, _("Extension of AT_HWCAP"), AUXV_FORMAT_HEX); |
a879b4d5 | 1503 | TAG (BSDFLAGS, _("ELF BSD flags"), AUXV_FORMAT_HEX); |
fc238d4a JB |
1504 | TAG (ARGC, _("Argument count"), AUXV_FORMAT_DEC); |
1505 | TAG (ARGV, _("Argument vector"), AUXV_FORMAT_HEX); | |
1506 | TAG (ENVC, _("Environment count"), AUXV_FORMAT_DEC); | |
1507 | TAG (ENVV, _("Environment vector"), AUXV_FORMAT_HEX); | |
1508 | TAG (PS_STRINGS, _("Pointer to ps_strings"), AUXV_FORMAT_HEX); | |
82372b2f JB |
1509 | } |
1510 | ||
1511 | fprint_auxv_entry (file, name, description, format, type, val); | |
1512 | } | |
1513 | ||
762c974a JB |
1514 | /* Implement the "get_siginfo_type" gdbarch method. */ |
1515 | ||
1516 | static struct type * | |
1517 | fbsd_get_siginfo_type (struct gdbarch *gdbarch) | |
1518 | { | |
1519 | struct fbsd_gdbarch_data *fbsd_gdbarch_data; | |
1520 | struct type *int_type, *int32_type, *uint32_type, *long_type, *void_ptr_type; | |
1521 | struct type *uid_type, *pid_type; | |
1522 | struct type *sigval_type, *reason_type; | |
1523 | struct type *siginfo_type; | |
1524 | struct type *type; | |
1525 | ||
1526 | fbsd_gdbarch_data = get_fbsd_gdbarch_data (gdbarch); | |
1527 | if (fbsd_gdbarch_data->siginfo_type != NULL) | |
1528 | return fbsd_gdbarch_data->siginfo_type; | |
1529 | ||
1530 | int_type = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch), | |
1531 | 0, "int"); | |
1532 | int32_type = arch_integer_type (gdbarch, 32, 0, "int32_t"); | |
1533 | uint32_type = arch_integer_type (gdbarch, 32, 1, "uint32_t"); | |
1534 | long_type = arch_integer_type (gdbarch, gdbarch_long_bit (gdbarch), | |
1535 | 0, "long"); | |
1536 | void_ptr_type = lookup_pointer_type (builtin_type (gdbarch)->builtin_void); | |
1537 | ||
1538 | /* union sigval */ | |
1539 | sigval_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_UNION); | |
d0e39ea2 | 1540 | sigval_type->set_name (xstrdup ("sigval")); |
762c974a JB |
1541 | append_composite_type_field (sigval_type, "sival_int", int_type); |
1542 | append_composite_type_field (sigval_type, "sival_ptr", void_ptr_type); | |
1543 | ||
1544 | /* __pid_t */ | |
1545 | pid_type = arch_type (gdbarch, TYPE_CODE_TYPEDEF, | |
77b7c781 | 1546 | TYPE_LENGTH (int32_type) * TARGET_CHAR_BIT, "__pid_t"); |
762c974a | 1547 | TYPE_TARGET_TYPE (pid_type) = int32_type; |
8f53807e | 1548 | pid_type->set_target_is_stub (true); |
762c974a JB |
1549 | |
1550 | /* __uid_t */ | |
1551 | uid_type = arch_type (gdbarch, TYPE_CODE_TYPEDEF, | |
77b7c781 UW |
1552 | TYPE_LENGTH (uint32_type) * TARGET_CHAR_BIT, |
1553 | "__uid_t"); | |
762c974a | 1554 | TYPE_TARGET_TYPE (uid_type) = uint32_type; |
8f53807e | 1555 | pid_type->set_target_is_stub (true); |
762c974a JB |
1556 | |
1557 | /* _reason */ | |
1558 | reason_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_UNION); | |
1559 | ||
1560 | /* _fault */ | |
1561 | type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT); | |
1562 | append_composite_type_field (type, "si_trapno", int_type); | |
1563 | append_composite_type_field (reason_type, "_fault", type); | |
1564 | ||
1565 | /* _timer */ | |
1566 | type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT); | |
1567 | append_composite_type_field (type, "si_timerid", int_type); | |
1568 | append_composite_type_field (type, "si_overrun", int_type); | |
1569 | append_composite_type_field (reason_type, "_timer", type); | |
1570 | ||
1571 | /* _mesgq */ | |
1572 | type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT); | |
1573 | append_composite_type_field (type, "si_mqd", int_type); | |
1574 | append_composite_type_field (reason_type, "_mesgq", type); | |
1575 | ||
1576 | /* _poll */ | |
1577 | type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT); | |
1578 | append_composite_type_field (type, "si_band", long_type); | |
1579 | append_composite_type_field (reason_type, "_poll", type); | |
1580 | ||
1581 | /* __spare__ */ | |
1582 | type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT); | |
1583 | append_composite_type_field (type, "__spare1__", long_type); | |
1584 | append_composite_type_field (type, "__spare2__", | |
1585 | init_vector_type (int_type, 7)); | |
1586 | append_composite_type_field (reason_type, "__spare__", type); | |
1587 | ||
1588 | /* struct siginfo */ | |
1589 | siginfo_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT); | |
d0e39ea2 | 1590 | siginfo_type->set_name (xstrdup ("siginfo")); |
762c974a JB |
1591 | append_composite_type_field (siginfo_type, "si_signo", int_type); |
1592 | append_composite_type_field (siginfo_type, "si_errno", int_type); | |
1593 | append_composite_type_field (siginfo_type, "si_code", int_type); | |
1594 | append_composite_type_field (siginfo_type, "si_pid", pid_type); | |
1595 | append_composite_type_field (siginfo_type, "si_uid", uid_type); | |
1596 | append_composite_type_field (siginfo_type, "si_status", int_type); | |
1597 | append_composite_type_field (siginfo_type, "si_addr", void_ptr_type); | |
1598 | append_composite_type_field (siginfo_type, "si_value", sigval_type); | |
1599 | append_composite_type_field (siginfo_type, "_reason", reason_type); | |
1600 | ||
1601 | fbsd_gdbarch_data->siginfo_type = siginfo_type; | |
1602 | ||
1603 | return siginfo_type; | |
1604 | } | |
1605 | ||
e61667ef RS |
1606 | /* Implement the "gdb_signal_from_target" gdbarch method. */ |
1607 | ||
1608 | static enum gdb_signal | |
1609 | fbsd_gdb_signal_from_target (struct gdbarch *gdbarch, int signal) | |
1610 | { | |
1611 | switch (signal) | |
1612 | { | |
1613 | case 0: | |
1614 | return GDB_SIGNAL_0; | |
1615 | ||
1616 | case FREEBSD_SIGHUP: | |
1617 | return GDB_SIGNAL_HUP; | |
1618 | ||
1619 | case FREEBSD_SIGINT: | |
1620 | return GDB_SIGNAL_INT; | |
1621 | ||
1622 | case FREEBSD_SIGQUIT: | |
1623 | return GDB_SIGNAL_QUIT; | |
1624 | ||
1625 | case FREEBSD_SIGILL: | |
1626 | return GDB_SIGNAL_ILL; | |
1627 | ||
1628 | case FREEBSD_SIGTRAP: | |
1629 | return GDB_SIGNAL_TRAP; | |
1630 | ||
1631 | case FREEBSD_SIGABRT: | |
1632 | return GDB_SIGNAL_ABRT; | |
1633 | ||
1634 | case FREEBSD_SIGEMT: | |
1635 | return GDB_SIGNAL_EMT; | |
1636 | ||
1637 | case FREEBSD_SIGFPE: | |
1638 | return GDB_SIGNAL_FPE; | |
1639 | ||
1640 | case FREEBSD_SIGKILL: | |
1641 | return GDB_SIGNAL_KILL; | |
1642 | ||
1643 | case FREEBSD_SIGBUS: | |
1644 | return GDB_SIGNAL_BUS; | |
1645 | ||
1646 | case FREEBSD_SIGSEGV: | |
1647 | return GDB_SIGNAL_SEGV; | |
1648 | ||
1649 | case FREEBSD_SIGSYS: | |
1650 | return GDB_SIGNAL_SYS; | |
1651 | ||
1652 | case FREEBSD_SIGPIPE: | |
1653 | return GDB_SIGNAL_PIPE; | |
1654 | ||
1655 | case FREEBSD_SIGALRM: | |
1656 | return GDB_SIGNAL_ALRM; | |
1657 | ||
1658 | case FREEBSD_SIGTERM: | |
1659 | return GDB_SIGNAL_TERM; | |
1660 | ||
1661 | case FREEBSD_SIGURG: | |
1662 | return GDB_SIGNAL_URG; | |
1663 | ||
1664 | case FREEBSD_SIGSTOP: | |
1665 | return GDB_SIGNAL_STOP; | |
1666 | ||
1667 | case FREEBSD_SIGTSTP: | |
1668 | return GDB_SIGNAL_TSTP; | |
1669 | ||
1670 | case FREEBSD_SIGCONT: | |
1671 | return GDB_SIGNAL_CONT; | |
1672 | ||
1673 | case FREEBSD_SIGCHLD: | |
1674 | return GDB_SIGNAL_CHLD; | |
1675 | ||
1676 | case FREEBSD_SIGTTIN: | |
1677 | return GDB_SIGNAL_TTIN; | |
1678 | ||
1679 | case FREEBSD_SIGTTOU: | |
1680 | return GDB_SIGNAL_TTOU; | |
1681 | ||
1682 | case FREEBSD_SIGIO: | |
1683 | return GDB_SIGNAL_IO; | |
1684 | ||
1685 | case FREEBSD_SIGXCPU: | |
1686 | return GDB_SIGNAL_XCPU; | |
1687 | ||
1688 | case FREEBSD_SIGXFSZ: | |
1689 | return GDB_SIGNAL_XFSZ; | |
1690 | ||
1691 | case FREEBSD_SIGVTALRM: | |
1692 | return GDB_SIGNAL_VTALRM; | |
1693 | ||
1694 | case FREEBSD_SIGPROF: | |
1695 | return GDB_SIGNAL_PROF; | |
1696 | ||
1697 | case FREEBSD_SIGWINCH: | |
1698 | return GDB_SIGNAL_WINCH; | |
1699 | ||
1700 | case FREEBSD_SIGINFO: | |
1701 | return GDB_SIGNAL_INFO; | |
1702 | ||
1703 | case FREEBSD_SIGUSR1: | |
1704 | return GDB_SIGNAL_USR1; | |
1705 | ||
1706 | case FREEBSD_SIGUSR2: | |
1707 | return GDB_SIGNAL_USR2; | |
1708 | ||
1709 | /* SIGTHR is the same as SIGLWP on FreeBSD. */ | |
1710 | case FREEBSD_SIGTHR: | |
1711 | return GDB_SIGNAL_LWP; | |
1712 | ||
1713 | case FREEBSD_SIGLIBRT: | |
1714 | return GDB_SIGNAL_LIBRT; | |
1715 | } | |
1716 | ||
1717 | if (signal >= FREEBSD_SIGRTMIN && signal <= FREEBSD_SIGRTMAX) | |
1718 | { | |
1719 | int offset = signal - FREEBSD_SIGRTMIN; | |
1720 | ||
1721 | return (enum gdb_signal) ((int) GDB_SIGNAL_REALTIME_65 + offset); | |
1722 | } | |
1723 | ||
1724 | return GDB_SIGNAL_UNKNOWN; | |
1725 | } | |
1726 | ||
1727 | /* Implement the "gdb_signal_to_target" gdbarch method. */ | |
1728 | ||
1729 | static int | |
1730 | fbsd_gdb_signal_to_target (struct gdbarch *gdbarch, | |
dda83cd7 | 1731 | enum gdb_signal signal) |
e61667ef RS |
1732 | { |
1733 | switch (signal) | |
1734 | { | |
1735 | case GDB_SIGNAL_0: | |
1736 | return 0; | |
1737 | ||
1738 | case GDB_SIGNAL_HUP: | |
1739 | return FREEBSD_SIGHUP; | |
1740 | ||
1741 | case GDB_SIGNAL_INT: | |
1742 | return FREEBSD_SIGINT; | |
1743 | ||
1744 | case GDB_SIGNAL_QUIT: | |
1745 | return FREEBSD_SIGQUIT; | |
1746 | ||
1747 | case GDB_SIGNAL_ILL: | |
1748 | return FREEBSD_SIGILL; | |
1749 | ||
1750 | case GDB_SIGNAL_TRAP: | |
1751 | return FREEBSD_SIGTRAP; | |
1752 | ||
1753 | case GDB_SIGNAL_ABRT: | |
1754 | return FREEBSD_SIGABRT; | |
1755 | ||
1756 | case GDB_SIGNAL_EMT: | |
1757 | return FREEBSD_SIGEMT; | |
1758 | ||
1759 | case GDB_SIGNAL_FPE: | |
1760 | return FREEBSD_SIGFPE; | |
1761 | ||
1762 | case GDB_SIGNAL_KILL: | |
1763 | return FREEBSD_SIGKILL; | |
1764 | ||
1765 | case GDB_SIGNAL_BUS: | |
1766 | return FREEBSD_SIGBUS; | |
1767 | ||
1768 | case GDB_SIGNAL_SEGV: | |
1769 | return FREEBSD_SIGSEGV; | |
1770 | ||
1771 | case GDB_SIGNAL_SYS: | |
1772 | return FREEBSD_SIGSYS; | |
1773 | ||
1774 | case GDB_SIGNAL_PIPE: | |
1775 | return FREEBSD_SIGPIPE; | |
1776 | ||
1777 | case GDB_SIGNAL_ALRM: | |
1778 | return FREEBSD_SIGALRM; | |
1779 | ||
1780 | case GDB_SIGNAL_TERM: | |
1781 | return FREEBSD_SIGTERM; | |
1782 | ||
1783 | case GDB_SIGNAL_URG: | |
1784 | return FREEBSD_SIGURG; | |
1785 | ||
1786 | case GDB_SIGNAL_STOP: | |
1787 | return FREEBSD_SIGSTOP; | |
1788 | ||
1789 | case GDB_SIGNAL_TSTP: | |
1790 | return FREEBSD_SIGTSTP; | |
1791 | ||
1792 | case GDB_SIGNAL_CONT: | |
1793 | return FREEBSD_SIGCONT; | |
1794 | ||
1795 | case GDB_SIGNAL_CHLD: | |
1796 | return FREEBSD_SIGCHLD; | |
1797 | ||
1798 | case GDB_SIGNAL_TTIN: | |
1799 | return FREEBSD_SIGTTIN; | |
1800 | ||
1801 | case GDB_SIGNAL_TTOU: | |
1802 | return FREEBSD_SIGTTOU; | |
1803 | ||
1804 | case GDB_SIGNAL_IO: | |
1805 | return FREEBSD_SIGIO; | |
1806 | ||
1807 | case GDB_SIGNAL_XCPU: | |
1808 | return FREEBSD_SIGXCPU; | |
1809 | ||
1810 | case GDB_SIGNAL_XFSZ: | |
1811 | return FREEBSD_SIGXFSZ; | |
1812 | ||
1813 | case GDB_SIGNAL_VTALRM: | |
1814 | return FREEBSD_SIGVTALRM; | |
1815 | ||
1816 | case GDB_SIGNAL_PROF: | |
1817 | return FREEBSD_SIGPROF; | |
1818 | ||
1819 | case GDB_SIGNAL_WINCH: | |
1820 | return FREEBSD_SIGWINCH; | |
1821 | ||
1822 | case GDB_SIGNAL_INFO: | |
1823 | return FREEBSD_SIGINFO; | |
1824 | ||
1825 | case GDB_SIGNAL_USR1: | |
1826 | return FREEBSD_SIGUSR1; | |
1827 | ||
1828 | case GDB_SIGNAL_USR2: | |
1829 | return FREEBSD_SIGUSR2; | |
1830 | ||
1831 | case GDB_SIGNAL_LWP: | |
1832 | return FREEBSD_SIGTHR; | |
1833 | ||
1834 | case GDB_SIGNAL_LIBRT: | |
1835 | return FREEBSD_SIGLIBRT; | |
1836 | } | |
1837 | ||
1838 | if (signal >= GDB_SIGNAL_REALTIME_65 | |
1839 | && signal <= GDB_SIGNAL_REALTIME_126) | |
1840 | { | |
1841 | int offset = signal - GDB_SIGNAL_REALTIME_65; | |
1842 | ||
1843 | return FREEBSD_SIGRTMIN + offset; | |
1844 | } | |
1845 | ||
1846 | return -1; | |
1847 | } | |
1848 | ||
e6cdd38e JB |
1849 | /* Implement the "get_syscall_number" gdbarch method. */ |
1850 | ||
1851 | static LONGEST | |
00431a78 | 1852 | fbsd_get_syscall_number (struct gdbarch *gdbarch, thread_info *thread) |
e6cdd38e JB |
1853 | { |
1854 | ||
1855 | /* FreeBSD doesn't use gdbarch_get_syscall_number since FreeBSD | |
1856 | native targets fetch the system call number from the | |
1857 | 'pl_syscall_code' member of struct ptrace_lwpinfo in fbsd_wait. | |
1858 | However, system call catching requires this function to be | |
1859 | set. */ | |
1860 | ||
1861 | internal_error (__FILE__, __LINE__, _("fbsd_get_sycall_number called")); | |
1862 | } | |
1863 | ||
945f3901 JB |
1864 | /* Read an integer symbol value from the current target. */ |
1865 | ||
1866 | static LONGEST | |
1867 | fbsd_read_integer_by_name (struct gdbarch *gdbarch, const char *name) | |
1868 | { | |
1869 | bound_minimal_symbol ms = lookup_minimal_symbol (name, NULL, NULL); | |
1870 | if (ms.minsym == NULL) | |
1871 | error (_("Unable to resolve symbol '%s'"), name); | |
1872 | ||
1873 | gdb_byte buf[4]; | |
1874 | if (target_read_memory (BMSYMBOL_VALUE_ADDRESS (ms), buf, sizeof buf) != 0) | |
1875 | error (_("Unable to read value of '%s'"), name); | |
1876 | ||
1877 | return extract_signed_integer (buf, sizeof buf, gdbarch_byte_order (gdbarch)); | |
1878 | } | |
1879 | ||
1880 | /* Lookup offsets of fields in the runtime linker's 'Obj_Entry' | |
1881 | structure needed to determine the TLS index of an object file. */ | |
1882 | ||
1883 | static void | |
1884 | fbsd_fetch_rtld_offsets (struct gdbarch *gdbarch, struct fbsd_pspace_data *data) | |
1885 | { | |
a70b8144 | 1886 | try |
945f3901 JB |
1887 | { |
1888 | /* Fetch offsets from debug symbols in rtld. */ | |
1889 | struct symbol *obj_entry_sym | |
1890 | = lookup_symbol_in_language ("Struct_Obj_Entry", NULL, STRUCT_DOMAIN, | |
1891 | language_c, NULL).symbol; | |
1892 | if (obj_entry_sym == NULL) | |
1893 | error (_("Unable to find Struct_Obj_Entry symbol")); | |
78134374 | 1894 | data->off_linkmap = lookup_struct_elt (SYMBOL_TYPE (obj_entry_sym), |
945f3901 | 1895 | "linkmap", 0).offset / 8; |
78134374 | 1896 | data->off_tlsindex = lookup_struct_elt (SYMBOL_TYPE (obj_entry_sym), |
945f3901 JB |
1897 | "tlsindex", 0).offset / 8; |
1898 | data->rtld_offsets_valid = true; | |
1899 | return; | |
1900 | } | |
230d2906 | 1901 | catch (const gdb_exception_error &e) |
945f3901 JB |
1902 | { |
1903 | data->off_linkmap = -1; | |
1904 | } | |
945f3901 | 1905 | |
a70b8144 | 1906 | try |
945f3901 JB |
1907 | { |
1908 | /* Fetch offsets from global variables in libthr. Note that | |
1909 | this does not work for single-threaded processes that are not | |
1910 | linked against libthr. */ | |
1911 | data->off_linkmap = fbsd_read_integer_by_name (gdbarch, | |
1912 | "_thread_off_linkmap"); | |
1913 | data->off_tlsindex = fbsd_read_integer_by_name (gdbarch, | |
1914 | "_thread_off_tlsindex"); | |
1915 | data->rtld_offsets_valid = true; | |
1916 | return; | |
1917 | } | |
230d2906 | 1918 | catch (const gdb_exception_error &e) |
945f3901 JB |
1919 | { |
1920 | data->off_linkmap = -1; | |
1921 | } | |
945f3901 JB |
1922 | } |
1923 | ||
1924 | /* Helper function to read the TLS index of an object file associated | |
1925 | with a link map entry at LM_ADDR. */ | |
1926 | ||
1927 | static LONGEST | |
1928 | fbsd_get_tls_index (struct gdbarch *gdbarch, CORE_ADDR lm_addr) | |
1929 | { | |
1930 | struct fbsd_pspace_data *data = get_fbsd_pspace_data (current_program_space); | |
1931 | ||
1932 | if (!data->rtld_offsets_valid) | |
1933 | fbsd_fetch_rtld_offsets (gdbarch, data); | |
1934 | ||
1935 | if (data->off_linkmap == -1) | |
1936 | throw_error (TLS_GENERIC_ERROR, | |
1937 | _("Cannot fetch runtime linker structure offsets")); | |
1938 | ||
1939 | /* Simulate container_of to convert from LM_ADDR to the Obj_Entry | |
1940 | pointer and then compute the offset of the tlsindex member. */ | |
1941 | CORE_ADDR tlsindex_addr = lm_addr - data->off_linkmap + data->off_tlsindex; | |
1942 | ||
1943 | gdb_byte buf[4]; | |
1944 | if (target_read_memory (tlsindex_addr, buf, sizeof buf) != 0) | |
1945 | throw_error (TLS_GENERIC_ERROR, | |
1946 | _("Cannot find thread-local variables on this target")); | |
1947 | ||
1948 | return extract_signed_integer (buf, sizeof buf, gdbarch_byte_order (gdbarch)); | |
1949 | } | |
1950 | ||
1951 | /* See fbsd-tdep.h. */ | |
1952 | ||
1953 | CORE_ADDR | |
1954 | fbsd_get_thread_local_address (struct gdbarch *gdbarch, CORE_ADDR dtv_addr, | |
1955 | CORE_ADDR lm_addr, CORE_ADDR offset) | |
1956 | { | |
1957 | LONGEST tls_index = fbsd_get_tls_index (gdbarch, lm_addr); | |
1958 | ||
1959 | gdb_byte buf[gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT]; | |
1960 | if (target_read_memory (dtv_addr, buf, sizeof buf) != 0) | |
1961 | throw_error (TLS_GENERIC_ERROR, | |
1962 | _("Cannot find thread-local variables on this target")); | |
1963 | ||
1964 | const struct builtin_type *builtin = builtin_type (gdbarch); | |
1965 | CORE_ADDR addr = gdbarch_pointer_to_address (gdbarch, | |
1966 | builtin->builtin_data_ptr, buf); | |
1967 | ||
1968 | addr += (tls_index + 1) * TYPE_LENGTH (builtin->builtin_data_ptr); | |
1969 | if (target_read_memory (addr, buf, sizeof buf) != 0) | |
1970 | throw_error (TLS_GENERIC_ERROR, | |
1971 | _("Cannot find thread-local variables on this target")); | |
1972 | ||
1973 | addr = gdbarch_pointer_to_address (gdbarch, builtin->builtin_data_ptr, buf); | |
1974 | return addr + offset; | |
1975 | } | |
1976 | ||
ed810cc7 JB |
1977 | /* See fbsd-tdep.h. */ |
1978 | ||
1979 | CORE_ADDR | |
1980 | fbsd_skip_solib_resolver (struct gdbarch *gdbarch, CORE_ADDR pc) | |
1981 | { | |
1982 | struct bound_minimal_symbol msym = lookup_bound_minimal_symbol ("_rtld_bind"); | |
1983 | if (msym.minsym != nullptr && BMSYMBOL_VALUE_ADDRESS (msym) == pc) | |
1984 | return frame_unwind_caller_pc (get_current_frame ()); | |
1985 | ||
1986 | return 0; | |
1987 | } | |
1988 | ||
1736a7bd | 1989 | /* To be called from GDB_OSABI_FREEBSD handlers. */ |
a904c024 AA |
1990 | |
1991 | void | |
1992 | fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) | |
1993 | { | |
79117428 JB |
1994 | set_gdbarch_core_pid_to_str (gdbarch, fbsd_core_pid_to_str); |
1995 | set_gdbarch_core_thread_name (gdbarch, fbsd_core_thread_name); | |
4b654465 | 1996 | set_gdbarch_core_xfer_siginfo (gdbarch, fbsd_core_xfer_siginfo); |
a904c024 | 1997 | set_gdbarch_make_corefile_notes (gdbarch, fbsd_make_corefile_notes); |
d2176225 | 1998 | set_gdbarch_core_info_proc (gdbarch, fbsd_core_info_proc); |
82372b2f | 1999 | set_gdbarch_print_auxv_entry (gdbarch, fbsd_print_auxv_entry); |
762c974a | 2000 | set_gdbarch_get_siginfo_type (gdbarch, fbsd_get_siginfo_type); |
e61667ef RS |
2001 | set_gdbarch_gdb_signal_from_target (gdbarch, fbsd_gdb_signal_from_target); |
2002 | set_gdbarch_gdb_signal_to_target (gdbarch, fbsd_gdb_signal_to_target); | |
ed810cc7 | 2003 | set_gdbarch_skip_solib_resolver (gdbarch, fbsd_skip_solib_resolver); |
e6cdd38e JB |
2004 | |
2005 | /* `catch syscall' */ | |
2006 | set_xml_syscall_file_name (gdbarch, "syscalls/freebsd.xml"); | |
2007 | set_gdbarch_get_syscall_number (gdbarch, fbsd_get_syscall_number); | |
a904c024 | 2008 | } |
762c974a | 2009 | |
6c265988 | 2010 | void _initialize_fbsd_tdep (); |
762c974a | 2011 | void |
6c265988 | 2012 | _initialize_fbsd_tdep () |
762c974a JB |
2013 | { |
2014 | fbsd_gdbarch_data_handle = | |
2015 | gdbarch_data_register_post_init (init_fbsd_gdbarch_data); | |
2016 | } |