GDB (xrefs)
Loading...
Searching...
No Matches
fbsd-tdep.c
Go to the documentation of this file.
1/* Target-dependent code for FreeBSD, architecture-independent.
2
3 Copyright (C) 2002-2023 Free Software Foundation, Inc.
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 "auxv.h"
22#include "gdbcore.h"
23#include "inferior.h"
24#include "objfiles.h"
25#include "regcache.h"
26#include "regset.h"
27#include "gdbthread.h"
28#include "objfiles.h"
29#include "xml-syscall.h"
30#include <sys/socket.h>
31#include <arpa/inet.h>
32
33#include "elf-bfd.h"
34#include "fbsd-tdep.h"
35#include "gcore-elf.h"
36
37/* This enum is derived from FreeBSD's <sys/signal.h>. */
38
39enum
40 {
76 };
77
78/* Constants for values of si_code as defined in FreeBSD's
79 <sys/signal.h>. */
80
81#define FBSD_SI_USER 0x10001
82#define FBSD_SI_QUEUE 0x10002
83#define FBSD_SI_TIMER 0x10003
84#define FBSD_SI_ASYNCIO 0x10004
85#define FBSD_SI_MESGQ 0x10005
86#define FBSD_SI_KERNEL 0x10006
87#define FBSD_SI_LWP 0x10007
88
89#define FBSD_ILL_ILLOPC 1
90#define FBSD_ILL_ILLOPN 2
91#define FBSD_ILL_ILLADR 3
92#define FBSD_ILL_ILLTRP 4
93#define FBSD_ILL_PRVOPC 5
94#define FBSD_ILL_PRVREG 6
95#define FBSD_ILL_COPROC 7
96#define FBSD_ILL_BADSTK 8
97
98#define FBSD_BUS_ADRALN 1
99#define FBSD_BUS_ADRERR 2
100#define FBSD_BUS_OBJERR 3
101#define FBSD_BUS_OOMERR 100
102
103#define FBSD_SEGV_MAPERR 1
104#define FBSD_SEGV_ACCERR 2
105#define FBSD_SEGV_PKUERR 100
106
107#define FBSD_FPE_INTOVF 1
108#define FBSD_FPE_INTDIV 2
109#define FBSD_FPE_FLTDIV 3
110#define FBSD_FPE_FLTOVF 4
111#define FBSD_FPE_FLTUND 5
112#define FBSD_FPE_FLTRES 6
113#define FBSD_FPE_FLTINV 7
114#define FBSD_FPE_FLTSUB 8
115
116#define FBSD_TRAP_BRKPT 1
117#define FBSD_TRAP_TRACE 2
118#define FBSD_TRAP_DTRACE 3
119#define FBSD_TRAP_CAP 4
120
121#define FBSD_CLD_EXITED 1
122#define FBSD_CLD_KILLED 2
123#define FBSD_CLD_DUMPED 3
124#define FBSD_CLD_TRAPPED 4
125#define FBSD_CLD_STOPPED 5
126#define FBSD_CLD_CONTINUED 6
127
128#define FBSD_POLL_IN 1
129#define FBSD_POLL_OUT 2
130#define FBSD_POLL_MSG 3
131#define FBSD_POLL_ERR 4
132#define FBSD_POLL_PRI 5
133#define FBSD_POLL_HUP 6
134
135/* FreeBSD kernels 12.0 and later include a copy of the
136 'ptrace_lwpinfo' structure returned by the PT_LWPINFO ptrace
137 operation in an ELF core note (NT_FREEBSD_PTLWPINFO) for each LWP.
138 The constants below define the offset of field members and flags in
139 this structure used by methods in this file. Note that the
140 'ptrace_lwpinfo' struct in the note is preceded by a 4 byte integer
141 containing the size of the structure. */
142
143#define LWPINFO_OFFSET 0x4
144
145/* Offsets in ptrace_lwpinfo. */
146#define LWPINFO_PL_FLAGS 0x8
147#define LWPINFO64_PL_SIGINFO 0x30
148#define LWPINFO32_PL_SIGINFO 0x2c
149
150/* Flags in pl_flags. */
151#define PL_FLAG_SI 0x20 /* siginfo is valid */
152
153/* Sizes of siginfo_t. */
154#define SIZE64_SIGINFO_T 80
155#define SIZE32_SIGINFO_T 64
156
157/* Offsets in data structure used in NT_FREEBSD_PROCSTAT_VMMAP core
158 dump notes. See <sys/user.h> for the definition of struct
159 kinfo_vmentry. This data structure should have the same layout on
160 all architectures.
161
162 Note that FreeBSD 7.0 used an older version of this structure
163 (struct kinfo_vmentry), but the NT_FREEBSD_PROCSTAT_VMMAP core
164 dump note wasn't introduced until FreeBSD 9.2. As a result, the
165 core dump note has always used the 7.1 and later structure
166 format. */
167
168#define KVE_STRUCTSIZE 0x0
169#define KVE_START 0x8
170#define KVE_END 0x10
171#define KVE_OFFSET 0x18
172#define KVE_FLAGS 0x2c
173#define KVE_PROTECTION 0x38
174#define KVE_PATH 0x88
175
176/* Flags in the 'kve_protection' field in struct kinfo_vmentry. These
177 match the KVME_PROT_* constants in <sys/user.h>. */
178
179#define KINFO_VME_PROT_READ 0x00000001
180#define KINFO_VME_PROT_WRITE 0x00000002
181#define KINFO_VME_PROT_EXEC 0x00000004
182
183/* Flags in the 'kve_flags' field in struct kinfo_vmentry. These
184 match the KVME_FLAG_* constants in <sys/user.h>. */
185
186#define KINFO_VME_FLAG_COW 0x00000001
187#define KINFO_VME_FLAG_NEEDS_COPY 0x00000002
188#define KINFO_VME_FLAG_NOCOREDUMP 0x00000004
189#define KINFO_VME_FLAG_SUPER 0x00000008
190#define KINFO_VME_FLAG_GROWS_UP 0x00000010
191#define KINFO_VME_FLAG_GROWS_DOWN 0x00000020
192
193/* Offsets in data structure used in NT_FREEBSD_PROCSTAT_FILES core
194 dump notes. See <sys/user.h> for the definition of struct
195 kinfo_file. This data structure should have the same layout on all
196 architectures.
197
198 Note that FreeBSD 7.0 used an older version of this structure
199 (struct kinfo_ofile), but the NT_FREEBSD_PROCSTAT_FILES core dump
200 note wasn't introduced until FreeBSD 9.2. As a result, the core
201 dump note has always used the 7.1 and later structure format. */
202
203#define KF_STRUCTSIZE 0x0
204#define KF_TYPE 0x4
205#define KF_FD 0x8
206#define KF_FLAGS 0x10
207#define KF_OFFSET 0x18
208#define KF_VNODE_TYPE 0x20
209#define KF_SOCK_DOMAIN 0x24
210#define KF_SOCK_TYPE 0x28
211#define KF_SOCK_PROTOCOL 0x2c
212#define KF_SA_LOCAL 0x30
213#define KF_SA_PEER 0xb0
214#define KF_PATH 0x170
215
216/* Constants for the 'kf_type' field in struct kinfo_file. These
217 match the KF_TYPE_* constants in <sys/user.h>. */
218
219#define KINFO_FILE_TYPE_VNODE 1
220#define KINFO_FILE_TYPE_SOCKET 2
221#define KINFO_FILE_TYPE_PIPE 3
222#define KINFO_FILE_TYPE_FIFO 4
223#define KINFO_FILE_TYPE_KQUEUE 5
224#define KINFO_FILE_TYPE_CRYPTO 6
225#define KINFO_FILE_TYPE_MQUEUE 7
226#define KINFO_FILE_TYPE_SHM 8
227#define KINFO_FILE_TYPE_SEM 9
228#define KINFO_FILE_TYPE_PTS 10
229#define KINFO_FILE_TYPE_PROCDESC 11
230
231/* Special values for the 'kf_fd' field in struct kinfo_file. These
232 match the KF_FD_TYPE_* constants in <sys/user.h>. */
233
234#define KINFO_FILE_FD_TYPE_CWD -1
235#define KINFO_FILE_FD_TYPE_ROOT -2
236#define KINFO_FILE_FD_TYPE_JAIL -3
237#define KINFO_FILE_FD_TYPE_TRACE -4
238#define KINFO_FILE_FD_TYPE_TEXT -5
239#define KINFO_FILE_FD_TYPE_CTTY -6
240
241/* Flags in the 'kf_flags' field in struct kinfo_file. These match
242 the KF_FLAG_* constants in <sys/user.h>. */
243
244#define KINFO_FILE_FLAG_READ 0x00000001
245#define KINFO_FILE_FLAG_WRITE 0x00000002
246#define KINFO_FILE_FLAG_APPEND 0x00000004
247#define KINFO_FILE_FLAG_ASYNC 0x00000008
248#define KINFO_FILE_FLAG_FSYNC 0x00000010
249#define KINFO_FILE_FLAG_NONBLOCK 0x00000020
250#define KINFO_FILE_FLAG_DIRECT 0x00000040
251#define KINFO_FILE_FLAG_HASLOCK 0x00000080
252#define KINFO_FILE_FLAG_EXEC 0x00004000
253
254/* Constants for the 'kf_vnode_type' field in struct kinfo_file.
255 These match the KF_VTYPE_* constants in <sys/user.h>. */
256
257#define KINFO_FILE_VTYPE_VREG 1
258#define KINFO_FILE_VTYPE_VDIR 2
259#define KINFO_FILE_VTYPE_VCHR 4
260#define KINFO_FILE_VTYPE_VLNK 5
261#define KINFO_FILE_VTYPE_VSOCK 6
262#define KINFO_FILE_VTYPE_VFIFO 7
263
264/* Constants for socket address families. These match AF_* constants
265 in <sys/socket.h>. */
266
267#define FBSD_AF_UNIX 1
268#define FBSD_AF_INET 2
269#define FBSD_AF_INET6 28
270
271/* Constants for socket types. These match SOCK_* constants in
272 <sys/socket.h>. */
273
274#define FBSD_SOCK_STREAM 1
275#define FBSD_SOCK_DGRAM 2
276#define FBSD_SOCK_SEQPACKET 5
277
278/* Constants for IP protocols. These match IPPROTO_* constants in
279 <netinet/in.h>. */
280
281#define FBSD_IPPROTO_ICMP 1
282#define FBSD_IPPROTO_TCP 6
283#define FBSD_IPPROTO_UDP 17
284#define FBSD_IPPROTO_SCTP 132
285
286/* Socket address structures. These have the same layout on all
287 FreeBSD architectures. In addition, multibyte fields such as IP
288 addresses are always stored in network byte order. */
289
291{
292 uint8_t sin_len;
293 uint8_t sin_family;
294 uint8_t sin_port[2];
295 uint8_t sin_addr[4];
296 char sin_zero[8];
297};
298
300{
301 uint8_t sin6_len;
302 uint8_t sin6_family;
303 uint8_t sin6_port[2];
305 uint8_t sin6_addr[16];
307};
308
310{
311 uint8_t sun_len;
312 uint8_t sun_family;
313 char sun_path[104];
314};
315
316/* Number of 32-bit words in a signal set. This matches _SIG_WORDS in
317 <sys/_sigset.h> and is the same value on all architectures. */
318
319#define SIG_WORDS 4
320
321/* Offsets in data structure used in NT_FREEBSD_PROCSTAT_PROC core
322 dump notes. See <sys/user.h> for the definition of struct
323 kinfo_proc. This data structure has different layouts on different
324 architectures mostly due to ILP32 vs LP64. However, FreeBSD/i386
325 uses a 32-bit time_t while all other architectures use a 64-bit
326 time_t.
327
328 The core dump note actually contains one kinfo_proc structure for
329 each thread, but all of the process-wide data can be obtained from
330 the first structure. One result of this note's format is that some
331 of the process-wide status available in the native target method
332 from the kern.proc.pid.<pid> sysctl such as ki_stat and ki_siglist
333 is not available from a core dump. Instead, the per-thread data
334 structures contain the value of these fields for individual
335 threads. */
336
338{
339 /* Offsets of struct kinfo_proc members. */
367
368 /* Offsets of struct rusage members. */
374};
375
377 {
378 .ki_layout = 0x4,
379 .ki_pid = 0x28,
380 .ki_ppid = 0x2c,
381 .ki_pgid = 0x30,
382 .ki_tpgid = 0x34,
383 .ki_sid = 0x38,
384 .ki_tdev_freebsd11 = 0x44,
385 .ki_sigignore = 0x68,
386 .ki_sigcatch = 0x78,
387 .ki_uid = 0x88,
388 .ki_ruid = 0x8c,
389 .ki_svuid = 0x90,
390 .ki_rgid = 0x94,
391 .ki_svgid = 0x98,
392 .ki_ngroups = 0x9c,
393 .ki_groups = 0xa0,
394 .ki_size = 0xe0,
395 .ki_rssize = 0xe4,
396 .ki_tsize = 0xec,
397 .ki_dsize = 0xf0,
398 .ki_ssize = 0xf4,
399 .ki_start = 0x118,
400 .ki_nice = 0x145,
401 .ki_comm = 0x17f,
402 .ki_tdev = 0x1f0,
403 .ki_rusage = 0x220,
404 .ki_rusage_ch = 0x278,
405
406 .ru_utime = 0x0,
407 .ru_stime = 0x10,
408 .ru_maxrss = 0x20,
409 .ru_minflt = 0x30,
410 .ru_majflt = 0x34,
411 };
412
414 {
415 .ki_layout = 0x4,
416 .ki_pid = 0x28,
417 .ki_ppid = 0x2c,
418 .ki_pgid = 0x30,
419 .ki_tpgid = 0x34,
420 .ki_sid = 0x38,
421 .ki_tdev_freebsd11 = 0x44,
422 .ki_sigignore = 0x68,
423 .ki_sigcatch = 0x78,
424 .ki_uid = 0x88,
425 .ki_ruid = 0x8c,
426 .ki_svuid = 0x90,
427 .ki_rgid = 0x94,
428 .ki_svgid = 0x98,
429 .ki_ngroups = 0x9c,
430 .ki_groups = 0xa0,
431 .ki_size = 0xe0,
432 .ki_rssize = 0xe4,
433 .ki_tsize = 0xec,
434 .ki_dsize = 0xf0,
435 .ki_ssize = 0xf4,
436 .ki_start = 0x118,
437 .ki_nice = 0x135,
438 .ki_comm = 0x16f,
439 .ki_tdev = 0x1e0,
440 .ki_rusage = 0x210,
441 .ki_rusage_ch = 0x258,
442
443 .ru_utime = 0x0,
444 .ru_stime = 0x8,
445 .ru_maxrss = 0x10,
446 .ru_minflt = 0x20,
447 .ru_majflt = 0x24,
448 };
449
451 {
452 .ki_layout = 0x4,
453 .ki_pid = 0x48,
454 .ki_ppid = 0x4c,
455 .ki_pgid = 0x50,
456 .ki_tpgid = 0x54,
457 .ki_sid = 0x58,
458 .ki_tdev_freebsd11 = 0x64,
459 .ki_sigignore = 0x88,
460 .ki_sigcatch = 0x98,
461 .ki_uid = 0xa8,
462 .ki_ruid = 0xac,
463 .ki_svuid = 0xb0,
464 .ki_rgid = 0xb4,
465 .ki_svgid = 0xb8,
466 .ki_ngroups = 0xbc,
467 .ki_groups = 0xc0,
468 .ki_size = 0x100,
469 .ki_rssize = 0x108,
470 .ki_tsize = 0x118,
471 .ki_dsize = 0x120,
472 .ki_ssize = 0x128,
473 .ki_start = 0x150,
474 .ki_nice = 0x185,
475 .ki_comm = 0x1bf,
476 .ki_tdev = 0x230,
477 .ki_rusage = 0x260,
478 .ki_rusage_ch = 0x2f0,
479
480 .ru_utime = 0x0,
481 .ru_stime = 0x10,
482 .ru_maxrss = 0x20,
483 .ru_minflt = 0x40,
484 .ru_majflt = 0x48,
485 };
486
488 {
489 struct type *siginfo_type = nullptr;
490 };
491
494
495static struct fbsd_gdbarch_data *
497{
499 if (result == nullptr)
500 result = fbsd_gdbarch_data_handle.emplace (gdbarch);
501 return result;
502}
503
505{
506 /* Offsets in the runtime linker's 'Obj_Entry' structure. */
507 LONGEST off_linkmap = 0;
508 LONGEST off_tlsindex = 0;
509 bool rtld_offsets_valid = false;
510
511 /* vDSO mapping range. */
513
514 /* Zero if the range hasn't been searched for, > 0 if a range was
515 found, or < 0 if a range was not found. */
517};
518
519/* Per-program-space data for FreeBSD architectures. */
522
523static struct fbsd_pspace_data *
525{
526 struct fbsd_pspace_data *data;
527
528 data = fbsd_pspace_data_handle.get (pspace);
529 if (data == NULL)
530 data = fbsd_pspace_data_handle.emplace (pspace);
531
532 return data;
533}
534
535/* This is how we want PTIDs from core files to be printed. */
536
537static std::string
539{
540 if (ptid.lwp () != 0)
541 return string_printf ("LWP %ld", ptid.lwp ());
542
543 return normal_pid_to_str (ptid);
544}
545
546/* Extract the name assigned to a thread from a core. Returns the
547 string in a static buffer. */
548
549static const char *
551{
552 static char buf[80];
553 struct bfd_section *section;
554 bfd_size_type size;
555
556 if (thr->ptid.lwp () != 0)
557 {
558 /* FreeBSD includes a NT_FREEBSD_THRMISC note for each thread
559 whose contents are defined by a "struct thrmisc" declared in
560 <sys/procfs.h> on FreeBSD. The per-thread name is stored as
561 a null-terminated string as the first member of the
562 structure. Rather than define the full structure here, just
563 extract the null-terminated name from the start of the
564 note. */
565 thread_section_name section_name (".thrmisc", thr->ptid);
566
567 section = bfd_get_section_by_name (core_bfd, section_name.c_str ());
568 if (section != NULL && bfd_section_size (section) > 0)
569 {
570 /* Truncate the name if it is longer than "buf". */
571 size = bfd_section_size (section);
572 if (size > sizeof buf - 1)
573 size = sizeof buf - 1;
574 if (bfd_get_section_contents (core_bfd, section, buf, (file_ptr) 0,
575 size)
576 && buf[0] != '\0')
577 {
578 buf[size] = '\0';
579
580 /* Note that each thread will report the process command
581 as its thread name instead of an empty name if a name
582 has not been set explicitly. Return a NULL name in
583 that case. */
584 if (strcmp (buf, elf_tdata (core_bfd)->core->program) != 0)
585 return buf;
586 }
587 }
588 }
589
590 return NULL;
591}
592
593/* Implement the "core_xfer_siginfo" gdbarch method. */
594
595static LONGEST
596fbsd_core_xfer_siginfo (struct gdbarch *gdbarch, gdb_byte *readbuf,
597 ULONGEST offset, ULONGEST len)
598{
599 size_t siginfo_size;
600
601 if (gdbarch_long_bit (gdbarch) == 32)
602 siginfo_size = SIZE32_SIGINFO_T;
603 else
604 siginfo_size = SIZE64_SIGINFO_T;
605 if (offset > siginfo_size)
606 return -1;
607
608 thread_section_name section_name (".note.freebsdcore.lwpinfo", inferior_ptid);
609 asection *section = bfd_get_section_by_name (core_bfd, section_name.c_str ());
610 if (section == NULL)
611 return -1;
612
613 gdb_byte buf[4];
614 if (!bfd_get_section_contents (core_bfd, section, buf,
616 return -1;
617
618 int pl_flags = extract_signed_integer (buf, gdbarch_byte_order (gdbarch));
619 if (!(pl_flags & PL_FLAG_SI))
620 return -1;
621
622 if (offset + len > siginfo_size)
623 len = siginfo_size - offset;
624
625 ULONGEST siginfo_offset;
626 if (gdbarch_long_bit (gdbarch) == 32)
627 siginfo_offset = LWPINFO_OFFSET + LWPINFO32_PL_SIGINFO;
628 else
629 siginfo_offset = LWPINFO_OFFSET + LWPINFO64_PL_SIGINFO;
630
631 if (!bfd_get_section_contents (core_bfd, section, readbuf,
632 siginfo_offset + offset, len))
633 return -1;
634
635 return len;
636}
637
638static int
639find_signalled_thread (struct thread_info *info, void *data)
640{
641 if (info->stop_signal () != GDB_SIGNAL_0
642 && info->ptid.pid () == inferior_ptid.pid ())
643 return 1;
644
645 return 0;
646}
647
648/* Return a byte_vector containing the contents of a core dump note
649 for the target object of type OBJECT. If STRUCTSIZE is non-zero,
650 the data is prefixed with a 32-bit integer size to match the format
651 used in FreeBSD NT_PROCSTAT_* notes. */
652
653static gdb::optional<gdb::byte_vector>
654fbsd_make_note_desc (enum target_object object, uint32_t structsize)
655{
656 gdb::optional<gdb::byte_vector> buf =
657 target_read_alloc (current_inferior ()->top_target (), object, NULL);
658 if (!buf || buf->empty ())
659 return {};
660
661 if (structsize == 0)
662 return buf;
663
664 gdb::byte_vector desc (sizeof (structsize) + buf->size ());
665 memcpy (desc.data (), &structsize, sizeof (structsize));
666 memcpy (desc.data () + sizeof (structsize), buf->data (), buf->size ());
667 return desc;
668}
669
670/* Create appropriate note sections for a corefile, returning them in
671 allocated memory. */
672
673static gdb::unique_xmalloc_ptr<char>
675{
676 gdb::unique_xmalloc_ptr<char> note_data;
677 Elf_Internal_Ehdr *i_ehdrp;
678 struct thread_info *curr_thr, *signalled_thr;
679
680 /* Put a "FreeBSD" label in the ELF header. */
681 i_ehdrp = elf_elfheader (obfd);
682 i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_FREEBSD;
683
685
686 if (get_exec_file (0))
687 {
688 const char *fname = lbasename (get_exec_file (0));
689 std::string psargs = fname;
690
691 const std::string &infargs = current_inferior ()->args ();
692 if (!infargs.empty ())
693 psargs += ' ' + infargs;
694
695 note_data.reset (elfcore_write_prpsinfo (obfd, note_data.release (),
696 note_size, fname,
697 psargs.c_str ()));
698 }
699
700 /* Thread register information. */
701 try
702 {
704 }
705 catch (const gdb_exception_error &e)
706 {
708 }
709
710 /* Like the kernel, prefer dumping the signalled thread first.
711 "First thread" is what tools use to infer the signalled thread.
712 In case there's more than one signalled thread, prefer the
713 current thread, if it is signalled. */
714 curr_thr = inferior_thread ();
715 if (curr_thr->stop_signal () != GDB_SIGNAL_0)
716 signalled_thr = curr_thr;
717 else
718 {
719 signalled_thr = iterate_over_threads (find_signalled_thread, NULL);
720 if (signalled_thr == NULL)
721 signalled_thr = curr_thr;
722 }
723
724 enum gdb_signal stop_signal = signalled_thr->stop_signal ();
725 gcore_elf_build_thread_register_notes (gdbarch, signalled_thr, stop_signal,
726 obfd, &note_data, note_size);
728 {
729 if (thr == signalled_thr)
730 continue;
731
733 obfd, &note_data, note_size);
734 }
735
736 /* Auxiliary vector. */
737 uint32_t structsize = gdbarch_ptr_bit (gdbarch) / 4; /* Elf_Auxinfo */
738 gdb::optional<gdb::byte_vector> note_desc =
740 if (note_desc && !note_desc->empty ())
741 {
742 note_data.reset (elfcore_write_note (obfd, note_data.release (),
743 note_size, "FreeBSD",
744 NT_FREEBSD_PROCSTAT_AUXV,
745 note_desc->data (),
746 note_desc->size ()));
747 if (!note_data)
748 return NULL;
749 }
750
751 /* Virtual memory mappings. */
753 if (note_desc && !note_desc->empty ())
754 {
755 note_data.reset (elfcore_write_note (obfd, note_data.release (),
756 note_size, "FreeBSD",
757 NT_FREEBSD_PROCSTAT_VMMAP,
758 note_desc->data (),
759 note_desc->size ()));
760 if (!note_data)
761 return NULL;
762 }
763
765 if (note_desc && !note_desc->empty ())
766 {
767 note_data.reset (elfcore_write_note (obfd, note_data.release (),
768 note_size, "FreeBSD",
769 NT_FREEBSD_PROCSTAT_PSSTRINGS,
770 note_desc->data (),
771 note_desc->size ()));
772 if (!note_data)
773 return NULL;
774 }
775
776 /* Include the target description when possible. */
778
779 return note_data;
780}
781
782/* Helper function to generate the file descriptor description for a
783 single open file in 'info proc files'. */
784
785static const char *
786fbsd_file_fd (int kf_fd)
787{
788 switch (kf_fd)
789 {
791 return "cwd";
793 return "root";
795 return "jail";
797 return "trace";
799 return "text";
801 return "ctty";
802 default:
803 return int_string (kf_fd, 10, 1, 0, 0);
804 }
805}
806
807/* Helper function to generate the file type for a single open file in
808 'info proc files'. */
809
810static const char *
811fbsd_file_type (int kf_type, int kf_vnode_type)
812{
813 switch (kf_type)
814 {
816 switch (kf_vnode_type)
817 {
819 return "file";
821 return "dir";
823 return "chr";
825 return "link";
827 return "socket";
829 return "fifo";
830 default:
831 {
832 char *str = get_print_cell ();
833
834 xsnprintf (str, PRINT_CELL_SIZE, "vn:%d", kf_vnode_type);
835 return str;
836 }
837 }
839 return "socket";
841 return "pipe";
843 return "fifo";
845 return "kqueue";
847 return "crypto";
849 return "mqueue";
851 return "shm";
853 return "sem";
855 return "pts";
857 return "proc";
858 default:
859 return int_string (kf_type, 10, 1, 0, 0);
860 }
861}
862
863/* Helper function to generate the file flags for a single open file in
864 'info proc files'. */
865
866static const char *
867fbsd_file_flags (int kf_flags)
868{
869 static char file_flags[10];
870
871 file_flags[0] = (kf_flags & KINFO_FILE_FLAG_READ) ? 'r' : '-';
872 file_flags[1] = (kf_flags & KINFO_FILE_FLAG_WRITE) ? 'w' : '-';
873 file_flags[2] = (kf_flags & KINFO_FILE_FLAG_EXEC) ? 'x' : '-';
874 file_flags[3] = (kf_flags & KINFO_FILE_FLAG_APPEND) ? 'a' : '-';
875 file_flags[4] = (kf_flags & KINFO_FILE_FLAG_ASYNC) ? 's' : '-';
876 file_flags[5] = (kf_flags & KINFO_FILE_FLAG_FSYNC) ? 'f' : '-';
877 file_flags[6] = (kf_flags & KINFO_FILE_FLAG_NONBLOCK) ? 'n' : '-';
878 file_flags[7] = (kf_flags & KINFO_FILE_FLAG_DIRECT) ? 'd' : '-';
879 file_flags[8] = (kf_flags & KINFO_FILE_FLAG_HASLOCK) ? 'l' : '-';
880 file_flags[9] = '\0';
881
882 return file_flags;
883}
884
885/* Helper function to generate the name of an IP protocol. */
886
887static const char *
888fbsd_ipproto (int protocol)
889{
890 switch (protocol)
891 {
893 return "icmp";
894 case FBSD_IPPROTO_TCP:
895 return "tcp";
896 case FBSD_IPPROTO_UDP:
897 return "udp";
899 return "sctp";
900 default:
901 {
902 char *str = get_print_cell ();
903
904 xsnprintf (str, PRINT_CELL_SIZE, "ip<%d>", protocol);
905 return str;
906 }
907 }
908}
909
910/* Helper function to print out an IPv4 socket address. */
911
912static void
913fbsd_print_sockaddr_in (const void *sockaddr)
914{
915 const struct fbsd_sockaddr_in *sin =
916 reinterpret_cast<const struct fbsd_sockaddr_in *> (sockaddr);
917 char buf[INET_ADDRSTRLEN];
918
919 if (inet_ntop (AF_INET, sin->sin_addr, buf, sizeof buf) == nullptr)
920 error (_("Failed to format IPv4 address"));
921 gdb_printf ("%s:%u", buf,
922 (sin->sin_port[0] << 8) | sin->sin_port[1]);
923}
924
925/* Helper function to print out an IPv6 socket address. */
926
927static void
928fbsd_print_sockaddr_in6 (const void *sockaddr)
929{
930 const struct fbsd_sockaddr_in6 *sin6 =
931 reinterpret_cast<const struct fbsd_sockaddr_in6 *> (sockaddr);
932 char buf[INET6_ADDRSTRLEN];
933
934 if (inet_ntop (AF_INET6, sin6->sin6_addr, buf, sizeof buf) == nullptr)
935 error (_("Failed to format IPv6 address"));
936 gdb_printf ("%s.%u", buf,
937 (sin6->sin6_port[0] << 8) | sin6->sin6_port[1]);
938}
939
940/* See fbsd-tdep.h. */
941
942void
944{
945 gdb_printf (_("Open files:\n\n"));
946 gdb_printf (" %6s %6s %10s %9s %s\n",
947 "FD", "Type", "Offset", "Flags ", "Name");
948}
949
950/* See fbsd-tdep.h. */
951
952void
953fbsd_info_proc_files_entry (int kf_type, int kf_fd, int kf_flags,
954 LONGEST kf_offset, int kf_vnode_type,
955 int kf_sock_domain, int kf_sock_type,
956 int kf_sock_protocol, const void *kf_sa_local,
957 const void *kf_sa_peer, const void *kf_path)
958{
959 gdb_printf (" %6s %6s %10s %8s ",
960 fbsd_file_fd (kf_fd),
961 fbsd_file_type (kf_type, kf_vnode_type),
962 kf_offset > -1 ? hex_string (kf_offset) : "-",
963 fbsd_file_flags (kf_flags));
964 if (kf_type == KINFO_FILE_TYPE_SOCKET)
965 {
966 switch (kf_sock_domain)
967 {
968 case FBSD_AF_UNIX:
969 {
970 switch (kf_sock_type)
971 {
972 case FBSD_SOCK_STREAM:
973 gdb_printf ("unix stream:");
974 break;
975 case FBSD_SOCK_DGRAM:
976 gdb_printf ("unix dgram:");
977 break;
979 gdb_printf ("unix seqpacket:");
980 break;
981 default:
982 gdb_printf ("unix <%d>:", kf_sock_type);
983 break;
984 }
985
986 /* For local sockets, print out the first non-nul path
987 rather than both paths. */
988 const struct fbsd_sockaddr_un *saddr_un
989 = reinterpret_cast<const struct fbsd_sockaddr_un *> (kf_sa_local);
990 if (saddr_un->sun_path[0] == 0)
991 saddr_un = reinterpret_cast<const struct fbsd_sockaddr_un *>
992 (kf_sa_peer);
993 gdb_printf ("%s", saddr_un->sun_path);
994 break;
995 }
996 case FBSD_AF_INET:
997 gdb_printf ("%s4 ", fbsd_ipproto (kf_sock_protocol));
998 fbsd_print_sockaddr_in (kf_sa_local);
999 gdb_printf (" -> ");
1000 fbsd_print_sockaddr_in (kf_sa_peer);
1001 break;
1002 case FBSD_AF_INET6:
1003 gdb_printf ("%s6 ", fbsd_ipproto (kf_sock_protocol));
1004 fbsd_print_sockaddr_in6 (kf_sa_local);
1005 gdb_printf (" -> ");
1006 fbsd_print_sockaddr_in6 (kf_sa_peer);
1007 break;
1008 }
1009 }
1010 else
1011 gdb_printf ("%s", reinterpret_cast<const char *> (kf_path));
1012 gdb_printf ("\n");
1013}
1014
1015/* Implement "info proc files" for a corefile. */
1016
1017static void
1019{
1020 asection *section
1021 = bfd_get_section_by_name (core_bfd, ".note.freebsdcore.files");
1022 if (section == NULL)
1023 {
1024 warning (_("unable to find open files in core file"));
1025 return;
1026 }
1027
1028 size_t note_size = bfd_section_size (section);
1029 if (note_size < 4)
1030 error (_("malformed core note - too short for header"));
1031
1032 gdb::def_vector<unsigned char> contents (note_size);
1033 if (!bfd_get_section_contents (core_bfd, section, contents.data (),
1034 0, note_size))
1035 error (_("could not get core note contents"));
1036
1037 unsigned char *descdata = contents.data ();
1038 unsigned char *descend = descdata + note_size;
1039
1040 /* Skip over the structure size. */
1041 descdata += 4;
1042
1044
1045 while (descdata + KF_PATH < descend)
1046 {
1047 ULONGEST structsize = bfd_get_32 (core_bfd, descdata + KF_STRUCTSIZE);
1048 if (structsize < KF_PATH)
1049 error (_("malformed core note - file structure too small"));
1050
1051 LONGEST type = bfd_get_signed_32 (core_bfd, descdata + KF_TYPE);
1052 LONGEST fd = bfd_get_signed_32 (core_bfd, descdata + KF_FD);
1053 LONGEST flags = bfd_get_signed_32 (core_bfd, descdata + KF_FLAGS);
1054 LONGEST offset = bfd_get_signed_64 (core_bfd, descdata + KF_OFFSET);
1055 LONGEST vnode_type = bfd_get_signed_32 (core_bfd,
1056 descdata + KF_VNODE_TYPE);
1057 LONGEST sock_domain = bfd_get_signed_32 (core_bfd,
1058 descdata + KF_SOCK_DOMAIN);
1059 LONGEST sock_type = bfd_get_signed_32 (core_bfd, descdata + KF_SOCK_TYPE);
1060 LONGEST sock_protocol = bfd_get_signed_32 (core_bfd,
1061 descdata + KF_SOCK_PROTOCOL);
1062 fbsd_info_proc_files_entry (type, fd, flags, offset, vnode_type,
1063 sock_domain, sock_type, sock_protocol,
1064 descdata + KF_SA_LOCAL, descdata + KF_SA_PEER,
1065 descdata + KF_PATH);
1066
1067 descdata += structsize;
1068 }
1069}
1070
1071/* Helper function to generate mappings flags for a single VM map
1072 entry in 'info proc mappings'. */
1073
1074static const char *
1075fbsd_vm_map_entry_flags (int kve_flags, int kve_protection)
1076{
1077 static char vm_flags[9];
1078
1079 vm_flags[0] = (kve_protection & KINFO_VME_PROT_READ) ? 'r' : '-';
1080 vm_flags[1] = (kve_protection & KINFO_VME_PROT_WRITE) ? 'w' : '-';
1081 vm_flags[2] = (kve_protection & KINFO_VME_PROT_EXEC) ? 'x' : '-';
1082 vm_flags[3] = ' ';
1083 vm_flags[4] = (kve_flags & KINFO_VME_FLAG_COW) ? 'C' : '-';
1084 vm_flags[5] = (kve_flags & KINFO_VME_FLAG_NEEDS_COPY) ? 'N' : '-';
1085 vm_flags[6] = (kve_flags & KINFO_VME_FLAG_SUPER) ? 'S' : '-';
1086 vm_flags[7] = (kve_flags & KINFO_VME_FLAG_GROWS_UP) ? 'U'
1087 : (kve_flags & KINFO_VME_FLAG_GROWS_DOWN) ? 'D' : '-';
1088 vm_flags[8] = '\0';
1089
1090 return vm_flags;
1091}
1092
1093/* See fbsd-tdep.h. */
1094
1095void
1097{
1098 gdb_printf (_("Mapped address spaces:\n\n"));
1099 if (addr_bit == 64)
1100 {
1101 gdb_printf (" %18s %18s %10s %10s %9s %s\n",
1102 "Start Addr",
1103 " End Addr",
1104 " Size", " Offset", "Flags ", "File");
1105 }
1106 else
1107 {
1108 gdb_printf ("\t%10s %10s %10s %10s %9s %s\n",
1109 "Start Addr",
1110 " End Addr",
1111 " Size", " Offset", "Flags ", "File");
1112 }
1113}
1114
1115/* See fbsd-tdep.h. */
1116
1117void
1118fbsd_info_proc_mappings_entry (int addr_bit, ULONGEST kve_start,
1119 ULONGEST kve_end, ULONGEST kve_offset,
1120 int kve_flags, int kve_protection,
1121 const void *kve_path)
1122{
1123 if (addr_bit == 64)
1124 {
1125 gdb_printf (" %18s %18s %10s %10s %9s %s\n",
1126 hex_string (kve_start),
1127 hex_string (kve_end),
1128 hex_string (kve_end - kve_start),
1129 hex_string (kve_offset),
1130 fbsd_vm_map_entry_flags (kve_flags, kve_protection),
1131 reinterpret_cast<const char *> (kve_path));
1132 }
1133 else
1134 {
1135 gdb_printf ("\t%10s %10s %10s %10s %9s %s\n",
1136 hex_string (kve_start),
1137 hex_string (kve_end),
1138 hex_string (kve_end - kve_start),
1139 hex_string (kve_offset),
1140 fbsd_vm_map_entry_flags (kve_flags, kve_protection),
1141 reinterpret_cast<const char *> (kve_path));
1142 }
1143}
1144
1145/* Implement "info proc mappings" for a corefile. */
1146
1147static void
1149{
1150 asection *section;
1151 unsigned char *descdata, *descend;
1152 size_t note_size;
1153
1154 section = bfd_get_section_by_name (core_bfd, ".note.freebsdcore.vmmap");
1155 if (section == NULL)
1156 {
1157 warning (_("unable to find mappings in core file"));
1158 return;
1159 }
1160
1161 note_size = bfd_section_size (section);
1162 if (note_size < 4)
1163 error (_("malformed core note - too short for header"));
1164
1165 gdb::def_vector<unsigned char> contents (note_size);
1166 if (!bfd_get_section_contents (core_bfd, section, contents.data (),
1167 0, note_size))
1168 error (_("could not get core note contents"));
1169
1170 descdata = contents.data ();
1171 descend = descdata + note_size;
1172
1173 /* Skip over the structure size. */
1174 descdata += 4;
1175
1177 while (descdata + KVE_PATH < descend)
1178 {
1179 ULONGEST structsize = bfd_get_32 (core_bfd, descdata + KVE_STRUCTSIZE);
1180 if (structsize < KVE_PATH)
1181 error (_("malformed core note - vmmap entry too small"));
1182
1183 ULONGEST start = bfd_get_64 (core_bfd, descdata + KVE_START);
1184 ULONGEST end = bfd_get_64 (core_bfd, descdata + KVE_END);
1185 ULONGEST offset = bfd_get_64 (core_bfd, descdata + KVE_OFFSET);
1186 LONGEST flags = bfd_get_signed_32 (core_bfd, descdata + KVE_FLAGS);
1187 LONGEST prot = bfd_get_signed_32 (core_bfd, descdata + KVE_PROTECTION);
1189 offset, flags, prot, descdata + KVE_PATH);
1190
1191 descdata += structsize;
1192 }
1193}
1194
1195/* Fetch the pathname of a vnode for a single file descriptor from the
1196 file table core note. */
1197
1198static gdb::unique_xmalloc_ptr<char>
1200{
1201 asection *section;
1202 unsigned char *descdata, *descend;
1203 size_t note_size;
1204
1205 section = bfd_get_section_by_name (core_bfd, ".note.freebsdcore.files");
1206 if (section == NULL)
1207 return nullptr;
1208
1209 note_size = bfd_section_size (section);
1210 if (note_size < 4)
1211 error (_("malformed core note - too short for header"));
1212
1213 gdb::def_vector<unsigned char> contents (note_size);
1214 if (!bfd_get_section_contents (core_bfd, section, contents.data (),
1215 0, note_size))
1216 error (_("could not get core note contents"));
1217
1218 descdata = contents.data ();
1219 descend = descdata + note_size;
1220
1221 /* Skip over the structure size. */
1222 descdata += 4;
1223
1224 while (descdata + KF_PATH < descend)
1225 {
1226 ULONGEST structsize;
1227
1228 structsize = bfd_get_32 (core_bfd, descdata + KF_STRUCTSIZE);
1229 if (structsize < KF_PATH)
1230 error (_("malformed core note - file structure too small"));
1231
1232 if (bfd_get_32 (core_bfd, descdata + KF_TYPE) == KINFO_FILE_TYPE_VNODE
1233 && bfd_get_signed_32 (core_bfd, descdata + KF_FD) == fd)
1234 {
1235 char *path = (char *) descdata + KF_PATH;
1236 return make_unique_xstrdup (path);
1237 }
1238
1239 descdata += structsize;
1240 }
1241 return nullptr;
1242}
1243
1244/* Helper function to read a struct timeval. */
1245
1246static void
1247fbsd_core_fetch_timeval (struct gdbarch *gdbarch, unsigned char *data,
1248 LONGEST &sec, ULONGEST &usec)
1249{
1250 if (gdbarch_addr_bit (gdbarch) == 64)
1251 {
1252 sec = bfd_get_signed_64 (core_bfd, data);
1253 usec = bfd_get_64 (core_bfd, data + 8);
1254 }
1255 else if (bfd_get_arch (core_bfd) == bfd_arch_i386)
1256 {
1257 sec = bfd_get_signed_32 (core_bfd, data);
1258 usec = bfd_get_32 (core_bfd, data + 4);
1259 }
1260 else
1261 {
1262 sec = bfd_get_signed_64 (core_bfd, data);
1263 usec = bfd_get_32 (core_bfd, data + 8);
1264 }
1265}
1266
1267/* Print out the contents of a signal set. */
1268
1269static void
1270fbsd_print_sigset (const char *descr, unsigned char *sigset)
1271{
1272 gdb_printf ("%s: ", descr);
1273 for (int i = 0; i < SIG_WORDS; i++)
1274 gdb_printf ("%08x ",
1275 (unsigned int) bfd_get_32 (core_bfd, sigset + i * 4));
1276 gdb_printf ("\n");
1277}
1278
1279/* Implement "info proc status" for a corefile. */
1280
1281static void
1283{
1284 const struct kinfo_proc_layout *kp;
1285 asection *section;
1286 unsigned char *descdata;
1287 int addr_bit, long_bit;
1288 size_t note_size;
1289 ULONGEST value;
1290 LONGEST sec;
1291
1292 section = bfd_get_section_by_name (core_bfd, ".note.freebsdcore.proc");
1293 if (section == NULL)
1294 {
1295 warning (_("unable to find process info in core file"));
1296 return;
1297 }
1298
1299 addr_bit = gdbarch_addr_bit (gdbarch);
1300 if (addr_bit == 64)
1302 else if (bfd_get_arch (core_bfd) == bfd_arch_i386)
1304 else
1306 long_bit = gdbarch_long_bit (gdbarch);
1307
1308 /*
1309 * Ensure that the note is large enough for all of the fields fetched
1310 * by this function. In particular, the note must contain the 32-bit
1311 * structure size, then it must be long enough to access the last
1312 * field used (ki_rusage_ch.ru_majflt) which is the size of a long.
1313 */
1314 note_size = bfd_section_size (section);
1315 if (note_size < (4 + kp->ki_rusage_ch + kp->ru_majflt
1316 + long_bit / TARGET_CHAR_BIT))
1317 error (_("malformed core note - too short"));
1318
1319 gdb::def_vector<unsigned char> contents (note_size);
1320 if (!bfd_get_section_contents (core_bfd, section, contents.data (),
1321 0, note_size))
1322 error (_("could not get core note contents"));
1323
1324 descdata = contents.data ();
1325
1326 /* Skip over the structure size. */
1327 descdata += 4;
1328
1329 /* Verify 'ki_layout' is 0. */
1330 if (bfd_get_32 (core_bfd, descdata + kp->ki_layout) != 0)
1331 {
1332 warning (_("unsupported process information in core file"));
1333 return;
1334 }
1335
1336 gdb_printf ("Name: %.19s\n", descdata + kp->ki_comm);
1337 gdb_printf ("Process ID: %s\n",
1338 pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_pid)));
1339 gdb_printf ("Parent process: %s\n",
1340 pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_ppid)));
1341 gdb_printf ("Process group: %s\n",
1342 pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_pgid)));
1343 gdb_printf ("Session id: %s\n",
1344 pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_sid)));
1345
1346 /* FreeBSD 12.0 and later store a 64-bit dev_t at 'ki_tdev'. Older
1347 kernels store a 32-bit dev_t at 'ki_tdev_freebsd11'. In older
1348 kernels the 64-bit 'ki_tdev' field is in a reserved section of
1349 the structure that is cleared to zero. Assume that a zero value
1350 in ki_tdev indicates a core dump from an older kernel and use the
1351 value in 'ki_tdev_freebsd11' instead. */
1352 value = bfd_get_64 (core_bfd, descdata + kp->ki_tdev);
1353 if (value == 0)
1354 value = bfd_get_32 (core_bfd, descdata + kp->ki_tdev_freebsd11);
1355 gdb_printf ("TTY: %s\n", pulongest (value));
1356 gdb_printf ("TTY owner process group: %s\n",
1357 pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_tpgid)));
1358 gdb_printf ("User IDs (real, effective, saved): %s %s %s\n",
1359 pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_ruid)),
1360 pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_uid)),
1361 pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_svuid)));
1362 gdb_printf ("Group IDs (real, effective, saved): %s %s %s\n",
1363 pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_rgid)),
1364 pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_groups)),
1365 pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_svgid)));
1366 gdb_printf ("Groups: ");
1367 uint16_t ngroups = bfd_get_16 (core_bfd, descdata + kp->ki_ngroups);
1368 for (int i = 0; i < ngroups; i++)
1369 gdb_printf ("%s ",
1370 pulongest (bfd_get_32 (core_bfd,
1371 descdata + kp->ki_groups + i * 4)));
1372 gdb_printf ("\n");
1373 value = bfd_get (long_bit, core_bfd,
1374 descdata + kp->ki_rusage + kp->ru_minflt);
1375 gdb_printf ("Minor faults (no memory page): %s\n", pulongest (value));
1376 value = bfd_get (long_bit, core_bfd,
1377 descdata + kp->ki_rusage_ch + kp->ru_minflt);
1378 gdb_printf ("Minor faults, children: %s\n", pulongest (value));
1379 value = bfd_get (long_bit, core_bfd,
1380 descdata + kp->ki_rusage + kp->ru_majflt);
1381 gdb_printf ("Major faults (memory page faults): %s\n",
1382 pulongest (value));
1383 value = bfd_get (long_bit, core_bfd,
1384 descdata + kp->ki_rusage_ch + kp->ru_majflt);
1385 gdb_printf ("Major faults, children: %s\n", pulongest (value));
1387 descdata + kp->ki_rusage + kp->ru_utime,
1388 sec, value);
1389 gdb_printf ("utime: %s.%06d\n", plongest (sec), (int) value);
1391 descdata + kp->ki_rusage + kp->ru_stime,
1392 sec, value);
1393 gdb_printf ("stime: %s.%06d\n", plongest (sec), (int) value);
1395 descdata + kp->ki_rusage_ch + kp->ru_utime,
1396 sec, value);
1397 gdb_printf ("utime, children: %s.%06d\n", plongest (sec), (int) value);
1399 descdata + kp->ki_rusage_ch + kp->ru_stime,
1400 sec, value);
1401 gdb_printf ("stime, children: %s.%06d\n", plongest (sec), (int) value);
1402 gdb_printf ("'nice' value: %d\n",
1403 (int) bfd_get_signed_8 (core_bfd, descdata + kp->ki_nice));
1404 fbsd_core_fetch_timeval (gdbarch, descdata + kp->ki_start, sec, value);
1405 gdb_printf ("Start time: %s.%06d\n", plongest (sec), (int) value);
1406 gdb_printf ("Virtual memory size: %s kB\n",
1407 pulongest (bfd_get (addr_bit, core_bfd,
1408 descdata + kp->ki_size) / 1024));
1409 gdb_printf ("Data size: %s pages\n",
1410 pulongest (bfd_get (addr_bit, core_bfd,
1411 descdata + kp->ki_dsize)));
1412 gdb_printf ("Stack size: %s pages\n",
1413 pulongest (bfd_get (addr_bit, core_bfd,
1414 descdata + kp->ki_ssize)));
1415 gdb_printf ("Text size: %s pages\n",
1416 pulongest (bfd_get (addr_bit, core_bfd,
1417 descdata + kp->ki_tsize)));
1418 gdb_printf ("Resident set size: %s pages\n",
1419 pulongest (bfd_get (addr_bit, core_bfd,
1420 descdata + kp->ki_rssize)));
1421 gdb_printf ("Maximum RSS: %s pages\n",
1422 pulongest (bfd_get (long_bit, core_bfd,
1423 descdata + kp->ki_rusage
1424 + kp->ru_maxrss)));
1425 fbsd_print_sigset ("Ignored Signals", descdata + kp->ki_sigignore);
1426 fbsd_print_sigset ("Caught Signals", descdata + kp->ki_sigcatch);
1427}
1428
1429/* Implement the "core_info_proc" gdbarch method. */
1430
1431static void
1432fbsd_core_info_proc (struct gdbarch *gdbarch, const char *args,
1433 enum info_proc_what what)
1434{
1435 bool do_cmdline = false;
1436 bool do_cwd = false;
1437 bool do_exe = false;
1438 bool do_files = false;
1439 bool do_mappings = false;
1440 bool do_status = false;
1441 int pid;
1442
1443 switch (what)
1444 {
1445 case IP_MINIMAL:
1446 do_cmdline = true;
1447 do_cwd = true;
1448 do_exe = true;
1449 break;
1450 case IP_MAPPINGS:
1451 do_mappings = true;
1452 break;
1453 case IP_STATUS:
1454 case IP_STAT:
1455 do_status = true;
1456 break;
1457 case IP_CMDLINE:
1458 do_cmdline = true;
1459 break;
1460 case IP_EXE:
1461 do_exe = true;
1462 break;
1463 case IP_CWD:
1464 do_cwd = true;
1465 break;
1466 case IP_FILES:
1467 do_files = true;
1468 break;
1469 case IP_ALL:
1470 do_cmdline = true;
1471 do_cwd = true;
1472 do_exe = true;
1473 do_files = true;
1474 do_mappings = true;
1475 do_status = true;
1476 break;
1477 default:
1478 return;
1479 }
1480
1481 pid = bfd_core_file_pid (core_bfd);
1482 if (pid != 0)
1483 gdb_printf (_("process %d\n"), pid);
1484
1485 if (do_cmdline)
1486 {
1487 const char *cmdline;
1488
1489 cmdline = bfd_core_file_failing_command (core_bfd);
1490 if (cmdline)
1491 gdb_printf ("cmdline = '%s'\n", cmdline);
1492 else
1493 warning (_("Command line unavailable"));
1494 }
1495 if (do_cwd)
1496 {
1497 gdb::unique_xmalloc_ptr<char> cwd =
1499 if (cwd)
1500 gdb_printf ("cwd = '%s'\n", cwd.get ());
1501 else
1502 warning (_("unable to read current working directory"));
1503 }
1504 if (do_exe)
1505 {
1506 gdb::unique_xmalloc_ptr<char> exe =
1508 if (exe)
1509 gdb_printf ("exe = '%s'\n", exe.get ());
1510 else
1511 warning (_("unable to read executable path name"));
1512 }
1513 if (do_files)
1515 if (do_mappings)
1517 if (do_status)
1519}
1520
1521/* Print descriptions of FreeBSD-specific AUXV entries to FILE. */
1522
1523static void
1525 CORE_ADDR type, CORE_ADDR val)
1526{
1527 const char *name = "???";
1528 const char *description = "";
1529 enum auxv_format format = AUXV_FORMAT_HEX;
1530
1531 switch (type)
1532 {
1533 case AT_NULL:
1534 case AT_IGNORE:
1535 case AT_EXECFD:
1536 case AT_PHDR:
1537 case AT_PHENT:
1538 case AT_PHNUM:
1539 case AT_PAGESZ:
1540 case AT_BASE:
1541 case AT_FLAGS:
1542 case AT_ENTRY:
1543 case AT_NOTELF:
1544 case AT_UID:
1545 case AT_EUID:
1546 case AT_GID:
1547 case AT_EGID:
1549 return;
1550#define _TAGNAME(tag) #tag
1551#define TAGNAME(tag) _TAGNAME(AT_##tag)
1552#define TAG(tag, text, kind) \
1553 case AT_FREEBSD_##tag: name = TAGNAME(tag); description = text; format = kind; break
1554 TAG (EXECPATH, _("Executable path"), AUXV_FORMAT_STR);
1555 TAG (CANARY, _("Canary for SSP"), AUXV_FORMAT_HEX);
1556 TAG (CANARYLEN, ("Length of the SSP canary"), AUXV_FORMAT_DEC);
1557 TAG (OSRELDATE, _("OSRELDATE"), AUXV_FORMAT_DEC);
1558 TAG (NCPUS, _("Number of CPUs"), AUXV_FORMAT_DEC);
1559 TAG (PAGESIZES, _("Pagesizes"), AUXV_FORMAT_HEX);
1560 TAG (PAGESIZESLEN, _("Number of pagesizes"), AUXV_FORMAT_DEC);
1561 TAG (TIMEKEEP, _("Pointer to timehands"), AUXV_FORMAT_HEX);
1562 TAG (STACKPROT, _("Initial stack protection"), AUXV_FORMAT_HEX);
1563 TAG (EHDRFLAGS, _("ELF header e_flags"), AUXV_FORMAT_HEX);
1564 TAG (HWCAP, _("Machine-dependent CPU capability hints"), AUXV_FORMAT_HEX);
1565 TAG (HWCAP2, _("Extension of AT_HWCAP"), AUXV_FORMAT_HEX);
1566 TAG (BSDFLAGS, _("ELF BSD flags"), AUXV_FORMAT_HEX);
1567 TAG (ARGC, _("Argument count"), AUXV_FORMAT_DEC);
1568 TAG (ARGV, _("Argument vector"), AUXV_FORMAT_HEX);
1569 TAG (ENVC, _("Environment count"), AUXV_FORMAT_DEC);
1570 TAG (ENVV, _("Environment vector"), AUXV_FORMAT_HEX);
1571 TAG (PS_STRINGS, _("Pointer to ps_strings"), AUXV_FORMAT_HEX);
1572 TAG (FXRNG, _("Pointer to root RNG seed version"), AUXV_FORMAT_HEX);
1573 TAG (KPRELOAD, _("Base address of vDSO"), AUXV_FORMAT_HEX);
1574 TAG (USRSTACKBASE, _("Top of user stack"), AUXV_FORMAT_HEX);
1575 TAG (USRSTACKLIM, _("Grow limit of user stack"), AUXV_FORMAT_HEX);
1576 }
1577
1578 fprint_auxv_entry (file, name, description, format, type, val);
1579}
1580
1581/* Implement the "get_siginfo_type" gdbarch method. */
1582
1583static struct type *
1585{
1587 struct type *int_type, *int32_type, *uint32_type, *long_type, *void_ptr_type;
1588 struct type *uid_type, *pid_type;
1589 struct type *sigval_type, *reason_type;
1590 struct type *siginfo_type;
1591 struct type *type;
1592
1594 if (fbsd_gdbarch_data->siginfo_type != NULL)
1596
1598 0, "int");
1599 int32_type = arch_integer_type (gdbarch, 32, 0, "int32_t");
1600 uint32_type = arch_integer_type (gdbarch, 32, 1, "uint32_t");
1602 0, "long");
1603 void_ptr_type = lookup_pointer_type (builtin_type (gdbarch)->builtin_void);
1604
1605 /* union sigval */
1606 sigval_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_UNION);
1607 sigval_type->set_name (xstrdup ("sigval"));
1608 append_composite_type_field (sigval_type, "sival_int", int_type);
1609 append_composite_type_field (sigval_type, "sival_ptr", void_ptr_type);
1610
1611 /* __pid_t */
1612 pid_type = arch_type (gdbarch, TYPE_CODE_TYPEDEF,
1613 int32_type->length () * TARGET_CHAR_BIT, "__pid_t");
1614 pid_type->set_target_type (int32_type);
1615 pid_type->set_target_is_stub (true);
1616
1617 /* __uid_t */
1618 uid_type = arch_type (gdbarch, TYPE_CODE_TYPEDEF,
1619 uint32_type->length () * TARGET_CHAR_BIT,
1620 "__uid_t");
1621 uid_type->set_target_type (uint32_type);
1622 pid_type->set_target_is_stub (true);
1623
1624 /* _reason */
1625 reason_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_UNION);
1626
1627 /* _fault */
1628 type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
1629 append_composite_type_field (type, "si_trapno", int_type);
1630 append_composite_type_field (reason_type, "_fault", type);
1631
1632 /* _timer */
1633 type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
1634 append_composite_type_field (type, "si_timerid", int_type);
1635 append_composite_type_field (type, "si_overrun", int_type);
1636 append_composite_type_field (reason_type, "_timer", type);
1637
1638 /* _mesgq */
1639 type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
1640 append_composite_type_field (type, "si_mqd", int_type);
1641 append_composite_type_field (reason_type, "_mesgq", type);
1642
1643 /* _poll */
1644 type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
1645 append_composite_type_field (type, "si_band", long_type);
1646 append_composite_type_field (reason_type, "_poll", type);
1647
1648 /* __spare__ */
1649 type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
1650 append_composite_type_field (type, "__spare1__", long_type);
1651 append_composite_type_field (type, "__spare2__",
1652 init_vector_type (int_type, 7));
1653 append_composite_type_field (reason_type, "__spare__", type);
1654
1655 /* struct siginfo */
1656 siginfo_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
1657 siginfo_type->set_name (xstrdup ("siginfo"));
1658 append_composite_type_field (siginfo_type, "si_signo", int_type);
1659 append_composite_type_field (siginfo_type, "si_errno", int_type);
1660 append_composite_type_field (siginfo_type, "si_code", int_type);
1661 append_composite_type_field (siginfo_type, "si_pid", pid_type);
1662 append_composite_type_field (siginfo_type, "si_uid", uid_type);
1663 append_composite_type_field (siginfo_type, "si_status", int_type);
1664 append_composite_type_field (siginfo_type, "si_addr", void_ptr_type);
1665 append_composite_type_field (siginfo_type, "si_value", sigval_type);
1666 append_composite_type_field (siginfo_type, "_reason", reason_type);
1667
1668 fbsd_gdbarch_data->siginfo_type = siginfo_type;
1669
1670 return siginfo_type;
1671}
1672
1673/* Implement the "gdb_signal_from_target" gdbarch method. */
1674
1675static enum gdb_signal
1677{
1678 switch (signal)
1679 {
1680 case 0:
1681 return GDB_SIGNAL_0;
1682
1683 case FREEBSD_SIGHUP:
1684 return GDB_SIGNAL_HUP;
1685
1686 case FREEBSD_SIGINT:
1687 return GDB_SIGNAL_INT;
1688
1689 case FREEBSD_SIGQUIT:
1690 return GDB_SIGNAL_QUIT;
1691
1692 case FREEBSD_SIGILL:
1693 return GDB_SIGNAL_ILL;
1694
1695 case FREEBSD_SIGTRAP:
1696 return GDB_SIGNAL_TRAP;
1697
1698 case FREEBSD_SIGABRT:
1699 return GDB_SIGNAL_ABRT;
1700
1701 case FREEBSD_SIGEMT:
1702 return GDB_SIGNAL_EMT;
1703
1704 case FREEBSD_SIGFPE:
1705 return GDB_SIGNAL_FPE;
1706
1707 case FREEBSD_SIGKILL:
1708 return GDB_SIGNAL_KILL;
1709
1710 case FREEBSD_SIGBUS:
1711 return GDB_SIGNAL_BUS;
1712
1713 case FREEBSD_SIGSEGV:
1714 return GDB_SIGNAL_SEGV;
1715
1716 case FREEBSD_SIGSYS:
1717 return GDB_SIGNAL_SYS;
1718
1719 case FREEBSD_SIGPIPE:
1720 return GDB_SIGNAL_PIPE;
1721
1722 case FREEBSD_SIGALRM:
1723 return GDB_SIGNAL_ALRM;
1724
1725 case FREEBSD_SIGTERM:
1726 return GDB_SIGNAL_TERM;
1727
1728 case FREEBSD_SIGURG:
1729 return GDB_SIGNAL_URG;
1730
1731 case FREEBSD_SIGSTOP:
1732 return GDB_SIGNAL_STOP;
1733
1734 case FREEBSD_SIGTSTP:
1735 return GDB_SIGNAL_TSTP;
1736
1737 case FREEBSD_SIGCONT:
1738 return GDB_SIGNAL_CONT;
1739
1740 case FREEBSD_SIGCHLD:
1741 return GDB_SIGNAL_CHLD;
1742
1743 case FREEBSD_SIGTTIN:
1744 return GDB_SIGNAL_TTIN;
1745
1746 case FREEBSD_SIGTTOU:
1747 return GDB_SIGNAL_TTOU;
1748
1749 case FREEBSD_SIGIO:
1750 return GDB_SIGNAL_IO;
1751
1752 case FREEBSD_SIGXCPU:
1753 return GDB_SIGNAL_XCPU;
1754
1755 case FREEBSD_SIGXFSZ:
1756 return GDB_SIGNAL_XFSZ;
1757
1758 case FREEBSD_SIGVTALRM:
1759 return GDB_SIGNAL_VTALRM;
1760
1761 case FREEBSD_SIGPROF:
1762 return GDB_SIGNAL_PROF;
1763
1764 case FREEBSD_SIGWINCH:
1765 return GDB_SIGNAL_WINCH;
1766
1767 case FREEBSD_SIGINFO:
1768 return GDB_SIGNAL_INFO;
1769
1770 case FREEBSD_SIGUSR1:
1771 return GDB_SIGNAL_USR1;
1772
1773 case FREEBSD_SIGUSR2:
1774 return GDB_SIGNAL_USR2;
1775
1776 /* SIGTHR is the same as SIGLWP on FreeBSD. */
1777 case FREEBSD_SIGTHR:
1778 return GDB_SIGNAL_LWP;
1779
1780 case FREEBSD_SIGLIBRT:
1781 return GDB_SIGNAL_LIBRT;
1782 }
1783
1784 if (signal >= FREEBSD_SIGRTMIN && signal <= FREEBSD_SIGRTMAX)
1785 {
1786 int offset = signal - FREEBSD_SIGRTMIN;
1787
1788 return (enum gdb_signal) ((int) GDB_SIGNAL_REALTIME_65 + offset);
1789 }
1790
1791 return GDB_SIGNAL_UNKNOWN;
1792}
1793
1794/* Implement the "gdb_signal_to_target" gdbarch method. */
1795
1796static int
1798 enum gdb_signal signal)
1799{
1800 switch (signal)
1801 {
1802 case GDB_SIGNAL_0:
1803 return 0;
1804
1805 case GDB_SIGNAL_HUP:
1806 return FREEBSD_SIGHUP;
1807
1808 case GDB_SIGNAL_INT:
1809 return FREEBSD_SIGINT;
1810
1811 case GDB_SIGNAL_QUIT:
1812 return FREEBSD_SIGQUIT;
1813
1814 case GDB_SIGNAL_ILL:
1815 return FREEBSD_SIGILL;
1816
1817 case GDB_SIGNAL_TRAP:
1818 return FREEBSD_SIGTRAP;
1819
1820 case GDB_SIGNAL_ABRT:
1821 return FREEBSD_SIGABRT;
1822
1823 case GDB_SIGNAL_EMT:
1824 return FREEBSD_SIGEMT;
1825
1826 case GDB_SIGNAL_FPE:
1827 return FREEBSD_SIGFPE;
1828
1829 case GDB_SIGNAL_KILL:
1830 return FREEBSD_SIGKILL;
1831
1832 case GDB_SIGNAL_BUS:
1833 return FREEBSD_SIGBUS;
1834
1835 case GDB_SIGNAL_SEGV:
1836 return FREEBSD_SIGSEGV;
1837
1838 case GDB_SIGNAL_SYS:
1839 return FREEBSD_SIGSYS;
1840
1841 case GDB_SIGNAL_PIPE:
1842 return FREEBSD_SIGPIPE;
1843
1844 case GDB_SIGNAL_ALRM:
1845 return FREEBSD_SIGALRM;
1846
1847 case GDB_SIGNAL_TERM:
1848 return FREEBSD_SIGTERM;
1849
1850 case GDB_SIGNAL_URG:
1851 return FREEBSD_SIGURG;
1852
1853 case GDB_SIGNAL_STOP:
1854 return FREEBSD_SIGSTOP;
1855
1856 case GDB_SIGNAL_TSTP:
1857 return FREEBSD_SIGTSTP;
1858
1859 case GDB_SIGNAL_CONT:
1860 return FREEBSD_SIGCONT;
1861
1862 case GDB_SIGNAL_CHLD:
1863 return FREEBSD_SIGCHLD;
1864
1865 case GDB_SIGNAL_TTIN:
1866 return FREEBSD_SIGTTIN;
1867
1868 case GDB_SIGNAL_TTOU:
1869 return FREEBSD_SIGTTOU;
1870
1871 case GDB_SIGNAL_IO:
1872 return FREEBSD_SIGIO;
1873
1874 case GDB_SIGNAL_XCPU:
1875 return FREEBSD_SIGXCPU;
1876
1877 case GDB_SIGNAL_XFSZ:
1878 return FREEBSD_SIGXFSZ;
1879
1880 case GDB_SIGNAL_VTALRM:
1881 return FREEBSD_SIGVTALRM;
1882
1883 case GDB_SIGNAL_PROF:
1884 return FREEBSD_SIGPROF;
1885
1886 case GDB_SIGNAL_WINCH:
1887 return FREEBSD_SIGWINCH;
1888
1889 case GDB_SIGNAL_INFO:
1890 return FREEBSD_SIGINFO;
1891
1892 case GDB_SIGNAL_USR1:
1893 return FREEBSD_SIGUSR1;
1894
1895 case GDB_SIGNAL_USR2:
1896 return FREEBSD_SIGUSR2;
1897
1898 case GDB_SIGNAL_LWP:
1899 return FREEBSD_SIGTHR;
1900
1901 case GDB_SIGNAL_LIBRT:
1902 return FREEBSD_SIGLIBRT;
1903 }
1904
1905 if (signal >= GDB_SIGNAL_REALTIME_65
1906 && signal <= GDB_SIGNAL_REALTIME_126)
1907 {
1908 int offset = signal - GDB_SIGNAL_REALTIME_65;
1909
1910 return FREEBSD_SIGRTMIN + offset;
1911 }
1912
1913 return -1;
1914}
1915
1916/* Implement the "get_syscall_number" gdbarch method. */
1917
1918static LONGEST
1920{
1921
1922 /* FreeBSD doesn't use gdbarch_get_syscall_number since FreeBSD
1923 native targets fetch the system call number from the
1924 'pl_syscall_code' member of struct ptrace_lwpinfo in fbsd_wait.
1925 However, system call catching requires this function to be
1926 set. */
1927
1928 internal_error (_("fbsd_get_sycall_number called"));
1929}
1930
1931/* Read an integer symbol value from the current target. */
1932
1933static LONGEST
1935{
1937 if (ms.minsym == NULL)
1938 error (_("Unable to resolve symbol '%s'"), name);
1939
1940 gdb_byte buf[4];
1941 if (target_read_memory (ms.value_address (), buf, sizeof buf) != 0)
1942 error (_("Unable to read value of '%s'"), name);
1943
1945}
1946
1947/* Lookup offsets of fields in the runtime linker's 'Obj_Entry'
1948 structure needed to determine the TLS index of an object file. */
1949
1950static void
1952{
1953 try
1954 {
1955 /* Fetch offsets from debug symbols in rtld. */
1956 struct symbol *obj_entry_sym
1957 = lookup_symbol_in_language ("Struct_Obj_Entry", NULL, STRUCT_DOMAIN,
1958 language_c, NULL).symbol;
1959 if (obj_entry_sym == NULL)
1960 error (_("Unable to find Struct_Obj_Entry symbol"));
1961 data->off_linkmap = lookup_struct_elt (obj_entry_sym->type (),
1962 "linkmap", 0).offset / 8;
1963 data->off_tlsindex = lookup_struct_elt (obj_entry_sym->type (),
1964 "tlsindex", 0).offset / 8;
1965 data->rtld_offsets_valid = true;
1966 return;
1967 }
1968 catch (const gdb_exception_error &e)
1969 {
1970 data->off_linkmap = -1;
1971 }
1972
1973 try
1974 {
1975 /* Fetch offsets from global variables in libthr. Note that
1976 this does not work for single-threaded processes that are not
1977 linked against libthr. */
1978 data->off_linkmap = fbsd_read_integer_by_name (gdbarch,
1979 "_thread_off_linkmap");
1980 data->off_tlsindex = fbsd_read_integer_by_name (gdbarch,
1981 "_thread_off_tlsindex");
1982 data->rtld_offsets_valid = true;
1983 return;
1984 }
1985 catch (const gdb_exception_error &e)
1986 {
1987 data->off_linkmap = -1;
1988 }
1989}
1990
1991/* Helper function to read the TLS index of an object file associated
1992 with a link map entry at LM_ADDR. */
1993
1994static LONGEST
1996{
1998
1999 if (!data->rtld_offsets_valid)
2001
2002 if (data->off_linkmap == -1)
2003 throw_error (TLS_GENERIC_ERROR,
2004 _("Cannot fetch runtime linker structure offsets"));
2005
2006 /* Simulate container_of to convert from LM_ADDR to the Obj_Entry
2007 pointer and then compute the offset of the tlsindex member. */
2008 CORE_ADDR tlsindex_addr = lm_addr - data->off_linkmap + data->off_tlsindex;
2009
2010 gdb_byte buf[4];
2011 if (target_read_memory (tlsindex_addr, buf, sizeof buf) != 0)
2012 throw_error (TLS_GENERIC_ERROR,
2013 _("Cannot find thread-local variables on this target"));
2014
2016}
2017
2018/* See fbsd-tdep.h. */
2019
2020CORE_ADDR
2021fbsd_get_thread_local_address (struct gdbarch *gdbarch, CORE_ADDR dtv_addr,
2022 CORE_ADDR lm_addr, CORE_ADDR offset)
2023{
2024 LONGEST tls_index = fbsd_get_tls_index (gdbarch, lm_addr);
2025
2026 gdb_byte buf[gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT];
2027 if (target_read_memory (dtv_addr, buf, sizeof buf) != 0)
2028 throw_error (TLS_GENERIC_ERROR,
2029 _("Cannot find thread-local variables on this target"));
2030
2031 const struct builtin_type *builtin = builtin_type (gdbarch);
2032 CORE_ADDR addr = gdbarch_pointer_to_address (gdbarch,
2033 builtin->builtin_data_ptr, buf);
2034
2035 addr += (tls_index + 1) * builtin->builtin_data_ptr->length ();
2036 if (target_read_memory (addr, buf, sizeof buf) != 0)
2037 throw_error (TLS_GENERIC_ERROR,
2038 _("Cannot find thread-local variables on this target"));
2039
2040 addr = gdbarch_pointer_to_address (gdbarch, builtin->builtin_data_ptr, buf);
2041 return addr + offset;
2042}
2043
2044/* See fbsd-tdep.h. */
2045
2046CORE_ADDR
2048{
2049 struct bound_minimal_symbol msym = lookup_bound_minimal_symbol ("_rtld_bind");
2050 if (msym.minsym != nullptr && msym.value_address () == pc)
2052
2053 return 0;
2054}
2055
2056/* Return description of signal code or nullptr. */
2057
2058static const char *
2059fbsd_signal_cause (enum gdb_signal siggnal, int code)
2060{
2061 /* Signal-independent causes. */
2062 switch (code)
2063 {
2064 case FBSD_SI_USER:
2065 return _("Sent by kill()");
2066 case FBSD_SI_QUEUE:
2067 return _("Sent by sigqueue()");
2068 case FBSD_SI_TIMER:
2069 return _("Timer expired");
2070 case FBSD_SI_ASYNCIO:
2071 return _("Asynchronous I/O request completed");
2072 case FBSD_SI_MESGQ:
2073 return _("Message arrived on empty message queue");
2074 case FBSD_SI_KERNEL:
2075 return _("Sent by kernel");
2076 case FBSD_SI_LWP:
2077 return _("Sent by thr_kill()");
2078 }
2079
2080 switch (siggnal)
2081 {
2082 case GDB_SIGNAL_ILL:
2083 switch (code)
2084 {
2085 case FBSD_ILL_ILLOPC:
2086 return _("Illegal opcode");
2087 case FBSD_ILL_ILLOPN:
2088 return _("Illegal operand");
2089 case FBSD_ILL_ILLADR:
2090 return _("Illegal addressing mode");
2091 case FBSD_ILL_ILLTRP:
2092 return _("Illegal trap");
2093 case FBSD_ILL_PRVOPC:
2094 return _("Privileged opcode");
2095 case FBSD_ILL_PRVREG:
2096 return _("Privileged register");
2097 case FBSD_ILL_COPROC:
2098 return _("Coprocessor error");
2099 case FBSD_ILL_BADSTK:
2100 return _("Internal stack error");
2101 }
2102 break;
2103 case GDB_SIGNAL_BUS:
2104 switch (code)
2105 {
2106 case FBSD_BUS_ADRALN:
2107 return _("Invalid address alignment");
2108 case FBSD_BUS_ADRERR:
2109 return _("Address not present");
2110 case FBSD_BUS_OBJERR:
2111 return _("Object-specific hardware error");
2112 case FBSD_BUS_OOMERR:
2113 return _("Out of memory");
2114 }
2115 break;
2116 case GDB_SIGNAL_SEGV:
2117 switch (code)
2118 {
2119 case FBSD_SEGV_MAPERR:
2120 return _("Address not mapped to object");
2121 case FBSD_SEGV_ACCERR:
2122 return _("Invalid permissions for mapped object");
2123 case FBSD_SEGV_PKUERR:
2124 return _("PKU violation");
2125 }
2126 break;
2127 case GDB_SIGNAL_FPE:
2128 switch (code)
2129 {
2130 case FBSD_FPE_INTOVF:
2131 return _("Integer overflow");
2132 case FBSD_FPE_INTDIV:
2133 return _("Integer divide by zero");
2134 case FBSD_FPE_FLTDIV:
2135 return _("Floating point divide by zero");
2136 case FBSD_FPE_FLTOVF:
2137 return _("Floating point overflow");
2138 case FBSD_FPE_FLTUND:
2139 return _("Floating point underflow");
2140 case FBSD_FPE_FLTRES:
2141 return _("Floating point inexact result");
2142 case FBSD_FPE_FLTINV:
2143 return _("Invalid floating point operation");
2144 case FBSD_FPE_FLTSUB:
2145 return _("Subscript out of range");
2146 }
2147 break;
2148 case GDB_SIGNAL_TRAP:
2149 switch (code)
2150 {
2151 case FBSD_TRAP_BRKPT:
2152 return _("Breakpoint");
2153 case FBSD_TRAP_TRACE:
2154 return _("Trace trap");
2155 case FBSD_TRAP_DTRACE:
2156 return _("DTrace-induced trap");
2157 case FBSD_TRAP_CAP:
2158 return _("Capability violation");
2159 }
2160 break;
2161 case GDB_SIGNAL_CHLD:
2162 switch (code)
2163 {
2164 case FBSD_CLD_EXITED:
2165 return _("Child has exited");
2166 case FBSD_CLD_KILLED:
2167 return _("Child has terminated abnormally");
2168 case FBSD_CLD_DUMPED:
2169 return _("Child has dumped core");
2170 case FBSD_CLD_TRAPPED:
2171 return _("Traced child has trapped");
2172 case FBSD_CLD_STOPPED:
2173 return _("Child has stopped");
2174 case FBSD_CLD_CONTINUED:
2175 return _("Stopped child has continued");
2176 }
2177 break;
2178 case GDB_SIGNAL_POLL:
2179 switch (code)
2180 {
2181 case FBSD_POLL_IN:
2182 return _("Data input available");
2183 case FBSD_POLL_OUT:
2184 return _("Output buffers available");
2185 case FBSD_POLL_MSG:
2186 return _("Input message available");
2187 case FBSD_POLL_ERR:
2188 return _("I/O error");
2189 case FBSD_POLL_PRI:
2190 return _("High priority input available");
2191 case FBSD_POLL_HUP:
2192 return _("Device disconnected");
2193 }
2194 break;
2195 }
2196
2197 return nullptr;
2198}
2199
2200/* Report additional details for a signal stop. */
2201
2202static void
2204 enum gdb_signal siggnal)
2205{
2206 LONGEST code, mqd, pid, status, timerid, uid;
2207
2208 try
2209 {
2210 code = parse_and_eval_long ("$_siginfo.si_code");
2211 pid = parse_and_eval_long ("$_siginfo.si_pid");
2212 uid = parse_and_eval_long ("$_siginfo.si_uid");
2213 status = parse_and_eval_long ("$_siginfo.si_status");
2214 timerid = parse_and_eval_long ("$_siginfo._reason._timer.si_timerid");
2215 mqd = parse_and_eval_long ("$_siginfo._reason._mesgq.si_mqd");
2216 }
2217 catch (const gdb_exception_error &e)
2218 {
2219 return;
2220 }
2221
2222 const char *meaning = fbsd_signal_cause (siggnal, code);
2223 if (meaning == nullptr)
2224 return;
2225
2226 uiout->text (".\n");
2227 uiout->field_string ("sigcode-meaning", meaning);
2228
2229 switch (code)
2230 {
2231 case FBSD_SI_USER:
2232 case FBSD_SI_QUEUE:
2233 case FBSD_SI_LWP:
2234 uiout->text (" from pid ");
2235 uiout->field_string ("sending-pid", plongest (pid));
2236 uiout->text (" and user ");
2237 uiout->field_string ("sending-uid", plongest (uid));
2238 return;
2239 case FBSD_SI_TIMER:
2240 uiout->text (": timerid ");
2241 uiout->field_string ("timerid", plongest (timerid));
2242 return;
2243 case FBSD_SI_MESGQ:
2244 uiout->text (": message queue ");
2245 uiout->field_string ("message-queue", plongest (mqd));
2246 return;
2247 case FBSD_SI_ASYNCIO:
2248 return;
2249 }
2250
2251 if (siggnal == GDB_SIGNAL_CHLD)
2252 {
2253 uiout->text (": pid ");
2254 uiout->field_string ("child-pid", plongest (pid));
2255 uiout->text (", uid ");
2256 uiout->field_string ("child-uid", plongest (uid));
2257 if (code == FBSD_CLD_EXITED)
2258 {
2259 uiout->text (", exit status ");
2260 uiout->field_string ("exit-status", plongest (status));
2261 }
2262 else
2263 {
2264 uiout->text (", signal ");
2265 uiout->field_string ("signal", plongest (status));
2266 }
2267 }
2268}
2269
2270/* Search a list of struct kinfo_vmmap entries in the ENTRIES buffer
2271 of LEN bytes to find the length of the entry starting at ADDR.
2272 Returns the length of the entry or zero if no entry was found. */
2273
2274static ULONGEST
2275fbsd_vmmap_length (struct gdbarch *gdbarch, unsigned char *entries, size_t len,
2276 CORE_ADDR addr)
2277{
2278 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
2279 unsigned char *descdata = entries;
2280 unsigned char *descend = descdata + len;
2281
2282 /* Skip over the structure size. */
2283 descdata += 4;
2284
2285 while (descdata + KVE_PATH < descend)
2286 {
2287 ULONGEST structsize = extract_unsigned_integer (descdata
2288 + KVE_STRUCTSIZE, 4,
2289 byte_order);
2290 if (structsize < KVE_PATH)
2291 return false;
2292
2293 ULONGEST start = extract_unsigned_integer (descdata + KVE_START, 8,
2294 byte_order);
2295 ULONGEST end = extract_unsigned_integer (descdata + KVE_END, 8,
2296 byte_order);
2297 if (start == addr)
2298 return end - start;
2299
2300 descdata += structsize;
2301 }
2302 return 0;
2303}
2304
2305/* Helper for fbsd_vsyscall_range that does the real work of finding
2306 the vDSO's address range. */
2307
2308static bool
2310{
2311 if (target_auxv_search (AT_FREEBSD_KPRELOAD, &range->start) <= 0)
2312 return false;
2313
2314 if (!target_has_execution ())
2315 {
2316 /* Search for the ending address in the NT_PROCSTAT_VMMAP note. */
2317 asection *section = bfd_get_section_by_name (core_bfd,
2318 ".note.freebsdcore.vmmap");
2319 if (section == nullptr)
2320 return false;
2321
2322 size_t note_size = bfd_section_size (section);
2323 if (note_size < 4)
2324 return false;
2325
2326 gdb::def_vector<unsigned char> contents (note_size);
2327 if (!bfd_get_section_contents (core_bfd, section, contents.data (),
2328 0, note_size))
2329 return false;
2330
2331 range->length = fbsd_vmmap_length (gdbarch, contents.data (), note_size,
2332 range->start);
2333 }
2334 else
2335 {
2336 /* Fetch the list of address space entries from the running target. */
2337 gdb::optional<gdb::byte_vector> buf =
2338 target_read_alloc (current_inferior ()->top_target (),
2340 if (!buf || buf->empty ())
2341 return false;
2342
2343 range->length = fbsd_vmmap_length (gdbarch, buf->data (), buf->size (),
2344 range->start);
2345 }
2346 return range->length != 0;
2347}
2348
2349/* Return the address range of the vDSO for the current inferior. */
2350
2351static int
2353{
2355
2356 if (data->vdso_range_p == 0)
2357 {
2358 if (fbsd_vdso_range (gdbarch, &data->vdso_range))
2359 data->vdso_range_p = 1;
2360 else
2361 data->vdso_range_p = -1;
2362 }
2363
2364 if (data->vdso_range_p < 0)
2365 return 0;
2366
2367 *range = data->vdso_range;
2368 return 1;
2369}
2370
2371/* To be called from GDB_OSABI_FREEBSD handlers. */
2372
2373void
2375{
2388
2389 /* `catch syscall' */
2390 set_xml_syscall_file_name (gdbarch, "syscalls/freebsd.xml");
2392}
const char *const name
int code
Definition ada-lex.l:688
int target_auxv_search(const gdb::byte_vector &auxv, target_ops *ops, gdbarch *gdbarch, CORE_ADDR match, CORE_ADDR *valp)
Definition auxv.c:383
void fprint_auxv_entry(struct ui_file *file, const char *name, const char *description, enum auxv_format format, CORE_ADDR type, CORE_ADDR val)
Definition auxv.c:425
void default_print_auxv_entry(struct gdbarch *gdbarch, struct ui_file *file, CORE_ADDR type, CORE_ADDR val)
Definition auxv.c:457
auxv_format
Definition auxv.h:75
@ AUXV_FORMAT_DEC
Definition auxv.h:75
@ AUXV_FORMAT_STR
Definition auxv.h:75
@ AUXV_FORMAT_HEX
Definition auxv.h:75
const std::string & args() const
Definition inferior.h:498
inf_non_exited_threads_range non_exited_threads()
Definition inferior.h:451
void * get(unsigned key)
Definition registry.h:211
ptid_t ptid
Definition gdbthread.h:256
gdb_signal stop_signal() const
Definition gdbthread.h:421
const char * c_str() const
Definition gdbcore.h:194
void field_string(const char *fldname, const char *string, const ui_file_style &style=ui_file_style())
Definition ui-out.c:511
void text(const char *string)
Definition ui-out.c:566
const char * get_exec_file(int err)
Definition corefile.c:149
info_proc_what
Definition defs.h:381
@ IP_CMDLINE
Definition defs.h:395
@ IP_EXE
Definition defs.h:398
@ IP_ALL
Definition defs.h:407
@ IP_FILES
Definition defs.h:404
@ IP_MAPPINGS
Definition defs.h:386
@ IP_STATUS
Definition defs.h:389
@ IP_MINIMAL
Definition defs.h:383
@ IP_CWD
Definition defs.h:401
@ IP_STAT
Definition defs.h:392
@ language_c
Definition defs.h:214
static LONGEST extract_signed_integer(gdb::array_view< const gdb_byte > buf, enum bfd_endian byte_order)
Definition defs.h:511
static ULONGEST extract_unsigned_integer(gdb::array_view< const gdb_byte > buf, enum bfd_endian byte_order)
Definition defs.h:526
LONGEST parse_and_eval_long(const char *exp)
Definition eval.c:62
void exception_print(struct ui_file *file, const struct gdb_exception &e)
Definition exceptions.c:105
#define KINFO_FILE_TYPE_PROCDESC
Definition fbsd-tdep.c:229
#define FBSD_ILL_PRVOPC
Definition fbsd-tdep.c:93
#define KF_OFFSET
Definition fbsd-tdep.c:207
static void fbsd_fetch_rtld_offsets(struct gdbarch *gdbarch, struct fbsd_pspace_data *data)
Definition fbsd-tdep.c:1951
#define FBSD_FPE_FLTINV
Definition fbsd-tdep.c:113
#define LWPINFO32_PL_SIGINFO
Definition fbsd-tdep.c:148
#define FBSD_CLD_EXITED
Definition fbsd-tdep.c:121
#define KINFO_VME_FLAG_SUPER
Definition fbsd-tdep.c:189
#define FBSD_TRAP_BRKPT
Definition fbsd-tdep.c:116
#define FBSD_ILL_ILLTRP
Definition fbsd-tdep.c:92
#define FBSD_ILL_COPROC
Definition fbsd-tdep.c:95
#define FBSD_SI_LWP
Definition fbsd-tdep.c:87
#define KINFO_VME_PROT_EXEC
Definition fbsd-tdep.c:181
static const char * fbsd_vm_map_entry_flags(int kve_flags, int kve_protection)
Definition fbsd-tdep.c:1075
#define KF_SOCK_TYPE
Definition fbsd-tdep.c:210
#define FBSD_POLL_HUP
Definition fbsd-tdep.c:133
#define KVE_PROTECTION
Definition fbsd-tdep.c:173
#define FBSD_SI_KERNEL
Definition fbsd-tdep.c:86
static void fbsd_core_info_proc(struct gdbarch *gdbarch, const char *args, enum info_proc_what what)
Definition fbsd-tdep.c:1432
const struct kinfo_proc_layout kinfo_proc_layout_i386
Definition fbsd-tdep.c:413
#define FBSD_POLL_MSG
Definition fbsd-tdep.c:130
#define FBSD_ILL_PRVREG
Definition fbsd-tdep.c:94
#define KINFO_VME_FLAG_GROWS_UP
Definition fbsd-tdep.c:190
static void fbsd_core_info_proc_status(struct gdbarch *gdbarch)
Definition fbsd-tdep.c:1282
#define FBSD_TRAP_TRACE
Definition fbsd-tdep.c:117
#define KVE_START
Definition fbsd-tdep.c:169
static struct type * fbsd_get_siginfo_type(struct gdbarch *gdbarch)
Definition fbsd-tdep.c:1584
#define KF_STRUCTSIZE
Definition fbsd-tdep.c:203
#define KINFO_FILE_VTYPE_VFIFO
Definition fbsd-tdep.c:262
#define KINFO_FILE_TYPE_SOCKET
Definition fbsd-tdep.c:220
const struct kinfo_proc_layout kinfo_proc_layout_32
Definition fbsd-tdep.c:376
static const char * fbsd_file_flags(int kf_flags)
Definition fbsd-tdep.c:867
CORE_ADDR fbsd_get_thread_local_address(struct gdbarch *gdbarch, CORE_ADDR dtv_addr, CORE_ADDR lm_addr, CORE_ADDR offset)
Definition fbsd-tdep.c:2021
static void fbsd_core_info_proc_mappings(struct gdbarch *gdbarch)
Definition fbsd-tdep.c:1148
#define KINFO_FILE_FD_TYPE_TRACE
Definition fbsd-tdep.c:237
#define FBSD_ILL_ILLOPC
Definition fbsd-tdep.c:89
static LONGEST fbsd_get_syscall_number(struct gdbarch *gdbarch, thread_info *thread)
Definition fbsd-tdep.c:1919
#define KINFO_FILE_FLAG_FSYNC
Definition fbsd-tdep.c:248
#define SIG_WORDS
Definition fbsd-tdep.c:319
#define FBSD_ILL_ILLOPN
Definition fbsd-tdep.c:90
#define KINFO_FILE_VTYPE_VLNK
Definition fbsd-tdep.c:260
#define FBSD_POLL_OUT
Definition fbsd-tdep.c:129
#define FBSD_BUS_OOMERR
Definition fbsd-tdep.c:101
static gdb::unique_xmalloc_ptr< char > fbsd_core_vnode_path(struct gdbarch *gdbarch, int fd)
Definition fbsd-tdep.c:1199
void fbsd_info_proc_files_entry(int kf_type, int kf_fd, int kf_flags, LONGEST kf_offset, int kf_vnode_type, int kf_sock_domain, int kf_sock_type, int kf_sock_protocol, const void *kf_sa_local, const void *kf_sa_peer, const void *kf_path)
Definition fbsd-tdep.c:953
static gdb::unique_xmalloc_ptr< char > fbsd_make_corefile_notes(struct gdbarch *gdbarch, bfd *obfd, int *note_size)
Definition fbsd-tdep.c:674
#define FBSD_SI_ASYNCIO
Definition fbsd-tdep.c:84
#define FBSD_FPE_FLTSUB
Definition fbsd-tdep.c:114
#define FBSD_POLL_IN
Definition fbsd-tdep.c:128
#define FBSD_SOCK_DGRAM
Definition fbsd-tdep.c:275
#define FBSD_SOCK_SEQPACKET
Definition fbsd-tdep.c:276
#define KF_SA_PEER
Definition fbsd-tdep.c:213
#define FBSD_SOCK_STREAM
Definition fbsd-tdep.c:274
CORE_ADDR fbsd_skip_solib_resolver(struct gdbarch *gdbarch, CORE_ADDR pc)
Definition fbsd-tdep.c:2047
static LONGEST fbsd_read_integer_by_name(struct gdbarch *gdbarch, const char *name)
Definition fbsd-tdep.c:1934
#define FBSD_AF_INET
Definition fbsd-tdep.c:268
#define KINFO_FILE_FD_TYPE_TEXT
Definition fbsd-tdep.c:238
#define KF_FLAGS
Definition fbsd-tdep.c:206
#define FBSD_FPE_FLTDIV
Definition fbsd-tdep.c:109
#define FBSD_POLL_ERR
Definition fbsd-tdep.c:131
static const char * fbsd_signal_cause(enum gdb_signal siggnal, int code)
Definition fbsd-tdep.c:2059
#define KINFO_FILE_TYPE_PIPE
Definition fbsd-tdep.c:221
#define TAG(tag, text, kind)
#define KINFO_FILE_VTYPE_VCHR
Definition fbsd-tdep.c:259
#define FBSD_FPE_FLTUND
Definition fbsd-tdep.c:111
#define SIZE64_SIGINFO_T
Definition fbsd-tdep.c:154
static const char * fbsd_core_thread_name(struct gdbarch *gdbarch, struct thread_info *thr)
Definition fbsd-tdep.c:550
static LONGEST fbsd_get_tls_index(struct gdbarch *gdbarch, CORE_ADDR lm_addr)
Definition fbsd-tdep.c:1995
#define PL_FLAG_SI
Definition fbsd-tdep.c:151
static int fbsd_gdb_signal_to_target(struct gdbarch *gdbarch, enum gdb_signal signal)
Definition fbsd-tdep.c:1797
#define KF_FD
Definition fbsd-tdep.c:205
#define KINFO_FILE_FLAG_WRITE
Definition fbsd-tdep.c:245
static enum gdb_signal fbsd_gdb_signal_from_target(struct gdbarch *gdbarch, int signal)
Definition fbsd-tdep.c:1676
#define KF_SOCK_DOMAIN
Definition fbsd-tdep.c:209
#define FBSD_IPPROTO_TCP
Definition fbsd-tdep.c:282
#define FBSD_TRAP_CAP
Definition fbsd-tdep.c:119
static void fbsd_report_signal_info(struct gdbarch *gdbarch, struct ui_out *uiout, enum gdb_signal siggnal)
Definition fbsd-tdep.c:2203
#define KF_PATH
Definition fbsd-tdep.c:214
static const char * fbsd_file_fd(int kf_fd)
Definition fbsd-tdep.c:786
static void fbsd_print_sigset(const char *descr, unsigned char *sigset)
Definition fbsd-tdep.c:1270
static ULONGEST fbsd_vmmap_length(struct gdbarch *gdbarch, unsigned char *entries, size_t len, CORE_ADDR addr)
Definition fbsd-tdep.c:2275
#define FBSD_BUS_ADRERR
Definition fbsd-tdep.c:99
#define KINFO_FILE_FLAG_ASYNC
Definition fbsd-tdep.c:247
#define KINFO_FILE_VTYPE_VSOCK
Definition fbsd-tdep.c:261
#define KINFO_FILE_FD_TYPE_JAIL
Definition fbsd-tdep.c:236
static struct fbsd_gdbarch_data * get_fbsd_gdbarch_data(struct gdbarch *gdbarch)
Definition fbsd-tdep.c:496
void fbsd_info_proc_mappings_entry(int addr_bit, ULONGEST kve_start, ULONGEST kve_end, ULONGEST kve_offset, int kve_flags, int kve_protection, const void *kve_path)
Definition fbsd-tdep.c:1118
#define KINFO_FILE_VTYPE_VREG
Definition fbsd-tdep.c:257
#define FBSD_BUS_OBJERR
Definition fbsd-tdep.c:100
#define FBSD_AF_UNIX
Definition fbsd-tdep.c:267
#define FBSD_IPPROTO_ICMP
Definition fbsd-tdep.c:281
#define KINFO_FILE_TYPE_CRYPTO
Definition fbsd-tdep.c:224
static bool fbsd_vdso_range(struct gdbarch *gdbarch, struct mem_range *range)
Definition fbsd-tdep.c:2309
#define FBSD_CLD_CONTINUED
Definition fbsd-tdep.c:126
#define KF_VNODE_TYPE
Definition fbsd-tdep.c:208
#define FBSD_SEGV_MAPERR
Definition fbsd-tdep.c:103
#define KINFO_FILE_TYPE_SEM
Definition fbsd-tdep.c:227
@ FREEBSD_SIGFPE
Definition fbsd-tdep.c:48
@ FREEBSD_SIGWINCH
Definition fbsd-tdep.c:68
@ FREEBSD_SIGTERM
Definition fbsd-tdep.c:55
@ FREEBSD_SIGTTOU
Definition fbsd-tdep.c:62
@ FREEBSD_SIGXCPU
Definition fbsd-tdep.c:64
@ FREEBSD_SIGQUIT
Definition fbsd-tdep.c:43
@ FREEBSD_SIGLIBRT
Definition fbsd-tdep.c:73
@ FREEBSD_SIGURG
Definition fbsd-tdep.c:56
@ FREEBSD_SIGINFO
Definition fbsd-tdep.c:69
@ FREEBSD_SIGPIPE
Definition fbsd-tdep.c:53
@ FREEBSD_SIGEMT
Definition fbsd-tdep.c:47
@ FREEBSD_SIGSEGV
Definition fbsd-tdep.c:51
@ FREEBSD_SIGUSR2
Definition fbsd-tdep.c:71
@ FREEBSD_SIGALRM
Definition fbsd-tdep.c:54
@ FREEBSD_SIGSTOP
Definition fbsd-tdep.c:57
@ FREEBSD_SIGKILL
Definition fbsd-tdep.c:49
@ FREEBSD_SIGRTMIN
Definition fbsd-tdep.c:74
@ FREEBSD_SIGABRT
Definition fbsd-tdep.c:46
@ FREEBSD_SIGPROF
Definition fbsd-tdep.c:67
@ FREEBSD_SIGIO
Definition fbsd-tdep.c:63
@ FREEBSD_SIGHUP
Definition fbsd-tdep.c:41
@ FREEBSD_SIGILL
Definition fbsd-tdep.c:44
@ FREEBSD_SIGBUS
Definition fbsd-tdep.c:50
@ FREEBSD_SIGVTALRM
Definition fbsd-tdep.c:66
@ FREEBSD_SIGXFSZ
Definition fbsd-tdep.c:65
@ FREEBSD_SIGTHR
Definition fbsd-tdep.c:72
@ FREEBSD_SIGCHLD
Definition fbsd-tdep.c:60
@ FREEBSD_SIGINT
Definition fbsd-tdep.c:42
@ FREEBSD_SIGTRAP
Definition fbsd-tdep.c:45
@ FREEBSD_SIGSYS
Definition fbsd-tdep.c:52
@ FREEBSD_SIGCONT
Definition fbsd-tdep.c:59
@ FREEBSD_SIGUSR1
Definition fbsd-tdep.c:70
@ FREEBSD_SIGTTIN
Definition fbsd-tdep.c:61
@ FREEBSD_SIGRTMAX
Definition fbsd-tdep.c:75
@ FREEBSD_SIGTSTP
Definition fbsd-tdep.c:58
#define FBSD_IPPROTO_UDP
Definition fbsd-tdep.c:283
#define FBSD_SI_MESGQ
Definition fbsd-tdep.c:85
#define KVE_STRUCTSIZE
Definition fbsd-tdep.c:168
static gdb::optional< gdb::byte_vector > fbsd_make_note_desc(enum target_object object, uint32_t structsize)
Definition fbsd-tdep.c:654
#define KINFO_VME_FLAG_COW
Definition fbsd-tdep.c:186
#define KINFO_FILE_TYPE_PTS
Definition fbsd-tdep.c:228
static struct fbsd_pspace_data * get_fbsd_pspace_data(struct program_space *pspace)
Definition fbsd-tdep.c:524
void fbsd_info_proc_mappings_header(int addr_bit)
Definition fbsd-tdep.c:1096
static void fbsd_core_fetch_timeval(struct gdbarch *gdbarch, unsigned char *data, LONGEST &sec, ULONGEST &usec)
Definition fbsd-tdep.c:1247
#define KINFO_FILE_FD_TYPE_CTTY
Definition fbsd-tdep.c:239
#define KINFO_FILE_FD_TYPE_CWD
Definition fbsd-tdep.c:234
#define FBSD_IPPROTO_SCTP
Definition fbsd-tdep.c:284
#define KINFO_VME_PROT_READ
Definition fbsd-tdep.c:179
const struct kinfo_proc_layout kinfo_proc_layout_64
Definition fbsd-tdep.c:450
#define KINFO_FILE_FD_TYPE_ROOT
Definition fbsd-tdep.c:235
#define FBSD_SEGV_PKUERR
Definition fbsd-tdep.c:105
#define KINFO_VME_FLAG_GROWS_DOWN
Definition fbsd-tdep.c:191
#define KVE_PATH
Definition fbsd-tdep.c:174
#define KINFO_VME_PROT_WRITE
Definition fbsd-tdep.c:180
#define FBSD_CLD_DUMPED
Definition fbsd-tdep.c:123
#define KINFO_FILE_TYPE_KQUEUE
Definition fbsd-tdep.c:223
#define KINFO_FILE_FLAG_DIRECT
Definition fbsd-tdep.c:250
void fbsd_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
Definition fbsd-tdep.c:2374
static int fbsd_vsyscall_range(struct gdbarch *gdbarch, struct mem_range *range)
Definition fbsd-tdep.c:2352
#define FBSD_SI_TIMER
Definition fbsd-tdep.c:83
#define LWPINFO_OFFSET
Definition fbsd-tdep.c:143
#define KF_TYPE
Definition fbsd-tdep.c:204
static const registry< gdbarch >::key< fbsd_gdbarch_data > fbsd_gdbarch_data_handle
Definition fbsd-tdep.c:493
#define LWPINFO_PL_FLAGS
Definition fbsd-tdep.c:146
#define FBSD_FPE_FLTRES
Definition fbsd-tdep.c:112
#define KINFO_FILE_FLAG_NONBLOCK
Definition fbsd-tdep.c:249
#define KINFO_VME_FLAG_NEEDS_COPY
Definition fbsd-tdep.c:187
#define FBSD_FPE_INTOVF
Definition fbsd-tdep.c:107
#define KVE_END
Definition fbsd-tdep.c:170
#define KINFO_FILE_FLAG_HASLOCK
Definition fbsd-tdep.c:251
#define KINFO_FILE_TYPE_VNODE
Definition fbsd-tdep.c:219
#define FBSD_ILL_BADSTK
Definition fbsd-tdep.c:96
static void fbsd_print_sockaddr_in6(const void *sockaddr)
Definition fbsd-tdep.c:928
#define KINFO_FILE_VTYPE_VDIR
Definition fbsd-tdep.c:258
#define FBSD_TRAP_DTRACE
Definition fbsd-tdep.c:118
void fbsd_info_proc_files_header()
Definition fbsd-tdep.c:943
#define FBSD_POLL_PRI
Definition fbsd-tdep.c:132
#define KINFO_FILE_FLAG_READ
Definition fbsd-tdep.c:244
#define FBSD_ILL_ILLADR
Definition fbsd-tdep.c:91
static const registry< program_space >::key< fbsd_pspace_data > fbsd_pspace_data_handle
Definition fbsd-tdep.c:521
#define KINFO_FILE_FLAG_APPEND
Definition fbsd-tdep.c:246
#define FBSD_CLD_KILLED
Definition fbsd-tdep.c:122
static void fbsd_print_sockaddr_in(const void *sockaddr)
Definition fbsd-tdep.c:913
static int find_signalled_thread(struct thread_info *info, void *data)
Definition fbsd-tdep.c:639
static void fbsd_print_auxv_entry(struct gdbarch *gdbarch, struct ui_file *file, CORE_ADDR type, CORE_ADDR val)
Definition fbsd-tdep.c:1524
#define FBSD_CLD_TRAPPED
Definition fbsd-tdep.c:124
#define FBSD_SI_QUEUE
Definition fbsd-tdep.c:82
#define KINFO_FILE_TYPE_SHM
Definition fbsd-tdep.c:226
#define FBSD_SEGV_ACCERR
Definition fbsd-tdep.c:104
#define KF_SA_LOCAL
Definition fbsd-tdep.c:212
static const char * fbsd_file_type(int kf_type, int kf_vnode_type)
Definition fbsd-tdep.c:811
#define FBSD_FPE_INTDIV
Definition fbsd-tdep.c:108
static LONGEST fbsd_core_xfer_siginfo(struct gdbarch *gdbarch, gdb_byte *readbuf, ULONGEST offset, ULONGEST len)
Definition fbsd-tdep.c:596
static const char * fbsd_ipproto(int protocol)
Definition fbsd-tdep.c:888
#define FBSD_CLD_STOPPED
Definition fbsd-tdep.c:125
#define KVE_FLAGS
Definition fbsd-tdep.c:172
#define FBSD_BUS_ADRALN
Definition fbsd-tdep.c:98
#define FBSD_SI_USER
Definition fbsd-tdep.c:81
#define FBSD_AF_INET6
Definition fbsd-tdep.c:269
#define KF_SOCK_PROTOCOL
Definition fbsd-tdep.c:211
static void fbsd_core_info_proc_files(struct gdbarch *gdbarch)
Definition fbsd-tdep.c:1018
#define KVE_OFFSET
Definition fbsd-tdep.c:171
#define LWPINFO64_PL_SIGINFO
Definition fbsd-tdep.c:147
#define SIZE32_SIGINFO_T
Definition fbsd-tdep.c:155
#define KINFO_FILE_FLAG_EXEC
Definition fbsd-tdep.c:252
#define FBSD_FPE_FLTOVF
Definition fbsd-tdep.c:110
#define KINFO_FILE_TYPE_FIFO
Definition fbsd-tdep.c:222
static std::string fbsd_core_pid_to_str(struct gdbarch *gdbarch, ptid_t ptid)
Definition fbsd-tdep.c:538
#define KINFO_FILE_TYPE_MQUEUE
Definition fbsd-tdep.c:225
CORE_ADDR frame_unwind_caller_pc(frame_info_ptr this_frame)
Definition frame.c:994
frame_info_ptr get_current_frame(void)
Definition frame.c:1615
void gcore_elf_make_tdesc_note(bfd *obfd, gdb::unique_xmalloc_ptr< char > *note_data, int *note_size)
Definition gcore-elf.c:142
void gcore_elf_build_thread_register_notes(struct gdbarch *gdbarch, struct thread_info *info, gdb_signal stop_signal, bfd *obfd, gdb::unique_xmalloc_ptr< char > *note_data, int *note_size)
Definition gcore-elf.c:128
enum bfd_endian gdbarch_byte_order(struct gdbarch *gdbarch)
Definition gdbarch.c:1370
CORE_ADDR gdbarch_pointer_to_address(struct gdbarch *gdbarch, struct type *type, const gdb_byte *buf)
Definition gdbarch.c:2514
int gdbarch_addr_bit(struct gdbarch *gdbarch)
Definition gdbarch.c:1708
bfd int * note_size
void set_gdbarch_core_info_proc(struct gdbarch *gdbarch, gdbarch_core_info_proc_ftype *core_info_proc)
void set_gdbarch_get_syscall_number(struct gdbarch *gdbarch, gdbarch_get_syscall_number_ftype *get_syscall_number)
bfd * obfd
void set_gdbarch_core_xfer_siginfo(struct gdbarch *gdbarch, gdbarch_core_xfer_siginfo_ftype *core_xfer_siginfo)
void set_gdbarch_vsyscall_range(struct gdbarch *gdbarch, gdbarch_vsyscall_range_ftype *vsyscall_range)
void set_gdbarch_get_siginfo_type(struct gdbarch *gdbarch, gdbarch_get_siginfo_type_ftype *get_siginfo_type)
int gdbarch_int_bit(struct gdbarch *gdbarch)
Definition gdbarch.c:1423
void set_gdbarch_gdb_signal_from_target(struct gdbarch *gdbarch, gdbarch_gdb_signal_from_target_ftype *gdb_signal_from_target)
void set_gdbarch_core_pid_to_str(struct gdbarch *gdbarch, gdbarch_core_pid_to_str_ftype *core_pid_to_str)
void set_gdbarch_core_thread_name(struct gdbarch *gdbarch, gdbarch_core_thread_name_ftype *core_thread_name)
void set_gdbarch_report_signal_info(struct gdbarch *gdbarch, gdbarch_report_signal_info_ftype *report_signal_info)
void set_gdbarch_gdb_signal_to_target(struct gdbarch *gdbarch, gdbarch_gdb_signal_to_target_ftype *gdb_signal_to_target)
bool gdbarch_iterate_over_regset_sections_p(struct gdbarch *gdbarch)
Definition gdbarch.c:3645
void set_gdbarch_make_corefile_notes(struct gdbarch *gdbarch, gdbarch_make_corefile_notes_ftype *make_corefile_notes)
void set_gdbarch_print_auxv_entry(struct gdbarch *gdbarch, gdbarch_print_auxv_entry_ftype *print_auxv_entry)
int gdbarch_long_bit(struct gdbarch *gdbarch)
Definition gdbarch.c:1440
int gdbarch_ptr_bit(struct gdbarch *gdbarch)
Definition gdbarch.c:1691
void set_gdbarch_skip_solib_resolver(struct gdbarch *gdbarch, gdbarch_skip_solib_resolver_ftype *skip_solib_resolver)
#define core_bfd
Definition gdbcore.h:130
void update_thread_list(void)
Definition thread.c:2037
struct thread_info * inferior_thread(void)
Definition thread.c:83
struct thread_info * iterate_over_threads(thread_callback_func, void *)
Definition thread.c:565
struct type * lookup_pointer_type(struct type *type)
Definition gdbtypes.c:402
struct_elt lookup_struct_elt(struct type *type, const char *name, int noerr)
Definition gdbtypes.c:1838
struct type * arch_composite_type(struct gdbarch *gdbarch, const char *name, enum type_code code)
Definition gdbtypes.c:5989
struct type * init_vector_type(struct type *elt_type, int n)
Definition gdbtypes.c:1540
struct type * arch_type(struct gdbarch *gdbarch, enum type_code code, int bit, const char *name)
Definition gdbtypes.c:5815
void append_composite_type_field(struct type *t, const char *name, struct type *field)
Definition gdbtypes.c:6065
struct type * arch_integer_type(struct gdbarch *gdbarch, int bit, int unsigned_p, const char *name)
Definition gdbtypes.c:5836
mach_port_t kern_return_t mach_port_t mach_msg_type_name_t msgportsPoly mach_port_t kern_return_t pid_t pid mach_port_t kern_return_t mach_port_t task mach_port_t kern_return_t int flags
Definition gnu-nat.c:1862
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t int int rusage_t pid_t pid
Definition gnu-nat.c:1792
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t int status
Definition gnu-nat.c:1791
size_t size
Definition go32-nat.c:241
ptid_t inferior_ptid
Definition infcmd.c:91
struct inferior * current_inferior(void)
Definition inferior.c:54
struct bound_minimal_symbol lookup_minimal_symbol(const char *name, const char *sfile, struct objfile *objf)
Definition minsyms.c:363
struct bound_minimal_symbol lookup_bound_minimal_symbol(const char *name)
Definition minsyms.c:481
static CORE_ADDR lm_addr(struct so_list *so)
Definition nto-tdep.c:246
struct program_space * current_program_space
Definition progspace.c:39
struct symbol * symbol
Definition symtab.h:1494
CORE_ADDR value_address() const
Definition minsyms.h:41
struct minimal_symbol * minsym
Definition minsyms.h:49
struct type * builtin_data_ptr
Definition gdbtypes.h:2303
struct type * siginfo_type
Definition fbsd-tdep.c:489
LONGEST off_tlsindex
Definition fbsd-tdep.c:508
bool rtld_offsets_valid
Definition fbsd-tdep.c:509
LONGEST off_linkmap
Definition fbsd-tdep.c:507
uint8_t sin6_family
Definition fbsd-tdep.c:302
uint8_t sin6_addr[16]
Definition fbsd-tdep.c:305
uint8_t sin6_port[2]
Definition fbsd-tdep.c:303
uint32_t sin6_scope_id
Definition fbsd-tdep.c:306
uint32_t sin6_flowinfo
Definition fbsd-tdep.c:304
uint8_t sin_port[2]
Definition fbsd-tdep.c:294
uint8_t sin_family
Definition fbsd-tdep.c:293
uint8_t sin_addr[4]
Definition fbsd-tdep.c:295
char sun_path[104]
Definition fbsd-tdep.c:313
uint8_t sun_family
Definition fbsd-tdep.c:312
Definition value.c:72
LONGEST length
Definition value.c:77
LONGEST offset
Definition gdbtypes.h:2553
struct type * type() const
Definition symtab.h:1285
ULONGEST length() const
Definition gdbtypes.h:954
void set_target_type(struct type *target_type)
Definition gdbtypes.h:1005
void set_name(const char *name)
Definition gdbtypes.h:945
void set_target_is_stub(bool target_is_stub)
Definition gdbtypes.h:1112
Definition value.c:181
struct block_symbol lookup_symbol_in_language(const char *name, const struct block *block, const domain_enum domain, enum language lang, struct field_of_this_result *is_a_field_of_this)
Definition symtab.c:1949
@ STRUCT_DOMAIN
Definition symtab.h:887
bool target_has_execution(inferior *inf)
Definition target.c:202
gdb::optional< gdb::byte_vector > target_read_alloc(struct target_ops *ops, enum target_object object, const char *annex)
Definition target.c:2298
std::string normal_pid_to_str(ptid_t ptid)
Definition target.c:3672
int target_read_memory(CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
Definition target.c:1771
target_object
Definition target.h:138
@ TARGET_OBJECT_FREEBSD_PS_STRINGS
Definition target.h:207
@ TARGET_OBJECT_AUXV
Definition target.h:157
@ TARGET_OBJECT_FREEBSD_VMMAP
Definition target.h:205
void gdb_printf(struct ui_file *stream, const char *format,...)
Definition utils.c:1865
#define gdb_stderr
Definition utils.h:193
void set_xml_syscall_file_name(struct gdbarch *gdbarch, const char *name)
Definition xml-syscall.c:50