1 # Buildsheet autogenerated by ravenadm tool -- Do not edit.
7 SDESC[standard]= GNU debugger
8 HOMEPAGE= http://www.gnu.org/software/gdb/
13 DISTFILE[1]= gdb-11.2.tar.xz:main
15 SPKGS[standard]= single
17 OPTIONS_AVAILABLE= none
18 OPTIONS_STANDARD= none
22 BUILD_DEPENDS= gmp:static:standard
23 BUILDRUN_DEPENDS= gmp:shared:standard
24 source-highlight:primary:standard
26 USES= cpe iconv gmake libtool readline pkgconfig makeinfo
27 python expat ncurses gettext
29 EXTRACT_HEAD[1]= {{TAR}} -xf
30 EXTRACT_TAIL[1]= --exclude dejagnu --exclude expect --exclude sim --exclude texinfo --exclude intl --exclude readline
32 LICENSE= GPLv3+:single
33 LICENSE_TERMS= single:{{WRKDIR}}/TERMS
34 LICENSE_FILE= GPLv3+:{{WRKSRC}}/COPYING
35 LICENSE_AWK= TERMS:"^\#include"
36 LICENSE_SOURCE= TERMS:{{WRKSRC}}/gdb/gdb.c
40 FPC_EQUIVALENT= devel/gdb
43 CONFIGURE_OUTSOURCE= yes
44 CONFIGURE_ARGS= --program-suffix=112
48 --disable-build-with-cxx
49 --with-gdb-datadir={{PREFIX}}/share/gdb112
50 {{ICONV_CONFIGURE_ARG}}
51 --with-system-readline
53 --with-libexpat-prefix={{LOCALBASE}}
54 --without-libunwind-ia64
55 --with-python={{PYTHON_CMD}}
56 --with-source-highlight
57 CONFIGURE_ENV= CONFIGURED_M4=m4
58 CONFIGURED_BISON=byacc
62 CFLAGS= -DRL_NO_COMPAT
63 -D__STDC_CONSTANT_MACROS
69 ${REINPLACE_CMD} -e 's|$$| [GDB v11.2 for ${OPSYS}]|' \
70 ${WRKSRC}/gdb/version.in
71 # remove leftover readline removed garbage
72 ${REINPLACE_CMD} -e 's|..READLINE.*user.texi||' \
73 ${WRKSRC}/gdb/doc/Makefile.in
76 ${CP} ${OPSYSDIR}/dfly-tdep.* ${WRKSRC}/gdb/
77 ${CP} ${OPSYSDIR}/dfly-nat.* ${WRKSRC}/gdb/
78 ${CP} ${OPSYSDIR}/i386* ${WRKSRC}/gdb/
79 ${CP} ${OPSYSDIR}/amd64* ${WRKSRC}/gdb/
82 ${INSTALL_PROGRAM} ${INSTALL_WRKSRC}/gdb/gdb \
83 ${STAGEDIR}${PREFIX}/bin/gdb112
84 ${INSTALL_MAN} ${WRKSRC}/gdb/doc/gdb.1 \
85 ${STAGEDIR}${MAN1PREFIX}/man/man1/gdb112.1
86 (cd ${INSTALL_WRKSRC}/gdb/data-directory ; \
87 ${SETENV} ${MAKE_ENV} ${MAKE_CMD} ${MAKE_ARGS} install-syscalls )
88 ${LN} -sf gdb112 ${STAGEDIR}${PREFIX}/bin/gdbtui112
89 ${LN} -sf gdb112 ${STAGEDIR}${PREFIX}/bin/gdb
90 (cd ${INSTALL_WRKSRC}/gdb && ${SETENV} ${MAKE_ENV} \
91 ${MAKE_CMD} ${MAKE_ARGS} install-python )
92 (cd ${INSTALL_WRKSRC}/gdb/data-directory && ${SETENV} ${MAKE_ENV} \
93 ${MAKE_CMD} ${MAKE_ARGS} install-python )
94 . for f in gdb gdb/command gdb/function gdb/printer
95 (cd ${STAGEDIR}${PREFIX}/share/gdb112/python/${f} ; ${CHMOD} 644 *.py* )
98 [FILE:284:descriptions/desc.single]
99 GDB is a source-level debugger for Ada, C, C++, Objective-C, Pascal and
100 many other languages. GDB can target (i.e., debug programs running on)
101 more than a dozen different processor architectures, and GDB itself can
102 run on most popular GNU/Linux, Unix and Microsoft Windows variants.
106 1497c36a71881b8671a9a84a0ee40faab788ca30d7ba19d8463c3cc787152e32 22039420 gdb-11.2.tar.xz
109 [FILE:831:manifests/plist.single]
114 share/gdb%%VER%%/python/gdb/
124 share/gdb%%VER%%/python/gdb/command/
133 share/gdb%%VER%%/python/gdb/function/
138 share/gdb%%VER%%/python/gdb/printer/
141 share/gdb%%VER%%/syscalls/
158 share/man/man1/gdb%%VER%%.1.gz
161 [FILE:1242:patches/patch-gdb_aarch64-linux-tdep.c]
162 --- gdb/aarch64-linux-tdep.c.orig 2022-01-16 11:21:18 UTC
163 +++ gdb/aarch64-linux-tdep.c
164 @@ -1725,13 +1725,13 @@ aarch64_linux_report_signal_info (struct
167 CORE_ADDR fault_addr = 0;
169 + long db_si_code = 0;
173 /* Sigcode tells us if the segfault is actually a memory tag
175 - si_code = parse_and_eval_long ("$_siginfo.si_code");
176 + db_si_code = parse_and_eval_long ("$_siginfo.si_code");
179 = parse_and_eval_long ("$_siginfo._sifields._sigfault.si_addr");
180 @@ -1743,7 +1743,7 @@ aarch64_linux_report_signal_info (struct
183 /* If this is not a memory tag violation, just return. */
184 - if (si_code != SEGV_MTEAERR && si_code != SEGV_MTESERR)
185 + if (db_si_code != SEGV_MTEAERR && db_si_code != SEGV_MTESERR)
189 @@ -1751,7 +1751,7 @@ aarch64_linux_report_signal_info (struct
190 uiout->field_string ("sigcode-meaning", _("Memory tag violation"));
192 /* For synchronous faults, show additional information. */
193 - if (si_code == SEGV_MTESERR)
194 + if (db_si_code == SEGV_MTESERR)
196 uiout->text (_(" while accessing address "));
197 uiout->field_core_addr ("fault-addr", gdbarch, fault_addr);
200 [FILE:1122:patches/patch-gdb_amd64-bsd-nat.c]
201 --- gdb/amd64-bsd-nat.c.orig 2022-01-16 11:21:18 UTC
202 +++ gdb/amd64-bsd-nat.c
204 #include <sys/types.h>
205 #include <sys/ptrace.h>
206 #include <machine/reg.h>
207 +#include <machine/psl.h>
209 #include "amd64-tdep.h"
210 #include "amd64-nat.h"
211 @@ -142,12 +143,25 @@ amd64bsd_store_inferior_registers (struc
212 if (regnum == -1 || amd64_native_gregset_supplies_p (gdbarch, regnum))
216 + register_t old_rflags;
219 if (gdb_ptrace (PT_GETREGS, ptid, (PTRACE_TYPE_ARG3) ®s, 0) == -1)
220 perror_with_name (_("Couldn't get registers"));
223 + old_rflags = regs.r_rflags;
225 amd64_collect_native_gregset (regcache, ®s, regnum);
228 + /* This is a workaround about the PSL_USERCHANGE posix limitation. */
229 + if ((regs.r_rflags ^ old_rflags ) & ~PSL_USERCHANGE)
231 + regs.r_rflags ^= (regs.r_rflags ^ old_rflags ) & ~PSL_USERCHANGE;
234 if (gdb_ptrace (PT_SETREGS, ptid, (PTRACE_TYPE_ARG3) ®s, 0) == -1)
235 perror_with_name (_("Couldn't write registers"));
239 [FILE:312:patches/patch-gdb_compile_compile-loc2c.c]
240 --- gdb/compile/compile-loc2c.c.orig 2022-01-16 11:21:18 UTC
241 +++ gdb/compile/compile-loc2c.c
242 @@ -674,6 +674,7 @@ do_compile_dwarf_expr_to_c (int indent,
243 uint64_t uoffset, reg;
247 print_spaces (indent - 2, stream);
248 if (info[op_ptr - base].label)
252 [FILE:850:patches/patch-gdb_completer.c]
253 X-Git-Url: https://sourceware.org/git/?p=binutils-gdb.git;a=blobdiff_plain;f=gdb%2Fcompleter.c;h=a51c16ac7f8ffce28cca7d9a4220f2d940c9f626;hp=d3900ae201443ab0a5510816e9c5589ef36b9f5b;hb=1add37b567a7dee39d99f37b37802034c3fce9c4;hpb=692e92c5af88ae509d81e484d270dd6072a41ff2
255 --- gdb/completer.c.orig
258 calling a hook instead so we eliminate the CLI dependency. */
261 -/* Needed for rl_completer_word_break_characters() and for
262 +/* Needed for rl_completer_word_break_characters and for
263 rl_filename_completion_function. */
264 #include "readline/readline.h"
266 @@ -2011,7 +2011,7 @@ gdb_completion_word_break_characters_throw ()
267 rl_basic_quote_characters = NULL;
270 - return rl_completer_word_break_characters;
271 + return (char *) rl_completer_word_break_characters;
277 [FILE:710:patches/patch-gdb_fbsd-nat.c]
278 --- gdb/fbsd-nat.c.orig 2022-01-16 11:21:18 UTC
280 @@ -1052,6 +1052,14 @@ fbsd_nat_target::resume (ptid_t ptid, in
281 /* If ptid is a specific LWP, suspend all other LWPs in the process. */
282 inferior *inf = find_inferior_ptid (this, ptid);
284 +#ifndef PT_LWP_EVENTS
285 + /* When LWP events are not supported, a new thread might already be
286 + running that has not yet reported an event when GDB wishes to
287 + only run a single thread. Force an update of the thread list
288 + to ensure that any such threads are suspended before the process
290 + fbsd_add_threads (ptid.pid ());
292 for (thread_info *tp : inf->non_exited_threads ())
297 [FILE:923:patches/patch-gdb_gdb__wchar.h]
298 diff --git gdb/gdb_wchar.h gdb/gdb_wchar.h
299 index 868fe04..1311080 100644
300 --- gdb/gdb_wchar.h.orig 2022-01-16 11:19:02 UTC
304 #if defined (HAVE_ICONV) && defined (HAVE_BTOWC) \
305 && (defined (__STDC_ISO_10646__) \
306 - || (defined (_LIBICONV_VERSION) && _LIBICONV_VERSION >= 0x108))
307 + || (!defined (LIBICONV_PLUG) && defined (_LIBICONV_VERSION) && _LIBICONV_VERSION >= 0x108))
309 typedef wchar_t gdb_wchar_t;
310 typedef wint_t gdb_wint_t;
311 @@ -82,7 +82,7 @@ typedef wint_t gdb_wint_t;
312 #define INTERMEDIATE_ENCODING intermediate_encoding ()
313 const char *intermediate_encoding (void);
315 -#elif defined (_LIBICONV_VERSION) && _LIBICONV_VERSION >= 0x108
316 +#elif !defined (LIBICONV_PLUG) && defined (_LIBICONV_VERSION) && _LIBICONV_VERSION >= 0x108
317 #define INTERMEDIATE_ENCODING "wchar_t"
319 /* This shouldn't happen, because the earlier #if should have filtered
322 [FILE:801:patches/patch-gdb_i386-fbsd-nat.c]
323 --- gdb/i386-fbsd-nat.c.orig 2022-01-16 11:19:02 UTC
324 +++ gdb/i386-fbsd-nat.c
325 @@ -43,8 +43,6 @@ public:
326 const struct target_desc *read_description () override;
329 - void resume (ptid_t, int, enum gdb_signal) override;
331 #if defined(HAVE_PT_GETDBREGS) && defined(USE_SIGTRAP_SIGINFO)
332 bool supports_stopped_by_hw_breakpoint () override;
334 @@ -52,6 +50,7 @@ public:
336 static i386_fbsd_nat_target the_i386_fbsd_nat_target;
339 /* Resume execution of the inferior process. If STEP is nonzero,
340 single-step it. If SIGNAL is nonzero, give it that signal. */
342 @@ -98,6 +97,7 @@ i386_fbsd_nat_target::resume (ptid_t pti
343 gdb_signal_to_host (signal)) == -1)
344 perror_with_name (("ptrace"));
349 /* Support for debugging kernel virtual memory images. */
352 [FILE:452:patches/patch-gdb_python_python-config.py]
353 --- gdb/python/python-config.py.orig 2022-01-16 11:19:03 UTC
354 +++ gdb/python/python-config.py
355 @@ -65,6 +65,8 @@ for opt in opt_flags:
357 elif opt in ("--libs", "--ldflags"):
358 libs = ["-lpython" + pyver + abiflags]
359 + if getvar('LDFLAGS') is not None:
360 + libs.extend(getvar('LDFLAGS').split())
361 if getvar("LIBS") is not None:
362 libs.extend(getvar("LIBS").split())
363 if getvar("SYSLIBS") is not None:
366 [FILE:245:patches/patch-gdb_s390-tdep.c]
367 --- gdb/s390-tdep.c.orig 2022-01-16 11:21:18 UTC
371 #include "inferior.h"
377 #include "features/s390-linux32.c"
378 #include "features/s390x-linux64.c"
382 [FILE:1017:patches/patch-gdb_sparc64-linux-tdep.c]
383 --- gdb/sparc64-linux-tdep.c.orig 2022-01-16 11:21:18 UTC
384 +++ gdb/sparc64-linux-tdep.c
385 @@ -129,14 +129,14 @@ sparc64_linux_report_signal_info (struct
390 + long db_si_code = 0;
394 - /* Evaluate si_code to see if the segfault is ADI related. */
395 - si_code = parse_and_eval_long ("$_siginfo.si_code\n");
396 + /* Evaluate db_si_code to see if the segfault is ADI related. */
397 + db_si_code = parse_and_eval_long ("$_siginfo.si_code\n");
399 - if (si_code >= SEGV_ACCADI && si_code <= SEGV_ADIPERR)
400 + if (db_si_code >= SEGV_ACCADI && db_si_code <= SEGV_ADIPERR)
401 addr = parse_and_eval_long ("$_siginfo._sifields._sigfault.si_addr");
403 catch (const gdb_exception &exception)
404 @@ -145,7 +145,7 @@ sparc64_linux_report_signal_info (struct
407 /* Print out ADI event based on sig_code value */
409 + switch (db_si_code)
411 case SEGV_ACCADI: /* adi not enabled */
415 [FILE:580:patches/patch-gdbsupport_common-defs.h]
416 --- gdbsupport/common-defs.h.orig 2022-01-16 11:19:03 UTC
417 +++ gdbsupport/common-defs.h
420 Must do this before including any system header, since other system
421 headers may include stdint.h/inttypes.h. */
422 +#ifndef __STDC_CONSTANT_MACROS
423 #define __STDC_CONSTANT_MACROS 1
425 +#ifndef __STDC_LIMIT_MACROS
426 #define __STDC_LIMIT_MACROS 1
428 +#ifndef __STDC_FORMAT_MACROS
429 #define __STDC_FORMAT_MACROS 1
432 /* Some distros enable _FORTIFY_SOURCE by default, which on occasion
433 has caused build failures with -Wunused-result when a patch is
436 [FILE:457:patches/patch-gnulib_import_stddef.in.h]
437 --- gnulib/import/stddef.in.h.orig 2022-01-16 11:19:03 UTC
438 +++ gnulib/import/stddef.in.h
439 @@ -107,7 +107,7 @@ typedef long max_align_t;
440 #if defined _MSC_VER && defined __cplusplus
443 -# if ! (@HAVE_MAX_ALIGN_T@ || defined _GCC_MAX_ALIGN_T)
445 # if !GNULIB_defined_max_align_t
446 /* On the x86, the maximum storage alignment of double, long, etc. is 4,
447 but GCC's C11 ABI for x86 says that max_align_t has an alignment of 8,
450 [FILE:601:patches/patch-libiberty-basename]
451 --- include/libiberty.h.orig 2022-01-16 11:21:18 UTC
452 +++ include/libiberty.h
453 @@ -109,7 +109,7 @@ extern int countargv (char * const *);
454 || defined (__FreeBSD__) || defined (__OpenBSD__) || defined (__NetBSD__) \
455 || defined (__CYGWIN__) || defined (__CYGWIN32__) || defined (__MINGW32__) \
456 || defined (__DragonFly__) || defined (HAVE_DECL_BASENAME)
457 -extern char *basename (const char *) ATTRIBUTE_RETURNS_NONNULL ATTRIBUTE_NONNULL(1);
460 /* Do not allow basename to be used if there is no prototype seen. We
461 either need to use the above prototype or have one from
464 [FILE:505:patches/patch-unified]
465 --- gdb/gdb.c.orig 2022-01-16 11:19:02 UTC
467 @@ -28,6 +28,12 @@ main (int argc, char **argv)
468 memset (&args, 0, sizeof args);
471 - args.interpreter_p = INTERP_CONSOLE;
472 + if (strncmp(basename(argv[0]), "insight", 7) == 0) {
473 + args.interpreter_p = "insight";
474 + } else if (strncmp(basename(argv[0]), "gdbtui", 6) == 0) {
475 + args.interpreter_p = INTERP_TUI;
477 + args.interpreter_p = INTERP_CONSOLE;
479 return gdb_main (&args);
483 [FILE:9620:dragonfly/amd64-dfly-nat.c]
484 /* Native-dependent code for DragonFly/amd64.
486 Copyright (C) 2003-2019 Free Software Foundation, Inc.
488 This file is part of GDB.
490 This program is free software; you can redistribute it and/or modify
491 it under the terms of the GNU General Public License as published by
492 the Free Software Foundation; either version 3 of the License, or
493 (at your option) any later version.
495 This program is distributed in the hope that it will be useful,
496 but WITHOUT ANY WARRANTY; without even the implied warranty of
497 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
498 GNU General Public License for more details.
500 You should have received a copy of the GNU General Public License
501 along with this program. If not, see <http://www.gnu.org/licenses/>. */
504 #include "inferior.h"
505 #include "regcache.h"
511 #include <sys/types.h>
512 #include <sys/procfs.h>
513 #include <sys/ptrace.h>
514 #include <sys/sysctl.h>
515 #include <sys/user.h>
516 #include <machine/reg.h>
517 #include <machine/segments.h>
519 #include "dfly-nat.h"
520 #include "amd64-tdep.h"
521 #include "amd64-nat.h"
522 #include "amd64-bsd-nat.h"
524 #include "gdbsupport/x86-xstate.h"
527 class amd64_dfly_nat_target final
528 : public amd64_bsd_nat_target<dfly_nat_target>
531 /* Add some extra features to the common *BSD/amd64 target. */
532 const struct target_desc *read_description () override;
534 #if defined(HAVE_PT_GETDBREGS) && defined(USE_SIGTRAP_SIGINFO)
535 bool supports_stopped_by_hw_breakpoint () override;
539 static amd64_dfly_nat_target the_amd64_dfly_nat_target;
541 /* Offset in `struct reg' where MEMBER is stored. */
542 #define REG_OFFSET(member) offsetof (struct reg, member)
544 /* At amd64dfly64_r_reg_offset[REGNUM] you'll find the offset in
545 `struct reg' location where the GDB register REGNUM is stored.
546 Unsupported registers are marked with `-1'. */
547 static int amd64dfly64_r_reg_offset[] =
566 REG_OFFSET (r_rflags),
576 /* Mapping between the general-purpose registers in DragonFly/amd64
577 `struct reg' format and GDB's register cache layout for
580 Note that most DragonFly/amd64 registers are 64-bit, while the
581 DragonFly/x86 registers are all 32-bit, but since we're
582 little-endian we get away with that. */
584 /* From <machine/reg.h>. */
585 static int amd64dfly32_r_reg_offset[I386_NUM_GREGS] =
587 14 * 8, 13 * 8, /* %eax, %ecx */
588 12 * 8, 11 * 8, /* %edx, %ebx */
589 20 * 8, 10 * 8, /* %esp, %ebp */
590 9 * 8, 8 * 8, /* %esi, %edi */
591 17 * 8, 19 * 8, /* %eip, %eflags */
592 18 * 8, 21 * 8, /* %cs, %ss */
593 -1, -1, -1, -1 /* %ds, %es, %fs, %gs */
597 #ifdef DFLY_PCB_SUPPLY
598 /* Transfering the registers between GDB, inferiors and core files. */
600 /* Fill GDB's register array with the general-purpose register values
604 supply_gregset (struct regcache *regcache, const gregset_t *gregsetp)
606 amd64_supply_native_gregset (regcache, gregsetp, -1);
609 /* Fill register REGNUM (if it is a general-purpose register) in
610 *GREGSETPS with the value in GDB's register array. If REGNUM is -1,
611 do this for all registers. */
614 fill_gregset (const struct regcache *regcache, gdb_gregset_t *gregsetp, int regnum)
616 amd64_collect_native_gregset (regcache, gregsetp, regnum);
619 /* Fill GDB's register array with the floating-point register values
623 supply_fpregset (struct regcache *regcache, const fpregset_t *fpregsetp)
625 amd64_supply_fxsave (regcache, -1, fpregsetp);
628 /* Fill register REGNUM (if it is a floating-point register) in
629 *FPREGSETP with the value in GDB's register array. If REGNUM is -1,
630 do this for all registers. */
633 fill_fpregset (const struct regcache *regcache, gdb_fpregset_t *fpregsetp, int regnum)
635 amd64_collect_fxsave (regcache, regnum, fpregsetp);
638 /* Support for debugging kernel virtual memory images. */
640 #include <sys/types.h>
641 #include <machine/pcb.h>
642 #include <osreldate.h>
647 amd64dfly_supply_pcb (struct regcache *regcache, struct pcb *pcb)
649 /* The following is true for FreeBSD 5.2:
651 The pcb contains %rip, %rbx, %rsp, %rbp, %r12, %r13, %r14, %r15,
652 %ds, %es, %fs and %gs. This accounts for all callee-saved
653 registers specified by the psABI and then some. Here %esp
654 contains the stack pointer at the point just after the call to
655 cpu_switch(). From this information we reconstruct the register
656 state as it would like when we just returned from cpu_switch(). */
658 /* The stack pointer shouldn't be zero. */
659 if (pcb->pcb_rsp == 0)
663 regcache->raw_supply (AMD64_RIP_REGNUM, &pcb->pcb_rip);
664 regcache->raw_supply (AMD64_RBX_REGNUM, &pcb->pcb_rbx);
665 regcache->raw_supply (AMD64_RSP_REGNUM, &pcb->pcb_rsp);
666 regcache->raw_supply (AMD64_RBP_REGNUM, &pcb->pcb_rbp);
667 regcache->raw_supply (12, &pcb->pcb_r12);
668 regcache->raw_supply (13, &pcb->pcb_r13);
669 regcache->raw_supply (14, &pcb->pcb_r14);
670 regcache->raw_supply (15, &pcb->pcb_r15);
674 #endif /* DFLY_PCB_SUPPLY */
677 /* Implement the read_description method. */
679 const struct target_desc *
680 amd64_dfly_nat_target::read_description ()
682 #ifdef PT_GETXSTATE_INFO
683 static int xsave_probed;
684 static uint64_t xcr0;
689 if (ptrace (PT_GETREGS, inferior_ptid.pid (),
690 (PTRACE_TYPE_ARG3) ®s, 0) == -1)
691 perror_with_name (_("Couldn't get registers"));
692 is64 = (regs.r_cs == GSEL (GUCODE_SEL, SEL_UPL));
693 #ifdef PT_GETXSTATE_INFO
696 struct ptrace_xstate_info info;
698 if (ptrace (PT_GETXSTATE_INFO, inferior_ptid.pid (),
699 (PTRACE_TYPE_ARG3) &info, sizeof (info)) == 0)
701 x86bsd_xsave_len = info.xsave_len;
702 xcr0 = info.xsave_mask;
707 if (x86bsd_xsave_len != 0)
710 return amd64_target_description (xcr0, true);
712 return i386_target_description (xcr0, true);
716 return amd64_target_description (X86_XSTATE_SSE_MASK, true);
718 return i386_target_description (X86_XSTATE_SSE_MASK, true);
721 #if defined(HAVE_PT_GETDBREGS) && defined(USE_SIGTRAP_SIGINFO)
722 /* Implement the supports_stopped_by_hw_breakpoints method. */
725 amd64_dfly_nat_target::supports_stopped_by_hw_breakpoint ()
732 _initialize_amd64dfly_nat (void)
736 amd64_native_gregset32_reg_offset = amd64dfly32_r_reg_offset;
737 amd64_native_gregset64_reg_offset = amd64dfly64_r_reg_offset;
739 add_inf_child_target (&the_amd64_dfly_nat_target);
741 #ifdef DFLY_PCB_SUPPLY
742 /* Support debugging kernel virtual memory images. */
743 bsd_kvm_add_target (amd64dfly_supply_pcb);
746 /* To support the recognition of signal handlers, i386-bsd-tdep.c
747 hardcodes some constants. Inclusion of this file means that we
748 are compiling a native debugger, which means that we can use the
749 system header files and sysctl(3) to get at the relevant
752 #define SC_REG_OFFSET amd64dfly_sc_reg_offset
754 /* We only check the program counter, stack pointer and frame
755 pointer since these members of `struct sigcontext' are essential
756 for providing backtraces. */
758 #define SC_RIP_OFFSET SC_REG_OFFSET[AMD64_RIP_REGNUM]
759 #define SC_RSP_OFFSET SC_REG_OFFSET[AMD64_RSP_REGNUM]
760 #define SC_RBP_OFFSET SC_REG_OFFSET[AMD64_RBP_REGNUM]
762 /* Override the default value for the offset of the program counter
763 in the sigcontext structure. */
764 offset = offsetof (struct sigcontext, sc_rip);
766 if (SC_RIP_OFFSET != offset)
769 offsetof (struct sigcontext, sc_rip) yields %d instead of %d.\n\
770 Please report this to <bug-gdb@gnu.org>."),
771 offset, SC_RIP_OFFSET);
774 SC_RIP_OFFSET = offset;
776 /* Likewise for the stack pointer. */
777 offset = offsetof (struct sigcontext, sc_rsp);
779 if (SC_RSP_OFFSET != offset)
782 offsetof (struct sigcontext, sc_rsp) yields %d instead of %d.\n\
783 Please report this to <bug-gdb@gnu.org>."),
784 offset, SC_RSP_OFFSET);
787 SC_RSP_OFFSET = offset;
789 /* And the frame pointer. */
790 offset = offsetof (struct sigcontext, sc_rbp);
792 if (SC_RBP_OFFSET != offset)
795 offsetof (struct sigcontext, sc_rbp) yields %d instead of %d.\n\
796 Please report this to <bug-gdb@gnu.org>."),
797 offset, SC_RBP_OFFSET);
800 SC_RBP_OFFSET = offset;
802 #ifdef KERN_PROC_SIGTRAMP
804 struct kinfo_sigtramp kst = {0};
805 size_t len = sizeof (kst);
806 int mib[3] = { CTL_KERN, KERN_PROC, KERN_PROC_SIGTRAMP };
807 if (sysctl (mib, 3, &kst, &len, NULL, 0) == 0)
809 amd64dfly_sigtramp_start_addr = (uintptr_t) kst.ksigtramp_start;
810 amd64dfly_sigtramp_end_addr = (uintptr_t) kst.ksigtramp_end;
820 mib[1] = KERN_PS_STRINGS;
821 len = sizeof (ps_strings);
822 if (sysctl (mib, 2, &ps_strings, &len, NULL, 0) == 0)
824 amd64dfly_sigtramp_start_addr = ps_strings - 32;
825 amd64dfly_sigtramp_end_addr = ps_strings;
832 [FILE:6089:dragonfly/amd64-dfly-tdep.c]
833 /* Target-dependent code for DragonFly/amd64.
835 Copyright (C) 2003-2019 Free Software Foundation, Inc.
837 This file is part of GDB.
839 This program is free software; you can redistribute it and/or modify
840 it under the terms of the GNU General Public License as published by
841 the Free Software Foundation; either version 3 of the License, or
842 (at your option) any later version.
844 This program is distributed in the hope that it will be useful,
845 but WITHOUT ANY WARRANTY; without even the implied warranty of
846 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
847 GNU General Public License for more details.
849 You should have received a copy of the GNU General Public License
850 along with this program. If not, see <http://www.gnu.org/licenses/>. */
853 #include "arch-utils.h"
856 #include "regcache.h"
859 #include "gdbsupport/x86-xstate.h"
863 #include "amd64-tdep.h"
864 #include "dfly-tdep.h"
865 #include "solib-svr4.h"
867 /* Support for signal handlers. */
870 /* Return whether THIS_FRAME corresponds to a FreeBSD sigtramp
873 static const gdb_byte amd64fbsd_sigtramp_code[] =
875 0x48, 0x8d, 0x7c, 0x24, 0x10, /* lea SIGF_UC(%rsp),%rdi */
876 0x6a, 0x00, /* pushq $0 */
877 0x48, 0xc7, 0xc0, 0xa1, 0x01, 0x00, 0x00,
878 /* movq $SYS_sigreturn,%rax */
879 0x0f, 0x05 /* syscall */
883 amd64fbsd_sigtramp_p (struct frame_info *this_frame)
885 CORE_ADDR pc = get_frame_pc (this_frame);
886 gdb_byte buf[sizeof amd64fbsd_sigtramp_code];
888 if (!safe_frame_unwind_memory (this_frame, pc, buf, sizeof buf))
890 if (memcmp (buf, amd64fbsd_sigtramp_code, sizeof amd64fbsd_sigtramp_code)
898 /* Assuming THIS_FRAME is for a BSD sigtramp routine, return the
899 address of the associated sigcontext structure. */
902 amd64dfly_sigcontext_addr (struct frame_info *this_frame)
904 struct gdbarch *gdbarch = get_frame_arch (this_frame);
905 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
909 /* The `struct sigcontext' (which really is an `ucontext_t' on
910 DragonFly/amd64) lives at a fixed offset in the signal frame. See
911 <machine/sigframe.h>. */
912 get_frame_register (this_frame, AMD64_RSP_REGNUM, buf);
913 sp = extract_unsigned_integer (buf, 8, byte_order);
917 /* Mapping between the general-purpose registers in `struct reg'
918 format and GDB's register cache layout.
920 Note that some registers are 32-bit, but since we're little-endian
921 we get away with that. */
923 /* From <machine/reg.h>. */
924 static int amd64dfly_r_reg_offset[] =
941 14 * 8, /* ... %r15 */
943 22 * 8, /* %eflags */
952 /* Location of the signal trampoline. */
953 CORE_ADDR amd64dfly_sigtramp_start_addr = 0x7fffffffffc0ULL;
954 CORE_ADDR amd64dfly_sigtramp_end_addr = 0x7fffffffffe0ULL;
956 /* From <machine/signal.h>. */
957 int amd64dfly_sc_reg_offset[] =
959 24 + 6 * 8, /* %rax */
960 24 + 7 * 8, /* %rbx */
961 24 + 3 * 8, /* %rcx */
962 24 + 2 * 8, /* %rdx */
963 24 + 1 * 8, /* %rsi */
964 24 + 0 * 8, /* %rdi */
965 24 + 8 * 8, /* %rbp */
966 24 + 23 * 8, /* %rsp */
967 24 + 4 * 8, /* %r8 ... */
974 24 + 14 * 8, /* ... %r15 */
975 24 + 20 * 8, /* %rip */
976 24 + 22 * 8, /* %eflags */
977 24 + 21 * 8, /* %cs */
978 24 + 24 * 8, /* %ss */
985 /* From /usr/src/lib/libc/amd64/gen/_setjmp.S. */
986 static int amd64dfly_jmp_buf_reg_offset[] =
1000 4 * 8, /* %r12 ... */
1003 7 * 8, /* ... %r15 */
1008 amd64dfly_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
1010 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1012 /* Generic DragonFly support. */
1013 dfly_init_abi (info, gdbarch);
1015 /* Obviously DragonFly is BSD-based. */
1016 i386bsd_init_abi (info, gdbarch);
1018 tdep->gregset_reg_offset = amd64dfly_r_reg_offset;
1019 tdep->gregset_num_regs = ARRAY_SIZE (amd64dfly_r_reg_offset);
1020 tdep->sizeof_gregset = 25 * 8;
1022 amd64_init_abi (info, gdbarch,
1023 amd64_target_description (X86_XSTATE_SSE_MASK, true));
1026 tdep->sigtramp_p = amd64dfly_sigtramp_p;
1028 tdep->sigtramp_start = amd64dfly_sigtramp_start_addr;
1029 tdep->sigtramp_end = amd64dfly_sigtramp_end_addr;
1030 tdep->sigcontext_addr = amd64dfly_sigcontext_addr;
1031 tdep->sc_reg_offset = amd64dfly_sc_reg_offset;
1032 tdep->sc_num_regs = ARRAY_SIZE (amd64dfly_sc_reg_offset);
1035 tdep->xsave_xcr0_offset = I386_DFLY_XSAVE_XCR0_OFFSET;
1037 /* Iterate over core file register note sections. */
1038 set_gdbarch_iterate_over_regset_sections
1039 (gdbarch, amd64dfly_iterate_over_regset_sections);
1041 set_gdbarch_core_read_description (gdbarch,
1042 amd64dfly_core_read_description);
1045 /* FreeBSD uses SVR4-style shared libraries. */
1046 set_solib_svr4_fetch_link_map_offsets
1047 (gdbarch, svr4_lp64_fetch_link_map_offsets);
1049 set_gdbarch_fetch_tls_load_module_address (gdbarch,
1050 svr4_fetch_objfile_link_map);
1052 set_gdbarch_get_thread_local_address (gdbarch,
1053 amd64fbsd_get_thread_local_address);
1058 _initialize_amd64dfly_tdep (void)
1060 gdbarch_register_osabi (bfd_arch_i386, bfd_mach_x86_64,
1061 GDB_OSABI_DRAGONFLY, amd64dfly_init_abi);
1065 [FILE:4794:dragonfly/dfly-nat.c]
1066 /* Native-dependent code for DragonFly.
1068 Copyright (C) 2002-2016 Free Software Foundation, Inc.
1070 This file is part of GDB.
1072 This program is free software; you can redistribute it and/or modify
1073 it under the terms of the GNU General Public License as published by
1074 the Free Software Foundation; either version 3 of the License, or
1075 (at your option) any later version.
1077 This program is distributed in the hope that it will be useful,
1078 but WITHOUT ANY WARRANTY; without even the implied warranty of
1079 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1080 GNU General Public License for more details.
1082 You should have received a copy of the GNU General Public License
1083 along with this program. If not, see <http://www.gnu.org/licenses/>. */
1086 #include "gdbsupport/byte-vector.h"
1087 #include "gdbcore.h"
1088 #include "inferior.h"
1089 #include "regcache.h"
1091 #include "gdbarch.h"
1093 #include "gdbthread.h"
1094 #include "gdbsupport/gdb_wait.h"
1095 #include "inf-ptrace.h"
1096 #include <sys/types.h>
1097 #include <sys/procfs.h>
1098 #include <sys/ptrace.h>
1099 #include <sys/signal.h>
1100 #include <sys/sysctl.h>
1101 #include <sys/user.h>
1102 #ifdef HAVE_KINFO_GETVMMAP
1103 #include <libutil.h>
1105 #include "gdbsupport/filestuff.h"
1107 #include "elf-bfd.h"
1108 #include "dfly-nat.h"
1109 #include "dfly-tdep.h"
1113 /* Return the name of a file that can be opened to get the symbols for
1114 the child process identified by PID. */
1117 dfly_nat_target::pid_to_exec_file (int pid)
1120 static char buf[PATH_MAX];
1121 char name[PATH_MAX];
1123 #ifdef KERN_PROC_PATHNAME
1129 mib[2] = KERN_PROC_PATHNAME;
1131 buflen = sizeof buf;
1132 if (sysctl (mib, 4, buf, &buflen, NULL, 0) == 0)
1133 /* The kern.proc.pathname.<pid> sysctl returns a length of zero
1134 for processes without an associated executable such as kernel
1136 return buflen == 0 ? NULL : buf;
1139 xsnprintf (name, PATH_MAX, "/proc/%d/exe", pid);
1140 len = readlink (name, buf, PATH_MAX - 1);
1151 dfly_read_mapping (FILE *mapfile, unsigned long *start, unsigned long *end,
1154 /* FreeBSD 5.1-RELEASE uses a 256-byte buffer. */
1156 int resident, privateresident;
1160 /* As of FreeBSD 5.0-RELEASE, the layout is described in
1161 /usr/src/sys/fs/procfs/procfs_map.c. Somewhere in 5.1-CURRENT a
1162 new column was added to the procfs map. Therefore we can't use
1163 fscanf since we need to support older releases too. */
1164 if (fgets (buf, sizeof buf, mapfile) != NULL)
1165 ret = sscanf (buf, "%lx %lx %d %d %lx %s", start, end,
1166 &resident, &privateresident, &obj, protection);
1168 return (ret != 0 && ret != EOF);
1171 /* Iterate over all the memory regions in the current inferior,
1172 calling FUNC for each memory region. OBFD is passed as the last
1173 argument to FUNC. */
1176 dfly_nat_target::find_memory_regions (find_memory_region_ftype func,
1179 pid_t pid = inferior_ptid.pid ();
1180 unsigned long start, end, size;
1182 int read, write, exec;
1184 std::string mapfilename = string_printf ("/proc/%ld/map", (long) pid);
1185 gdb_file_up mapfile (fopen (mapfilename.c_str (), "r"));
1186 if (mapfile == NULL)
1187 error (_("Couldn't open %s."), mapfilename.c_str ());
1190 fprintf_filtered (gdb_stdout,
1191 "Reading memory regions from %s\n", mapfilename.c_str ());
1193 /* Now iterate until end-of-file. */
1194 while (dfly_read_mapping (mapfile.get (), &start, &end, &protection[0]))
1198 read = (strchr (protection, 'r') != 0);
1199 write = (strchr (protection, 'w') != 0);
1200 exec = (strchr (protection, 'x') != 0);
1204 fprintf_filtered (gdb_stdout,
1205 "Save segment, %ld bytes at %s (%c%c%c)\n",
1206 size, paddress (target_gdbarch (), start),
1212 /* Invoke the callback function to create the corefile segment.
1213 Pass MODIFIED as true, we do not know the real modification state. */
1214 func (start, size, read, write, exec, 1, obfd);
1222 dfly_nat_add_target (struct target_ops *t)
1224 t->to_pid_to_exec_file = dfly_pid_to_exec_file;
1225 t->to_find_memory_regions = dfly_find_memory_regions;
1226 /* XXX: thread vfork support */
1231 /* Provide a prototype to silence -Wmissing-prototypes. */
1232 extern initialize_file_ftype _initialize_dfly_nat;
1235 _initialize_dfly_nat (void)
1237 /* XXX: todo add_setshow_boolean_cmd() */
1241 [FILE:1305:dragonfly/dfly-nat.h]
1242 /* Native-dependent code for DragonFly.
1244 Copyright (C) 2004-2019 Free Software Foundation, Inc.
1246 This file is part of GDB.
1248 This program is free software; you can redistribute it and/or modify
1249 it under the terms of the GNU General Public License as published by
1250 the Free Software Foundation; either version 3 of the License, or
1251 (at your option) any later version.
1253 This program is distributed in the hope that it will be useful,
1254 but WITHOUT ANY WARRANTY; without even the implied warranty of
1255 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1256 GNU General Public License for more details.
1258 You should have received a copy of the GNU General Public License
1259 along with this program. If not, see <http://www.gnu.org/licenses/>. */
1264 #include "inf-ptrace.h"
1265 #include <sys/user.h>
1267 /* A prototype DragonFly target. */
1269 class dfly_nat_target : public inf_ptrace_target
1272 char *pid_to_exec_file (int pid) override;
1274 int find_memory_regions (find_memory_region_ftype func, void *data) override;
1279 /* Register the customized DragonFly target. This should be used
1280 instead of calling add_target directly. */
1281 extern void dfly_nat_add_target (struct target_ops *);
1284 #endif /* dfly-nat.h */
1287 [FILE:59356:dragonfly/dfly-tdep.c]
1288 /* Target-dependent code for DragonFly, architecture-independent.
1290 Copyright (C) 2002-2019 Free Software Foundation, Inc.
1292 This file is part of GDB.
1294 This program is free software; you can redistribute it and/or modify
1295 it under the terms of the GNU General Public License as published by
1296 the Free Software Foundation; either version 3 of the License, or
1297 (at your option) any later version.
1299 This program is distributed in the hope that it will be useful,
1300 but WITHOUT ANY WARRANTY; without even the implied warranty of
1301 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1302 GNU General Public License for more details.
1304 You should have received a copy of the GNU General Public License
1305 along with this program. If not, see <http://www.gnu.org/licenses/>. */
1309 #include "gdbcore.h"
1310 #include "inferior.h"
1311 #include "regcache.h"
1313 #include "gdbthread.h"
1314 #include "objfiles.h"
1315 #include "xml-syscall.h"
1316 #include <sys/socket.h>
1317 #include <arpa/inet.h>
1319 #include "elf-bfd.h"
1320 #include "dfly-tdep.h"
1322 /* This enum is derived from FreeBSD's <sys/signal.h>. */
1326 DRAGONFLY_SIGHUP = 1,
1327 DRAGONFLY_SIGINT = 2,
1328 DRAGONFLY_SIGQUIT = 3,
1329 DRAGONFLY_SIGILL = 4,
1330 DRAGONFLY_SIGTRAP = 5,
1331 DRAGONFLY_SIGABRT = 6,
1332 DRAGONFLY_SIGEMT = 7,
1333 DRAGONFLY_SIGFPE = 8,
1334 DRAGONFLY_SIGKILL = 9,
1335 DRAGONFLY_SIGBUS = 10,
1336 DRAGONFLY_SIGSEGV = 11,
1337 DRAGONFLY_SIGSYS = 12,
1338 DRAGONFLY_SIGPIPE = 13,
1339 DRAGONFLY_SIGALRM = 14,
1340 DRAGONFLY_SIGTERM = 15,
1341 DRAGONFLY_SIGURG = 16,
1342 DRAGONFLY_SIGSTOP = 17,
1343 DRAGONFLY_SIGTSTP = 18,
1344 DRAGONFLY_SIGCONT = 19,
1345 DRAGONFLY_SIGCHLD = 20,
1346 DRAGONFLY_SIGTTIN = 21,
1347 DRAGONFLY_SIGTTOU = 22,
1348 DRAGONFLY_SIGIO = 23,
1349 DRAGONFLY_SIGXCPU = 24,
1350 DRAGONFLY_SIGXFSZ = 25,
1351 DRAGONFLY_SIGVTALRM = 26,
1352 DRAGONFLY_SIGPROF = 27,
1353 DRAGONFLY_SIGWINCH = 28,
1354 DRAGONFLY_SIGINFO = 29,
1355 DRAGONFLY_SIGUSR1 = 30,
1356 DRAGONFLY_SIGUSR2 = 31,
1357 DRAGONFLY_SIGTHR = 32,
1358 DRAGONFLY_SIGCKPT = 33,
1359 DRAGONFLY_SIGCKPTEXIT = 34,
1363 /* Flags in pl_flags. */
1364 #define PL_FLAG_SI 0x20 /* siginfo is valid */
1366 /* Sizes of siginfo_t. */
1367 #define SIZE64_SIGINFO_T 80
1368 #define SIZE32_SIGINFO_T 64
1370 /* Offsets in data structure used in NT_FREEBSD_PROCSTAT_VMMAP core
1371 dump notes. See <sys/user.h> for the definition of struct
1372 kinfo_vmentry. This data structure should have the same layout on
1375 Note that FreeBSD 7.0 used an older version of this structure
1376 (struct kinfo_ovmentry), but the NT_FREEBSD_PROCSTAT_VMMAP core
1377 dump note wasn't introduced until FreeBSD 9.2. As a result, the
1378 core dump note has always used the 7.1 and later structure
1381 #define KVE_STRUCTSIZE 0x0
1382 #define KVE_START 0x8
1383 #define KVE_END 0x10
1384 #define KVE_OFFSET 0x18
1385 #define KVE_FLAGS 0x2c
1386 #define KVE_PROTECTION 0x38
1387 #define KVE_PATH 0x88
1389 /* Flags in the 'kve_protection' field in struct kinfo_vmentry. These
1390 match the KVME_PROT_* constants in <sys/user.h>. */
1392 #define KINFO_VME_PROT_READ 0x00000001
1393 #define KINFO_VME_PROT_WRITE 0x00000002
1394 #define KINFO_VME_PROT_EXEC 0x00000004
1396 /* Flags in the 'kve_flags' field in struct kinfo_vmentry. These
1397 match the KVME_FLAG_* constants in <sys/user.h>. */
1399 #define KINFO_VME_FLAG_COW 0x00000001
1400 #define KINFO_VME_FLAG_NEEDS_COPY 0x00000002
1401 #define KINFO_VME_FLAG_NOCOREDUMP 0x00000004
1402 #define KINFO_VME_FLAG_SUPER 0x00000008
1403 #define KINFO_VME_FLAG_GROWS_UP 0x00000010
1404 #define KINFO_VME_FLAG_GROWS_DOWN 0x00000020
1406 /* Offsets in data structure used in NT_FREEBSD_PROCSTAT_FILES core
1407 dump notes. See <sys/user.h> for the definition of struct
1408 kinfo_file. This data structure should have the same layout on all
1411 Note that FreeBSD 7.0 used an older version of this structure
1412 (struct kinfo_ofile), but the NT_FREEBSD_PROCSTAT_FILES core dump
1413 note wasn't introduced until FreeBSD 9.2. As a result, the core
1414 dump note has always used the 7.1 and later structure format. */
1416 #define KF_STRUCTSIZE 0x0
1419 #define KF_FLAGS 0x10
1420 #define KF_OFFSET 0x18
1421 #define KF_VNODE_TYPE 0x20
1422 #define KF_SOCK_DOMAIN 0x24
1423 #define KF_SOCK_TYPE 0x28
1424 #define KF_SOCK_PROTOCOL 0x2c
1425 #define KF_SA_LOCAL 0x30
1426 #define KF_SA_PEER 0xb0
1427 #define KF_PATH 0x170
1429 /* Constants for the 'kf_type' field in struct kinfo_file. These
1430 match the KF_TYPE_* constants in <sys/user.h>. */
1432 #define KINFO_FILE_TYPE_VNODE 1
1433 #define KINFO_FILE_TYPE_SOCKET 2
1434 #define KINFO_FILE_TYPE_PIPE 3
1435 #define KINFO_FILE_TYPE_FIFO 4
1436 #define KINFO_FILE_TYPE_KQUEUE 5
1437 #define KINFO_FILE_TYPE_CRYPTO 6
1438 #define KINFO_FILE_TYPE_MQUEUE 7
1439 #define KINFO_FILE_TYPE_SHM 8
1440 #define KINFO_FILE_TYPE_SEM 9
1441 #define KINFO_FILE_TYPE_PTS 10
1442 #define KINFO_FILE_TYPE_PROCDESC 11
1444 /* Special values for the 'kf_fd' field in struct kinfo_file. These
1445 match the KF_FD_TYPE_* constants in <sys/user.h>. */
1447 #define KINFO_FILE_FD_TYPE_CWD -1
1448 #define KINFO_FILE_FD_TYPE_ROOT -2
1449 #define KINFO_FILE_FD_TYPE_JAIL -3
1450 #define KINFO_FILE_FD_TYPE_TRACE -4
1451 #define KINFO_FILE_FD_TYPE_TEXT -5
1452 #define KINFO_FILE_FD_TYPE_CTTY -6
1454 /* Flags in the 'kf_flags' field in struct kinfo_file. These match
1455 the KF_FLAG_* constants in <sys/user.h>. */
1457 #define KINFO_FILE_FLAG_READ 0x00000001
1458 #define KINFO_FILE_FLAG_WRITE 0x00000002
1459 #define KINFO_FILE_FLAG_APPEND 0x00000004
1460 #define KINFO_FILE_FLAG_ASYNC 0x00000008
1461 #define KINFO_FILE_FLAG_FSYNC 0x00000010
1462 #define KINFO_FILE_FLAG_NONBLOCK 0x00000020
1463 #define KINFO_FILE_FLAG_DIRECT 0x00000040
1464 #define KINFO_FILE_FLAG_HASLOCK 0x00000080
1465 #define KINFO_FILE_FLAG_EXEC 0x00004000
1467 /* Constants for the 'kf_vnode_type' field in struct kinfo_file.
1468 These match the KF_VTYPE_* constants in <sys/user.h>. */
1470 #define KINFO_FILE_VTYPE_VREG 1
1471 #define KINFO_FILE_VTYPE_VDIR 2
1472 #define KINFO_FILE_VTYPE_VCHR 4
1473 #define KINFO_FILE_VTYPE_VLNK 5
1474 #define KINFO_FILE_VTYPE_VSOCK 6
1475 #define KINFO_FILE_VTYPE_VFIFO 7
1478 /* Constants for socket address families. These match AF_* constants
1479 in <sys/socket.h>. */
1481 #define DFLY_AF_UNIX 1
1482 #define DFLY_AF_INET 2
1483 #define DFLY_AF_INET6 28
1485 /* Constants for socket types. These match SOCK_* constants in
1488 #define DFLY_SOCK_STREAM 1
1489 #define DFLY_SOCK_DGRAM 2
1490 #define DFLY_SOCK_SEQPACKET 5
1492 /* Constants for IP protocols. These match IPPROTO_* constants in
1495 #define DFLY_IPPROTO_ICMP 1
1496 #define DFLY_IPPROTO_TCP 6
1497 #define DFLY_IPPROTO_UDP 17
1499 /* Socket address structures. These have the same layout on all
1500 DragonFly architectures. In addition, multibyte fields such as IP
1501 addresses are always stored in network byte order. */
1503 struct dfly_sockaddr_in
1507 uint8_t sin_port[2];
1508 uint8_t sin_addr[4];
1512 struct dfly_sockaddr_in6
1515 uint8_t sin6_family;
1516 uint8_t sin6_port[2];
1517 uint32_t sin6_flowinfo;
1518 uint8_t sin6_addr[16];
1519 uint32_t sin6_scope_id;
1522 struct dfly_sockaddr_un
1530 /* Number of 32-bit words in a signal set. This matches _SIG_WORDS in
1531 <sys/_sigset.h> and is the same value on all architectures. */
1535 /* Offsets in data structure used in NT_FREEBSD_PROCSTAT_PROC core
1536 dump notes. See <sys/user.h> for the definition of struct
1537 kinfo_proc. This data structure has different layouts on different
1538 architectures mostly due to ILP32 vs LP64. However, FreeBSD/i386
1539 uses a 32-bit time_t while all other architectures use a 64-bit
1542 The core dump note actually contains one kinfo_proc structure for
1543 each thread, but all of the process-wide data can be obtained from
1544 the first structure. One result of this note's format is that some
1545 of the process-wide status available in the native target method
1546 from the kern.proc.pid.<pid> sysctl such as ki_stat and ki_siglist
1547 is not available from a core dump. Instead, the per-thread data
1548 structures contain the value of these fields for individual
1551 struct kinfo_proc_layout
1553 /* Offsets of struct kinfo_proc members. */
1560 int ki_tdev_freebsd11;
1582 /* Offsets of struct rusage members. */
1590 const struct kinfo_proc_layout kinfo_proc_layout_64 =
1598 .ki_tdev_freebsd11 = 0x64,
1599 .ki_sigignore = 0x88,
1600 .ki_sigcatch = 0x98,
1618 .ki_rusage_ch = 0x2f0,
1628 static struct gdbarch_data *dfly_gdbarch_data_handle;
1630 struct dfly_gdbarch_data
1632 struct type *siginfo_type;
1636 init_dfly_gdbarch_data (struct gdbarch *gdbarch)
1638 return GDBARCH_OBSTACK_ZALLOC (gdbarch, struct dfly_gdbarch_data);
1641 static struct dfly_gdbarch_data *
1642 get_dfly_gdbarch_data (struct gdbarch *gdbarch)
1644 return ((struct dfly_gdbarch_data *)
1645 gdbarch_data (gdbarch, dfly_gdbarch_data_handle));
1648 /* Per-program-space data for DragonFly architectures. */
1649 static const struct program_space_data *dfly_pspace_data_handle;
1651 struct dfly_pspace_data
1653 /* Offsets in the runtime linker's 'Obj_Entry' structure. */
1654 LONGEST off_linkmap;
1655 LONGEST off_tlsindex;
1656 bool rtld_offsets_valid;
1659 static struct dfly_pspace_data *
1660 get_dfly_pspace_data (struct program_space *pspace)
1662 struct dfly_pspace_data *data;
1664 data = ((struct dfly_pspace_data *)
1665 program_space_data (pspace, dfly_pspace_data_handle));
1668 data = XCNEW (struct dfly_pspace_data);
1669 set_program_space_data (pspace, dfly_pspace_data_handle, data);
1675 /* The cleanup callback for DragonFly architecture per-program-space data. */
1678 dfly_pspace_data_cleanup (struct program_space *pspace, void *data)
1683 /* This is how we want PTIDs from core files to be printed. */
1686 dfly_core_pid_to_str (struct gdbarch *gdbarch, ptid_t ptid)
1688 static char buf[80];
1690 if (ptid.lwp () != 0)
1692 xsnprintf (buf, sizeof buf, "LWP %ld", ptid.lwp ());
1696 return normal_pid_to_str (ptid);
1699 /* Extract the name assigned to a thread from a core. Returns the
1700 string in a static buffer. */
1704 dfly_core_thread_name (struct gdbarch *gdbarch, struct thread_info *thr)
1706 static char buf[80];
1707 struct bfd_section *section;
1710 if (thr->ptid.lwp () != 0)
1712 /* FreeBSD includes a NT_FREEBSD_THRMISC note for each thread
1713 whose contents are defined by a "struct thrmisc" declared in
1714 <sys/procfs.h> on FreeBSD. The per-thread name is stored as
1715 a null-terminated string as the first member of the
1716 structure. Rather than define the full structure here, just
1717 extract the null-terminated name from the start of the
1719 thread_section_name section_name (".thrmisc", thr->ptid);
1721 section = bfd_get_section_by_name (core_bfd, section_name.c_str ());
1722 if (section != NULL && bfd_section_size (core_bfd, section) > 0)
1724 /* Truncate the name if it is longer than "buf". */
1725 size = bfd_section_size (core_bfd, section);
1726 if (size > sizeof buf - 1)
1727 size = sizeof buf - 1;
1728 if (bfd_get_section_contents (core_bfd, section, buf, (file_ptr) 0,
1734 /* Note that each thread will report the process command
1735 as its thread name instead of an empty name if a name
1736 has not been set explicitly. Return a NULL name in
1738 if (strcmp (buf, elf_tdata (core_bfd)->core->program) != 0)
1748 /* Implement the "core_xfer_siginfo" gdbarch method. */
1752 dfly_core_xfer_siginfo (struct gdbarch *gdbarch, gdb_byte *readbuf,
1753 ULONGEST offset, ULONGEST len)
1755 size_t siginfo_size;
1757 if (gdbarch_long_bit (gdbarch) == 32)
1758 siginfo_size = SIZE32_SIGINFO_T;
1760 siginfo_size = SIZE64_SIGINFO_T;
1761 if (offset > siginfo_size)
1764 thread_section_name section_name (".note.freebsdcore.lwpinfo", inferior_ptid);
1765 asection *section = bfd_get_section_by_name (core_bfd, section_name.c_str ());
1766 if (section == NULL)
1770 if (!bfd_get_section_contents (core_bfd, section, buf,
1771 LWPINFO_OFFSET + LWPINFO_PL_FLAGS, 4))
1774 int pl_flags = extract_signed_integer (buf, 4, gdbarch_byte_order (gdbarch));
1775 if (!(pl_flags & PL_FLAG_SI))
1778 if (offset + len > siginfo_size)
1779 len = siginfo_size - offset;
1781 ULONGEST siginfo_offset;
1782 if (gdbarch_long_bit (gdbarch) == 32)
1783 siginfo_offset = LWPINFO_OFFSET + LWPINFO32_PL_SIGINFO;
1785 siginfo_offset = LWPINFO_OFFSET + LWPINFO64_PL_SIGINFO;
1787 if (!bfd_get_section_contents (core_bfd, section, readbuf,
1788 siginfo_offset + offset, len))
1797 find_signalled_thread (struct thread_info *info, void *data)
1799 if (info->suspend.stop_signal != GDB_SIGNAL_0
1800 && info->ptid.pid () == inferior_ptid.pid ())
1807 /* Structure for passing information from
1808 dfly_collect_thread_registers via an iterator to
1809 dfly_collect_regset_section_cb. */
1812 struct dfly_collect_regset_section_cb_data
1814 const struct regcache *regcache;
1819 enum gdb_signal stop_signal;
1820 int abort_iteration;
1826 dfly_collect_regset_section_cb (const char *sect_name, int supply_size,
1827 int collect_size, const struct regset *regset,
1828 const char *human_name, void *cb_data)
1831 struct dfly_collect_regset_section_cb_data *data
1832 = (struct dfly_collect_regset_section_cb_data *) cb_data;
1834 if (data->abort_iteration)
1837 gdb_assert (regset->collect_regset);
1839 buf = (char *) xmalloc (collect_size);
1840 regset->collect_regset (regset, data->regcache, -1, buf, collect_size);
1842 /* PRSTATUS still needs to be treated specially. */
1843 if (strcmp (sect_name, ".reg") == 0)
1844 data->note_data = (char *) elfcore_write_prstatus
1845 (data->obfd, data->note_data, data->note_size, data->lwp,
1846 gdb_signal_to_host (data->stop_signal), buf);
1848 data->note_data = (char *) elfcore_write_register_note
1849 (data->obfd, data->note_data, data->note_size,
1850 sect_name, buf, collect_size);
1853 if (data->note_data == NULL)
1854 data->abort_iteration = 1;
1858 /* Records the thread's register state for the corefile note
1863 dfly_collect_thread_registers (const struct regcache *regcache,
1864 ptid_t ptid, bfd *obfd,
1865 char *note_data, int *note_size,
1866 enum gdb_signal stop_signal)
1868 struct gdbarch *gdbarch = regcache->arch ();
1869 struct dfly_collect_regset_section_cb_data data;
1871 data.regcache = regcache;
1873 data.note_data = note_data;
1874 data.note_size = note_size;
1875 data.stop_signal = stop_signal;
1876 data.abort_iteration = 0;
1877 data.lwp = ptid.lwp ();
1879 gdbarch_iterate_over_regset_sections (gdbarch,
1880 dfly_collect_regset_section_cb,
1882 return data.note_data;
1887 struct dfly_corefile_thread_data
1889 struct gdbarch *gdbarch;
1893 enum gdb_signal stop_signal;
1897 /* Records the thread's register state for the corefile note
1902 dfly_corefile_thread (struct thread_info *info,
1903 struct dfly_corefile_thread_data *args)
1905 struct regcache *regcache;
1907 regcache = get_thread_arch_regcache (info->ptid, args->gdbarch);
1909 target_fetch_registers (regcache, -1);
1911 args->note_data = dfly_collect_thread_registers
1912 (regcache, info->ptid, args->obfd, args->note_data,
1913 args->note_size, args->stop_signal);
1917 /* Return a byte_vector containing the contents of a core dump note
1918 for the target object of type OBJECT. If STRUCTSIZE is non-zero,
1919 the data is prefixed with a 32-bit integer size to match the format
1920 used in FreeBSD NT_PROCSTAT_* notes. */
1923 static gdb::optional<gdb::byte_vector>
1924 dfly_make_note_desc (enum target_object object, uint32_t structsize)
1926 gdb::optional<gdb::byte_vector> buf =
1927 target_read_alloc (current_top_target (), object, NULL);
1928 if (!buf || buf->empty ())
1931 if (structsize == 0)
1934 gdb::byte_vector desc (sizeof (structsize) + buf->size ());
1935 memcpy (desc.data (), &structsize, sizeof (structsize));
1936 memcpy (desc.data () + sizeof (structsize), buf->data (), buf->size ());
1941 /* Create appropriate note sections for a corefile, returning them in
1942 allocated memory. */
1946 dfly_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size)
1948 struct dfly_corefile_thread_data thread_args;
1949 char *note_data = NULL;
1950 Elf_Internal_Ehdr *i_ehdrp;
1951 struct thread_info *curr_thr, *signalled_thr;
1953 gdb_assert (gdbarch_iterate_over_regset_sections_p (gdbarch));
1955 if (get_exec_file (0))
1957 const char *fname = lbasename (get_exec_file (0));
1958 char *psargs = xstrdup (fname);
1960 if (get_inferior_args ())
1961 psargs = reconcat (psargs, psargs, " ", get_inferior_args (),
1964 note_data = elfcore_write_prpsinfo (obfd, note_data, note_size,
1968 /* Thread register information. */
1971 update_thread_list ();
1973 CATCH (e, RETURN_MASK_ERROR)
1975 exception_print (gdb_stderr, e);
1979 /* Like the kernel, prefer dumping the signalled thread first.
1980 "First thread" is what tools use to infer the signalled thread.
1981 In case there's more than one signalled thread, prefer the
1982 current thread, if it is signalled. */
1983 curr_thr = inferior_thread ();
1984 if (curr_thr->suspend.stop_signal != GDB_SIGNAL_0)
1985 signalled_thr = curr_thr;
1988 signalled_thr = iterate_over_threads (find_signalled_thread, NULL);
1989 if (signalled_thr == NULL)
1990 signalled_thr = curr_thr;
1993 thread_args.gdbarch = gdbarch;
1994 thread_args.obfd = obfd;
1995 thread_args.note_data = note_data;
1996 thread_args.note_size = note_size;
1997 thread_args.stop_signal = signalled_thr->suspend.stop_signal;
1999 dfly_corefile_thread (signalled_thr, &thread_args);
2000 for (thread_info *thr : current_inferior ()->non_exited_threads ())
2002 if (thr == signalled_thr)
2005 dfly_corefile_thread (thr, &thread_args);
2008 note_data = thread_args.note_data;
2010 /* Auxiliary vector. */
2011 uint32_t structsize = gdbarch_ptr_bit (gdbarch) / 4; /* Elf_Auxinfo */
2012 gdb::optional<gdb::byte_vector> note_desc =
2013 dfly_make_note_desc (TARGET_OBJECT_AUXV, structsize);
2014 if (note_desc && !note_desc->empty ())
2016 note_data = elfcore_write_note (obfd, note_data, note_size, "FreeBSD",
2017 NT_FREEBSD_PROCSTAT_AUXV,
2018 note_desc->data (), note_desc->size ());
2023 /* Virtual memory mappings. */
2024 note_desc = dfly_make_note_desc (TARGET_OBJECT_FREEBSD_VMMAP, 0);
2025 if (note_desc && !note_desc->empty ())
2027 note_data = elfcore_write_note (obfd, note_data, note_size, "FreeBSD",
2028 NT_FREEBSD_PROCSTAT_VMMAP,
2029 note_desc->data (), note_desc->size ());
2034 note_desc = dfly_make_note_desc (TARGET_OBJECT_FREEBSD_PS_STRINGS, 0);
2035 if (note_desc && !note_desc->empty ())
2037 note_data = elfcore_write_note (obfd, note_data, note_size, "FreeBSD",
2038 NT_FREEBSD_PROCSTAT_PSSTRINGS,
2039 note_desc->data (), note_desc->size ());
2048 /* Helper function to generate the file descriptor description for a
2049 single open file in 'info proc files'. */
2053 dfly_file_fd (int kf_fd)
2057 case KINFO_FILE_FD_TYPE_CWD:
2059 case KINFO_FILE_FD_TYPE_ROOT:
2061 case KINFO_FILE_FD_TYPE_JAIL:
2063 case KINFO_FILE_FD_TYPE_TRACE:
2065 case KINFO_FILE_FD_TYPE_TEXT:
2067 case KINFO_FILE_FD_TYPE_CTTY:
2070 return int_string (kf_fd, 10, 1, 0, 0);
2075 /* Helper function to generate the file type for a single open file in
2076 'info proc files'. */
2080 dfly_file_type (int kf_type, int kf_vnode_type)
2084 case KINFO_FILE_TYPE_VNODE:
2085 switch (kf_vnode_type)
2087 case KINFO_FILE_VTYPE_VREG:
2089 case KINFO_FILE_VTYPE_VDIR:
2091 case KINFO_FILE_VTYPE_VCHR:
2093 case KINFO_FILE_VTYPE_VLNK:
2095 case KINFO_FILE_VTYPE_VSOCK:
2097 case KINFO_FILE_VTYPE_VFIFO:
2101 char *str = get_print_cell ();
2103 xsnprintf (str, PRINT_CELL_SIZE, "vn:%d", kf_vnode_type);
2107 case KINFO_FILE_TYPE_SOCKET:
2109 case KINFO_FILE_TYPE_PIPE:
2111 case KINFO_FILE_TYPE_FIFO:
2113 case KINFO_FILE_TYPE_KQUEUE:
2115 case KINFO_FILE_TYPE_CRYPTO:
2117 case KINFO_FILE_TYPE_MQUEUE:
2119 case KINFO_FILE_TYPE_SHM:
2121 case KINFO_FILE_TYPE_SEM:
2123 case KINFO_FILE_TYPE_PTS:
2125 case KINFO_FILE_TYPE_PROCDESC:
2128 return int_string (kf_type, 10, 1, 0, 0);
2133 /* Helper function to generate the file flags for a single open file in
2134 'info proc files'. */
2138 dfly_file_flags (int kf_flags)
2140 static char file_flags[10];
2142 file_flags[0] = (kf_flags & KINFO_FILE_FLAG_READ) ? 'r' : '-';
2143 file_flags[1] = (kf_flags & KINFO_FILE_FLAG_WRITE) ? 'w' : '-';
2144 file_flags[2] = (kf_flags & KINFO_FILE_FLAG_EXEC) ? 'x' : '-';
2145 file_flags[3] = (kf_flags & KINFO_FILE_FLAG_APPEND) ? 'a' : '-';
2146 file_flags[4] = (kf_flags & KINFO_FILE_FLAG_ASYNC) ? 's' : '-';
2147 file_flags[5] = (kf_flags & KINFO_FILE_FLAG_FSYNC) ? 'f' : '-';
2148 file_flags[6] = (kf_flags & KINFO_FILE_FLAG_NONBLOCK) ? 'n' : '-';
2149 file_flags[7] = (kf_flags & KINFO_FILE_FLAG_DIRECT) ? 'd' : '-';
2150 file_flags[8] = (kf_flags & KINFO_FILE_FLAG_HASLOCK) ? 'l' : '-';
2151 file_flags[9] = '\0';
2157 /* Helper function to generate the name of an IP protocol. */
2160 dfly_ipproto (int protocol)
2164 case DFLY_IPPROTO_ICMP:
2166 case DFLY_IPPROTO_TCP:
2168 case DFLY_IPPROTO_UDP:
2172 char *str = get_print_cell ();
2174 xsnprintf (str, PRINT_CELL_SIZE, "ip<%d>", protocol);
2180 /* Helper function to print out an IPv4 socket address. */
2183 dfly_print_sockaddr_in (const void *sockaddr)
2185 const struct dfly_sockaddr_in *sin =
2186 reinterpret_cast<const struct dfly_sockaddr_in *> (sockaddr);
2187 char buf[INET_ADDRSTRLEN];
2189 if (inet_ntop (AF_INET, sin->sin_addr, buf, sizeof buf) == nullptr)
2190 error (_("Failed to format IPv4 address"));
2191 printf_filtered ("%s:%u", buf,
2192 (sin->sin_port[0] << 8) | sin->sin_port[1]);
2195 /* Helper function to print out an IPv6 socket address. */
2198 dfly_print_sockaddr_in6 (const void *sockaddr)
2200 const struct dfly_sockaddr_in6 *sin6 =
2201 reinterpret_cast<const struct dfly_sockaddr_in6 *> (sockaddr);
2202 char buf[INET6_ADDRSTRLEN];
2204 if (inet_ntop (AF_INET6, sin6->sin6_addr, buf, sizeof buf) == nullptr)
2205 error (_("Failed to format IPv6 address"));
2206 printf_filtered ("%s.%u", buf,
2207 (sin6->sin6_port[0] << 8) | sin6->sin6_port[1]);
2210 /* See dfly-tdep.h. */
2214 dfly_info_proc_files_header ()
2216 printf_filtered (_("Open files:\n\n"));
2217 printf_filtered (" %6s %6s %10s %9s %s\n",
2218 "FD", "Type", "Offset", "Flags ", "Name");
2222 /* See dfly-tdep.h. */
2226 dfly_info_proc_files_entry (int kf_type, int kf_fd, int kf_flags,
2227 LONGEST kf_offset, int kf_vnode_type,
2228 int kf_sock_domain, int kf_sock_type,
2229 int kf_sock_protocol, const void *kf_sa_local,
2230 const void *kf_sa_peer, const void *kf_path)
2232 printf_filtered (" %6s %6s %10s %8s ",
2233 dfly_file_fd (kf_fd),
2234 dfly_file_type (kf_type, kf_vnode_type),
2235 kf_offset > -1 ? hex_string (kf_offset) : "-",
2236 dfly_file_flags (kf_flags));
2237 if (kf_type == KINFO_FILE_TYPE_SOCKET)
2239 switch (kf_sock_domain)
2243 switch (kf_sock_type)
2245 case DFLY_SOCK_STREAM:
2246 printf_filtered ("unix stream:");
2248 case DFLY_SOCK_DGRAM:
2249 printf_filtered ("unix dgram:");
2251 case DFLY_SOCK_SEQPACKET:
2252 printf_filtered ("unix seqpacket:");
2255 printf_filtered ("unix <%d>:", kf_sock_type);
2259 /* For local sockets, print out the first non-nul path
2260 rather than both paths. */
2261 const struct dfly_sockaddr_un *sun
2262 = reinterpret_cast<const struct dfly_sockaddr_un *> (kf_sa_local);
2263 if (sun->sun_path[0] == 0)
2264 sun = reinterpret_cast<const struct dfly_sockaddr_un *>
2266 printf_filtered ("%s", sun->sun_path);
2270 printf_filtered ("%s4 ", dfly_ipproto (kf_sock_protocol));
2271 dfly_print_sockaddr_in (kf_sa_local);
2272 printf_filtered (" -> ");
2273 dfly_print_sockaddr_in (kf_sa_peer);
2276 printf_filtered ("%s6 ", dfly_ipproto (kf_sock_protocol));
2277 dfly_print_sockaddr_in6 (kf_sa_local);
2278 printf_filtered (" -> ");
2279 dfly_print_sockaddr_in6 (kf_sa_peer);
2284 printf_filtered ("%s", reinterpret_cast<const char *> (kf_path));
2285 printf_filtered ("\n");
2289 /* Implement "info proc files" for a corefile. */
2293 dfly_core_info_proc_files (struct gdbarch *gdbarch)
2296 = bfd_get_section_by_name (core_bfd, ".note.freebsdcore.files");
2297 if (section == NULL)
2299 warning (_("unable to find open files in core file"));
2303 size_t note_size = bfd_get_section_size (section);
2305 error (_("malformed core note - too short for header"));
2307 gdb::def_vector<unsigned char> contents (note_size);
2308 if (!bfd_get_section_contents (core_bfd, section, contents.data (),
2310 error (_("could not get core note contents"));
2312 unsigned char *descdata = contents.data ();
2313 unsigned char *descend = descdata + note_size;
2315 /* Skip over the structure size. */
2318 dfly_info_proc_files_header ();
2320 while (descdata + KF_PATH < descend)
2322 ULONGEST structsize = bfd_get_32 (core_bfd, descdata + KF_STRUCTSIZE);
2323 if (structsize < KF_PATH)
2324 error (_("malformed core note - file structure too small"));
2326 LONGEST type = bfd_get_signed_32 (core_bfd, descdata + KF_TYPE);
2327 LONGEST fd = bfd_get_signed_32 (core_bfd, descdata + KF_FD);
2328 LONGEST flags = bfd_get_signed_32 (core_bfd, descdata + KF_FLAGS);
2329 LONGEST offset = bfd_get_signed_64 (core_bfd, descdata + KF_OFFSET);
2330 LONGEST vnode_type = bfd_get_signed_32 (core_bfd,
2331 descdata + KF_VNODE_TYPE);
2332 LONGEST sock_domain = bfd_get_signed_32 (core_bfd,
2333 descdata + KF_SOCK_DOMAIN);
2334 LONGEST sock_type = bfd_get_signed_32 (core_bfd, descdata + KF_SOCK_TYPE);
2335 LONGEST sock_protocol = bfd_get_signed_32 (core_bfd,
2336 descdata + KF_SOCK_PROTOCOL);
2337 dfly_info_proc_files_entry (type, fd, flags, offset, vnode_type,
2338 sock_domain, sock_type, sock_protocol,
2339 descdata + KF_SA_LOCAL, descdata + KF_SA_PEER,
2340 descdata + KF_PATH);
2342 descdata += structsize;
2347 /* Helper function to generate mappings flags for a single VM map
2348 entry in 'info proc mappings'. */
2352 dfly_vm_map_entry_flags (int kve_flags, int kve_protection)
2354 static char vm_flags[9];
2356 vm_flags[0] = (kve_protection & KINFO_VME_PROT_READ) ? 'r' : '-';
2357 vm_flags[1] = (kve_protection & KINFO_VME_PROT_WRITE) ? 'w' : '-';
2358 vm_flags[2] = (kve_protection & KINFO_VME_PROT_EXEC) ? 'x' : '-';
2360 vm_flags[4] = (kve_flags & KINFO_VME_FLAG_COW) ? 'C' : '-';
2361 vm_flags[5] = (kve_flags & KINFO_VME_FLAG_NEEDS_COPY) ? 'N' : '-';
2362 vm_flags[6] = (kve_flags & KINFO_VME_FLAG_SUPER) ? 'S' : '-';
2363 vm_flags[7] = (kve_flags & KINFO_VME_FLAG_GROWS_UP) ? 'U'
2364 : (kve_flags & KINFO_VME_FLAG_GROWS_DOWN) ? 'D' : '-';
2371 /* See dfly-tdep.h. */
2375 dfly_info_proc_mappings_header (int addr_bit)
2377 printf_filtered (_("Mapped address spaces:\n\n"));
2380 printf_filtered (" %18s %18s %10s %10s %9s %s\n",
2383 " Size", " Offset", "Flags ", "File");
2387 printf_filtered ("\t%10s %10s %10s %10s %9s %s\n",
2390 " Size", " Offset", "Flags ", "File");
2395 /* See dfly-tdep.h. */
2399 dfly_info_proc_mappings_entry (int addr_bit, ULONGEST kve_start,
2400 ULONGEST kve_end, ULONGEST kve_offset,
2401 int kve_flags, int kve_protection,
2402 const void *kve_path)
2406 printf_filtered (" %18s %18s %10s %10s %9s %s\n",
2407 hex_string (kve_start),
2408 hex_string (kve_end),
2409 hex_string (kve_end - kve_start),
2410 hex_string (kve_offset),
2411 dfly_vm_map_entry_flags (kve_flags, kve_protection),
2412 reinterpret_cast<const char *> (kve_path));
2416 printf_filtered ("\t%10s %10s %10s %10s %9s %s\n",
2417 hex_string (kve_start),
2418 hex_string (kve_end),
2419 hex_string (kve_end - kve_start),
2420 hex_string (kve_offset),
2421 dfly_vm_map_entry_flags (kve_flags, kve_protection),
2422 reinterpret_cast<const char *> (kve_path));
2427 /* Implement "info proc mappings" for a corefile. */
2431 dfly_core_info_proc_mappings (struct gdbarch *gdbarch)
2434 unsigned char *descdata, *descend;
2437 section = bfd_get_section_by_name (core_bfd, ".note.freebsdcore.vmmap");
2438 if (section == NULL)
2440 warning (_("unable to find mappings in core file"));
2444 note_size = bfd_get_section_size (section);
2446 error (_("malformed core note - too short for header"));
2448 gdb::def_vector<unsigned char> contents (note_size);
2449 if (!bfd_get_section_contents (core_bfd, section, contents.data (),
2451 error (_("could not get core note contents"));
2453 descdata = contents.data ();
2454 descend = descdata + note_size;
2456 /* Skip over the structure size. */
2459 dfly_info_proc_mappings_header (gdbarch_addr_bit (gdbarch));
2460 while (descdata + KVE_PATH < descend)
2462 ULONGEST structsize = bfd_get_32 (core_bfd, descdata + KVE_STRUCTSIZE);
2463 if (structsize < KVE_PATH)
2464 error (_("malformed core note - vmmap entry too small"));
2466 ULONGEST start = bfd_get_64 (core_bfd, descdata + KVE_START);
2467 ULONGEST end = bfd_get_64 (core_bfd, descdata + KVE_END);
2468 ULONGEST offset = bfd_get_64 (core_bfd, descdata + KVE_OFFSET);
2469 LONGEST flags = bfd_get_signed_32 (core_bfd, descdata + KVE_FLAGS);
2470 LONGEST prot = bfd_get_signed_32 (core_bfd, descdata + KVE_PROTECTION);
2471 dfly_info_proc_mappings_entry (gdbarch_addr_bit (gdbarch), start, end,
2472 offset, flags, prot, descdata + KVE_PATH);
2474 descdata += structsize;
2479 /* Fetch the pathname of a vnode for a single file descriptor from the
2480 file table core note. */
2483 static gdb::unique_xmalloc_ptr<char>
2484 dfly_core_vnode_path (struct gdbarch *gdbarch, int fd)
2487 unsigned char *descdata, *descend;
2490 section = bfd_get_section_by_name (core_bfd, ".note.freebsdcore.files");
2491 if (section == NULL)
2494 note_size = bfd_get_section_size (section);
2496 error (_("malformed core note - too short for header"));
2498 gdb::def_vector<unsigned char> contents (note_size);
2499 if (!bfd_get_section_contents (core_bfd, section, contents.data (),
2501 error (_("could not get core note contents"));
2503 descdata = contents.data ();
2504 descend = descdata + note_size;
2506 /* Skip over the structure size. */
2509 while (descdata + KF_PATH < descend)
2511 ULONGEST structsize;
2513 structsize = bfd_get_32 (core_bfd, descdata + KF_STRUCTSIZE);
2514 if (structsize < KF_PATH)
2515 error (_("malformed core note - file structure too small"));
2517 if (bfd_get_32 (core_bfd, descdata + KF_TYPE) == KINFO_FILE_TYPE_VNODE
2518 && bfd_get_signed_32 (core_bfd, descdata + KF_FD) == fd)
2520 char *path = (char *) descdata + KF_PATH;
2521 return gdb::unique_xmalloc_ptr<char> (xstrdup (path));
2524 descdata += structsize;
2530 /* Helper function to read a struct timeval. */
2534 dfly_core_fetch_timeval (struct gdbarch *gdbarch, unsigned char *data,
2535 LONGEST &sec, ULONGEST &usec)
2537 if (gdbarch_addr_bit (gdbarch) == 64)
2539 sec = bfd_get_signed_64 (core_bfd, data);
2540 usec = bfd_get_64 (core_bfd, data + 8);
2542 else if (bfd_get_arch (core_bfd) == bfd_arch_i386)
2544 sec = bfd_get_signed_32 (core_bfd, data);
2545 usec = bfd_get_32 (core_bfd, data + 4);
2549 sec = bfd_get_signed_64 (core_bfd, data);
2550 usec = bfd_get_32 (core_bfd, data + 8);
2555 /* Print out the contents of a signal set. */
2559 dfly_print_sigset (const char *descr, unsigned char *sigset)
2561 printf_filtered ("%s: ", descr);
2562 for (int i = 0; i < SIG_WORDS; i++)
2563 printf_filtered ("%08x ",
2564 (unsigned int) bfd_get_32 (core_bfd, sigset + i * 4));
2565 printf_filtered ("\n");
2569 /* Implement "info proc status" for a corefile. */
2573 dfly_core_info_proc_status (struct gdbarch *gdbarch)
2575 const struct kinfo_proc_layout *kp;
2577 unsigned char *descdata;
2578 int addr_bit, long_bit;
2583 section = bfd_get_section_by_name (core_bfd, ".note.freebsdcore.proc");
2584 if (section == NULL)
2586 warning (_("unable to find process info in core file"));
2590 addr_bit = gdbarch_addr_bit (gdbarch);
2592 kp = &kinfo_proc_layout_64;
2593 else if (bfd_get_arch (core_bfd) == bfd_arch_i386)
2594 kp = &kinfo_proc_layout_i386;
2596 kp = &kinfo_proc_layout_32;
2597 long_bit = gdbarch_long_bit (gdbarch);
2600 * Ensure that the note is large enough for all of the fields fetched
2601 * by this function. In particular, the note must contain the 32-bit
2602 * structure size, then it must be long enough to access the last
2603 * field used (ki_rusage_ch.ru_majflt) which is the size of a long.
2605 note_size = bfd_get_section_size (section);
2606 if (note_size < (4 + kp->ki_rusage_ch + kp->ru_majflt
2607 + long_bit / TARGET_CHAR_BIT))
2608 error (_("malformed core note - too short"));
2610 gdb::def_vector<unsigned char> contents (note_size);
2611 if (!bfd_get_section_contents (core_bfd, section, contents.data (),
2613 error (_("could not get core note contents"));
2615 descdata = contents.data ();
2617 /* Skip over the structure size. */
2620 /* Verify 'ki_layout' is 0. */
2621 if (bfd_get_32 (core_bfd, descdata + kp->ki_layout) != 0)
2623 warning (_("unsupported process information in core file"));
2627 printf_filtered ("Name: %.19s\n", descdata + kp->ki_comm);
2628 printf_filtered ("Process ID: %s\n",
2629 pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_pid)));
2630 printf_filtered ("Parent process: %s\n",
2631 pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_ppid)));
2632 printf_filtered ("Process group: %s\n",
2633 pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_pgid)));
2634 printf_filtered ("Session id: %s\n",
2635 pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_sid)));
2637 /* FreeBSD 12.0 and later store a 64-bit dev_t at 'ki_tdev'. Older
2638 kernels store a 32-bit dev_t at 'ki_tdev_freebsd11'. In older
2639 kernels the 64-bit 'ki_tdev' field is in a reserved section of
2640 the structure that is cleared to zero. Assume that a zero value
2641 in ki_tdev indicates a core dump from an older kernel and use the
2642 value in 'ki_tdev_freebsd11' instead. */
2643 value = bfd_get_64 (core_bfd, descdata + kp->ki_tdev);
2645 value = bfd_get_32 (core_bfd, descdata + kp->ki_tdev_freebsd11);
2646 printf_filtered ("TTY: %s\n", pulongest (value));
2647 printf_filtered ("TTY owner process group: %s\n",
2648 pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_tpgid)));
2649 printf_filtered ("User IDs (real, effective, saved): %s %s %s\n",
2650 pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_ruid)),
2651 pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_uid)),
2652 pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_svuid)));
2653 printf_filtered ("Group IDs (real, effective, saved): %s %s %s\n",
2654 pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_rgid)),
2655 pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_groups)),
2656 pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_svgid)));
2657 printf_filtered ("Groups: ");
2658 uint16_t ngroups = bfd_get_16 (core_bfd, descdata + kp->ki_ngroups);
2659 for (int i = 0; i < ngroups; i++)
2660 printf_filtered ("%s ",
2661 pulongest (bfd_get_32 (core_bfd,
2662 descdata + kp->ki_groups + i * 4)));
2663 printf_filtered ("\n");
2664 value = bfd_get (long_bit, core_bfd,
2665 descdata + kp->ki_rusage + kp->ru_minflt);
2666 printf_filtered ("Minor faults (no memory page): %s\n", pulongest (value));
2667 value = bfd_get (long_bit, core_bfd,
2668 descdata + kp->ki_rusage_ch + kp->ru_minflt);
2669 printf_filtered ("Minor faults, children: %s\n", pulongest (value));
2670 value = bfd_get (long_bit, core_bfd,
2671 descdata + kp->ki_rusage + kp->ru_majflt);
2672 printf_filtered ("Major faults (memory page faults): %s\n",
2674 value = bfd_get (long_bit, core_bfd,
2675 descdata + kp->ki_rusage_ch + kp->ru_majflt);
2676 printf_filtered ("Major faults, children: %s\n", pulongest (value));
2677 dfly_core_fetch_timeval (gdbarch,
2678 descdata + kp->ki_rusage + kp->ru_utime,
2680 printf_filtered ("utime: %s.%06d\n", plongest (sec), (int) value);
2681 dfly_core_fetch_timeval (gdbarch,
2682 descdata + kp->ki_rusage + kp->ru_stime,
2684 printf_filtered ("stime: %s.%06d\n", plongest (sec), (int) value);
2685 dfly_core_fetch_timeval (gdbarch,
2686 descdata + kp->ki_rusage_ch + kp->ru_utime,
2688 printf_filtered ("utime, children: %s.%06d\n", plongest (sec), (int) value);
2689 dfly_core_fetch_timeval (gdbarch,
2690 descdata + kp->ki_rusage_ch + kp->ru_stime,
2692 printf_filtered ("stime, children: %s.%06d\n", plongest (sec), (int) value);
2693 printf_filtered ("'nice' value: %d\n",
2694 bfd_get_signed_8 (core_bfd, descdata + kp->ki_nice));
2695 dfly_core_fetch_timeval (gdbarch, descdata + kp->ki_start, sec, value);
2696 printf_filtered ("Start time: %s.%06d\n", plongest (sec), (int) value);
2697 printf_filtered ("Virtual memory size: %s kB\n",
2698 pulongest (bfd_get (addr_bit, core_bfd,
2699 descdata + kp->ki_size) / 1024));
2700 printf_filtered ("Data size: %s pages\n",
2701 pulongest (bfd_get (addr_bit, core_bfd,
2702 descdata + kp->ki_dsize)));
2703 printf_filtered ("Stack size: %s pages\n",
2704 pulongest (bfd_get (addr_bit, core_bfd,
2705 descdata + kp->ki_ssize)));
2706 printf_filtered ("Text size: %s pages\n",
2707 pulongest (bfd_get (addr_bit, core_bfd,
2708 descdata + kp->ki_tsize)));
2709 printf_filtered ("Resident set size: %s pages\n",
2710 pulongest (bfd_get (addr_bit, core_bfd,
2711 descdata + kp->ki_rssize)));
2712 printf_filtered ("Maximum RSS: %s pages\n",
2713 pulongest (bfd_get (long_bit, core_bfd,
2714 descdata + kp->ki_rusage
2716 dfly_print_sigset ("Ignored Signals", descdata + kp->ki_sigignore);
2717 dfly_print_sigset ("Caught Signals", descdata + kp->ki_sigcatch);
2721 /* Implement the "core_info_proc" gdbarch method. */
2725 dfly_core_info_proc (struct gdbarch *gdbarch, const char *args,
2726 enum info_proc_what what)
2728 bool do_cmdline = false;
2729 bool do_cwd = false;
2730 bool do_exe = false;
2731 bool do_files = false;
2732 bool do_mappings = false;
2733 bool do_status = false;
2774 pid = bfd_core_file_pid (core_bfd);
2776 printf_filtered (_("process %d\n"), pid);
2780 const char *cmdline;
2782 cmdline = bfd_core_file_failing_command (core_bfd);
2784 printf_filtered ("cmdline = '%s'\n", cmdline);
2786 warning (_("Command line unavailable"));
2790 gdb::unique_xmalloc_ptr<char> cwd =
2791 dfly_core_vnode_path (gdbarch, KINFO_FILE_FD_TYPE_CWD);
2793 printf_filtered ("cwd = '%s'\n", cwd.get ());
2795 warning (_("unable to read current working directory"));
2799 gdb::unique_xmalloc_ptr<char> exe =
2800 dfly_core_vnode_path (gdbarch, KINFO_FILE_FD_TYPE_TEXT);
2802 printf_filtered ("exe = '%s'\n", exe.get ());
2804 warning (_("unable to read executable path name"));
2807 dfly_core_info_proc_files (gdbarch);
2809 dfly_core_info_proc_mappings (gdbarch);
2811 dfly_core_info_proc_status (gdbarch);
2815 /* Print descriptions of FreeBSD-specific AUXV entries to FILE. */
2819 dfly_print_auxv_entry (struct gdbarch *gdbarch, struct ui_file *file,
2820 CORE_ADDR type, CORE_ADDR val)
2822 const char *name = "???";
2823 const char *description = "";
2824 enum auxv_format format = AUXV_FORMAT_HEX;
2843 default_print_auxv_entry (gdbarch, file, type, val);
2845 #define _TAGNAME(tag) #tag
2846 #define TAGNAME(tag) _TAGNAME(AT_##tag)
2847 #define TAG(tag, text, kind) \
2848 case AT_FREEBSD_##tag: name = TAGNAME(tag); description = text; format = kind; break
2849 TAG (EXECPATH, _("Executable path"), AUXV_FORMAT_STR);
2850 TAG (CANARY, _("Canary for SSP"), AUXV_FORMAT_HEX);
2851 TAG (CANARYLEN, ("Length of the SSP canary"), AUXV_FORMAT_DEC);
2852 TAG (OSRELDATE, _("OSRELDATE"), AUXV_FORMAT_DEC);
2853 TAG (NCPUS, _("Number of CPUs"), AUXV_FORMAT_DEC);
2854 TAG (PAGESIZES, _("Pagesizes"), AUXV_FORMAT_HEX);
2855 TAG (PAGESIZESLEN, _("Number of pagesizes"), AUXV_FORMAT_DEC);
2856 TAG (TIMEKEEP, _("Pointer to timehands"), AUXV_FORMAT_HEX);
2857 TAG (STACKPROT, _("Initial stack protection"), AUXV_FORMAT_HEX);
2858 TAG (EHDRFLAGS, _("ELF header e_flags"), AUXV_FORMAT_HEX);
2859 TAG (HWCAP, _("Machine-dependent CPU capability hints"), AUXV_FORMAT_HEX);
2860 TAG (HWCAP2, _("Extension of AT_HWCAP"), AUXV_FORMAT_HEX);
2863 fprint_auxv_entry (file, name, description, format, type, val);
2867 /* Implement the "get_siginfo_type" gdbarch method. */
2870 static struct type *
2871 dfly_get_siginfo_type (struct gdbarch *gdbarch)
2873 struct dfly_gdbarch_data *dfly_gdbarch_data;
2874 struct type *int_type, *int32_type, *uint32_type, *long_type, *void_ptr_type;
2875 struct type *uid_type, *pid_type;
2876 struct type *sigval_type, *reason_type;
2877 struct type *siginfo_type;
2880 dfly_gdbarch_data = get_dfly_gdbarch_data (gdbarch);
2881 if (dfly_gdbarch_data->siginfo_type != NULL)
2882 return dfly_gdbarch_data->siginfo_type;
2884 int_type = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
2886 int32_type = arch_integer_type (gdbarch, 32, 0, "int32_t");
2887 uint32_type = arch_integer_type (gdbarch, 32, 1, "uint32_t");
2888 long_type = arch_integer_type (gdbarch, gdbarch_long_bit (gdbarch),
2890 void_ptr_type = lookup_pointer_type (builtin_type (gdbarch)->builtin_void);
2893 sigval_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_UNION);
2894 TYPE_NAME (sigval_type) = xstrdup ("sigval");
2895 append_composite_type_field (sigval_type, "sival_int", int_type);
2896 append_composite_type_field (sigval_type, "sival_ptr", void_ptr_type);
2899 pid_type = arch_type (gdbarch, TYPE_CODE_TYPEDEF,
2900 TYPE_LENGTH (int32_type) * TARGET_CHAR_BIT, "__pid_t");
2901 TYPE_TARGET_TYPE (pid_type) = int32_type;
2902 TYPE_TARGET_STUB (pid_type) = 1;
2905 uid_type = arch_type (gdbarch, TYPE_CODE_TYPEDEF,
2906 TYPE_LENGTH (uint32_type) * TARGET_CHAR_BIT,
2908 TYPE_TARGET_TYPE (uid_type) = uint32_type;
2909 TYPE_TARGET_STUB (uid_type) = 1;
2912 reason_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_UNION);
2915 type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
2916 append_composite_type_field (type, "si_trapno", int_type);
2917 append_composite_type_field (reason_type, "_fault", type);
2920 type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
2921 append_composite_type_field (type, "si_timerid", int_type);
2922 append_composite_type_field (type, "si_overrun", int_type);
2923 append_composite_type_field (reason_type, "_timer", type);
2926 type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
2927 append_composite_type_field (type, "si_mqd", int_type);
2928 append_composite_type_field (reason_type, "_mesgq", type);
2931 type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
2932 append_composite_type_field (type, "si_band", long_type);
2933 append_composite_type_field (reason_type, "_poll", type);
2936 type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
2937 append_composite_type_field (type, "__spare1__", long_type);
2938 append_composite_type_field (type, "__spare2__",
2939 init_vector_type (int_type, 7));
2940 append_composite_type_field (reason_type, "__spare__", type);
2942 /* struct siginfo */
2943 siginfo_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
2944 TYPE_NAME (siginfo_type) = xstrdup ("siginfo");
2945 append_composite_type_field (siginfo_type, "si_signo", int_type);
2946 append_composite_type_field (siginfo_type, "si_errno", int_type);
2947 append_composite_type_field (siginfo_type, "si_code", int_type);
2948 append_composite_type_field (siginfo_type, "si_pid", pid_type);
2949 append_composite_type_field (siginfo_type, "si_uid", uid_type);
2950 append_composite_type_field (siginfo_type, "si_status", int_type);
2951 append_composite_type_field (siginfo_type, "si_addr", void_ptr_type);
2952 append_composite_type_field (siginfo_type, "si_value", sigval_type);
2953 append_composite_type_field (siginfo_type, "_reason", reason_type);
2955 dfly_gdbarch_data->siginfo_type = siginfo_type;
2957 return siginfo_type;
2961 /* Implement the "gdb_signal_from_target" gdbarch method. */
2963 static enum gdb_signal
2964 dfly_gdb_signal_from_target (struct gdbarch *gdbarch, int signal)
2969 return GDB_SIGNAL_0;
2971 case DRAGONFLY_SIGHUP:
2972 return GDB_SIGNAL_HUP;
2974 case DRAGONFLY_SIGINT:
2975 return GDB_SIGNAL_INT;
2977 case DRAGONFLY_SIGQUIT:
2978 return GDB_SIGNAL_QUIT;
2980 case DRAGONFLY_SIGILL:
2981 return GDB_SIGNAL_ILL;
2983 case DRAGONFLY_SIGTRAP:
2984 return GDB_SIGNAL_TRAP;
2986 case DRAGONFLY_SIGABRT:
2987 return GDB_SIGNAL_ABRT;
2989 case DRAGONFLY_SIGEMT:
2990 return GDB_SIGNAL_EMT;
2992 case DRAGONFLY_SIGFPE:
2993 return GDB_SIGNAL_FPE;
2995 case DRAGONFLY_SIGKILL:
2996 return GDB_SIGNAL_KILL;
2998 case DRAGONFLY_SIGBUS:
2999 return GDB_SIGNAL_BUS;
3001 case DRAGONFLY_SIGSEGV:
3002 return GDB_SIGNAL_SEGV;
3004 case DRAGONFLY_SIGSYS:
3005 return GDB_SIGNAL_SYS;
3007 case DRAGONFLY_SIGPIPE:
3008 return GDB_SIGNAL_PIPE;
3010 case DRAGONFLY_SIGALRM:
3011 return GDB_SIGNAL_ALRM;
3013 case DRAGONFLY_SIGTERM:
3014 return GDB_SIGNAL_TERM;
3016 case DRAGONFLY_SIGURG:
3017 return GDB_SIGNAL_URG;
3019 case DRAGONFLY_SIGSTOP:
3020 return GDB_SIGNAL_STOP;
3022 case DRAGONFLY_SIGTSTP:
3023 return GDB_SIGNAL_TSTP;
3025 case DRAGONFLY_SIGCONT:
3026 return GDB_SIGNAL_CONT;
3028 case DRAGONFLY_SIGCHLD:
3029 return GDB_SIGNAL_CHLD;
3031 case DRAGONFLY_SIGTTIN:
3032 return GDB_SIGNAL_TTIN;
3034 case DRAGONFLY_SIGTTOU:
3035 return GDB_SIGNAL_TTOU;
3037 case DRAGONFLY_SIGIO:
3038 return GDB_SIGNAL_IO;
3040 case DRAGONFLY_SIGXCPU:
3041 return GDB_SIGNAL_XCPU;
3043 case DRAGONFLY_SIGXFSZ:
3044 return GDB_SIGNAL_XFSZ;
3046 case DRAGONFLY_SIGVTALRM:
3047 return GDB_SIGNAL_VTALRM;
3049 case DRAGONFLY_SIGPROF:
3050 return GDB_SIGNAL_PROF;
3052 case DRAGONFLY_SIGWINCH:
3053 return GDB_SIGNAL_WINCH;
3055 case DRAGONFLY_SIGINFO:
3056 return GDB_SIGNAL_INFO;
3058 case DRAGONFLY_SIGUSR1:
3059 return GDB_SIGNAL_USR1;
3061 case DRAGONFLY_SIGUSR2:
3062 return GDB_SIGNAL_USR2;
3065 /* SIGTHR is the same as SIGLWP on FreeBSD. */
3066 case FREEBSD_SIGTHR:
3067 return GDB_SIGNAL_LWP;
3069 case FREEBSD_SIGLIBRT:
3070 return GDB_SIGNAL_LIBRT;
3075 if (signal >= FREEBSD_SIGRTMIN && signal <= FREEBSD_SIGRTMAX)
3077 int offset = signal - FREEBSD_SIGRTMIN;
3079 return (enum gdb_signal) ((int) GDB_SIGNAL_REALTIME_65 + offset);
3083 return GDB_SIGNAL_UNKNOWN;
3086 /* Implement the "gdb_signal_to_target" gdbarch method. */
3089 dfly_gdb_signal_to_target (struct gdbarch *gdbarch,
3090 enum gdb_signal signal)
3097 case GDB_SIGNAL_HUP:
3098 return DRAGONFLY_SIGHUP;
3100 case GDB_SIGNAL_INT:
3101 return DRAGONFLY_SIGINT;
3103 case GDB_SIGNAL_QUIT:
3104 return DRAGONFLY_SIGQUIT;
3106 case GDB_SIGNAL_ILL:
3107 return DRAGONFLY_SIGILL;
3109 case GDB_SIGNAL_TRAP:
3110 return DRAGONFLY_SIGTRAP;
3112 case GDB_SIGNAL_ABRT:
3113 return DRAGONFLY_SIGABRT;
3115 case GDB_SIGNAL_EMT:
3116 return DRAGONFLY_SIGEMT;
3118 case GDB_SIGNAL_FPE:
3119 return DRAGONFLY_SIGFPE;
3121 case GDB_SIGNAL_KILL:
3122 return DRAGONFLY_SIGKILL;
3124 case GDB_SIGNAL_BUS:
3125 return DRAGONFLY_SIGBUS;
3127 case GDB_SIGNAL_SEGV:
3128 return DRAGONFLY_SIGSEGV;
3130 case GDB_SIGNAL_SYS:
3131 return DRAGONFLY_SIGSYS;
3133 case GDB_SIGNAL_PIPE:
3134 return DRAGONFLY_SIGPIPE;
3136 case GDB_SIGNAL_ALRM:
3137 return DRAGONFLY_SIGALRM;
3139 case GDB_SIGNAL_TERM:
3140 return DRAGONFLY_SIGTERM;
3142 case GDB_SIGNAL_URG:
3143 return DRAGONFLY_SIGURG;
3145 case GDB_SIGNAL_STOP:
3146 return DRAGONFLY_SIGSTOP;
3148 case GDB_SIGNAL_TSTP:
3149 return DRAGONFLY_SIGTSTP;
3151 case GDB_SIGNAL_CONT:
3152 return DRAGONFLY_SIGCONT;
3154 case GDB_SIGNAL_CHLD:
3155 return DRAGONFLY_SIGCHLD;
3157 case GDB_SIGNAL_TTIN:
3158 return DRAGONFLY_SIGTTIN;
3160 case GDB_SIGNAL_TTOU:
3161 return DRAGONFLY_SIGTTOU;
3164 return DRAGONFLY_SIGIO;
3166 case GDB_SIGNAL_XCPU:
3167 return DRAGONFLY_SIGXCPU;
3169 case GDB_SIGNAL_XFSZ:
3170 return DRAGONFLY_SIGXFSZ;
3172 case GDB_SIGNAL_VTALRM:
3173 return DRAGONFLY_SIGVTALRM;
3175 case GDB_SIGNAL_PROF:
3176 return DRAGONFLY_SIGPROF;
3178 case GDB_SIGNAL_WINCH:
3179 return DRAGONFLY_SIGWINCH;
3181 case GDB_SIGNAL_INFO:
3182 return DRAGONFLY_SIGINFO;
3184 case GDB_SIGNAL_USR1:
3185 return DRAGONFLY_SIGUSR1;
3187 case GDB_SIGNAL_USR2:
3188 return DRAGONFLY_SIGUSR2;
3191 case GDB_SIGNAL_LWP:
3192 return FREEBSD_SIGTHR;
3194 case GDB_SIGNAL_LIBRT:
3195 return FREEBSD_SIGLIBRT;
3200 if (signal >= GDB_SIGNAL_REALTIME_65
3201 && signal <= GDB_SIGNAL_REALTIME_126)
3203 int offset = signal - GDB_SIGNAL_REALTIME_65;
3205 return FREEBSD_SIGRTMIN + offset;
3213 /* Implement the "get_syscall_number" gdbarch method. */
3216 dfly_get_syscall_number (struct gdbarch *gdbarch, thread_info *thread)
3219 /* FreeBSD doesn't use gdbarch_get_syscall_number since FreeBSD
3220 native targets fetch the system call number from the
3221 'pl_syscall_code' member of struct ptrace_lwpinfo in dfly_wait.
3222 However, system call catching requires this function to be
3225 internal_error (__FILE__, __LINE__, _("dfly_get_sycall_number called"));
3229 /* Read an integer symbol value from the current target. */
3233 dfly_read_integer_by_name (struct gdbarch *gdbarch, const char *name)
3235 bound_minimal_symbol ms = lookup_minimal_symbol (name, NULL, NULL);
3236 if (ms.minsym == NULL)
3237 error (_("Unable to resolve symbol '%s'"), name);
3240 if (target_read_memory (BMSYMBOL_VALUE_ADDRESS (ms), buf, sizeof buf) != 0)
3241 error (_("Unable to read value of '%s'"), name);
3243 return extract_signed_integer (buf, sizeof buf, gdbarch_byte_order (gdbarch));
3247 /* Lookup offsets of fields in the runtime linker's 'Obj_Entry'
3248 structure needed to determine the TLS index of an object file. */
3252 dfly_fetch_rtld_offsets (struct gdbarch *gdbarch, struct dfly_pspace_data *data)
3256 /* Fetch offsets from debug symbols in rtld. */
3257 struct symbol *obj_entry_sym
3258 = lookup_symbol_in_language ("Struct_Obj_Entry", NULL, STRUCT_DOMAIN,
3259 language_c, NULL).symbol;
3260 if (obj_entry_sym == NULL)
3261 error (_("Unable to find Struct_Obj_Entry symbol"));
3262 data->off_linkmap = lookup_struct_elt (SYMBOL_TYPE(obj_entry_sym),
3263 "linkmap", 0).offset / 8;
3264 data->off_tlsindex = lookup_struct_elt (SYMBOL_TYPE(obj_entry_sym),
3265 "tlsindex", 0).offset / 8;
3266 data->rtld_offsets_valid = true;
3269 CATCH (e, RETURN_MASK_ERROR)
3271 data->off_linkmap = -1;
3277 /* Fetch offsets from global variables in libthr. Note that
3278 this does not work for single-threaded processes that are not
3279 linked against libthr. */
3280 data->off_linkmap = dfly_read_integer_by_name (gdbarch,
3281 "_thread_off_linkmap");
3282 data->off_tlsindex = dfly_read_integer_by_name (gdbarch,
3283 "_thread_off_tlsindex");
3284 data->rtld_offsets_valid = true;
3287 CATCH (e, RETURN_MASK_ERROR)
3289 data->off_linkmap = -1;
3295 /* Helper function to read the TLS index of an object file associated
3296 with a link map entry at LM_ADDR. */
3300 dfly_get_tls_index (struct gdbarch *gdbarch, CORE_ADDR lm_addr)
3302 struct dfly_pspace_data *data = get_dfly_pspace_data (current_program_space);
3304 if (!data->rtld_offsets_valid)
3305 dfly_fetch_rtld_offsets (gdbarch, data);
3307 if (data->off_linkmap == -1)
3308 throw_error (TLS_GENERIC_ERROR,
3309 _("Cannot fetch runtime linker structure offsets"));
3311 /* Simulate container_of to convert from LM_ADDR to the Obj_Entry
3312 pointer and then compute the offset of the tlsindex member. */
3313 CORE_ADDR tlsindex_addr = lm_addr - data->off_linkmap + data->off_tlsindex;
3316 if (target_read_memory (tlsindex_addr, buf, sizeof buf) != 0)
3317 throw_error (TLS_GENERIC_ERROR,
3318 _("Cannot find thread-local variables on this target"));
3320 return extract_signed_integer (buf, sizeof buf, gdbarch_byte_order (gdbarch));
3324 /* See dfly-tdep.h. */
3328 dfly_get_thread_local_address (struct gdbarch *gdbarch, CORE_ADDR dtv_addr,
3329 CORE_ADDR lm_addr, CORE_ADDR offset)
3331 LONGEST tls_index = dfly_get_tls_index (gdbarch, lm_addr);
3333 gdb_byte buf[gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT];
3334 if (target_read_memory (dtv_addr, buf, sizeof buf) != 0)
3335 throw_error (TLS_GENERIC_ERROR,
3336 _("Cannot find thread-local variables on this target"));
3338 const struct builtin_type *builtin = builtin_type (gdbarch);
3339 CORE_ADDR addr = gdbarch_pointer_to_address (gdbarch,
3340 builtin->builtin_data_ptr, buf);
3342 addr += (tls_index + 1) * TYPE_LENGTH (builtin->builtin_data_ptr);
3343 if (target_read_memory (addr, buf, sizeof buf) != 0)
3344 throw_error (TLS_GENERIC_ERROR,
3345 _("Cannot find thread-local variables on this target"));
3347 addr = gdbarch_pointer_to_address (gdbarch, builtin->builtin_data_ptr, buf);
3348 return addr + offset;
3352 /* To be called from GDB_OSABI_DRAGONFLY handlers. */
3355 dfly_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
3358 set_gdbarch_core_pid_to_str (gdbarch, dfly_core_pid_to_str);
3359 set_gdbarch_core_thread_name (gdbarch, dfly_core_thread_name);
3360 set_gdbarch_core_xfer_siginfo (gdbarch, dfly_core_xfer_siginfo);
3361 set_gdbarch_make_corefile_notes (gdbarch, dfly_make_corefile_notes);
3362 set_gdbarch_core_info_proc (gdbarch, dfly_core_info_proc);
3363 set_gdbarch_print_auxv_entry (gdbarch, dfly_print_auxv_entry);
3364 set_gdbarch_get_siginfo_type (gdbarch, dfly_get_siginfo_type);
3366 set_gdbarch_gdb_signal_from_target (gdbarch, dfly_gdb_signal_from_target);
3367 set_gdbarch_gdb_signal_to_target (gdbarch, dfly_gdb_signal_to_target);
3370 /* `catch syscall' */
3371 set_xml_syscall_file_name (gdbarch, "syscalls/dragonfly.xml");
3372 set_gdbarch_get_syscall_number (gdbarch, dfly_get_syscall_number);
3377 _initialize_dfly_tdep (void)
3379 dfly_gdbarch_data_handle =
3380 gdbarch_data_register_post_init (init_dfly_gdbarch_data);
3381 dfly_pspace_data_handle
3382 = register_program_space_data_with_cleanup (NULL, dfly_pspace_data_cleanup);
3386 [FILE:2986:dragonfly/dfly-tdep.h]
3387 /* Target-dependent code for DragonFly, architecture independent.
3389 Copyright (C) 2009-2019 Free Software Foundation, Inc.
3391 This file is part of GDB.
3393 This program is free software; you can redistribute it and/or modify
3394 it under the terms of the GNU General Public License as published by
3395 the Free Software Foundation; either version 3 of the License, or
3396 (at your option) any later version.
3398 This program is distributed in the hope that it will be useful,
3399 but WITHOUT ANY WARRANTY; without even the implied warranty of
3400 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3401 GNU General Public License for more details.
3403 You should have received a copy of the GNU General Public License
3404 along with this program. If not, see <http://www.gnu.org/licenses/>. */
3409 extern void dfly_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch);
3411 /* Output the header for "info proc files". */
3413 extern void dfly_info_proc_files_header ();
3415 /* Output description of a single file descriptor for "info proc
3416 files". The KF_TYPE, KF_FD, KF_FLAGS, KF_OFFSET, KF_VNODE_TYPE,
3417 KF_SOCK_DOMAIN, KF_SOCK_TYPE, and KF_SOCK_PROTOCOL parameters
3418 should contain the value of the corresponding fields in a 'struct
3419 kinfo_file'. The KF_SA_LOCAL, KF_SA_PEER, and KF_PATH parameters
3420 should contain pointers to the corresponding fields in a 'struct
3423 extern void dfly_info_proc_files_entry (int kf_type, int kf_fd, int kf_flags,
3424 LONGEST kf_offset, int kf_vnode_type,
3425 int kf_sock_domain, int kf_sock_type,
3426 int kf_sock_protocol,
3427 const void *kf_sa_local,
3428 const void *kf_sa_peer,
3429 const void *kf_path);
3431 /* Output the header for "info proc mappings". ADDR_BIT is the size
3432 of a virtual address in bits. */
3434 extern void dfly_info_proc_mappings_header (int addr_bit);
3436 /* Output description of a single memory range for "info proc
3437 mappings". ADDR_BIT is the size of a virtual address in bits. The
3438 KVE_START, KVE_END, KVE_OFFSET, KVE_FLAGS, and KVE_PROTECTION
3439 parameters should contain the value of the corresponding fields in
3440 a 'struct kinfo_vmentry'. The KVE_PATH parameter should contain a
3441 pointer to the 'kve_path' field in a 'struct kinfo_vmentry'. */
3443 extern void dfly_info_proc_mappings_entry (int addr_bit, ULONGEST kve_start,
3445 ULONGEST kve_offset,
3446 int kve_flags, int kve_protection,
3447 const void *kve_path);
3449 /* Helper function to fetch the address of a thread-local variable.
3450 DTV_ADDR is the base address of the thread's dtv array. LM_ADDR is
3451 the address of the link_map structure for the associated object
3452 file. OFFSET is the offset of the variable in the object file's
3453 thread-local variable block. */
3455 extern CORE_ADDR dfly_get_thread_local_address (struct gdbarch *gdbarch,
3460 #endif /* dfly-tdep.h */
3463 [FILE:2546:dragonfly/i386-dfly-tdep.c]
3464 /* Target-dependent code for DragonFly/i386.
3466 Copyright (C) 2003-2013 Free Software Foundation, Inc.
3468 This file is part of GDB.
3470 This program is free software; you can redistribute it and/or modify
3471 it under the terms of the GNU General Public License as published by
3472 the Free Software Foundation; either version 3 of the License, or
3473 (at your option) any later version.
3475 This program is distributed in the hope that it will be useful,
3476 but WITHOUT ANY WARRANTY; without even the implied warranty of
3477 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3478 GNU General Public License for more details.
3480 You should have received a copy of the GNU General Public License
3481 along with this program. If not, see <http://www.gnu.org/licenses/>. */
3484 #include "arch-utils.h"
3485 #include "gdbcore.h"
3487 #include "regcache.h"
3489 #include "gdbsupport/x86-xstate.h"
3491 #include "i386-tdep.h"
3492 #include "i387-tdep.h"
3493 #include "dfly-tdep.h"
3494 #include "solib-svr4.h"
3496 static int i386dfly_r_reg_offset[] =
3516 /* Sigtramp routine location. */
3517 CORE_ADDR i386dfly_sigtramp_start_addr = 0xbfbfdf20;
3518 CORE_ADDR i386dfly_sigtramp_end_addr = 0xbfbfdff0;
3520 int i386dfly_sc_reg_offset[] =
3541 i386dfly_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
3543 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
3545 i386_elf_init_abi(info, gdbarch);
3547 tdep->gregset_reg_offset = i386dfly_r_reg_offset;
3548 tdep->gregset_num_regs = ARRAY_SIZE (i386dfly_r_reg_offset);
3549 tdep->sizeof_gregset = 80;
3551 tdep->sc_reg_offset = i386dfly_sc_reg_offset;
3552 tdep->sc_num_regs = ARRAY_SIZE (i386dfly_sc_reg_offset);
3554 set_solib_svr4_fetch_link_map_offsets
3555 (gdbarch, svr4_ilp32_fetch_link_map_offsets);
3559 /* Provide a prototype to silence -Wmissing-prototypes. */
3560 void _initialize_i386dfly_tdep (void);
3563 _initialize_i386dfly_tdep (void)
3565 gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_DRAGONFLY,
3570 [FILE:420:dragonfly/patch-bfd_config.bfd]
3571 --- bfd/config.bfd.orig 2022-01-16 11:21:17 UTC
3573 @@ -661,7 +661,7 @@ case "${targ}" in
3575 x86_64-*-dragonfly*)
3576 targ_defvec=x86_64_elf64_vec
3577 - targ_selvecs="i386_elf32_vec iamcu_elf32_vec l1om_elf64_vec k1om_elf64_vec"
3578 + targ_selvecs="i386_elf32_vec iamcu_elf32_vec l1om_elf64_vec k1om_elf64_vec x86_64_pei_vec"
3581 x86_64-*-freebsd* | x86_64-*-kfreebsd*-gnu)
3584 [FILE:792:dragonfly/patch-gdb_Makefile.in]
3585 --- gdb/Makefile.in.orig 2022-01-16 11:21:18 UTC
3587 @@ -690,6 +690,7 @@ ALL_64_TARGET_OBS = \
3589 amd64-darwin-tdep.o \
3590 amd64-dicos-tdep.o \
3591 + amd64-dfly-tdep.o \
3593 amd64-linux-tdep.o \
3594 amd64-netbsd-tdep.o \
3595 @@ -745,6 +746,7 @@ ALL_TARGET_OBS = \
3603 @@ -759,6 +761,7 @@ ALL_TARGET_OBS = \
3605 i386-darwin-tdep.o \
3607 + i386-dfly-tdep.o \
3611 @@ -1292,6 +1295,8 @@ HFILES_NO_SRCDIR = \
3622 [FILE:518:dragonfly/patch-gdb_amd64-tdep.h]
3623 --- gdb/amd64-tdep.h.orig 2022-01-16 11:19:02 UTC
3624 +++ gdb/amd64-tdep.h
3625 @@ -145,8 +145,8 @@ extern int amd64nbsd_r_reg_offset[];
3626 extern int amd64obsd_r_reg_offset[];
3628 /* Variables exported from amd64-fbsd-tdep.c. */
3629 -extern CORE_ADDR amd64fbsd_sigtramp_start_addr;
3630 -extern CORE_ADDR amd64fbsd_sigtramp_end_addr;
3631 -extern int amd64fbsd_sc_reg_offset[];
3632 +extern CORE_ADDR amd64dfly_sigtramp_start_addr;
3633 +extern CORE_ADDR amd64dfly_sigtramp_end_addr;
3634 +extern int amd64dfly_sc_reg_offset[];
3636 #endif /* amd64-tdep.h */
3639 [FILE:644:dragonfly/patch-gdb_bsd-kvm.c]
3640 --- gdb/bsd-kvm.c.orig 2022-01-16 11:21:18 UTC
3644 #include "readline/readline.h"
3645 #include <sys/param.h>
3646 -#include <sys/proc.h>
3647 #ifdef HAVE_SYS_USER_H
3648 #include <sys/user.h>
3650 +#include <sys/proc.h>
3652 #include "bsd-kvm.h"
3654 @@ -330,8 +330,10 @@ bsd_kvm_proc_cmd (const char *arg, int f
3655 #ifdef HAVE_STRUCT_LWP
3656 addr += offsetof (struct lwp, l_addr);
3658 +#ifndef __DragonFly__ /* XXX FIXME */
3659 addr += offsetof (struct proc, p_addr);
3663 if (kvm_read (core_kd, addr, &bsd_kvm_paddr, sizeof bsd_kvm_paddr) == -1)
3664 error (("%s"), kvm_geterr (core_kd));
3667 [FILE:361:dragonfly/patch-gdb_configure.host]
3668 --- gdb/configure.host.orig 2022-01-16 11:21:18 UTC
3669 +++ gdb/configure.host
3670 @@ -176,6 +176,7 @@ vax-*-netbsdelf* | vax-*-knetbsd*-gnu)
3671 vax-*-openbsd*) gdb_host=obsd ;;
3673 x86_64-*-linux*) gdb_host=linux64 ;;
3674 +x86_64-*-dragonfly*) gdb_host=dfly64 ;;
3675 x86_64-*-freebsd* | x86_64-*-kfreebsd*-gnu)
3677 x86_64-*-netbsd* | x86_64-*-knetbsd*-gnu)
3680 [FILE:786:dragonfly/patch-gdb_configure.nat]
3681 --- gdb/configure.nat.orig 2022-01-16 11:21:18 UTC
3682 +++ gdb/configure.nat
3683 @@ -62,6 +62,11 @@ case ${gdb_host} in
3684 NAT_CDEPS='$(srcdir)/proc-service.list'
3685 LOADLIBES='-ldl $(RDYNAMIC)'
3688 + NATDEPFILES='fork-child.o nat/fork-inferior.o inf-ptrace.o dfly-nat.o'
3689 + HAVE_NATIVE_GCORE_HOST=1
3693 NATDEPFILES='fork-child.o nat/fork-inferior.o inf-ptrace.o fbsd-nat.o'
3694 HAVE_NATIVE_GCORE_HOST=1
3695 @@ -197,6 +202,16 @@ case ${gdb_host} in
3701 + case ${gdb_host_cpu} in
3703 + # Host: DragonFly/amd64
3704 + NATDEPFILES="${NATDEPFILES} amd64-nat.o amd64-bsd-nat.o \
3705 + amd64-dfly-nat.o bsd-kvm.o x86-nat.o nat/x86-dregs.o \
3711 case ${gdb_host_cpu} in
3714 [FILE:993:dragonfly/patch-gdb_configure.tgt]
3715 --- gdb/configure.tgt.orig 2022-01-16 11:21:18 UTC
3716 +++ gdb/configure.tgt
3717 @@ -102,6 +102,8 @@ esac
3718 # 2. Get the objects per os in $TARG.
3722 + os_obs="dfly-tdep.o solib-svr4.o";;
3723 *-*-freebsd* | *-*-kfreebsd*-gnu)
3724 os_obs="fbsd-tdep.o solib-svr4.o";;
3725 *-*-netbsd* | *-*-knetbsd*-gnu)
3726 @@ -733,6 +735,11 @@ x86_64-*-linux*)
3727 i386-linux-tdep.o glibc-tdep.o \
3728 solib-svr4.o symfile-mem.o linux-tdep.o linux-record.o"
3730 +x86_64-*-dragonfly*)
3731 + # Target: DragonFly/amd64
3732 + gdb_target_obs="amd64-dfly-tdep.o ${i386_tobjs} \
3733 + i386-bsd-tdep.o i386-dfly-tdep.o"
3735 x86_64-*-freebsd* | x86_64-*-kfreebsd*-gnu)
3736 # Target: FreeBSD/amd64
3737 gdb_target_obs="amd64-fbsd-tdep.o ${i386_tobjs} \
3738 @@ -775,6 +782,8 @@ gdb_target_obs="${cpu_obs} ${os_obs} ${g
3739 # map target onto default OS ABI
3743 + gdb_osabi=GDB_OSABI_DRAGONFLY ;;
3744 *-*-freebsd* | *-*-kfreebsd*-gnu)
3745 gdb_osabi=GDB_OSABI_FREEBSD ;;
3746 *-*-linux* | *-*-uclinux*)
3749 [FILE:344:dragonfly/patch-gdb_i386-bsd-nat.c]
3750 --- gdb/i386-bsd-nat.c.orig 2022-01-16 11:19:02 UTC
3751 +++ gdb/i386-bsd-nat.c
3752 @@ -356,6 +356,8 @@ _initialize_i386bsd_nat ()
3753 #define SC_REG_OFFSET i386fbsd_sc_reg_offset
3754 #elif defined (OpenBSD)
3755 #define SC_REG_OFFSET i386obsd_sc_reg_offset
3756 +#elif defined (DragonFly)
3757 +#define SC_REG_OFFSET i386dfly_sc_reg_offset
3760 #ifdef SC_REG_OFFSET
3763 [FILE:737:dragonfly/patch-gdb_i386-tdep.h]
3764 --- gdb/i386-tdep.h.orig 2022-01-16 11:21:18 UTC
3766 @@ -472,12 +472,11 @@ extern int i386_mpx_enabled (void);
3767 /* Functions and variables exported from i386-bsd-tdep.c. */
3769 extern void i386bsd_init_abi (struct gdbarch_info, struct gdbarch *);
3770 -extern CORE_ADDR i386fbsd_sigtramp_start_addr;
3771 -extern CORE_ADDR i386fbsd_sigtramp_end_addr;
3772 +extern CORE_ADDR i386dfly_sigtramp_start_addr;
3773 +extern CORE_ADDR i386dfly_sigtramp_end_addr;
3774 extern CORE_ADDR i386obsd_sigtramp_start_addr;
3775 extern CORE_ADDR i386obsd_sigtramp_end_addr;
3776 -extern int i386fbsd4_sc_reg_offset[];
3777 -extern int i386fbsd_sc_reg_offset[];
3778 +extern int i386dfly_sc_reg_offset[];
3779 extern int i386obsd_sc_reg_offset[];
3780 extern int i386bsd_sc_reg_offset[];
3784 [FILE:728:dragonfly/patch-gdb_osabi.c]
3785 --- gdb/osabi.c.orig 2022-01-16 11:19:03 UTC
3787 @@ -69,6 +69,7 @@ static const struct osabi_names gdb_osab
3788 { "FreeBSD", NULL },
3790 { "OpenBSD", NULL },
3791 + { "DragonFly", NULL },
3792 { "WindowsCE", NULL },
3794 { "QNX-Neutrino", NULL },
3795 @@ -497,6 +498,15 @@ generic_elf_osabi_sniff_abi_tag_sections
3800 + if (check_note (abfd, sect, note, §size, "DragonFly", 4,
3801 + NT_DRAGONFLY_ABI_TAG))
3803 + /* There is no need to check the version yet. */
3804 + *osabi = GDB_OSABI_DRAGONFLY;
3809 if (check_note (abfd, sect, note, §size, "FreeBSD", 4,
3810 NT_FREEBSD_ABI_TAG))
3813 [FILE:243:dragonfly/patch-gdb_osabi.h]
3814 --- gdb/osabi.h.orig 2022-01-16 11:19:03 UTC
3816 @@ -33,6 +33,7 @@ enum gdb_osabi
3820 + GDB_OSABI_DRAGONFLY,
3826 [FILE:390:dragonfly/patch-include_elf_common.h]
3827 --- include/elf/common.h.orig 2022-01-16 11:21:18 UTC
3828 +++ include/elf/common.h
3830 /* Values for FreeBSD .note.ABI-tag notes. Note name is "FreeBSD". */
3832 #define NT_FREEBSD_ABI_TAG 1
3833 +#define NT_DRAGONFLY_ABI_TAG 1
3835 /* These three macros disassemble and assemble a symbol table st_info field,
3836 which contains the symbol binding and symbol type. The STB_ and STT_
3839 [FILE:740:sunos/patch-gdb_fbsd-tdep.c]
3840 --- gdb/fbsd-tdep.c.orig 2020-05-23 21:10:29 UTC
3842 @@ -1018,12 +1018,12 @@ fbsd_info_proc_files_entry (int kf_type,
3844 /* For local sockets, print out the first non-nul path
3845 rather than both paths. */
3846 - const struct fbsd_sockaddr_un *sun
3847 + const struct fbsd_sockaddr_un *xsunx
3848 = reinterpret_cast<const struct fbsd_sockaddr_un *> (kf_sa_local);
3849 - if (sun->sun_path[0] == 0)
3850 - sun = reinterpret_cast<const struct fbsd_sockaddr_un *>
3851 + if (xsunx->sun_path[0] == 0)
3852 + xsunx = reinterpret_cast<const struct fbsd_sockaddr_un *>
3854 - printf_filtered ("%s", sun->sun_path);
3855 + printf_filtered ("%s", xsunx->sun_path);