Ravenports generated: 18 Jan 2021 12:16
[ravenports.git] / bucket_8E / gdb
1 # Buildsheet autogenerated by ravenadm tool -- Do not edit.
2
3 NAMEBASE=               gdb
4 VERSION=                10.1
5 KEYWORDS=               devel
6 VARIANTS=               standard
7 SDESC[standard]=        GNU debugger
8 HOMEPAGE=               http://www.gnu.org/software/gdb/
9 CONTACT=                nobody
10
11 DOWNLOAD_GROUPS=        main
12 SITES[main]=            GNU/gdb
13 DISTFILE[1]=            gdb-10.1.tar.xz:main
14 DF_INDEX=               1
15 SPKGS[standard]=        single
16
17 OPTIONS_AVAILABLE=      none
18 OPTIONS_STANDARD=       none
19
20 NOT_FOR_ARCH=           aarch64
21
22 BUILDRUN_DEPENDS=       source-highlight:primary:standard
23
24 USES=                   cpe iconv gmake libtool readline pkgconfig makeinfo
25                         python expat
26
27 EXTRACT_HEAD[1]=        {{TAR}} -xf
28 EXTRACT_TAIL[1]=        --exclude dejagnu --exclude expect --exclude sim --exclude texinfo --exclude intl --exclude readline
29
30 LICENSE=                GPLv3+:single
31 LICENSE_TERMS=          single:{{WRKDIR}}/TERMS
32 LICENSE_FILE=           GPLv3+:{{WRKSRC}}/COPYING
33 LICENSE_AWK=            TERMS:"^\#include"
34 LICENSE_SOURCE=         TERMS:{{WRKSRC}}/gdb/gdb.c
35 LICENSE_SCHEME=         solo
36
37 CPE_VENDOR=             gnu
38 FPC_EQUIVALENT=         devel/gdb
39
40 MUST_CONFIGURE=         gnu
41 CONFIGURE_OUTSOURCE=    yes
42 CONFIGURE_ARGS=         --program-suffix=101
43                         --enable-targets=all
44                         --enable-64-bit-bfd
45                         --enable-tui
46                         --disable-build-with-cxx
47                         --with-gdb-datadir={{PREFIX}}/share/gdb101
48                         {{ICONV_CONFIGURE_ARG}}
49                         --with-system-readline
50                         --with-expat=yes
51                         --with-libexpat-prefix={{LOCALBASE}}
52                         --without-libunwind-ia64
53                         --with-python={{PYTHON_CMD}}
54                         --with-source-highlight
55 CONFIGURE_ENV=          CONFIGURED_M4=m4
56                         CONFIGURED_BISON=byacc
57
58 PLIST_SUB=              VER=101
59
60 CFLAGS=                 -DRL_NO_COMPAT
61                         -D__STDC_CONSTANT_MACROS
62                         -D__STDC_LIMIT_MACROS
63                         -Wno-unused-function
64                         -Wno-unused-variable
65
66 post-patch:
67         ${REINPLACE_CMD} -e 's|$$| [GDB v10.1 for ${OPSYS}]|' \
68                 ${WRKSRC}/gdb/version.in
69         # remove leftover readline removed garbage
70         ${REINPLACE_CMD} -e 's|..READLINE.*user.texi||' \
71                 ${WRKSRC}/gdb/doc/Makefile.in
72
73 post-patch-dragonfly:
74         ${CP} ${OPSYSDIR}/dfly-tdep.* ${WRKSRC}/gdb/
75         ${CP} ${OPSYSDIR}/dfly-nat.*  ${WRKSRC}/gdb/
76         ${CP} ${OPSYSDIR}/i386*       ${WRKSRC}/gdb/
77         ${CP} ${OPSYSDIR}/amd64*      ${WRKSRC}/gdb/
78
79 do-install:
80         ${INSTALL_PROGRAM} ${INSTALL_WRKSRC}/gdb/gdb \
81                 ${STAGEDIR}${PREFIX}/bin/gdb101
82         ${INSTALL_MAN} ${WRKSRC}/gdb/doc/gdb.1 \
83                 ${STAGEDIR}${MAN1PREFIX}/man/man1/gdb101.1
84         (cd ${INSTALL_WRKSRC}/gdb/data-directory ; \
85                 ${SETENV} ${MAKE_ENV} ${MAKE_CMD} ${MAKE_ARGS} install-syscalls )
86         ${LN} -sf gdb101 ${STAGEDIR}${PREFIX}/bin/gdbtui101
87         ${LN} -sf gdb101 ${STAGEDIR}${PREFIX}/bin/gdb
88         (cd ${INSTALL_WRKSRC}/gdb && ${SETENV} ${MAKE_ENV} \
89                 ${MAKE_CMD} ${MAKE_ARGS} install-python )
90         (cd ${INSTALL_WRKSRC}/gdb/data-directory && ${SETENV} ${MAKE_ENV} \
91                 ${MAKE_CMD} ${MAKE_ARGS} install-python )
92 . for f in gdb gdb/command gdb/function gdb/printer
93         (cd ${STAGEDIR}${PREFIX}/share/gdb101/python/${f} ; ${CHMOD} 644 *.py* )
94 . endfor
95
96 [FILE:284:descriptions/desc.single]
97 GDB is a source-level debugger for Ada, C, C++, Objective-C, Pascal and
98 many other languages.  GDB can target (i.e., debug programs running on)
99 more than a dozen different processor architectures, and GDB itself can
100 run on most popular GNU/Linux, Unix and Microsoft Windows variants.
101
102
103 [FILE:94:distinfo]
104 f82f1eceeec14a3afa2de8d9b0d3c91d5a3820e23e0a01bbb70ef9f0276b62c0     21507112 gdb-10.1.tar.xz
105
106
107 [FILE:831:manifests/plist.single]
108 bin/
109  gdb
110  gdb%%VER%%
111  gdbtui%%VER%%
112 share/gdb%%VER%%/python/gdb/
113  FrameDecorator.py
114  FrameIterator.py
115  __init__.py
116  frames.py
117  printing.py
118  prompt.py
119  types.py
120  unwinder.py
121  xmethod.py
122 share/gdb%%VER%%/python/gdb/command/
123  __init__.py
124  explore.py
125  frame_filters.py
126  pretty_printers.py
127  prompt.py
128  type_printers.py
129  unwinders.py
130  xmethods.py
131 share/gdb%%VER%%/python/gdb/function/
132  __init__.py
133  as_string.py
134  caller_is.py
135  strfns.py
136 share/gdb%%VER%%/python/gdb/printer/
137  __init__.py
138  bound_registers.py
139 share/gdb%%VER%%/syscalls/
140  aarch64-linux.xml
141  amd64-linux.xml
142  arm-linux.xml
143  freebsd.xml
144  gdb-syscalls.dtd
145  i386-linux.xml
146  mips-n32-linux.xml
147  mips-n64-linux.xml
148  mips-o32-linux.xml
149  netbsd.xml
150  ppc-linux.xml
151  ppc64-linux.xml
152  s390-linux.xml
153  s390x-linux.xml
154  sparc-linux.xml
155  sparc64-linux.xml
156 share/man/man1/gdb%%VER%%.1.gz
157
158
159 [FILE:1057:patches/patch-gdb_amd64-bsd-nat.c]
160 --- gdb/amd64-bsd-nat.c.orig    2020-09-13 02:33:41 UTC
161 +++ gdb/amd64-bsd-nat.c
162 @@ -28,6 +28,7 @@
163  #include <sys/types.h>
164  #include <sys/ptrace.h>
165  #include <machine/reg.h>
166 +#include <machine/psl.h>
167  
168  #include "amd64-tdep.h"
169  #include "amd64-nat.h"
170 @@ -142,12 +143,19 @@ amd64bsd_store_inferior_registers (struc
171    if (regnum == -1 || amd64_native_gregset_supplies_p (gdbarch, regnum))
172      {
173        struct reg regs;
174 +      register_t old_rflags;
175  
176        if (gdb_ptrace (PT_GETREGS, ptid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
177          perror_with_name (_("Couldn't get registers"));
178  
179 +      old_rflags = regs.r_rflags;
180        amd64_collect_native_gregset (regcache, &regs, regnum);
181  
182 +      /* This is a workaround about the PSL_USERCHANGE posix limitation. */
183 +      if ((regs.r_rflags ^ old_rflags ) & ~PSL_USERCHANGE)
184 +        {
185 +          regs.r_rflags ^= (regs.r_rflags ^ old_rflags ) & ~PSL_USERCHANGE;
186 +        }
187        if (gdb_ptrace (PT_SETREGS, ptid, (PTRACE_TYPE_ARG3) &regs, 0) == -1)
188          perror_with_name (_("Couldn't write registers"));
189  
190
191
192 [FILE:312:patches/patch-gdb_compile_compile-loc2c.c]
193 --- gdb/compile/compile-loc2c.c.orig    2020-09-13 02:33:41 UTC
194 +++ gdb/compile/compile-loc2c.c
195 @@ -660,6 +660,7 @@ do_compile_dwarf_expr_to_c (int indent,
196        uint64_t uoffset, reg;
197        int64_t offset;
198  
199 +      uoffset = 0;
200        print_spaces (indent - 2, stream);
201        if (info[op_ptr - base].label)
202         {
203
204
205 [FILE:717:patches/patch-gdb_fbsd-nat.c]
206 --- gdb/fbsd-nat.c.orig 2020-10-24 04:23:02 UTC
207 +++ gdb/fbsd-nat.c
208 @@ -1176,6 +1176,14 @@ fbsd_nat_target::resume (ptid_t ptid, in
209        /* If ptid is a specific LWP, suspend all other LWPs in the process.  */
210        inferior *inf = find_inferior_ptid (this, ptid);
211  
212 +#ifndef PT_LWP_EVENTS
213 +      /* When LWP events are not supported, a new thread might already be
214 +        running that has not yet reported an event when GDB wishes to
215 +        only run a single thread.  Force an update of the thread list
216 +        to ensure that any such threads are suspended before the process
217 +        is resumed.  */
218 +      fbsd_add_threads (ptid.pid ());
219 +#endif
220        for (thread_info *tp : inf->non_exited_threads ())
221          {
222           int request;
223
224
225 [FILE:923:patches/patch-gdb_gdb__wchar.h]
226 diff --git gdb/gdb_wchar.h gdb/gdb_wchar.h
227 index 868fe04..1311080 100644
228 --- gdb/gdb_wchar.h.orig        2020-09-13 02:33:41 UTC
229 +++ gdb/gdb_wchar.h
230 @@ -59,7 +59,7 @@
231     iconvlist.  */
232  #if defined (HAVE_ICONV) && defined (HAVE_BTOWC) \
233    && (defined (__STDC_ISO_10646__) \
234 -      || (defined (_LIBICONV_VERSION) && _LIBICONV_VERSION >= 0x108))
235 +      || (!defined (LIBICONV_PLUG) && defined (_LIBICONV_VERSION) && _LIBICONV_VERSION >= 0x108))
236  
237  typedef wchar_t gdb_wchar_t;
238  typedef wint_t gdb_wint_t;
239 @@ -82,7 +82,7 @@ typedef wint_t gdb_wint_t;
240  #define INTERMEDIATE_ENCODING intermediate_encoding ()
241  const char *intermediate_encoding (void);
242  
243 -#elif defined (_LIBICONV_VERSION) && _LIBICONV_VERSION >= 0x108
244 +#elif !defined (LIBICONV_PLUG) && defined (_LIBICONV_VERSION) && _LIBICONV_VERSION >= 0x108
245  #define INTERMEDIATE_ENCODING "wchar_t"
246  #else
247  /* This shouldn't happen, because the earlier #if should have filtered
248
249
250 [FILE:801:patches/patch-gdb_i386-fbsd-nat.c]
251 --- gdb/i386-fbsd-nat.c.orig    2020-09-13 02:33:41 UTC
252 +++ gdb/i386-fbsd-nat.c
253 @@ -43,8 +43,6 @@ public:
254    const struct target_desc *read_description () override;
255  #endif
256  
257 -  void resume (ptid_t, int, enum gdb_signal) override;
258 -
259  #if defined(HAVE_PT_GETDBREGS) && defined(USE_SIGTRAP_SIGINFO)
260    bool supports_stopped_by_hw_breakpoint () override;
261  #endif
262 @@ -52,6 +50,7 @@ public:
263  
264  static i386_fbsd_nat_target the_i386_fbsd_nat_target;
265  
266 +#if 0
267  /* Resume execution of the inferior process.  If STEP is nonzero,
268     single-step it.  If SIGNAL is nonzero, give it that signal.  */
269  
270 @@ -98,6 +97,7 @@ i386_fbsd_nat_target::resume (ptid_t pti
271               gdb_signal_to_host (signal)) == -1)
272      perror_with_name (("ptrace"));
273  }
274 +#endif
275  \f
276  
277  /* Support for debugging kernel virtual memory images.  */
278
279
280 [FILE:452:patches/patch-gdb_python_python-config.py]
281 --- gdb/python/python-config.py.orig    2020-09-13 02:33:41 UTC
282 +++ gdb/python/python-config.py
283 @@ -59,6 +59,8 @@ for opt in opt_flags:
284  
285      elif opt in ('--libs', '--ldflags'):
286          libs = ['-lpython' + pyver + abiflags]
287 +        if getvar('LDFLAGS') is not None:
288 +            libs.extend(getvar('LDFLAGS').split())
289          if getvar('LIBS') is not None:
290              libs.extend(getvar('LIBS').split())
291          if getvar('SYSLIBS') is not None:
292
293
294 [FILE:247:patches/patch-gdb_s390-tdep.c]
295 --- gdb/s390-tdep.c.orig        2020-10-24 04:23:02 UTC
296 +++ gdb/s390-tdep.c
297 @@ -40,6 +40,10 @@
298  #include "trad-frame.h"
299  #include "value.h"
300  
301 +#ifdef __sun__
302 +#undef CS
303 +#endif
304 +
305  #include "features/s390-linux32.c"
306  #include "features/s390x-linux64.c"
307  
308
309
310 [FILE:580:patches/patch-gdbsupport_common-defs.h]
311 --- gdbsupport/common-defs.h.orig       2020-09-13 02:33:41 UTC
312 +++ gdbsupport/common-defs.h
313 @@ -47,9 +47,15 @@
314  
315     Must do this before including any system header, since other system
316     headers may include stdint.h/inttypes.h.  */
317 +#ifndef __STDC_CONSTANT_MACROS
318  #define __STDC_CONSTANT_MACROS 1
319 +#endif
320 +#ifndef __STDC_LIMIT_MACROS
321  #define __STDC_LIMIT_MACROS 1
322 +#endif
323 +#ifndef __STDC_FORMAT_MACROS
324  #define __STDC_FORMAT_MACROS 1
325 +#endif
326  
327  /* Some distros enable _FORTIFY_SOURCE by default, which on occasion
328     has caused build failures with -Wunused-result when a patch is
329
330
331 [FILE:429:patches/patch-gnulib_import_stddef.in.h]
332 --- gnulib/import/stddef.in.h.orig      2020-09-13 02:33:41 UTC
333 +++ gnulib/import/stddef.in.h
334 @@ -90,7 +90,7 @@
335  #if defined _MSC_VER && defined __cplusplus
336  # include <cstddef>
337  #else
338 -# if ! (@HAVE_MAX_ALIGN_T@ || defined _GCC_MAX_ALIGN_T)
339 +# if 0
340  #  if !GNULIB_defined_max_align_t
341  /* On the x86, the maximum storage alignment of double, long, etc. is 4,
342     but GCC's C11 ABI for x86 says that max_align_t has an alignment of 8,
343
344
345 [FILE:601:patches/patch-libiberty-basename]
346 --- include/libiberty.h.orig    2020-09-13 02:33:41 UTC
347 +++ include/libiberty.h
348 @@ -109,7 +109,7 @@ extern int countargv (char * const *);
349   || defined (__FreeBSD__) || defined (__OpenBSD__) || defined (__NetBSD__) \
350   || defined (__CYGWIN__) || defined (__CYGWIN32__) || defined (__MINGW32__) \
351   || defined (__DragonFly__) || defined (HAVE_DECL_BASENAME) 
352 -extern char *basename (const char *) ATTRIBUTE_RETURNS_NONNULL ATTRIBUTE_NONNULL(1);
353 +#include <libgen.h>
354  #else
355  /* Do not allow basename to be used if there is no prototype seen.  We
356     either need to use the above prototype or have one from
357
358
359 [FILE:505:patches/patch-unified]
360 --- gdb/gdb.c.orig      2020-09-13 02:33:41 UTC
361 +++ gdb/gdb.c
362 @@ -28,6 +28,12 @@ main (int argc, char **argv)
363    memset (&args, 0, sizeof args);
364    args.argc = argc;
365    args.argv = argv;
366 -  args.interpreter_p = INTERP_CONSOLE;
367 +  if (strncmp(basename(argv[0]), "insight", 7) == 0) {
368 +    args.interpreter_p = "insight";
369 +  } else if (strncmp(basename(argv[0]), "gdbtui", 6) == 0) {
370 +    args.interpreter_p = INTERP_TUI;
371 +  } else {
372 +    args.interpreter_p = INTERP_CONSOLE;
373 +  }
374    return gdb_main (&args);
375  }
376
377
378 [FILE:9620:dragonfly/amd64-dfly-nat.c]
379 /* Native-dependent code for DragonFly/amd64.
380
381    Copyright (C) 2003-2019 Free Software Foundation, Inc.
382
383    This file is part of GDB.
384
385    This program is free software; you can redistribute it and/or modify
386    it under the terms of the GNU General Public License as published by
387    the Free Software Foundation; either version 3 of the License, or
388    (at your option) any later version.
389
390    This program is distributed in the hope that it will be useful,
391    but WITHOUT ANY WARRANTY; without even the implied warranty of
392    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
393    GNU General Public License for more details.
394
395    You should have received a copy of the GNU General Public License
396    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
397
398 #include "defs.h"
399 #include "inferior.h"
400 #include "regcache.h"
401 #include "target.h"
402 #include "gregset.h"
403
404 #include <signal.h>
405 #include <stddef.h>
406 #include <sys/types.h>
407 #include <sys/procfs.h>
408 #include <sys/ptrace.h>
409 #include <sys/sysctl.h>
410 #include <sys/user.h>
411 #include <machine/reg.h>
412 #include <machine/segments.h>
413
414 #include "dfly-nat.h"
415 #include "amd64-tdep.h"
416 #include "amd64-nat.h"
417 #include "amd64-bsd-nat.h"
418 #include "x86-nat.h"
419 #include "gdbsupport/x86-xstate.h"
420 \f
421
422 class amd64_dfly_nat_target final
423   : public amd64_bsd_nat_target<dfly_nat_target>
424 {
425 public:
426   /* Add some extra features to the common *BSD/amd64 target.  */
427   const struct target_desc *read_description () override;
428
429 #if defined(HAVE_PT_GETDBREGS) && defined(USE_SIGTRAP_SIGINFO)
430   bool supports_stopped_by_hw_breakpoint () override;
431 #endif
432 };
433
434 static amd64_dfly_nat_target the_amd64_dfly_nat_target;
435
436 /* Offset in `struct reg' where MEMBER is stored.  */
437 #define REG_OFFSET(member) offsetof (struct reg, member)
438
439 /* At amd64dfly64_r_reg_offset[REGNUM] you'll find the offset in
440    `struct reg' location where the GDB register REGNUM is stored.
441    Unsupported registers are marked with `-1'.  */
442 static int amd64dfly64_r_reg_offset[] =
443 {
444   REG_OFFSET (r_rax),
445   REG_OFFSET (r_rbx),
446   REG_OFFSET (r_rcx),
447   REG_OFFSET (r_rdx),
448   REG_OFFSET (r_rsi),
449   REG_OFFSET (r_rdi),
450   REG_OFFSET (r_rbp),
451   REG_OFFSET (r_rsp),
452   REG_OFFSET (r_r8),
453   REG_OFFSET (r_r9),
454   REG_OFFSET (r_r10),
455   REG_OFFSET (r_r11),
456   REG_OFFSET (r_r12),
457   REG_OFFSET (r_r13),
458   REG_OFFSET (r_r14),
459   REG_OFFSET (r_r15),
460   REG_OFFSET (r_rip),
461   REG_OFFSET (r_rflags),
462   REG_OFFSET (r_cs),
463   REG_OFFSET (r_ss),
464   -1,
465   -1,
466   -1,
467   -1
468 };
469 \f
470
471 /* Mapping between the general-purpose registers in DragonFly/amd64
472    `struct reg' format and GDB's register cache layout for
473    DragonFly/x86.
474
475    Note that most DragonFly/amd64 registers are 64-bit, while the
476    DragonFly/x86 registers are all 32-bit, but since we're
477    little-endian we get away with that.  */
478
479 /* From <machine/reg.h>.  */
480 static int amd64dfly32_r_reg_offset[I386_NUM_GREGS] =
481 {
482   14 * 8, 13 * 8,               /* %eax, %ecx */
483   12 * 8, 11 * 8,               /* %edx, %ebx */
484   20 * 8, 10 * 8,               /* %esp, %ebp */
485   9 * 8, 8 * 8,                 /* %esi, %edi */
486   17 * 8, 19 * 8,               /* %eip, %eflags */
487   18 * 8, 21 * 8,               /* %cs, %ss */
488   -1, -1, -1, -1                /* %ds, %es, %fs, %gs */
489 };
490 \f
491
492 #ifdef DFLY_PCB_SUPPLY
493 /* Transfering the registers between GDB, inferiors and core files.  */
494
495 /* Fill GDB's register array with the general-purpose register values
496    in *GREGSETP.  */
497
498 void
499 supply_gregset (struct regcache *regcache, const gregset_t *gregsetp)
500 {
501   amd64_supply_native_gregset (regcache, gregsetp, -1);
502 }
503
504 /* Fill register REGNUM (if it is a general-purpose register) in
505    *GREGSETPS with the value in GDB's register array.  If REGNUM is -1,
506    do this for all registers.  */
507
508 void
509 fill_gregset (const struct regcache *regcache, gdb_gregset_t *gregsetp, int regnum)
510 {
511   amd64_collect_native_gregset (regcache, gregsetp, regnum);
512 }
513
514 /* Fill GDB's register array with the floating-point register values
515    in *FPREGSETP.  */
516
517 void
518 supply_fpregset (struct regcache *regcache, const fpregset_t *fpregsetp)
519 {
520   amd64_supply_fxsave (regcache, -1, fpregsetp);
521 }
522
523 /* Fill register REGNUM (if it is a floating-point register) in
524    *FPREGSETP with the value in GDB's register array.  If REGNUM is -1,
525    do this for all registers.  */
526
527 void
528 fill_fpregset (const struct regcache *regcache, gdb_fpregset_t *fpregsetp, int regnum)
529 {
530   amd64_collect_fxsave (regcache, regnum, fpregsetp);
531 }
532 \f
533 /* Support for debugging kernel virtual memory images.  */
534
535 #include <sys/types.h>
536 #include <machine/pcb.h>
537 #include <osreldate.h>
538
539 #include "bsd-kvm.h"
540
541 static int
542 amd64dfly_supply_pcb (struct regcache *regcache, struct pcb *pcb)
543 {
544   /* The following is true for FreeBSD 5.2:
545
546      The pcb contains %rip, %rbx, %rsp, %rbp, %r12, %r13, %r14, %r15,
547      %ds, %es, %fs and %gs.  This accounts for all callee-saved
548      registers specified by the psABI and then some.  Here %esp
549      contains the stack pointer at the point just after the call to
550      cpu_switch().  From this information we reconstruct the register
551      state as it would like when we just returned from cpu_switch().  */
552
553   /* The stack pointer shouldn't be zero.  */
554   if (pcb->pcb_rsp == 0)
555     return 0;
556
557   pcb->pcb_rsp += 8;
558   regcache->raw_supply (AMD64_RIP_REGNUM, &pcb->pcb_rip);
559   regcache->raw_supply (AMD64_RBX_REGNUM, &pcb->pcb_rbx);
560   regcache->raw_supply (AMD64_RSP_REGNUM, &pcb->pcb_rsp);
561   regcache->raw_supply (AMD64_RBP_REGNUM, &pcb->pcb_rbp);
562   regcache->raw_supply (12, &pcb->pcb_r12);
563   regcache->raw_supply (13, &pcb->pcb_r13);
564   regcache->raw_supply (14, &pcb->pcb_r14);
565   regcache->raw_supply (15, &pcb->pcb_r15);
566
567   return 1;
568 }
569 #endif /* DFLY_PCB_SUPPLY */
570 \f
571
572 /* Implement the read_description method.  */
573
574 const struct target_desc *
575 amd64_dfly_nat_target::read_description ()
576 {
577 #ifdef PT_GETXSTATE_INFO
578   static int xsave_probed;
579   static uint64_t xcr0;
580 #endif
581   struct reg regs;
582   int is64;
583
584   if (ptrace (PT_GETREGS, inferior_ptid.pid (),
585               (PTRACE_TYPE_ARG3) &regs, 0) == -1)
586     perror_with_name (_("Couldn't get registers"));
587   is64 = (regs.r_cs == GSEL (GUCODE_SEL, SEL_UPL));
588 #ifdef PT_GETXSTATE_INFO
589   if (!xsave_probed)
590     {
591       struct ptrace_xstate_info info;
592
593       if (ptrace (PT_GETXSTATE_INFO, inferior_ptid.pid (),
594                   (PTRACE_TYPE_ARG3) &info, sizeof (info)) == 0)
595         {
596           x86bsd_xsave_len = info.xsave_len;
597           xcr0 = info.xsave_mask;
598         }
599       xsave_probed = 1;
600     }
601
602   if (x86bsd_xsave_len != 0)
603     {
604       if (is64)
605         return amd64_target_description (xcr0, true);
606       else
607         return i386_target_description (xcr0, true);
608     }
609 #endif
610   if (is64)
611     return amd64_target_description (X86_XSTATE_SSE_MASK, true);
612   else
613     return i386_target_description (X86_XSTATE_SSE_MASK, true);
614 }
615
616 #if defined(HAVE_PT_GETDBREGS) && defined(USE_SIGTRAP_SIGINFO)
617 /* Implement the supports_stopped_by_hw_breakpoints method.  */
618
619 bool
620 amd64_dfly_nat_target::supports_stopped_by_hw_breakpoint ()
621 {
622   return true;
623 }
624 #endif
625
626 void
627 _initialize_amd64dfly_nat (void)
628 {
629   int offset;
630
631   amd64_native_gregset32_reg_offset = amd64dfly32_r_reg_offset;
632   amd64_native_gregset64_reg_offset = amd64dfly64_r_reg_offset;
633
634   add_inf_child_target (&the_amd64_dfly_nat_target);
635
636 #ifdef DFLY_PCB_SUPPLY
637   /* Support debugging kernel virtual memory images.  */
638   bsd_kvm_add_target (amd64dfly_supply_pcb);
639 #endif
640
641   /* To support the recognition of signal handlers, i386-bsd-tdep.c
642      hardcodes some constants.  Inclusion of this file means that we
643      are compiling a native debugger, which means that we can use the
644      system header files and sysctl(3) to get at the relevant
645      information.  */
646
647 #define SC_REG_OFFSET amd64dfly_sc_reg_offset
648
649   /* We only check the program counter, stack pointer and frame
650      pointer since these members of `struct sigcontext' are essential
651      for providing backtraces.  */
652
653 #define SC_RIP_OFFSET SC_REG_OFFSET[AMD64_RIP_REGNUM]
654 #define SC_RSP_OFFSET SC_REG_OFFSET[AMD64_RSP_REGNUM]
655 #define SC_RBP_OFFSET SC_REG_OFFSET[AMD64_RBP_REGNUM]
656
657   /* Override the default value for the offset of the program counter
658      in the sigcontext structure.  */
659   offset = offsetof (struct sigcontext, sc_rip);
660
661   if (SC_RIP_OFFSET != offset)
662     {
663       warning (_("\
664 offsetof (struct sigcontext, sc_rip) yields %d instead of %d.\n\
665 Please report this to <bug-gdb@gnu.org>."),
666                offset, SC_RIP_OFFSET);
667     }
668
669   SC_RIP_OFFSET = offset;
670
671   /* Likewise for the stack pointer.  */
672   offset = offsetof (struct sigcontext, sc_rsp);
673
674   if (SC_RSP_OFFSET != offset)
675     {
676       warning (_("\
677 offsetof (struct sigcontext, sc_rsp) yields %d instead of %d.\n\
678 Please report this to <bug-gdb@gnu.org>."),
679                offset, SC_RSP_OFFSET);
680     }
681
682   SC_RSP_OFFSET = offset;
683
684   /* And the frame pointer.  */
685   offset = offsetof (struct sigcontext, sc_rbp);
686
687   if (SC_RBP_OFFSET != offset)
688     {
689       warning (_("\
690 offsetof (struct sigcontext, sc_rbp) yields %d instead of %d.\n\
691 Please report this to <bug-gdb@gnu.org>."),
692                offset, SC_RBP_OFFSET);
693     }
694
695   SC_RBP_OFFSET = offset;
696
697 #ifdef KERN_PROC_SIGTRAMP
698   {
699     struct kinfo_sigtramp kst = {0};
700     size_t len = sizeof (kst);
701     int mib[3] = { CTL_KERN, KERN_PROC, KERN_PROC_SIGTRAMP };
702     if (sysctl (mib, 3, &kst, &len, NULL, 0) == 0)
703       {
704         amd64dfly_sigtramp_start_addr = (uintptr_t) kst.ksigtramp_start;
705         amd64dfly_sigtramp_end_addr   = (uintptr_t) kst.ksigtramp_end;
706       }
707   }
708 #else
709   {
710     int mib[2];
711     long ps_strings;
712     size_t len;
713
714     mib[0] = CTL_KERN;
715     mib[1] = KERN_PS_STRINGS;
716     len = sizeof (ps_strings);
717     if (sysctl (mib, 2, &ps_strings, &len, NULL, 0) == 0)
718       {
719         amd64dfly_sigtramp_start_addr = ps_strings - 32;
720         amd64dfly_sigtramp_end_addr = ps_strings;
721       }
722   }
723 #endif
724 }
725
726
727 [FILE:6089:dragonfly/amd64-dfly-tdep.c]
728 /* Target-dependent code for DragonFly/amd64.
729
730    Copyright (C) 2003-2019 Free Software Foundation, Inc.
731
732    This file is part of GDB.
733
734    This program is free software; you can redistribute it and/or modify
735    it under the terms of the GNU General Public License as published by
736    the Free Software Foundation; either version 3 of the License, or
737    (at your option) any later version.
738
739    This program is distributed in the hope that it will be useful,
740    but WITHOUT ANY WARRANTY; without even the implied warranty of
741    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
742    GNU General Public License for more details.
743
744    You should have received a copy of the GNU General Public License
745    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
746
747 #include "defs.h"
748 #include "arch-utils.h"
749 #include "frame.h"
750 #include "gdbcore.h"
751 #include "regcache.h"
752 #include "osabi.h"
753 #include "regset.h"
754 #include "gdbsupport/x86-xstate.h"
755
756 #include <string.h>
757
758 #include "amd64-tdep.h"
759 #include "dfly-tdep.h"
760 #include "solib-svr4.h"
761
762 /* Support for signal handlers.  */
763
764 #if 0
765 /* Return whether THIS_FRAME corresponds to a FreeBSD sigtramp
766    routine.  */
767
768 static const gdb_byte amd64fbsd_sigtramp_code[] =
769 {
770   0x48, 0x8d, 0x7c, 0x24, 0x10, /* lea     SIGF_UC(%rsp),%rdi */
771   0x6a, 0x00,                   /* pushq   $0 */
772   0x48, 0xc7, 0xc0, 0xa1, 0x01, 0x00, 0x00,
773                                 /* movq    $SYS_sigreturn,%rax */
774   0x0f, 0x05                    /* syscall */
775 };
776
777 static int
778 amd64fbsd_sigtramp_p (struct frame_info *this_frame)
779 {
780   CORE_ADDR pc = get_frame_pc (this_frame);
781   gdb_byte buf[sizeof amd64fbsd_sigtramp_code];
782
783   if (!safe_frame_unwind_memory (this_frame, pc, buf, sizeof buf))
784     return 0;
785   if (memcmp (buf, amd64fbsd_sigtramp_code, sizeof amd64fbsd_sigtramp_code)
786       != 0)
787     return 0;
788
789   return 1;
790 }
791 #endif
792
793 /* Assuming THIS_FRAME is for a BSD sigtramp routine, return the
794    address of the associated sigcontext structure.  */
795
796 static CORE_ADDR
797 amd64dfly_sigcontext_addr (struct frame_info *this_frame)
798 {
799   struct gdbarch *gdbarch = get_frame_arch (this_frame);
800   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
801   CORE_ADDR sp;
802   gdb_byte buf[8];
803
804   /* The `struct sigcontext' (which really is an `ucontext_t' on
805      DragonFly/amd64) lives at a fixed offset in the signal frame.  See
806      <machine/sigframe.h>.  */
807   get_frame_register (this_frame, AMD64_RSP_REGNUM, buf);
808   sp = extract_unsigned_integer (buf, 8, byte_order);
809   return sp + 16;
810 }
811 \f
812 /* Mapping between the general-purpose registers in `struct reg'
813    format and GDB's register cache layout.
814
815    Note that some registers are 32-bit, but since we're little-endian
816    we get away with that.  */
817
818 /* From <machine/reg.h>.  */
819 static int amd64dfly_r_reg_offset[] =
820 {
821   6 * 8,                        /* %rax */
822   7 * 8,                        /* %rbx */
823   3 * 8,                        /* %rcx */
824   2 * 8,                        /* %rdx */
825   1 * 8,                        /* %rsi */
826   0 * 8,                        /* %rdi */
827   8 * 8,                        /* %rbp */
828   23 * 8,                       /* %rsp */
829   4 * 8,                        /* %r8 ... */
830   5 * 8,
831   9 * 8,
832   10 * 8,
833   11 * 8,
834   12 * 8,
835   13 * 8,
836   14 * 8,                       /* ... %r15 */
837   20 * 8,                       /* %rip */
838   22 * 8,                       /* %eflags */
839   21 * 8,                       /* %cs */
840   24 * 8,                       /* %ss */
841   -1,                           /* %ds */
842   -1,                           /* %es */
843   -1,                           /* %fs */
844   -1                            /* %gs */
845 };
846
847 /* Location of the signal trampoline.  */
848 CORE_ADDR amd64dfly_sigtramp_start_addr = 0x7fffffffffc0ULL;
849 CORE_ADDR amd64dfly_sigtramp_end_addr = 0x7fffffffffe0ULL;
850
851 /* From <machine/signal.h>.  */
852 int amd64dfly_sc_reg_offset[] =
853 {
854   24 + 6 * 8,                   /* %rax */
855   24 + 7 * 8,                   /* %rbx */
856   24 + 3 * 8,                   /* %rcx */
857   24 + 2 * 8,                   /* %rdx */
858   24 + 1 * 8,                   /* %rsi */
859   24 + 0 * 8,                   /* %rdi */
860   24 + 8 * 8,                   /* %rbp */
861   24 + 23 * 8,                  /* %rsp */
862   24 + 4 * 8,                   /* %r8 ... */
863   24 + 5 * 8,
864   24 + 9 * 8,
865   24 + 10 * 8,
866   24 + 11 * 8,
867   24 + 12 * 8,
868   24 + 13 * 8,
869   24 + 14 * 8,                  /* ... %r15 */
870   24 + 20 * 8,                  /* %rip */
871   24 + 22 * 8,                  /* %eflags */
872   24 + 21 * 8,                  /* %cs */
873   24 + 24 * 8,                  /* %ss */
874   -1,                           /* %ds */
875   -1,                           /* %es */
876   -1,                           /* %fs */
877   -1                            /* %gs */
878 };
879
880 /* From /usr/src/lib/libc/amd64/gen/_setjmp.S.  */
881 static int amd64dfly_jmp_buf_reg_offset[] =
882 {
883   -1,                           /* %rax */
884   1 * 8,                        /* %rbx */
885   -1,                           /* %rcx */
886   -1,                           /* %rdx */
887   -1,                           /* %rsi */
888   -1,                           /* %rdi */
889   3 * 8,                        /* %rbp */
890   2 * 8,                        /* %rsp */
891   -1,                           /* %r8 ... */
892   -1,
893   -1,
894   -1,                           /* ... %r11 */
895   4 * 8,                        /* %r12 ... */
896   5 * 8,
897   6 * 8,
898   7 * 8,                        /* ... %r15 */
899   0 * 8                         /* %rip */
900 };
901
902 static void
903 amd64dfly_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
904 {
905   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
906
907   /* Generic DragonFly support. */
908   dfly_init_abi (info, gdbarch);
909
910   /* Obviously DragonFly is BSD-based.  */
911   i386bsd_init_abi (info, gdbarch);
912
913   tdep->gregset_reg_offset = amd64dfly_r_reg_offset;
914   tdep->gregset_num_regs = ARRAY_SIZE (amd64dfly_r_reg_offset);
915   tdep->sizeof_gregset = 25 * 8;
916
917   amd64_init_abi (info, gdbarch,
918                   amd64_target_description (X86_XSTATE_SSE_MASK, true));
919
920 #if 0
921   tdep->sigtramp_p = amd64dfly_sigtramp_p;
922 #endif
923   tdep->sigtramp_start = amd64dfly_sigtramp_start_addr;
924   tdep->sigtramp_end = amd64dfly_sigtramp_end_addr;
925   tdep->sigcontext_addr = amd64dfly_sigcontext_addr;
926   tdep->sc_reg_offset = amd64dfly_sc_reg_offset;
927   tdep->sc_num_regs = ARRAY_SIZE (amd64dfly_sc_reg_offset);
928
929 #if 0
930   tdep->xsave_xcr0_offset = I386_DFLY_XSAVE_XCR0_OFFSET;
931
932   /* Iterate over core file register note sections.  */
933   set_gdbarch_iterate_over_regset_sections
934     (gdbarch, amd64dfly_iterate_over_regset_sections);
935
936   set_gdbarch_core_read_description (gdbarch,
937                                      amd64dfly_core_read_description);
938 #endif
939
940   /* FreeBSD uses SVR4-style shared libraries.  */
941   set_solib_svr4_fetch_link_map_offsets
942     (gdbarch, svr4_lp64_fetch_link_map_offsets);
943
944   set_gdbarch_fetch_tls_load_module_address (gdbarch,
945                                              svr4_fetch_objfile_link_map);
946 #if 0
947   set_gdbarch_get_thread_local_address (gdbarch,
948                                         amd64fbsd_get_thread_local_address);
949 #endif
950 }
951
952 void
953 _initialize_amd64dfly_tdep (void)
954 {
955   gdbarch_register_osabi (bfd_arch_i386, bfd_mach_x86_64,
956                           GDB_OSABI_DRAGONFLY, amd64dfly_init_abi);
957 }
958
959
960 [FILE:4794:dragonfly/dfly-nat.c]
961 /* Native-dependent code for DragonFly.
962
963    Copyright (C) 2002-2016 Free Software Foundation, Inc.
964
965    This file is part of GDB.
966
967    This program is free software; you can redistribute it and/or modify
968    it under the terms of the GNU General Public License as published by
969    the Free Software Foundation; either version 3 of the License, or
970    (at your option) any later version.
971
972    This program is distributed in the hope that it will be useful,
973    but WITHOUT ANY WARRANTY; without even the implied warranty of
974    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
975    GNU General Public License for more details.
976
977    You should have received a copy of the GNU General Public License
978    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
979
980 #include "defs.h"
981 #include "gdbsupport/byte-vector.h"
982 #include "gdbcore.h"
983 #include "inferior.h"
984 #include "regcache.h"
985 #include "regset.h"
986 #include "gdbarch.h"
987 #include "gdbcmd.h"
988 #include "gdbthread.h"
989 #include "gdbsupport/gdb_wait.h"
990 #include "inf-ptrace.h"
991 #include <sys/types.h>
992 #include <sys/procfs.h>
993 #include <sys/ptrace.h>
994 #include <sys/signal.h>
995 #include <sys/sysctl.h>
996 #include <sys/user.h>
997 #ifdef HAVE_KINFO_GETVMMAP
998 #include <libutil.h>
999 #endif
1000 #include "gdbsupport/filestuff.h"
1001
1002 #include "elf-bfd.h"
1003 #include "dfly-nat.h"
1004 #include "dfly-tdep.h"
1005
1006 #include <list>
1007
1008 /* Return the name of a file that can be opened to get the symbols for
1009    the child process identified by PID.  */
1010
1011 char *
1012 dfly_nat_target::pid_to_exec_file (int pid)
1013 {
1014   ssize_t len;
1015   static char buf[PATH_MAX];
1016   char name[PATH_MAX];
1017
1018 #ifdef KERN_PROC_PATHNAME
1019   size_t buflen;
1020   int mib[4];
1021
1022   mib[0] = CTL_KERN;
1023   mib[1] = KERN_PROC;
1024   mib[2] = KERN_PROC_PATHNAME;
1025   mib[3] = pid;
1026   buflen = sizeof buf;
1027   if (sysctl (mib, 4, buf, &buflen, NULL, 0) == 0)
1028     /* The kern.proc.pathname.<pid> sysctl returns a length of zero
1029        for processes without an associated executable such as kernel
1030        processes.  */
1031     return buflen == 0 ? NULL : buf;
1032 #endif
1033
1034   xsnprintf (name, PATH_MAX, "/proc/%d/exe", pid);
1035   len = readlink (name, buf, PATH_MAX - 1);
1036   if (len != -1)
1037     {
1038       buf[len] = '\0';
1039       return buf;
1040     }
1041
1042   return NULL;
1043 }
1044
1045 static int
1046 dfly_read_mapping (FILE *mapfile, unsigned long *start, unsigned long *end,
1047                    char *protection)
1048 {
1049   /* FreeBSD 5.1-RELEASE uses a 256-byte buffer.  */
1050   char buf[256];
1051   int resident, privateresident;
1052   unsigned long obj;
1053   int ret = EOF;
1054
1055   /* As of FreeBSD 5.0-RELEASE, the layout is described in
1056      /usr/src/sys/fs/procfs/procfs_map.c.  Somewhere in 5.1-CURRENT a
1057      new column was added to the procfs map.  Therefore we can't use
1058      fscanf since we need to support older releases too.  */
1059   if (fgets (buf, sizeof buf, mapfile) != NULL)
1060     ret = sscanf (buf, "%lx %lx %d %d %lx %s", start, end,
1061                   &resident, &privateresident, &obj, protection);
1062
1063   return (ret != 0 && ret != EOF);
1064 }
1065
1066 /* Iterate over all the memory regions in the current inferior,
1067    calling FUNC for each memory region.  OBFD is passed as the last
1068    argument to FUNC.  */
1069
1070 int
1071 dfly_nat_target::find_memory_regions (find_memory_region_ftype func,
1072                                       void *obfd)
1073 {
1074   pid_t pid = inferior_ptid.pid ();
1075   unsigned long start, end, size;
1076   char protection[4];
1077   int read, write, exec;
1078
1079   std::string mapfilename = string_printf ("/proc/%ld/map", (long) pid);
1080   gdb_file_up mapfile (fopen (mapfilename.c_str (), "r"));
1081   if (mapfile == NULL)
1082     error (_("Couldn't open %s."), mapfilename.c_str ());
1083
1084   if (info_verbose)
1085     fprintf_filtered (gdb_stdout, 
1086                       "Reading memory regions from %s\n", mapfilename.c_str ());
1087
1088   /* Now iterate until end-of-file.  */
1089   while (dfly_read_mapping (mapfile.get (), &start, &end, &protection[0]))
1090     {
1091       size = end - start;
1092
1093       read = (strchr (protection, 'r') != 0);
1094       write = (strchr (protection, 'w') != 0);
1095       exec = (strchr (protection, 'x') != 0);
1096
1097       if (info_verbose)
1098         {
1099           fprintf_filtered (gdb_stdout, 
1100                             "Save segment, %ld bytes at %s (%c%c%c)\n",
1101                             size, paddress (target_gdbarch (), start),
1102                             read ? 'r' : '-',
1103                             write ? 'w' : '-',
1104                             exec ? 'x' : '-');
1105         }
1106
1107       /* Invoke the callback function to create the corefile segment.
1108          Pass MODIFIED as true, we do not know the real modification state.  */
1109       func (start, size, read, write, exec, 1, obfd);
1110     }
1111
1112   return 0;
1113 }
1114
1115 #ifdef OLDCODE
1116 void
1117 dfly_nat_add_target (struct target_ops *t)
1118 {
1119   t->to_pid_to_exec_file = dfly_pid_to_exec_file;
1120   t->to_find_memory_regions = dfly_find_memory_regions;
1121   /* XXX: thread vfork support */
1122   add_target (t);
1123 }
1124 #endif
1125
1126 /* Provide a prototype to silence -Wmissing-prototypes.  */
1127 extern initialize_file_ftype _initialize_dfly_nat;
1128
1129 void
1130 _initialize_dfly_nat (void)
1131 {
1132 /* XXX: todo add_setshow_boolean_cmd() */
1133 }
1134
1135
1136 [FILE:1305:dragonfly/dfly-nat.h]
1137 /* Native-dependent code for DragonFly.
1138
1139    Copyright (C) 2004-2019 Free Software Foundation, Inc.
1140
1141    This file is part of GDB.
1142
1143    This program is free software; you can redistribute it and/or modify
1144    it under the terms of the GNU General Public License as published by
1145    the Free Software Foundation; either version 3 of the License, or
1146    (at your option) any later version.
1147
1148    This program is distributed in the hope that it will be useful,
1149    but WITHOUT ANY WARRANTY; without even the implied warranty of
1150    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1151    GNU General Public License for more details.
1152
1153    You should have received a copy of the GNU General Public License
1154    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
1155
1156 #ifndef DFLY_NAT_H
1157 #define DFLY_NAT_H
1158
1159 #include "inf-ptrace.h"
1160 #include <sys/user.h>
1161
1162 /* A prototype DragonFly target. */
1163
1164 class dfly_nat_target : public inf_ptrace_target
1165 {
1166 public:
1167   char *pid_to_exec_file (int pid) override;
1168
1169   int find_memory_regions (find_memory_region_ftype func, void *data) override;
1170
1171 };
1172
1173 #ifdef OLDCODE
1174 /* Register the customized DragonFly target.  This should be used
1175    instead of calling add_target directly.  */
1176 extern void dfly_nat_add_target (struct target_ops *);
1177 #endif
1178
1179 #endif /* dfly-nat.h */
1180
1181
1182 [FILE:59356:dragonfly/dfly-tdep.c]
1183 /* Target-dependent code for DragonFly, architecture-independent.
1184
1185    Copyright (C) 2002-2019 Free Software Foundation, Inc.
1186
1187    This file is part of GDB.
1188
1189    This program is free software; you can redistribute it and/or modify
1190    it under the terms of the GNU General Public License as published by
1191    the Free Software Foundation; either version 3 of the License, or
1192    (at your option) any later version.
1193
1194    This program is distributed in the hope that it will be useful,
1195    but WITHOUT ANY WARRANTY; without even the implied warranty of
1196    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1197    GNU General Public License for more details.
1198
1199    You should have received a copy of the GNU General Public License
1200    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
1201
1202 #include "defs.h"
1203 #include "auxv.h"
1204 #include "gdbcore.h"
1205 #include "inferior.h"
1206 #include "regcache.h"
1207 #include "regset.h"
1208 #include "gdbthread.h"
1209 #include "objfiles.h"
1210 #include "xml-syscall.h"
1211 #include <sys/socket.h>
1212 #include <arpa/inet.h>
1213
1214 #include "elf-bfd.h"
1215 #include "dfly-tdep.h"
1216
1217 /* This enum is derived from FreeBSD's <sys/signal.h>.  */
1218
1219 enum
1220   {
1221     DRAGONFLY_SIGHUP = 1,
1222     DRAGONFLY_SIGINT = 2,
1223     DRAGONFLY_SIGQUIT = 3,
1224     DRAGONFLY_SIGILL = 4,
1225     DRAGONFLY_SIGTRAP = 5,
1226     DRAGONFLY_SIGABRT = 6,
1227     DRAGONFLY_SIGEMT = 7,
1228     DRAGONFLY_SIGFPE = 8,
1229     DRAGONFLY_SIGKILL = 9,
1230     DRAGONFLY_SIGBUS = 10,
1231     DRAGONFLY_SIGSEGV = 11,
1232     DRAGONFLY_SIGSYS = 12,
1233     DRAGONFLY_SIGPIPE = 13,
1234     DRAGONFLY_SIGALRM = 14,
1235     DRAGONFLY_SIGTERM = 15,
1236     DRAGONFLY_SIGURG = 16,
1237     DRAGONFLY_SIGSTOP = 17,
1238     DRAGONFLY_SIGTSTP = 18,
1239     DRAGONFLY_SIGCONT = 19,
1240     DRAGONFLY_SIGCHLD = 20,
1241     DRAGONFLY_SIGTTIN = 21,
1242     DRAGONFLY_SIGTTOU = 22,
1243     DRAGONFLY_SIGIO = 23,
1244     DRAGONFLY_SIGXCPU = 24,
1245     DRAGONFLY_SIGXFSZ = 25,
1246     DRAGONFLY_SIGVTALRM = 26,
1247     DRAGONFLY_SIGPROF = 27,
1248     DRAGONFLY_SIGWINCH = 28,
1249     DRAGONFLY_SIGINFO = 29,
1250     DRAGONFLY_SIGUSR1 = 30,
1251     DRAGONFLY_SIGUSR2 = 31,
1252     DRAGONFLY_SIGTHR = 32,
1253     DRAGONFLY_SIGCKPT = 33,
1254     DRAGONFLY_SIGCKPTEXIT = 34,
1255   };
1256
1257 #if 0
1258 /* Flags in pl_flags.  */
1259 #define PL_FLAG_SI      0x20    /* siginfo is valid */
1260
1261 /* Sizes of siginfo_t.  */
1262 #define SIZE64_SIGINFO_T        80
1263 #define SIZE32_SIGINFO_T        64
1264
1265 /* Offsets in data structure used in NT_FREEBSD_PROCSTAT_VMMAP core
1266    dump notes.  See <sys/user.h> for the definition of struct
1267    kinfo_vmentry.  This data structure should have the same layout on
1268    all architectures.
1269
1270    Note that FreeBSD 7.0 used an older version of this structure
1271    (struct kinfo_ovmentry), but the NT_FREEBSD_PROCSTAT_VMMAP core
1272    dump note wasn't introduced until FreeBSD 9.2.  As a result, the
1273    core dump note has always used the 7.1 and later structure
1274    format.  */
1275
1276 #define KVE_STRUCTSIZE          0x0
1277 #define KVE_START               0x8
1278 #define KVE_END                 0x10
1279 #define KVE_OFFSET              0x18
1280 #define KVE_FLAGS               0x2c
1281 #define KVE_PROTECTION          0x38
1282 #define KVE_PATH                0x88
1283
1284 /* Flags in the 'kve_protection' field in struct kinfo_vmentry.  These
1285    match the KVME_PROT_* constants in <sys/user.h>.  */
1286
1287 #define KINFO_VME_PROT_READ     0x00000001
1288 #define KINFO_VME_PROT_WRITE    0x00000002
1289 #define KINFO_VME_PROT_EXEC     0x00000004
1290
1291 /* Flags in the 'kve_flags' field in struct kinfo_vmentry.  These
1292    match the KVME_FLAG_* constants in <sys/user.h>.  */
1293
1294 #define KINFO_VME_FLAG_COW              0x00000001
1295 #define KINFO_VME_FLAG_NEEDS_COPY       0x00000002
1296 #define KINFO_VME_FLAG_NOCOREDUMP       0x00000004
1297 #define KINFO_VME_FLAG_SUPER            0x00000008
1298 #define KINFO_VME_FLAG_GROWS_UP         0x00000010
1299 #define KINFO_VME_FLAG_GROWS_DOWN       0x00000020
1300
1301 /* Offsets in data structure used in NT_FREEBSD_PROCSTAT_FILES core
1302    dump notes.  See <sys/user.h> for the definition of struct
1303    kinfo_file.  This data structure should have the same layout on all
1304    architectures.
1305
1306    Note that FreeBSD 7.0 used an older version of this structure
1307    (struct kinfo_ofile), but the NT_FREEBSD_PROCSTAT_FILES core dump
1308    note wasn't introduced until FreeBSD 9.2.  As a result, the core
1309    dump note has always used the 7.1 and later structure format.  */
1310
1311 #define KF_STRUCTSIZE           0x0
1312 #define KF_TYPE                 0x4
1313 #define KF_FD                   0x8
1314 #define KF_FLAGS                0x10
1315 #define KF_OFFSET               0x18
1316 #define KF_VNODE_TYPE           0x20
1317 #define KF_SOCK_DOMAIN          0x24
1318 #define KF_SOCK_TYPE            0x28
1319 #define KF_SOCK_PROTOCOL        0x2c
1320 #define KF_SA_LOCAL             0x30
1321 #define KF_SA_PEER              0xb0
1322 #define KF_PATH                 0x170
1323
1324 /* Constants for the 'kf_type' field in struct kinfo_file.  These
1325    match the KF_TYPE_* constants in <sys/user.h>.  */
1326
1327 #define KINFO_FILE_TYPE_VNODE   1
1328 #define KINFO_FILE_TYPE_SOCKET  2
1329 #define KINFO_FILE_TYPE_PIPE    3
1330 #define KINFO_FILE_TYPE_FIFO    4
1331 #define KINFO_FILE_TYPE_KQUEUE  5
1332 #define KINFO_FILE_TYPE_CRYPTO  6
1333 #define KINFO_FILE_TYPE_MQUEUE  7
1334 #define KINFO_FILE_TYPE_SHM     8
1335 #define KINFO_FILE_TYPE_SEM     9
1336 #define KINFO_FILE_TYPE_PTS     10
1337 #define KINFO_FILE_TYPE_PROCDESC 11
1338
1339 /* Special values for the 'kf_fd' field in struct kinfo_file.  These
1340    match the KF_FD_TYPE_* constants in <sys/user.h>.  */
1341
1342 #define KINFO_FILE_FD_TYPE_CWD  -1
1343 #define KINFO_FILE_FD_TYPE_ROOT -2
1344 #define KINFO_FILE_FD_TYPE_JAIL -3
1345 #define KINFO_FILE_FD_TYPE_TRACE -4
1346 #define KINFO_FILE_FD_TYPE_TEXT -5
1347 #define KINFO_FILE_FD_TYPE_CTTY -6
1348
1349 /* Flags in the 'kf_flags' field in struct kinfo_file.  These match
1350    the KF_FLAG_* constants in <sys/user.h>.  */
1351
1352 #define KINFO_FILE_FLAG_READ            0x00000001
1353 #define KINFO_FILE_FLAG_WRITE           0x00000002
1354 #define KINFO_FILE_FLAG_APPEND          0x00000004
1355 #define KINFO_FILE_FLAG_ASYNC           0x00000008
1356 #define KINFO_FILE_FLAG_FSYNC           0x00000010
1357 #define KINFO_FILE_FLAG_NONBLOCK        0x00000020
1358 #define KINFO_FILE_FLAG_DIRECT          0x00000040
1359 #define KINFO_FILE_FLAG_HASLOCK         0x00000080
1360 #define KINFO_FILE_FLAG_EXEC            0x00004000
1361
1362 /* Constants for the 'kf_vnode_type' field in struct kinfo_file.
1363    These match the KF_VTYPE_* constants in <sys/user.h>.  */
1364
1365 #define KINFO_FILE_VTYPE_VREG   1
1366 #define KINFO_FILE_VTYPE_VDIR   2
1367 #define KINFO_FILE_VTYPE_VCHR   4
1368 #define KINFO_FILE_VTYPE_VLNK   5
1369 #define KINFO_FILE_VTYPE_VSOCK  6
1370 #define KINFO_FILE_VTYPE_VFIFO  7
1371 #endif
1372
1373 /* Constants for socket address families.  These match AF_* constants
1374    in <sys/socket.h>.  */
1375
1376 #define DFLY_AF_UNIX            1
1377 #define DFLY_AF_INET            2
1378 #define DFLY_AF_INET6           28
1379
1380 /* Constants for socket types.  These match SOCK_* constants in
1381    <sys/socket.h>.  */
1382
1383 #define DFLY_SOCK_STREAM        1
1384 #define DFLY_SOCK_DGRAM         2
1385 #define DFLY_SOCK_SEQPACKET     5
1386
1387 /* Constants for IP protocols.  These match IPPROTO_* constants in
1388    <netinet/in.h>.  */
1389
1390 #define DFLY_IPPROTO_ICMP       1
1391 #define DFLY_IPPROTO_TCP        6
1392 #define DFLY_IPPROTO_UDP        17
1393
1394 /* Socket address structures.  These have the same layout on all
1395    DragonFly architectures.  In addition, multibyte fields such as IP
1396    addresses are always stored in network byte order.  */
1397
1398 struct dfly_sockaddr_in
1399 {
1400   uint8_t sin_len;
1401   uint8_t sin_family;
1402   uint8_t sin_port[2];
1403   uint8_t sin_addr[4];
1404   char sin_zero[8];
1405 };
1406
1407 struct dfly_sockaddr_in6
1408 {
1409   uint8_t sin6_len;
1410   uint8_t sin6_family;
1411   uint8_t sin6_port[2];
1412   uint32_t sin6_flowinfo;
1413   uint8_t sin6_addr[16];
1414   uint32_t sin6_scope_id;
1415 };
1416
1417 struct dfly_sockaddr_un
1418 {
1419   uint8_t sun_len;
1420   uint8_t sun_family;
1421   char sun_path[104];
1422 };
1423
1424 #if 0
1425 /* Number of 32-bit words in a signal set.  This matches _SIG_WORDS in
1426    <sys/_sigset.h> and is the same value on all architectures.  */
1427
1428 #define SIG_WORDS               4
1429
1430 /* Offsets in data structure used in NT_FREEBSD_PROCSTAT_PROC core
1431    dump notes.  See <sys/user.h> for the definition of struct
1432    kinfo_proc.  This data structure has different layouts on different
1433    architectures mostly due to ILP32 vs LP64.  However, FreeBSD/i386
1434    uses a 32-bit time_t while all other architectures use a 64-bit
1435    time_t.
1436
1437    The core dump note actually contains one kinfo_proc structure for
1438    each thread, but all of the process-wide data can be obtained from
1439    the first structure.  One result of this note's format is that some
1440    of the process-wide status available in the native target method
1441    from the kern.proc.pid.<pid> sysctl such as ki_stat and ki_siglist
1442    is not available from a core dump.  Instead, the per-thread data
1443    structures contain the value of these fields for individual
1444    threads.  */
1445
1446 struct kinfo_proc_layout
1447 {
1448   /* Offsets of struct kinfo_proc members.  */
1449   int ki_layout;
1450   int ki_pid;
1451   int ki_ppid;
1452   int ki_pgid;
1453   int ki_tpgid;
1454   int ki_sid;
1455   int ki_tdev_freebsd11;
1456   int ki_sigignore;
1457   int ki_sigcatch;
1458   int ki_uid;
1459   int ki_ruid;
1460   int ki_svuid;
1461   int ki_rgid;
1462   int ki_svgid;
1463   int ki_ngroups;
1464   int ki_groups;
1465   int ki_size;
1466   int ki_rssize;
1467   int ki_tsize;
1468   int ki_dsize;
1469   int ki_ssize;
1470   int ki_start;
1471   int ki_nice;
1472   int ki_comm;
1473   int ki_tdev;
1474   int ki_rusage;
1475   int ki_rusage_ch;
1476
1477   /* Offsets of struct rusage members.  */
1478   int ru_utime;
1479   int ru_stime;
1480   int ru_maxrss;
1481   int ru_minflt;
1482   int ru_majflt;
1483 };
1484
1485 const struct kinfo_proc_layout kinfo_proc_layout_64 =
1486   {
1487     .ki_layout = 0x4,
1488     .ki_pid = 0x48,
1489     .ki_ppid = 0x4c,
1490     .ki_pgid = 0x50,
1491     .ki_tpgid = 0x54,
1492     .ki_sid = 0x58,
1493     .ki_tdev_freebsd11 = 0x64,
1494     .ki_sigignore = 0x88,
1495     .ki_sigcatch = 0x98,
1496     .ki_uid = 0xa8,
1497     .ki_ruid = 0xac,
1498     .ki_svuid = 0xb0,
1499     .ki_rgid = 0xb4,
1500     .ki_svgid = 0xb8,
1501     .ki_ngroups = 0xbc,
1502     .ki_groups = 0xc0,
1503     .ki_size = 0x100,
1504     .ki_rssize = 0x108,
1505     .ki_tsize = 0x118,
1506     .ki_dsize = 0x120,
1507     .ki_ssize = 0x128,
1508     .ki_start = 0x150,
1509     .ki_nice = 0x185,
1510     .ki_comm = 0x1bf,
1511     .ki_tdev = 0x230,
1512     .ki_rusage = 0x260,
1513     .ki_rusage_ch = 0x2f0,
1514
1515     .ru_utime = 0x0,
1516     .ru_stime = 0x10,
1517     .ru_maxrss = 0x20,
1518     .ru_minflt = 0x40,
1519     .ru_majflt = 0x48,
1520   };
1521 #endif
1522
1523 static struct gdbarch_data *dfly_gdbarch_data_handle;
1524
1525 struct dfly_gdbarch_data
1526   {
1527     struct type *siginfo_type;
1528   };
1529
1530 static void *
1531 init_dfly_gdbarch_data (struct gdbarch *gdbarch)
1532 {
1533   return GDBARCH_OBSTACK_ZALLOC (gdbarch, struct dfly_gdbarch_data);
1534 }
1535
1536 static struct dfly_gdbarch_data *
1537 get_dfly_gdbarch_data (struct gdbarch *gdbarch)
1538 {
1539   return ((struct dfly_gdbarch_data *)
1540           gdbarch_data (gdbarch, dfly_gdbarch_data_handle));
1541 }
1542
1543 /* Per-program-space data for DragonFly architectures.  */
1544 static const struct program_space_data *dfly_pspace_data_handle;
1545
1546 struct dfly_pspace_data
1547 {
1548   /* Offsets in the runtime linker's 'Obj_Entry' structure.  */
1549   LONGEST off_linkmap;
1550   LONGEST off_tlsindex;
1551   bool rtld_offsets_valid;
1552 };
1553
1554 static struct dfly_pspace_data *
1555 get_dfly_pspace_data (struct program_space *pspace)
1556 {
1557   struct dfly_pspace_data *data;
1558
1559   data = ((struct dfly_pspace_data *)
1560           program_space_data (pspace, dfly_pspace_data_handle));
1561   if (data == NULL)
1562     {
1563       data = XCNEW (struct dfly_pspace_data);
1564       set_program_space_data (pspace, dfly_pspace_data_handle, data);
1565     }
1566
1567   return data;
1568 }
1569
1570 /* The cleanup callback for DragonFly architecture per-program-space data.  */
1571
1572 static void
1573 dfly_pspace_data_cleanup (struct program_space *pspace, void *data)
1574 {
1575   xfree (data);
1576 }
1577
1578 /* This is how we want PTIDs from core files to be printed.  */
1579
1580 static std::string
1581 dfly_core_pid_to_str (struct gdbarch *gdbarch, ptid_t ptid)
1582 {
1583   static char buf[80];
1584
1585   if (ptid.lwp () != 0)
1586     {
1587       xsnprintf (buf, sizeof buf, "LWP %ld", ptid.lwp ());
1588       return buf;
1589     }
1590
1591   return normal_pid_to_str (ptid);
1592 }
1593
1594 /* Extract the name assigned to a thread from a core.  Returns the
1595    string in a static buffer.  */
1596
1597 #if 0
1598 static const char *
1599 dfly_core_thread_name (struct gdbarch *gdbarch, struct thread_info *thr)
1600 {
1601   static char buf[80];
1602   struct bfd_section *section;
1603   bfd_size_type size;
1604
1605   if (thr->ptid.lwp () != 0)
1606     {
1607       /* FreeBSD includes a NT_FREEBSD_THRMISC note for each thread
1608          whose contents are defined by a "struct thrmisc" declared in
1609          <sys/procfs.h> on FreeBSD.  The per-thread name is stored as
1610          a null-terminated string as the first member of the
1611          structure.  Rather than define the full structure here, just
1612          extract the null-terminated name from the start of the
1613          note.  */
1614       thread_section_name section_name (".thrmisc", thr->ptid);
1615
1616       section = bfd_get_section_by_name (core_bfd, section_name.c_str ());
1617       if (section != NULL && bfd_section_size (core_bfd, section) > 0)
1618         {
1619           /* Truncate the name if it is longer than "buf".  */
1620           size = bfd_section_size (core_bfd, section);
1621           if (size > sizeof buf - 1)
1622             size = sizeof buf - 1;
1623           if (bfd_get_section_contents (core_bfd, section, buf, (file_ptr) 0,
1624                                         size)
1625               && buf[0] != '\0')
1626             {
1627               buf[size] = '\0';
1628
1629               /* Note that each thread will report the process command
1630                  as its thread name instead of an empty name if a name
1631                  has not been set explicitly.  Return a NULL name in
1632                  that case.  */
1633               if (strcmp (buf, elf_tdata (core_bfd)->core->program) != 0)
1634                 return buf;
1635             }
1636         }
1637     }
1638
1639   return NULL;
1640 }
1641 #endif
1642
1643 /* Implement the "core_xfer_siginfo" gdbarch method.  */
1644
1645 #if 0
1646 static LONGEST
1647 dfly_core_xfer_siginfo (struct gdbarch *gdbarch, gdb_byte *readbuf,
1648                         ULONGEST offset, ULONGEST len)
1649 {
1650   size_t siginfo_size;
1651
1652   if (gdbarch_long_bit (gdbarch) == 32)
1653     siginfo_size = SIZE32_SIGINFO_T;
1654   else
1655     siginfo_size = SIZE64_SIGINFO_T;
1656   if (offset > siginfo_size)
1657     return -1;
1658
1659   thread_section_name section_name (".note.freebsdcore.lwpinfo", inferior_ptid);
1660   asection *section = bfd_get_section_by_name (core_bfd, section_name.c_str ());
1661   if (section == NULL)
1662     return -1;
1663
1664   gdb_byte buf[4];
1665   if (!bfd_get_section_contents (core_bfd, section, buf,
1666                                  LWPINFO_OFFSET + LWPINFO_PL_FLAGS, 4))
1667     return -1;
1668
1669   int pl_flags = extract_signed_integer (buf, 4, gdbarch_byte_order (gdbarch));
1670   if (!(pl_flags & PL_FLAG_SI))
1671     return -1;
1672
1673   if (offset + len > siginfo_size)
1674     len = siginfo_size - offset;
1675
1676   ULONGEST siginfo_offset;
1677   if (gdbarch_long_bit (gdbarch) == 32)
1678     siginfo_offset = LWPINFO_OFFSET + LWPINFO32_PL_SIGINFO;
1679   else
1680     siginfo_offset = LWPINFO_OFFSET + LWPINFO64_PL_SIGINFO;
1681
1682   if (!bfd_get_section_contents (core_bfd, section, readbuf,
1683                                  siginfo_offset + offset, len))
1684     return -1;
1685
1686   return len;
1687 }
1688 #endif
1689
1690 #if 0
1691 static int
1692 find_signalled_thread (struct thread_info *info, void *data)
1693 {
1694   if (info->suspend.stop_signal != GDB_SIGNAL_0
1695       && info->ptid.pid () == inferior_ptid.pid ())
1696     return 1;
1697
1698   return 0;
1699 }
1700 #endif
1701
1702 /* Structure for passing information from
1703    dfly_collect_thread_registers via an iterator to
1704    dfly_collect_regset_section_cb. */
1705
1706 #if 0
1707 struct dfly_collect_regset_section_cb_data
1708 {
1709   const struct regcache *regcache;
1710   bfd *obfd;
1711   char *note_data;
1712   int *note_size;
1713   unsigned long lwp;
1714   enum gdb_signal stop_signal;
1715   int abort_iteration;
1716 };
1717 #endif
1718
1719 #if 0
1720 static void
1721 dfly_collect_regset_section_cb (const char *sect_name, int supply_size,
1722                                 int collect_size, const struct regset *regset,
1723                                 const char *human_name, void *cb_data)
1724 {
1725   char *buf;
1726   struct dfly_collect_regset_section_cb_data *data
1727     = (struct dfly_collect_regset_section_cb_data *) cb_data;
1728
1729   if (data->abort_iteration)
1730     return;
1731
1732   gdb_assert (regset->collect_regset);
1733
1734   buf = (char *) xmalloc (collect_size);
1735   regset->collect_regset (regset, data->regcache, -1, buf, collect_size);
1736
1737   /* PRSTATUS still needs to be treated specially.  */
1738   if (strcmp (sect_name, ".reg") == 0)
1739     data->note_data = (char *) elfcore_write_prstatus
1740       (data->obfd, data->note_data, data->note_size, data->lwp,
1741        gdb_signal_to_host (data->stop_signal), buf);
1742   else
1743     data->note_data = (char *) elfcore_write_register_note
1744       (data->obfd, data->note_data, data->note_size,
1745        sect_name, buf, collect_size);
1746   xfree (buf);
1747
1748   if (data->note_data == NULL)
1749     data->abort_iteration = 1;
1750 }
1751 #endif
1752
1753 /* Records the thread's register state for the corefile note
1754    section.  */
1755
1756 #if 0
1757 static char *
1758 dfly_collect_thread_registers (const struct regcache *regcache,
1759                                ptid_t ptid, bfd *obfd,
1760                                char *note_data, int *note_size,
1761                                enum gdb_signal stop_signal)
1762 {
1763   struct gdbarch *gdbarch = regcache->arch ();
1764   struct dfly_collect_regset_section_cb_data data;
1765
1766   data.regcache = regcache;
1767   data.obfd = obfd;
1768   data.note_data = note_data;
1769   data.note_size = note_size;
1770   data.stop_signal = stop_signal;
1771   data.abort_iteration = 0;
1772   data.lwp = ptid.lwp ();
1773
1774   gdbarch_iterate_over_regset_sections (gdbarch,
1775                                         dfly_collect_regset_section_cb,
1776                                         &data, regcache);
1777   return data.note_data;
1778 }
1779 #endif
1780
1781 #if 0
1782 struct dfly_corefile_thread_data
1783 {
1784   struct gdbarch *gdbarch;
1785   bfd *obfd;
1786   char *note_data;
1787   int *note_size;
1788   enum gdb_signal stop_signal;
1789 };
1790 #endif
1791
1792 /* Records the thread's register state for the corefile note
1793    section.  */
1794
1795 #if 0
1796 static void
1797 dfly_corefile_thread (struct thread_info *info,
1798                       struct dfly_corefile_thread_data *args)
1799 {
1800   struct regcache *regcache;
1801
1802   regcache = get_thread_arch_regcache (info->ptid, args->gdbarch);
1803
1804   target_fetch_registers (regcache, -1);
1805
1806   args->note_data = dfly_collect_thread_registers
1807     (regcache, info->ptid, args->obfd, args->note_data,
1808      args->note_size, args->stop_signal);
1809 }
1810 #endif
1811
1812 /* Return a byte_vector containing the contents of a core dump note
1813    for the target object of type OBJECT.  If STRUCTSIZE is non-zero,
1814    the data is prefixed with a 32-bit integer size to match the format
1815    used in FreeBSD NT_PROCSTAT_* notes.  */
1816
1817 #if 0
1818 static gdb::optional<gdb::byte_vector>
1819 dfly_make_note_desc (enum target_object object, uint32_t structsize)
1820 {
1821   gdb::optional<gdb::byte_vector> buf =
1822     target_read_alloc (current_top_target (), object, NULL);
1823   if (!buf || buf->empty ())
1824     return {};
1825
1826   if (structsize == 0)
1827     return buf;
1828
1829   gdb::byte_vector desc (sizeof (structsize) + buf->size ());
1830   memcpy (desc.data (), &structsize, sizeof (structsize));
1831   memcpy (desc.data () + sizeof (structsize), buf->data (), buf->size ());
1832   return desc;
1833 }
1834 #endif
1835
1836 /* Create appropriate note sections for a corefile, returning them in
1837    allocated memory.  */
1838
1839 #if 0
1840 static char *
1841 dfly_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size)
1842 {
1843   struct dfly_corefile_thread_data thread_args;
1844   char *note_data = NULL;
1845   Elf_Internal_Ehdr *i_ehdrp;
1846   struct thread_info *curr_thr, *signalled_thr;
1847
1848   gdb_assert (gdbarch_iterate_over_regset_sections_p (gdbarch));
1849
1850   if (get_exec_file (0))
1851     {
1852       const char *fname = lbasename (get_exec_file (0));
1853       char *psargs = xstrdup (fname);
1854
1855       if (get_inferior_args ())
1856         psargs = reconcat (psargs, psargs, " ", get_inferior_args (),
1857                            (char *) NULL);
1858
1859       note_data = elfcore_write_prpsinfo (obfd, note_data, note_size,
1860                                           fname, psargs);
1861     }
1862
1863   /* Thread register information.  */
1864   TRY
1865     {
1866       update_thread_list ();
1867     }
1868   CATCH (e, RETURN_MASK_ERROR)
1869     {
1870       exception_print (gdb_stderr, e);
1871     }
1872   END_CATCH
1873
1874   /* Like the kernel, prefer dumping the signalled thread first.
1875      "First thread" is what tools use to infer the signalled thread.
1876      In case there's more than one signalled thread, prefer the
1877      current thread, if it is signalled.  */
1878   curr_thr = inferior_thread ();
1879   if (curr_thr->suspend.stop_signal != GDB_SIGNAL_0)
1880     signalled_thr = curr_thr;
1881   else
1882     {
1883       signalled_thr = iterate_over_threads (find_signalled_thread, NULL);
1884       if (signalled_thr == NULL)
1885         signalled_thr = curr_thr;
1886     }
1887
1888   thread_args.gdbarch = gdbarch;
1889   thread_args.obfd = obfd;
1890   thread_args.note_data = note_data;
1891   thread_args.note_size = note_size;
1892   thread_args.stop_signal = signalled_thr->suspend.stop_signal;
1893
1894   dfly_corefile_thread (signalled_thr, &thread_args);
1895   for (thread_info *thr : current_inferior ()->non_exited_threads ())
1896     {
1897       if (thr == signalled_thr)
1898         continue;
1899
1900       dfly_corefile_thread (thr, &thread_args);
1901     }
1902
1903   note_data = thread_args.note_data;
1904
1905   /* Auxiliary vector.  */
1906   uint32_t structsize = gdbarch_ptr_bit (gdbarch) / 4; /* Elf_Auxinfo  */
1907   gdb::optional<gdb::byte_vector> note_desc =
1908     dfly_make_note_desc (TARGET_OBJECT_AUXV, structsize);
1909   if (note_desc && !note_desc->empty ())
1910     {
1911       note_data = elfcore_write_note (obfd, note_data, note_size, "FreeBSD",
1912                                       NT_FREEBSD_PROCSTAT_AUXV,
1913                                       note_desc->data (), note_desc->size ());
1914       if (!note_data)
1915         return NULL;
1916     }
1917
1918   /* Virtual memory mappings.  */
1919   note_desc = dfly_make_note_desc (TARGET_OBJECT_FREEBSD_VMMAP, 0);
1920   if (note_desc && !note_desc->empty ())
1921     {
1922       note_data = elfcore_write_note (obfd, note_data, note_size, "FreeBSD",
1923                                       NT_FREEBSD_PROCSTAT_VMMAP,
1924                                       note_desc->data (), note_desc->size ());
1925       if (!note_data)
1926         return NULL;
1927     }
1928
1929   note_desc = dfly_make_note_desc (TARGET_OBJECT_FREEBSD_PS_STRINGS, 0);
1930   if (note_desc && !note_desc->empty ())
1931     {
1932       note_data = elfcore_write_note (obfd, note_data, note_size, "FreeBSD",
1933                                       NT_FREEBSD_PROCSTAT_PSSTRINGS,
1934                                       note_desc->data (), note_desc->size ());
1935       if (!note_data)
1936         return NULL;
1937     }
1938
1939   return note_data;
1940 }
1941 #endif
1942
1943 /* Helper function to generate the file descriptor description for a
1944    single open file in 'info proc files'.  */
1945
1946 #if 0
1947 static const char *
1948 dfly_file_fd (int kf_fd)
1949 {
1950   switch (kf_fd)
1951     {
1952     case KINFO_FILE_FD_TYPE_CWD:
1953       return "cwd";
1954     case KINFO_FILE_FD_TYPE_ROOT:
1955       return "root";
1956     case KINFO_FILE_FD_TYPE_JAIL:
1957       return "jail";
1958     case KINFO_FILE_FD_TYPE_TRACE:
1959       return "trace";
1960     case KINFO_FILE_FD_TYPE_TEXT:
1961       return "text";
1962     case KINFO_FILE_FD_TYPE_CTTY:
1963       return "ctty";
1964     default:
1965       return int_string (kf_fd, 10, 1, 0, 0);
1966     }
1967 }
1968 #endif
1969
1970 /* Helper function to generate the file type for a single open file in
1971    'info proc files'.  */
1972
1973 #if 0
1974 static const char *
1975 dfly_file_type (int kf_type, int kf_vnode_type)
1976 {
1977   switch (kf_type)
1978     {
1979     case KINFO_FILE_TYPE_VNODE:
1980       switch (kf_vnode_type)
1981         {
1982         case KINFO_FILE_VTYPE_VREG:
1983           return "file";
1984         case KINFO_FILE_VTYPE_VDIR:
1985           return "dir";
1986         case KINFO_FILE_VTYPE_VCHR:
1987           return "chr";
1988         case KINFO_FILE_VTYPE_VLNK:
1989           return "link";
1990         case KINFO_FILE_VTYPE_VSOCK:
1991           return "socket";
1992         case KINFO_FILE_VTYPE_VFIFO:
1993           return "fifo";
1994         default:
1995           {
1996             char *str = get_print_cell ();
1997
1998             xsnprintf (str, PRINT_CELL_SIZE, "vn:%d", kf_vnode_type);
1999             return str;
2000           }
2001         }
2002     case KINFO_FILE_TYPE_SOCKET:
2003       return "socket";
2004     case KINFO_FILE_TYPE_PIPE:
2005       return "pipe";
2006     case KINFO_FILE_TYPE_FIFO:
2007       return "fifo";
2008     case KINFO_FILE_TYPE_KQUEUE:
2009       return "kqueue";
2010     case KINFO_FILE_TYPE_CRYPTO:
2011       return "crypto";
2012     case KINFO_FILE_TYPE_MQUEUE:
2013       return "mqueue";
2014     case KINFO_FILE_TYPE_SHM:
2015       return "shm";
2016     case KINFO_FILE_TYPE_SEM:
2017       return "sem";
2018     case KINFO_FILE_TYPE_PTS:
2019       return "pts";
2020     case KINFO_FILE_TYPE_PROCDESC:
2021       return "proc";
2022     default:
2023       return int_string (kf_type, 10, 1, 0, 0);
2024     }
2025 }
2026 #endif
2027
2028 /* Helper function to generate the file flags for a single open file in
2029    'info proc files'.  */
2030
2031 #if 0
2032 static const char *
2033 dfly_file_flags (int kf_flags)
2034 {
2035   static char file_flags[10];
2036
2037   file_flags[0] = (kf_flags & KINFO_FILE_FLAG_READ) ? 'r' : '-';
2038   file_flags[1] = (kf_flags & KINFO_FILE_FLAG_WRITE) ? 'w' : '-';
2039   file_flags[2] = (kf_flags & KINFO_FILE_FLAG_EXEC) ? 'x' : '-';
2040   file_flags[3] = (kf_flags & KINFO_FILE_FLAG_APPEND) ? 'a' : '-';
2041   file_flags[4] = (kf_flags & KINFO_FILE_FLAG_ASYNC) ? 's' : '-';
2042   file_flags[5] = (kf_flags & KINFO_FILE_FLAG_FSYNC) ? 'f' : '-';
2043   file_flags[6] = (kf_flags & KINFO_FILE_FLAG_NONBLOCK) ? 'n' : '-';
2044   file_flags[7] = (kf_flags & KINFO_FILE_FLAG_DIRECT) ? 'd' : '-';
2045   file_flags[8] = (kf_flags & KINFO_FILE_FLAG_HASLOCK) ? 'l' : '-';
2046   file_flags[9] = '\0';
2047
2048   return file_flags;
2049 }
2050 #endif
2051
2052 /* Helper function to generate the name of an IP protocol.  */
2053
2054 static const char *
2055 dfly_ipproto (int protocol)
2056 {
2057   switch (protocol)
2058     {
2059     case DFLY_IPPROTO_ICMP:
2060       return "icmp";
2061     case DFLY_IPPROTO_TCP:
2062       return "tcp";
2063     case DFLY_IPPROTO_UDP:
2064       return "udp";
2065     default:
2066       {
2067         char *str = get_print_cell ();
2068
2069         xsnprintf (str, PRINT_CELL_SIZE, "ip<%d>", protocol);
2070         return str;
2071       }
2072     }
2073 }
2074
2075 /* Helper function to print out an IPv4 socket address.  */
2076
2077 static void
2078 dfly_print_sockaddr_in (const void *sockaddr)
2079 {
2080   const struct dfly_sockaddr_in *sin =
2081     reinterpret_cast<const struct dfly_sockaddr_in *> (sockaddr);
2082   char buf[INET_ADDRSTRLEN];
2083
2084   if (inet_ntop (AF_INET, sin->sin_addr, buf, sizeof buf) == nullptr)
2085     error (_("Failed to format IPv4 address"));
2086   printf_filtered ("%s:%u", buf,
2087                    (sin->sin_port[0] << 8) | sin->sin_port[1]);
2088 }
2089
2090 /* Helper function to print out an IPv6 socket address.  */
2091
2092 static void
2093 dfly_print_sockaddr_in6 (const void *sockaddr)
2094 {
2095   const struct dfly_sockaddr_in6 *sin6 =
2096     reinterpret_cast<const struct dfly_sockaddr_in6 *> (sockaddr);
2097   char buf[INET6_ADDRSTRLEN];
2098
2099   if (inet_ntop (AF_INET6, sin6->sin6_addr, buf, sizeof buf) == nullptr)
2100     error (_("Failed to format IPv6 address"));
2101   printf_filtered ("%s.%u", buf,
2102                    (sin6->sin6_port[0] << 8) | sin6->sin6_port[1]);
2103 }
2104
2105 /* See dfly-tdep.h.  */
2106
2107 #if 0
2108 void
2109 dfly_info_proc_files_header ()
2110 {
2111   printf_filtered (_("Open files:\n\n"));
2112   printf_filtered ("  %6s %6s %10s %9s %s\n",
2113                    "FD", "Type", "Offset", "Flags  ", "Name");
2114 }
2115 #endif
2116
2117 /* See dfly-tdep.h.  */
2118
2119 #if 0
2120 void
2121 dfly_info_proc_files_entry (int kf_type, int kf_fd, int kf_flags,
2122                             LONGEST kf_offset, int kf_vnode_type,
2123                             int kf_sock_domain, int kf_sock_type,
2124                             int kf_sock_protocol, const void *kf_sa_local,
2125                             const void *kf_sa_peer, const void *kf_path)
2126 {
2127   printf_filtered ("  %6s %6s %10s %8s ",
2128                    dfly_file_fd (kf_fd),
2129                    dfly_file_type (kf_type, kf_vnode_type),
2130                    kf_offset > -1 ? hex_string (kf_offset) : "-",
2131                    dfly_file_flags (kf_flags));
2132   if (kf_type == KINFO_FILE_TYPE_SOCKET)
2133     {
2134       switch (kf_sock_domain)
2135         {
2136         case DFLY_AF_UNIX:
2137           {
2138             switch (kf_sock_type)
2139               {
2140               case DFLY_SOCK_STREAM:
2141                 printf_filtered ("unix stream:");
2142                 break;
2143               case DFLY_SOCK_DGRAM:
2144                 printf_filtered ("unix dgram:");
2145                 break;
2146               case DFLY_SOCK_SEQPACKET:
2147                 printf_filtered ("unix seqpacket:");
2148                 break;
2149               default:
2150                 printf_filtered ("unix <%d>:", kf_sock_type);
2151                 break;
2152               }
2153
2154             /* For local sockets, print out the first non-nul path
2155                rather than both paths.  */
2156             const struct dfly_sockaddr_un *sun
2157               = reinterpret_cast<const struct dfly_sockaddr_un *> (kf_sa_local);
2158             if (sun->sun_path[0] == 0)
2159               sun = reinterpret_cast<const struct dfly_sockaddr_un *>
2160                 (kf_sa_peer);
2161             printf_filtered ("%s", sun->sun_path);
2162             break;
2163           }
2164         case DFLY_AF_INET:
2165           printf_filtered ("%s4 ", dfly_ipproto (kf_sock_protocol));
2166           dfly_print_sockaddr_in (kf_sa_local);
2167           printf_filtered (" -> ");
2168           dfly_print_sockaddr_in (kf_sa_peer);
2169           break;
2170         case DFLY_AF_INET6:
2171           printf_filtered ("%s6 ", dfly_ipproto (kf_sock_protocol));
2172           dfly_print_sockaddr_in6 (kf_sa_local);
2173           printf_filtered (" -> ");
2174           dfly_print_sockaddr_in6 (kf_sa_peer);
2175           break;
2176         }
2177     }
2178   else
2179     printf_filtered ("%s", reinterpret_cast<const char *> (kf_path));
2180   printf_filtered ("\n");
2181 }
2182 #endif
2183
2184 /* Implement "info proc files" for a corefile.  */
2185
2186 #if 0
2187 static void
2188 dfly_core_info_proc_files (struct gdbarch *gdbarch)
2189 {
2190   asection *section
2191     = bfd_get_section_by_name (core_bfd, ".note.freebsdcore.files");
2192   if (section == NULL)
2193     {
2194       warning (_("unable to find open files in core file"));
2195       return;
2196     }
2197
2198   size_t note_size = bfd_get_section_size (section);
2199   if (note_size < 4)
2200     error (_("malformed core note - too short for header"));
2201
2202   gdb::def_vector<unsigned char> contents (note_size);
2203   if (!bfd_get_section_contents (core_bfd, section, contents.data (),
2204                                  0, note_size))
2205     error (_("could not get core note contents"));
2206
2207   unsigned char *descdata = contents.data ();
2208   unsigned char *descend = descdata + note_size;
2209
2210   /* Skip over the structure size.  */
2211   descdata += 4;
2212
2213   dfly_info_proc_files_header ();
2214
2215   while (descdata + KF_PATH < descend)
2216     {
2217       ULONGEST structsize = bfd_get_32 (core_bfd, descdata + KF_STRUCTSIZE);
2218       if (structsize < KF_PATH)
2219         error (_("malformed core note - file structure too small"));
2220
2221       LONGEST type = bfd_get_signed_32 (core_bfd, descdata + KF_TYPE);
2222       LONGEST fd = bfd_get_signed_32 (core_bfd, descdata + KF_FD);
2223       LONGEST flags = bfd_get_signed_32 (core_bfd, descdata + KF_FLAGS);
2224       LONGEST offset = bfd_get_signed_64 (core_bfd, descdata + KF_OFFSET);
2225       LONGEST vnode_type = bfd_get_signed_32 (core_bfd,
2226                                               descdata + KF_VNODE_TYPE);
2227       LONGEST sock_domain = bfd_get_signed_32 (core_bfd,
2228                                                descdata + KF_SOCK_DOMAIN);
2229       LONGEST sock_type = bfd_get_signed_32 (core_bfd, descdata + KF_SOCK_TYPE);
2230       LONGEST sock_protocol = bfd_get_signed_32 (core_bfd,
2231                                                  descdata + KF_SOCK_PROTOCOL);
2232       dfly_info_proc_files_entry (type, fd, flags, offset, vnode_type,
2233                                   sock_domain, sock_type, sock_protocol,
2234                                   descdata + KF_SA_LOCAL, descdata + KF_SA_PEER,
2235                                   descdata + KF_PATH);
2236
2237       descdata += structsize;
2238     }
2239 }
2240 #endif
2241
2242 /* Helper function to generate mappings flags for a single VM map
2243    entry in 'info proc mappings'.  */
2244
2245 #if 0
2246 static const char *
2247 dfly_vm_map_entry_flags (int kve_flags, int kve_protection)
2248 {
2249   static char vm_flags[9];
2250
2251   vm_flags[0] = (kve_protection & KINFO_VME_PROT_READ) ? 'r' : '-';
2252   vm_flags[1] = (kve_protection & KINFO_VME_PROT_WRITE) ? 'w' : '-';
2253   vm_flags[2] = (kve_protection & KINFO_VME_PROT_EXEC) ? 'x' : '-';
2254   vm_flags[3] = ' ';
2255   vm_flags[4] = (kve_flags & KINFO_VME_FLAG_COW) ? 'C' : '-';
2256   vm_flags[5] = (kve_flags & KINFO_VME_FLAG_NEEDS_COPY) ? 'N' : '-';
2257   vm_flags[6] = (kve_flags & KINFO_VME_FLAG_SUPER) ? 'S' : '-';
2258   vm_flags[7] = (kve_flags & KINFO_VME_FLAG_GROWS_UP) ? 'U'
2259     : (kve_flags & KINFO_VME_FLAG_GROWS_DOWN) ? 'D' : '-';
2260   vm_flags[8] = '\0';
2261
2262   return vm_flags;
2263 }
2264 #endif
2265
2266 /* See dfly-tdep.h.  */
2267
2268 #if 0
2269 void
2270 dfly_info_proc_mappings_header (int addr_bit)
2271 {
2272   printf_filtered (_("Mapped address spaces:\n\n"));
2273   if (addr_bit == 64)
2274     {
2275       printf_filtered ("  %18s %18s %10s %10s %9s %s\n",
2276                        "Start Addr",
2277                        "  End Addr",
2278                        "      Size", "    Offset", "Flags  ", "File");
2279     }
2280   else
2281     {
2282       printf_filtered ("\t%10s %10s %10s %10s %9s %s\n",
2283                        "Start Addr",
2284                        "  End Addr",
2285                        "      Size", "    Offset", "Flags  ", "File");
2286     }
2287 }
2288 #endif
2289
2290 /* See dfly-tdep.h.  */
2291
2292 #if 0
2293 void
2294 dfly_info_proc_mappings_entry (int addr_bit, ULONGEST kve_start,
2295                                ULONGEST kve_end, ULONGEST kve_offset,
2296                                int kve_flags, int kve_protection,
2297                                const void *kve_path)
2298 {
2299   if (addr_bit == 64)
2300     {
2301       printf_filtered ("  %18s %18s %10s %10s %9s %s\n",
2302                        hex_string (kve_start),
2303                        hex_string (kve_end),
2304                        hex_string (kve_end - kve_start),
2305                        hex_string (kve_offset),
2306                        dfly_vm_map_entry_flags (kve_flags, kve_protection),
2307                        reinterpret_cast<const char *> (kve_path));
2308     }
2309   else
2310     {
2311       printf_filtered ("\t%10s %10s %10s %10s %9s %s\n",
2312                        hex_string (kve_start),
2313                        hex_string (kve_end),
2314                        hex_string (kve_end - kve_start),
2315                        hex_string (kve_offset),
2316                        dfly_vm_map_entry_flags (kve_flags, kve_protection),
2317                        reinterpret_cast<const char *> (kve_path));
2318     }
2319 }
2320 #endif
2321
2322 /* Implement "info proc mappings" for a corefile.  */
2323
2324 #if 0
2325 static void
2326 dfly_core_info_proc_mappings (struct gdbarch *gdbarch)
2327 {
2328   asection *section;
2329   unsigned char *descdata, *descend;
2330   size_t note_size;
2331
2332   section = bfd_get_section_by_name (core_bfd, ".note.freebsdcore.vmmap");
2333   if (section == NULL)
2334     {
2335       warning (_("unable to find mappings in core file"));
2336       return;
2337     }
2338
2339   note_size = bfd_get_section_size (section);
2340   if (note_size < 4)
2341     error (_("malformed core note - too short for header"));
2342
2343   gdb::def_vector<unsigned char> contents (note_size);
2344   if (!bfd_get_section_contents (core_bfd, section, contents.data (),
2345                                  0, note_size))
2346     error (_("could not get core note contents"));
2347
2348   descdata = contents.data ();
2349   descend = descdata + note_size;
2350
2351   /* Skip over the structure size.  */
2352   descdata += 4;
2353
2354   dfly_info_proc_mappings_header (gdbarch_addr_bit (gdbarch));
2355   while (descdata + KVE_PATH < descend)
2356     {
2357       ULONGEST structsize = bfd_get_32 (core_bfd, descdata + KVE_STRUCTSIZE);
2358       if (structsize < KVE_PATH)
2359         error (_("malformed core note - vmmap entry too small"));
2360
2361       ULONGEST start = bfd_get_64 (core_bfd, descdata + KVE_START);
2362       ULONGEST end = bfd_get_64 (core_bfd, descdata + KVE_END);
2363       ULONGEST offset = bfd_get_64 (core_bfd, descdata + KVE_OFFSET);
2364       LONGEST flags = bfd_get_signed_32 (core_bfd, descdata + KVE_FLAGS);
2365       LONGEST prot = bfd_get_signed_32 (core_bfd, descdata + KVE_PROTECTION);
2366       dfly_info_proc_mappings_entry (gdbarch_addr_bit (gdbarch), start, end,
2367                                      offset, flags, prot, descdata + KVE_PATH);
2368
2369       descdata += structsize;
2370     }
2371 }
2372 #endif
2373
2374 /* Fetch the pathname of a vnode for a single file descriptor from the
2375    file table core note.  */
2376
2377 #if 0
2378 static gdb::unique_xmalloc_ptr<char>
2379 dfly_core_vnode_path (struct gdbarch *gdbarch, int fd)
2380 {
2381   asection *section;
2382   unsigned char *descdata, *descend;
2383   size_t note_size;
2384
2385   section = bfd_get_section_by_name (core_bfd, ".note.freebsdcore.files");
2386   if (section == NULL)
2387     return nullptr;
2388
2389   note_size = bfd_get_section_size (section);
2390   if (note_size < 4)
2391     error (_("malformed core note - too short for header"));
2392
2393   gdb::def_vector<unsigned char> contents (note_size);
2394   if (!bfd_get_section_contents (core_bfd, section, contents.data (),
2395                                  0, note_size))
2396     error (_("could not get core note contents"));
2397
2398   descdata = contents.data ();
2399   descend = descdata + note_size;
2400
2401   /* Skip over the structure size.  */
2402   descdata += 4;
2403
2404   while (descdata + KF_PATH < descend)
2405     {
2406       ULONGEST structsize;
2407
2408       structsize = bfd_get_32 (core_bfd, descdata + KF_STRUCTSIZE);
2409       if (structsize < KF_PATH)
2410         error (_("malformed core note - file structure too small"));
2411
2412       if (bfd_get_32 (core_bfd, descdata + KF_TYPE) == KINFO_FILE_TYPE_VNODE
2413           && bfd_get_signed_32 (core_bfd, descdata + KF_FD) == fd)
2414         {
2415           char *path = (char *) descdata + KF_PATH;
2416           return gdb::unique_xmalloc_ptr<char> (xstrdup (path));
2417         }
2418
2419       descdata += structsize;
2420     }
2421   return nullptr;
2422 }
2423 #endif
2424
2425 /* Helper function to read a struct timeval.  */
2426
2427 #if 0
2428 static void
2429 dfly_core_fetch_timeval (struct gdbarch *gdbarch, unsigned char *data,
2430                          LONGEST &sec, ULONGEST &usec)
2431 {
2432   if (gdbarch_addr_bit (gdbarch) == 64)
2433     {
2434       sec = bfd_get_signed_64 (core_bfd, data);
2435       usec = bfd_get_64 (core_bfd, data + 8);
2436     }
2437   else if (bfd_get_arch (core_bfd) == bfd_arch_i386)
2438     {
2439       sec = bfd_get_signed_32 (core_bfd, data);
2440       usec = bfd_get_32 (core_bfd, data + 4);
2441     }
2442   else
2443     {
2444       sec = bfd_get_signed_64 (core_bfd, data);
2445       usec = bfd_get_32 (core_bfd, data + 8);
2446     }
2447 }
2448 #endif
2449
2450 /* Print out the contents of a signal set.  */
2451
2452 #if 0
2453 static void
2454 dfly_print_sigset (const char *descr, unsigned char *sigset)
2455 {
2456   printf_filtered ("%s: ", descr);
2457   for (int i = 0; i < SIG_WORDS; i++)
2458     printf_filtered ("%08x ",
2459                      (unsigned int) bfd_get_32 (core_bfd, sigset + i * 4));
2460   printf_filtered ("\n");
2461 }
2462 #endif
2463
2464 /* Implement "info proc status" for a corefile.  */
2465
2466 #if 0
2467 static void
2468 dfly_core_info_proc_status (struct gdbarch *gdbarch)
2469 {
2470   const struct kinfo_proc_layout *kp;
2471   asection *section;
2472   unsigned char *descdata;
2473   int addr_bit, long_bit;
2474   size_t note_size;
2475   ULONGEST value;
2476   LONGEST sec;
2477
2478   section = bfd_get_section_by_name (core_bfd, ".note.freebsdcore.proc");
2479   if (section == NULL)
2480     {
2481       warning (_("unable to find process info in core file"));
2482       return;
2483     }
2484
2485   addr_bit = gdbarch_addr_bit (gdbarch);
2486   if (addr_bit == 64)
2487     kp = &kinfo_proc_layout_64;
2488   else if (bfd_get_arch (core_bfd) == bfd_arch_i386)
2489     kp = &kinfo_proc_layout_i386;
2490   else
2491     kp = &kinfo_proc_layout_32;
2492   long_bit = gdbarch_long_bit (gdbarch);
2493
2494   /*
2495    * Ensure that the note is large enough for all of the fields fetched
2496    * by this function.  In particular, the note must contain the 32-bit
2497    * structure size, then it must be long enough to access the last
2498    * field used (ki_rusage_ch.ru_majflt) which is the size of a long.
2499    */
2500   note_size = bfd_get_section_size (section);
2501   if (note_size < (4 + kp->ki_rusage_ch + kp->ru_majflt
2502                    + long_bit / TARGET_CHAR_BIT))
2503     error (_("malformed core note - too short"));
2504
2505   gdb::def_vector<unsigned char> contents (note_size);
2506   if (!bfd_get_section_contents (core_bfd, section, contents.data (),
2507                                  0, note_size))
2508     error (_("could not get core note contents"));
2509
2510   descdata = contents.data ();
2511
2512   /* Skip over the structure size.  */
2513   descdata += 4;
2514
2515   /* Verify 'ki_layout' is 0.  */
2516   if (bfd_get_32 (core_bfd, descdata + kp->ki_layout) != 0)
2517     {
2518       warning (_("unsupported process information in core file"));
2519       return;
2520     }
2521
2522   printf_filtered ("Name: %.19s\n", descdata + kp->ki_comm);
2523   printf_filtered ("Process ID: %s\n",
2524                    pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_pid)));
2525   printf_filtered ("Parent process: %s\n",
2526                    pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_ppid)));
2527   printf_filtered ("Process group: %s\n",
2528                    pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_pgid)));
2529   printf_filtered ("Session id: %s\n",
2530                    pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_sid)));
2531
2532   /* FreeBSD 12.0 and later store a 64-bit dev_t at 'ki_tdev'.  Older
2533      kernels store a 32-bit dev_t at 'ki_tdev_freebsd11'.  In older
2534      kernels the 64-bit 'ki_tdev' field is in a reserved section of
2535      the structure that is cleared to zero.  Assume that a zero value
2536      in ki_tdev indicates a core dump from an older kernel and use the
2537      value in 'ki_tdev_freebsd11' instead.  */
2538   value = bfd_get_64 (core_bfd, descdata + kp->ki_tdev);
2539   if (value == 0)
2540     value = bfd_get_32 (core_bfd, descdata + kp->ki_tdev_freebsd11);
2541   printf_filtered ("TTY: %s\n", pulongest (value));
2542   printf_filtered ("TTY owner process group: %s\n",
2543                    pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_tpgid)));
2544   printf_filtered ("User IDs (real, effective, saved): %s %s %s\n",
2545                    pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_ruid)),
2546                    pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_uid)),
2547                    pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_svuid)));
2548   printf_filtered ("Group IDs (real, effective, saved): %s %s %s\n",
2549                    pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_rgid)),
2550                    pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_groups)),
2551                    pulongest (bfd_get_32 (core_bfd, descdata + kp->ki_svgid)));
2552   printf_filtered ("Groups: ");
2553   uint16_t ngroups = bfd_get_16 (core_bfd, descdata + kp->ki_ngroups);
2554   for (int i = 0; i < ngroups; i++)
2555     printf_filtered ("%s ",
2556                      pulongest (bfd_get_32 (core_bfd,
2557                                             descdata + kp->ki_groups + i * 4)));
2558   printf_filtered ("\n");
2559   value = bfd_get (long_bit, core_bfd,
2560                    descdata + kp->ki_rusage + kp->ru_minflt);
2561   printf_filtered ("Minor faults (no memory page): %s\n", pulongest (value));
2562   value = bfd_get (long_bit, core_bfd,
2563                    descdata + kp->ki_rusage_ch + kp->ru_minflt);
2564   printf_filtered ("Minor faults, children: %s\n", pulongest (value));
2565   value = bfd_get (long_bit, core_bfd,
2566                    descdata + kp->ki_rusage + kp->ru_majflt);
2567   printf_filtered ("Major faults (memory page faults): %s\n",
2568                    pulongest (value));
2569   value = bfd_get (long_bit, core_bfd,
2570                    descdata + kp->ki_rusage_ch + kp->ru_majflt);
2571   printf_filtered ("Major faults, children: %s\n", pulongest (value));
2572   dfly_core_fetch_timeval (gdbarch,
2573                            descdata + kp->ki_rusage + kp->ru_utime,
2574                            sec, value);
2575   printf_filtered ("utime: %s.%06d\n", plongest (sec), (int) value);
2576   dfly_core_fetch_timeval (gdbarch,
2577                            descdata + kp->ki_rusage + kp->ru_stime,
2578                            sec, value);
2579   printf_filtered ("stime: %s.%06d\n", plongest (sec), (int) value);
2580   dfly_core_fetch_timeval (gdbarch,
2581                            descdata + kp->ki_rusage_ch + kp->ru_utime,
2582                            sec, value);
2583   printf_filtered ("utime, children: %s.%06d\n", plongest (sec), (int) value);
2584   dfly_core_fetch_timeval (gdbarch,
2585                            descdata + kp->ki_rusage_ch + kp->ru_stime,
2586                            sec, value);
2587   printf_filtered ("stime, children: %s.%06d\n", plongest (sec), (int) value);
2588   printf_filtered ("'nice' value: %d\n",
2589                    bfd_get_signed_8 (core_bfd, descdata + kp->ki_nice));
2590   dfly_core_fetch_timeval (gdbarch, descdata + kp->ki_start, sec, value);
2591   printf_filtered ("Start time: %s.%06d\n", plongest (sec), (int) value);
2592   printf_filtered ("Virtual memory size: %s kB\n",
2593                    pulongest (bfd_get (addr_bit, core_bfd,
2594                                        descdata + kp->ki_size) / 1024));
2595   printf_filtered ("Data size: %s pages\n",
2596                    pulongest (bfd_get (addr_bit, core_bfd,
2597                                        descdata + kp->ki_dsize)));
2598   printf_filtered ("Stack size: %s pages\n",
2599                    pulongest (bfd_get (addr_bit, core_bfd,
2600                                        descdata + kp->ki_ssize)));
2601   printf_filtered ("Text size: %s pages\n",
2602                    pulongest (bfd_get (addr_bit, core_bfd,
2603                                        descdata + kp->ki_tsize)));
2604   printf_filtered ("Resident set size: %s pages\n",
2605                    pulongest (bfd_get (addr_bit, core_bfd,
2606                                        descdata + kp->ki_rssize)));
2607   printf_filtered ("Maximum RSS: %s pages\n",
2608                    pulongest (bfd_get (long_bit, core_bfd,
2609                                        descdata + kp->ki_rusage
2610                                        + kp->ru_maxrss)));
2611   dfly_print_sigset ("Ignored Signals", descdata + kp->ki_sigignore);
2612   dfly_print_sigset ("Caught Signals", descdata + kp->ki_sigcatch);
2613 }
2614 #endif
2615
2616 /* Implement the "core_info_proc" gdbarch method.  */
2617
2618 #if 0
2619 static void
2620 dfly_core_info_proc (struct gdbarch *gdbarch, const char *args,
2621                      enum info_proc_what what)
2622 {
2623   bool do_cmdline = false;
2624   bool do_cwd = false;
2625   bool do_exe = false;
2626   bool do_files = false;
2627   bool do_mappings = false;
2628   bool do_status = false;
2629   int pid;
2630
2631   switch (what)
2632     {
2633     case IP_MINIMAL:
2634       do_cmdline = true;
2635       do_cwd = true;
2636       do_exe = true;
2637       break;
2638     case IP_MAPPINGS:
2639       do_mappings = true;
2640       break;
2641     case IP_STATUS:
2642     case IP_STAT:
2643       do_status = true;
2644       break;
2645     case IP_CMDLINE:
2646       do_cmdline = true;
2647       break;
2648     case IP_EXE:
2649       do_exe = true;
2650       break;
2651     case IP_CWD:
2652       do_cwd = true;
2653       break;
2654     case IP_FILES:
2655       do_files = true;
2656       break;
2657     case IP_ALL:
2658       do_cmdline = true;
2659       do_cwd = true;
2660       do_exe = true;
2661       do_files = true;
2662       do_mappings = true;
2663       do_status = true;
2664       break;
2665     default:
2666       return;
2667     }
2668
2669   pid = bfd_core_file_pid (core_bfd);
2670   if (pid != 0)
2671     printf_filtered (_("process %d\n"), pid);
2672
2673   if (do_cmdline)
2674     {
2675       const char *cmdline;
2676
2677       cmdline = bfd_core_file_failing_command (core_bfd);
2678       if (cmdline)
2679         printf_filtered ("cmdline = '%s'\n", cmdline);
2680       else
2681         warning (_("Command line unavailable"));
2682     }
2683   if (do_cwd)
2684     {
2685       gdb::unique_xmalloc_ptr<char> cwd =
2686         dfly_core_vnode_path (gdbarch, KINFO_FILE_FD_TYPE_CWD);
2687       if (cwd)
2688         printf_filtered ("cwd = '%s'\n", cwd.get ());
2689       else
2690         warning (_("unable to read current working directory"));
2691     }
2692   if (do_exe)
2693     {
2694       gdb::unique_xmalloc_ptr<char> exe =
2695         dfly_core_vnode_path (gdbarch, KINFO_FILE_FD_TYPE_TEXT);
2696       if (exe)
2697         printf_filtered ("exe = '%s'\n", exe.get ());
2698       else
2699         warning (_("unable to read executable path name"));
2700     }
2701   if (do_files)
2702     dfly_core_info_proc_files (gdbarch);
2703   if (do_mappings)
2704     dfly_core_info_proc_mappings (gdbarch);
2705   if (do_status)
2706     dfly_core_info_proc_status (gdbarch);
2707 }
2708 #endif
2709
2710 /* Print descriptions of FreeBSD-specific AUXV entries to FILE.  */
2711
2712 #if 0
2713 static void
2714 dfly_print_auxv_entry (struct gdbarch *gdbarch, struct ui_file *file,
2715                        CORE_ADDR type, CORE_ADDR val)
2716 {
2717   const char *name = "???";
2718   const char *description = "";
2719   enum auxv_format format = AUXV_FORMAT_HEX;
2720
2721   switch (type)
2722     {
2723     case AT_NULL:
2724     case AT_IGNORE:
2725     case AT_EXECFD:
2726     case AT_PHDR:
2727     case AT_PHENT:
2728     case AT_PHNUM:
2729     case AT_PAGESZ:
2730     case AT_BASE:
2731     case AT_FLAGS:
2732     case AT_ENTRY:
2733     case AT_NOTELF:
2734     case AT_UID:
2735     case AT_EUID:
2736     case AT_GID:
2737     case AT_EGID:
2738       default_print_auxv_entry (gdbarch, file, type, val);
2739       return;
2740 #define _TAGNAME(tag) #tag
2741 #define TAGNAME(tag) _TAGNAME(AT_##tag)
2742 #define TAG(tag, text, kind) \
2743       case AT_FREEBSD_##tag: name = TAGNAME(tag); description = text; format = kind; break
2744       TAG (EXECPATH, _("Executable path"), AUXV_FORMAT_STR);
2745       TAG (CANARY, _("Canary for SSP"), AUXV_FORMAT_HEX);
2746       TAG (CANARYLEN, ("Length of the SSP canary"), AUXV_FORMAT_DEC);
2747       TAG (OSRELDATE, _("OSRELDATE"), AUXV_FORMAT_DEC);
2748       TAG (NCPUS, _("Number of CPUs"), AUXV_FORMAT_DEC);
2749       TAG (PAGESIZES, _("Pagesizes"), AUXV_FORMAT_HEX);
2750       TAG (PAGESIZESLEN, _("Number of pagesizes"), AUXV_FORMAT_DEC);
2751       TAG (TIMEKEEP, _("Pointer to timehands"), AUXV_FORMAT_HEX);
2752       TAG (STACKPROT, _("Initial stack protection"), AUXV_FORMAT_HEX);
2753       TAG (EHDRFLAGS, _("ELF header e_flags"), AUXV_FORMAT_HEX);
2754       TAG (HWCAP, _("Machine-dependent CPU capability hints"), AUXV_FORMAT_HEX);
2755       TAG (HWCAP2, _("Extension of AT_HWCAP"), AUXV_FORMAT_HEX);
2756     }
2757
2758   fprint_auxv_entry (file, name, description, format, type, val);
2759 }
2760 #endif
2761
2762 /* Implement the "get_siginfo_type" gdbarch method.  */
2763
2764 #if 0
2765 static struct type *
2766 dfly_get_siginfo_type (struct gdbarch *gdbarch)
2767 {
2768   struct dfly_gdbarch_data *dfly_gdbarch_data;
2769   struct type *int_type, *int32_type, *uint32_type, *long_type, *void_ptr_type;
2770   struct type *uid_type, *pid_type;
2771   struct type *sigval_type, *reason_type;
2772   struct type *siginfo_type;
2773   struct type *type;
2774
2775   dfly_gdbarch_data = get_dfly_gdbarch_data (gdbarch);
2776   if (dfly_gdbarch_data->siginfo_type != NULL)
2777     return dfly_gdbarch_data->siginfo_type;
2778
2779   int_type = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch),
2780                                 0, "int");
2781   int32_type = arch_integer_type (gdbarch, 32, 0, "int32_t");
2782   uint32_type = arch_integer_type (gdbarch, 32, 1, "uint32_t");
2783   long_type = arch_integer_type (gdbarch, gdbarch_long_bit (gdbarch),
2784                                  0, "long");
2785   void_ptr_type = lookup_pointer_type (builtin_type (gdbarch)->builtin_void);
2786
2787   /* union sigval */
2788   sigval_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_UNION);
2789   TYPE_NAME (sigval_type) = xstrdup ("sigval");
2790   append_composite_type_field (sigval_type, "sival_int", int_type);
2791   append_composite_type_field (sigval_type, "sival_ptr", void_ptr_type);
2792
2793   /* __pid_t */
2794   pid_type = arch_type (gdbarch, TYPE_CODE_TYPEDEF,
2795                         TYPE_LENGTH (int32_type) * TARGET_CHAR_BIT, "__pid_t");
2796   TYPE_TARGET_TYPE (pid_type) = int32_type;
2797   TYPE_TARGET_STUB (pid_type) = 1;
2798
2799   /* __uid_t */
2800   uid_type = arch_type (gdbarch, TYPE_CODE_TYPEDEF,
2801                         TYPE_LENGTH (uint32_type) * TARGET_CHAR_BIT,
2802                         "__uid_t");
2803   TYPE_TARGET_TYPE (uid_type) = uint32_type;
2804   TYPE_TARGET_STUB (uid_type) = 1;
2805
2806   /* _reason */
2807   reason_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_UNION);
2808
2809   /* _fault */
2810   type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
2811   append_composite_type_field (type, "si_trapno", int_type);
2812   append_composite_type_field (reason_type, "_fault", type);
2813
2814   /* _timer */
2815   type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
2816   append_composite_type_field (type, "si_timerid", int_type);
2817   append_composite_type_field (type, "si_overrun", int_type);
2818   append_composite_type_field (reason_type, "_timer", type);
2819
2820   /* _mesgq */
2821   type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
2822   append_composite_type_field (type, "si_mqd", int_type);
2823   append_composite_type_field (reason_type, "_mesgq", type);
2824
2825   /* _poll */
2826   type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
2827   append_composite_type_field (type, "si_band", long_type);
2828   append_composite_type_field (reason_type, "_poll", type);
2829
2830   /* __spare__ */
2831   type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
2832   append_composite_type_field (type, "__spare1__", long_type);
2833   append_composite_type_field (type, "__spare2__",
2834                                init_vector_type (int_type, 7));
2835   append_composite_type_field (reason_type, "__spare__", type);
2836
2837   /* struct siginfo */
2838   siginfo_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
2839   TYPE_NAME (siginfo_type) = xstrdup ("siginfo");
2840   append_composite_type_field (siginfo_type, "si_signo", int_type);
2841   append_composite_type_field (siginfo_type, "si_errno", int_type);
2842   append_composite_type_field (siginfo_type, "si_code", int_type);
2843   append_composite_type_field (siginfo_type, "si_pid", pid_type);
2844   append_composite_type_field (siginfo_type, "si_uid", uid_type);
2845   append_composite_type_field (siginfo_type, "si_status", int_type);
2846   append_composite_type_field (siginfo_type, "si_addr", void_ptr_type);
2847   append_composite_type_field (siginfo_type, "si_value", sigval_type);
2848   append_composite_type_field (siginfo_type, "_reason", reason_type);
2849
2850   dfly_gdbarch_data->siginfo_type = siginfo_type;
2851
2852   return siginfo_type;
2853 }
2854 #endif
2855
2856 /* Implement the "gdb_signal_from_target" gdbarch method.  */
2857
2858 static enum gdb_signal
2859 dfly_gdb_signal_from_target (struct gdbarch *gdbarch, int signal)
2860 {
2861   switch (signal)
2862     {
2863     case 0:
2864       return GDB_SIGNAL_0;
2865
2866     case DRAGONFLY_SIGHUP:
2867       return GDB_SIGNAL_HUP;
2868
2869     case DRAGONFLY_SIGINT:
2870       return GDB_SIGNAL_INT;
2871
2872     case DRAGONFLY_SIGQUIT:
2873       return GDB_SIGNAL_QUIT;
2874
2875     case DRAGONFLY_SIGILL:
2876       return GDB_SIGNAL_ILL;
2877
2878     case DRAGONFLY_SIGTRAP:
2879       return GDB_SIGNAL_TRAP;
2880
2881     case DRAGONFLY_SIGABRT:
2882       return GDB_SIGNAL_ABRT;
2883
2884     case DRAGONFLY_SIGEMT:
2885       return GDB_SIGNAL_EMT;
2886
2887     case DRAGONFLY_SIGFPE:
2888       return GDB_SIGNAL_FPE;
2889
2890     case DRAGONFLY_SIGKILL:
2891       return GDB_SIGNAL_KILL;
2892
2893     case DRAGONFLY_SIGBUS:
2894       return GDB_SIGNAL_BUS;
2895
2896     case DRAGONFLY_SIGSEGV:
2897       return GDB_SIGNAL_SEGV;
2898
2899     case DRAGONFLY_SIGSYS:
2900       return GDB_SIGNAL_SYS;
2901
2902     case DRAGONFLY_SIGPIPE:
2903       return GDB_SIGNAL_PIPE;
2904
2905     case DRAGONFLY_SIGALRM:
2906       return GDB_SIGNAL_ALRM;
2907
2908     case DRAGONFLY_SIGTERM:
2909       return GDB_SIGNAL_TERM;
2910
2911     case DRAGONFLY_SIGURG:
2912       return GDB_SIGNAL_URG;
2913
2914     case DRAGONFLY_SIGSTOP:
2915       return GDB_SIGNAL_STOP;
2916
2917     case DRAGONFLY_SIGTSTP:
2918       return GDB_SIGNAL_TSTP;
2919
2920     case DRAGONFLY_SIGCONT:
2921       return GDB_SIGNAL_CONT;
2922
2923     case DRAGONFLY_SIGCHLD:
2924       return GDB_SIGNAL_CHLD;
2925
2926     case DRAGONFLY_SIGTTIN:
2927       return GDB_SIGNAL_TTIN;
2928
2929     case DRAGONFLY_SIGTTOU:
2930       return GDB_SIGNAL_TTOU;
2931
2932     case DRAGONFLY_SIGIO:
2933       return GDB_SIGNAL_IO;
2934
2935     case DRAGONFLY_SIGXCPU:
2936       return GDB_SIGNAL_XCPU;
2937
2938     case DRAGONFLY_SIGXFSZ:
2939       return GDB_SIGNAL_XFSZ;
2940
2941     case DRAGONFLY_SIGVTALRM:
2942       return GDB_SIGNAL_VTALRM;
2943
2944     case DRAGONFLY_SIGPROF:
2945       return GDB_SIGNAL_PROF;
2946
2947     case DRAGONFLY_SIGWINCH:
2948       return GDB_SIGNAL_WINCH;
2949
2950     case DRAGONFLY_SIGINFO:
2951       return GDB_SIGNAL_INFO;
2952
2953     case DRAGONFLY_SIGUSR1:
2954       return GDB_SIGNAL_USR1;
2955
2956     case DRAGONFLY_SIGUSR2:
2957       return GDB_SIGNAL_USR2;
2958
2959 #if 0
2960     /* SIGTHR is the same as SIGLWP on FreeBSD. */
2961     case FREEBSD_SIGTHR:
2962       return GDB_SIGNAL_LWP;
2963
2964     case FREEBSD_SIGLIBRT:
2965       return GDB_SIGNAL_LIBRT;
2966 #endif
2967     }
2968
2969 #if 0
2970   if (signal >= FREEBSD_SIGRTMIN && signal <= FREEBSD_SIGRTMAX)
2971     {
2972       int offset = signal - FREEBSD_SIGRTMIN;
2973
2974       return (enum gdb_signal) ((int) GDB_SIGNAL_REALTIME_65 + offset);
2975     }
2976 #endif
2977
2978   return GDB_SIGNAL_UNKNOWN;
2979 }
2980
2981 /* Implement the "gdb_signal_to_target" gdbarch method.  */
2982
2983 static int
2984 dfly_gdb_signal_to_target (struct gdbarch *gdbarch,
2985                 enum gdb_signal signal)
2986 {
2987   switch (signal)
2988     {
2989     case GDB_SIGNAL_0:
2990       return 0;
2991
2992     case GDB_SIGNAL_HUP:
2993       return DRAGONFLY_SIGHUP;
2994
2995     case GDB_SIGNAL_INT:
2996       return DRAGONFLY_SIGINT;
2997
2998     case GDB_SIGNAL_QUIT:
2999       return DRAGONFLY_SIGQUIT;
3000
3001     case GDB_SIGNAL_ILL:
3002       return DRAGONFLY_SIGILL;
3003
3004     case GDB_SIGNAL_TRAP:
3005       return DRAGONFLY_SIGTRAP;
3006
3007     case GDB_SIGNAL_ABRT:
3008       return DRAGONFLY_SIGABRT;
3009
3010     case GDB_SIGNAL_EMT:
3011       return DRAGONFLY_SIGEMT;
3012
3013     case GDB_SIGNAL_FPE:
3014       return DRAGONFLY_SIGFPE;
3015
3016     case GDB_SIGNAL_KILL:
3017       return DRAGONFLY_SIGKILL;
3018
3019     case GDB_SIGNAL_BUS:
3020       return DRAGONFLY_SIGBUS;
3021
3022     case GDB_SIGNAL_SEGV:
3023       return DRAGONFLY_SIGSEGV;
3024
3025     case GDB_SIGNAL_SYS:
3026       return DRAGONFLY_SIGSYS;
3027
3028     case GDB_SIGNAL_PIPE:
3029       return DRAGONFLY_SIGPIPE;
3030
3031     case GDB_SIGNAL_ALRM:
3032       return DRAGONFLY_SIGALRM;
3033
3034     case GDB_SIGNAL_TERM:
3035       return DRAGONFLY_SIGTERM;
3036
3037     case GDB_SIGNAL_URG:
3038       return DRAGONFLY_SIGURG;
3039
3040     case GDB_SIGNAL_STOP:
3041       return DRAGONFLY_SIGSTOP;
3042
3043     case GDB_SIGNAL_TSTP:
3044       return DRAGONFLY_SIGTSTP;
3045
3046     case GDB_SIGNAL_CONT:
3047       return DRAGONFLY_SIGCONT;
3048
3049     case GDB_SIGNAL_CHLD:
3050       return DRAGONFLY_SIGCHLD;
3051
3052     case GDB_SIGNAL_TTIN:
3053       return DRAGONFLY_SIGTTIN;
3054
3055     case GDB_SIGNAL_TTOU:
3056       return DRAGONFLY_SIGTTOU;
3057
3058     case GDB_SIGNAL_IO:
3059       return DRAGONFLY_SIGIO;
3060
3061     case GDB_SIGNAL_XCPU:
3062       return DRAGONFLY_SIGXCPU;
3063
3064     case GDB_SIGNAL_XFSZ:
3065       return DRAGONFLY_SIGXFSZ;
3066
3067     case GDB_SIGNAL_VTALRM:
3068       return DRAGONFLY_SIGVTALRM;
3069
3070     case GDB_SIGNAL_PROF:
3071       return DRAGONFLY_SIGPROF;
3072
3073     case GDB_SIGNAL_WINCH:
3074       return DRAGONFLY_SIGWINCH;
3075
3076     case GDB_SIGNAL_INFO:
3077       return DRAGONFLY_SIGINFO;
3078
3079     case GDB_SIGNAL_USR1:
3080       return DRAGONFLY_SIGUSR1;
3081
3082     case GDB_SIGNAL_USR2:
3083       return DRAGONFLY_SIGUSR2;
3084
3085 #if 0
3086     case GDB_SIGNAL_LWP:
3087       return FREEBSD_SIGTHR;
3088
3089     case GDB_SIGNAL_LIBRT:
3090       return FREEBSD_SIGLIBRT;
3091 #endif
3092     }
3093
3094 #if 0
3095   if (signal >= GDB_SIGNAL_REALTIME_65
3096       && signal <= GDB_SIGNAL_REALTIME_126)
3097     {
3098       int offset = signal - GDB_SIGNAL_REALTIME_65;
3099
3100       return FREEBSD_SIGRTMIN + offset;
3101     }
3102 #endif
3103
3104   return -1;
3105 }
3106
3107 #if 0
3108 /* Implement the "get_syscall_number" gdbarch method.  */
3109
3110 static LONGEST
3111 dfly_get_syscall_number (struct gdbarch *gdbarch, thread_info *thread)
3112 {
3113
3114   /* FreeBSD doesn't use gdbarch_get_syscall_number since FreeBSD
3115      native targets fetch the system call number from the
3116      'pl_syscall_code' member of struct ptrace_lwpinfo in dfly_wait.
3117      However, system call catching requires this function to be
3118      set.  */
3119
3120   internal_error (__FILE__, __LINE__, _("dfly_get_sycall_number called"));
3121 }
3122 #endif
3123
3124 /* Read an integer symbol value from the current target.  */
3125
3126 #if 0
3127 static LONGEST
3128 dfly_read_integer_by_name (struct gdbarch *gdbarch, const char *name)
3129 {
3130   bound_minimal_symbol ms = lookup_minimal_symbol (name, NULL, NULL);
3131   if (ms.minsym == NULL)
3132     error (_("Unable to resolve symbol '%s'"), name);
3133
3134   gdb_byte buf[4];
3135   if (target_read_memory (BMSYMBOL_VALUE_ADDRESS (ms), buf, sizeof buf) != 0)
3136     error (_("Unable to read value of '%s'"), name);
3137
3138   return extract_signed_integer (buf, sizeof buf, gdbarch_byte_order (gdbarch));
3139 }
3140 #endif
3141
3142 /* Lookup offsets of fields in the runtime linker's 'Obj_Entry'
3143    structure needed to determine the TLS index of an object file.  */
3144
3145 #if 0
3146 static void
3147 dfly_fetch_rtld_offsets (struct gdbarch *gdbarch, struct dfly_pspace_data *data)
3148 {
3149   TRY
3150     {
3151       /* Fetch offsets from debug symbols in rtld.  */
3152       struct symbol *obj_entry_sym
3153         = lookup_symbol_in_language ("Struct_Obj_Entry", NULL, STRUCT_DOMAIN,
3154                                      language_c, NULL).symbol;
3155       if (obj_entry_sym == NULL)
3156         error (_("Unable to find Struct_Obj_Entry symbol"));
3157       data->off_linkmap = lookup_struct_elt (SYMBOL_TYPE(obj_entry_sym),
3158                                              "linkmap", 0).offset / 8;
3159       data->off_tlsindex = lookup_struct_elt (SYMBOL_TYPE(obj_entry_sym),
3160                                               "tlsindex", 0).offset / 8;
3161       data->rtld_offsets_valid = true;
3162       return;
3163     }
3164   CATCH (e, RETURN_MASK_ERROR)
3165     {
3166       data->off_linkmap = -1;
3167     }
3168   END_CATCH
3169
3170   TRY
3171     {
3172       /* Fetch offsets from global variables in libthr.  Note that
3173          this does not work for single-threaded processes that are not
3174          linked against libthr.  */
3175       data->off_linkmap = dfly_read_integer_by_name (gdbarch,
3176                                                      "_thread_off_linkmap");
3177       data->off_tlsindex = dfly_read_integer_by_name (gdbarch,
3178                                                       "_thread_off_tlsindex");
3179       data->rtld_offsets_valid = true;
3180       return;
3181     }
3182   CATCH (e, RETURN_MASK_ERROR)
3183     {
3184       data->off_linkmap = -1;
3185     }
3186   END_CATCH
3187 }
3188 #endif
3189
3190 /* Helper function to read the TLS index of an object file associated
3191    with a link map entry at LM_ADDR.  */
3192
3193 #if 0
3194 static LONGEST
3195 dfly_get_tls_index (struct gdbarch *gdbarch, CORE_ADDR lm_addr)
3196 {
3197   struct dfly_pspace_data *data = get_dfly_pspace_data (current_program_space);
3198
3199   if (!data->rtld_offsets_valid)
3200     dfly_fetch_rtld_offsets (gdbarch, data);
3201
3202   if (data->off_linkmap == -1)
3203     throw_error (TLS_GENERIC_ERROR,
3204                  _("Cannot fetch runtime linker structure offsets"));
3205
3206   /* Simulate container_of to convert from LM_ADDR to the Obj_Entry
3207      pointer and then compute the offset of the tlsindex member.  */
3208   CORE_ADDR tlsindex_addr = lm_addr - data->off_linkmap + data->off_tlsindex;
3209
3210   gdb_byte buf[4];
3211   if (target_read_memory (tlsindex_addr, buf, sizeof buf) != 0)
3212     throw_error (TLS_GENERIC_ERROR,
3213                  _("Cannot find thread-local variables on this target"));
3214
3215   return extract_signed_integer (buf, sizeof buf, gdbarch_byte_order (gdbarch));
3216 }
3217 #endif
3218
3219 /* See dfly-tdep.h.  */
3220
3221 #if 0
3222 CORE_ADDR
3223 dfly_get_thread_local_address (struct gdbarch *gdbarch, CORE_ADDR dtv_addr,
3224                                CORE_ADDR lm_addr, CORE_ADDR offset)
3225 {
3226   LONGEST tls_index = dfly_get_tls_index (gdbarch, lm_addr);
3227
3228   gdb_byte buf[gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT];
3229   if (target_read_memory (dtv_addr, buf, sizeof buf) != 0)
3230     throw_error (TLS_GENERIC_ERROR,
3231                  _("Cannot find thread-local variables on this target"));
3232
3233   const struct builtin_type *builtin = builtin_type (gdbarch);
3234   CORE_ADDR addr = gdbarch_pointer_to_address (gdbarch,
3235                                                builtin->builtin_data_ptr, buf);
3236
3237   addr += (tls_index + 1) * TYPE_LENGTH (builtin->builtin_data_ptr);
3238   if (target_read_memory (addr, buf, sizeof buf) != 0)
3239     throw_error (TLS_GENERIC_ERROR,
3240                  _("Cannot find thread-local variables on this target"));
3241
3242   addr = gdbarch_pointer_to_address (gdbarch, builtin->builtin_data_ptr, buf);
3243   return addr + offset;
3244 }
3245 #endif
3246
3247 /* To be called from GDB_OSABI_DRAGONFLY handlers. */
3248
3249 void
3250 dfly_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
3251 {
3252 #if 0
3253   set_gdbarch_core_pid_to_str (gdbarch, dfly_core_pid_to_str);
3254   set_gdbarch_core_thread_name (gdbarch, dfly_core_thread_name);
3255   set_gdbarch_core_xfer_siginfo (gdbarch, dfly_core_xfer_siginfo);
3256   set_gdbarch_make_corefile_notes (gdbarch, dfly_make_corefile_notes);
3257   set_gdbarch_core_info_proc (gdbarch, dfly_core_info_proc);
3258   set_gdbarch_print_auxv_entry (gdbarch, dfly_print_auxv_entry);
3259   set_gdbarch_get_siginfo_type (gdbarch, dfly_get_siginfo_type);
3260 #endif
3261   set_gdbarch_gdb_signal_from_target (gdbarch, dfly_gdb_signal_from_target);
3262   set_gdbarch_gdb_signal_to_target (gdbarch, dfly_gdb_signal_to_target);
3263
3264 #if 0
3265   /* `catch syscall' */
3266   set_xml_syscall_file_name (gdbarch, "syscalls/dragonfly.xml");
3267   set_gdbarch_get_syscall_number (gdbarch, dfly_get_syscall_number);
3268 #endif
3269 }
3270
3271 void
3272 _initialize_dfly_tdep (void)
3273 {
3274   dfly_gdbarch_data_handle =
3275     gdbarch_data_register_post_init (init_dfly_gdbarch_data);
3276   dfly_pspace_data_handle
3277     = register_program_space_data_with_cleanup (NULL, dfly_pspace_data_cleanup);
3278 }
3279
3280
3281 [FILE:2986:dragonfly/dfly-tdep.h]
3282 /* Target-dependent code for DragonFly, architecture independent.
3283
3284    Copyright (C) 2009-2019 Free Software Foundation, Inc.
3285
3286    This file is part of GDB.
3287
3288    This program is free software; you can redistribute it and/or modify
3289    it under the terms of the GNU General Public License as published by
3290    the Free Software Foundation; either version 3 of the License, or
3291    (at your option) any later version.
3292
3293    This program is distributed in the hope that it will be useful,
3294    but WITHOUT ANY WARRANTY; without even the implied warranty of
3295    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
3296    GNU General Public License for more details.
3297
3298    You should have received a copy of the GNU General Public License
3299    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
3300
3301 #ifndef DFLY_TDEP_H
3302 #define DFLY_TDEP_H
3303
3304 extern void dfly_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch);
3305
3306 /* Output the header for "info proc files".  */
3307
3308 extern void dfly_info_proc_files_header ();
3309
3310 /* Output description of a single file descriptor for "info proc
3311    files".  The KF_TYPE, KF_FD, KF_FLAGS, KF_OFFSET, KF_VNODE_TYPE,
3312    KF_SOCK_DOMAIN, KF_SOCK_TYPE, and KF_SOCK_PROTOCOL parameters
3313    should contain the value of the corresponding fields in a 'struct
3314    kinfo_file'.  The KF_SA_LOCAL, KF_SA_PEER, and KF_PATH parameters
3315    should contain pointers to the corresponding fields in a 'struct
3316    kinfo_file'. */
3317
3318 extern void dfly_info_proc_files_entry (int kf_type, int kf_fd, int kf_flags,
3319                                         LONGEST kf_offset, int kf_vnode_type,
3320                                         int kf_sock_domain, int kf_sock_type,
3321                                         int kf_sock_protocol,
3322                                         const void *kf_sa_local,
3323                                         const void *kf_sa_peer,
3324                                         const void *kf_path);
3325
3326 /* Output the header for "info proc mappings".  ADDR_BIT is the size
3327    of a virtual address in bits.  */
3328
3329 extern void dfly_info_proc_mappings_header (int addr_bit);
3330
3331 /* Output description of a single memory range for "info proc
3332    mappings".  ADDR_BIT is the size of a virtual address in bits.  The
3333    KVE_START, KVE_END, KVE_OFFSET, KVE_FLAGS, and KVE_PROTECTION
3334    parameters should contain the value of the corresponding fields in
3335    a 'struct kinfo_vmentry'.  The KVE_PATH parameter should contain a
3336    pointer to the 'kve_path' field in a 'struct kinfo_vmentry'. */
3337
3338 extern void dfly_info_proc_mappings_entry (int addr_bit, ULONGEST kve_start,
3339                                            ULONGEST kve_end,
3340                                            ULONGEST kve_offset,
3341                                            int kve_flags, int kve_protection,
3342                                            const void *kve_path);
3343
3344 /* Helper function to fetch the address of a thread-local variable.
3345    DTV_ADDR is the base address of the thread's dtv array.  LM_ADDR is
3346    the address of the link_map structure for the associated object
3347    file.  OFFSET is the offset of the variable in the object file's
3348    thread-local variable block.  */
3349
3350 extern CORE_ADDR dfly_get_thread_local_address (struct gdbarch *gdbarch,
3351                                                 CORE_ADDR dtv_addr,
3352                                                 CORE_ADDR lm_addr,
3353                                                 CORE_ADDR offset);
3354
3355 #endif /* dfly-tdep.h */
3356
3357
3358 [FILE:2546:dragonfly/i386-dfly-tdep.c]
3359 /* Target-dependent code for DragonFly/i386.
3360
3361    Copyright (C) 2003-2013 Free Software Foundation, Inc.
3362
3363    This file is part of GDB.
3364
3365    This program is free software; you can redistribute it and/or modify
3366    it under the terms of the GNU General Public License as published by
3367    the Free Software Foundation; either version 3 of the License, or
3368    (at your option) any later version.
3369
3370    This program is distributed in the hope that it will be useful,
3371    but WITHOUT ANY WARRANTY; without even the implied warranty of
3372    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
3373    GNU General Public License for more details.
3374
3375    You should have received a copy of the GNU General Public License
3376    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
3377
3378 #include "defs.h"
3379 #include "arch-utils.h"
3380 #include "gdbcore.h"
3381 #include "osabi.h"
3382 #include "regcache.h"
3383 #include "regset.h"
3384 #include "gdbsupport/x86-xstate.h"
3385
3386 #include "i386-tdep.h"
3387 #include "i387-tdep.h"
3388 #include "dfly-tdep.h"
3389 #include "solib-svr4.h"
3390
3391 static int i386dfly_r_reg_offset[] =
3392 {
3393   44, /* %eax */
3394   40, /* %ecx */
3395   36, /* %edx */
3396   32, /* %ebx */
3397   72, /* %esp */
3398   24, /* %ebp */
3399   20, /* %esi */
3400   16, /* %edi */
3401   60, /* %eip */
3402   68, /* %eflags */
3403   64, /* %cs */
3404   76, /* %ss */
3405   12, /* %ds */
3406   8, /* %es */
3407   4, /* %fs */
3408   0  /* %gs */
3409 };
3410
3411 /* Sigtramp routine location.  */
3412 CORE_ADDR i386dfly_sigtramp_start_addr = 0xbfbfdf20;
3413 CORE_ADDR i386dfly_sigtramp_end_addr = 0xbfbfdff0;
3414
3415 int i386dfly_sc_reg_offset[] =
3416 {
3417   64, /* %eax */
3418   60, /* %ecx */
3419   56, /* %edx */
3420   52, /* %ebx */
3421   92, /* %esp */
3422   44, /* %ebp */
3423   40, /* %esi */
3424   36, /* %edi */
3425   80, /* %eip */
3426   88, /* %eflags */
3427   84, /* %cs */
3428   96, /* %ss */
3429   32, /* %ds */
3430   28, /* %es */
3431   24, /* %fs */
3432   20  /* %gs */
3433 };
3434
3435 static void
3436 i386dfly_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
3437 {
3438   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
3439
3440   i386_elf_init_abi(info, gdbarch);
3441
3442   tdep->gregset_reg_offset = i386dfly_r_reg_offset;
3443   tdep->gregset_num_regs = ARRAY_SIZE (i386dfly_r_reg_offset);
3444   tdep->sizeof_gregset = 80;
3445
3446   tdep->sc_reg_offset = i386dfly_sc_reg_offset;
3447   tdep->sc_num_regs = ARRAY_SIZE (i386dfly_sc_reg_offset);
3448
3449   set_solib_svr4_fetch_link_map_offsets
3450     (gdbarch, svr4_ilp32_fetch_link_map_offsets);
3451 }
3452
3453 \f
3454 /* Provide a prototype to silence -Wmissing-prototypes.  */
3455 void _initialize_i386dfly_tdep (void);
3456
3457 void
3458 _initialize_i386dfly_tdep (void)
3459 {
3460   gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_DRAGONFLY,
3461                           i386dfly_init_abi);
3462 }
3463
3464
3465 [FILE:420:dragonfly/patch-bfd_config.bfd]
3466 --- bfd/config.bfd.orig 2020-10-24 04:23:01 UTC
3467 +++ bfd/config.bfd
3468 @@ -666,7 +666,7 @@ case "${targ}" in
3469      ;;
3470    x86_64-*-dragonfly*)
3471      targ_defvec=x86_64_elf64_vec
3472 -    targ_selvecs="i386_elf32_vec iamcu_elf32_vec l1om_elf64_vec k1om_elf64_vec"
3473 +    targ_selvecs="i386_elf32_vec iamcu_elf32_vec l1om_elf64_vec k1om_elf64_vec x86_64_pei_vec"
3474      want64=true
3475      ;;
3476    x86_64-*-freebsd* | x86_64-*-kfreebsd*-gnu)
3477
3478
3479 [FILE:785:dragonfly/patch-gdb_Makefile.in]
3480 --- gdb/Makefile.in.orig        2020-10-24 04:23:02 UTC
3481 +++ gdb/Makefile.in
3482 @@ -678,6 +678,7 @@ ALL_64_TARGET_OBS = \
3483         alpha-tdep.o \
3484         amd64-darwin-tdep.o \
3485         amd64-dicos-tdep.o \
3486 +       amd64-dfly-tdep.o \
3487         amd64-fbsd-tdep.o \
3488         amd64-linux-tdep.o \
3489         amd64-nbsd-tdep.o \
3490 @@ -731,6 +732,7 @@ ALL_TARGET_OBS = \
3491         csky-linux-tdep.o \
3492         csky-tdep.o \
3493         dicos-tdep.o \
3494 +       dfly-tdep.o \
3495         fbsd-tdep.o \
3496         frv-linux-tdep.o \
3497         frv-tdep.o \
3498 @@ -745,6 +747,7 @@ ALL_TARGET_OBS = \
3499         i386-bsd-tdep.o \
3500         i386-darwin-tdep.o \
3501         i386-dicos-tdep.o \
3502 +       i386-dfly-tdep.o \
3503         i386-fbsd-tdep.o \
3504         i386-gnu-tdep.o \
3505         i386-go32-tdep.o \
3506 @@ -1269,6 +1272,8 @@ HFILES_NO_SRCDIR = \
3507         extension.h \
3508         extension-priv.h \
3509         f-lang.h \
3510 +       dfly-nat.h \
3511 +       dfly-tdep.h \
3512         fbsd-nat.h \
3513         fbsd-tdep.h \
3514         filesystem.h \
3515
3516
3517 [FILE:518:dragonfly/patch-gdb_amd64-tdep.h]
3518 --- gdb/amd64-tdep.h.orig       2020-10-24 04:23:02 UTC
3519 +++ gdb/amd64-tdep.h
3520 @@ -146,8 +146,8 @@ extern int amd64nbsd_r_reg_offset[];
3521  extern int amd64obsd_r_reg_offset[];
3522  
3523  /* Variables exported from amd64-fbsd-tdep.c.  */
3524 -extern CORE_ADDR amd64fbsd_sigtramp_start_addr;
3525 -extern CORE_ADDR amd64fbsd_sigtramp_end_addr;
3526 -extern int amd64fbsd_sc_reg_offset[];
3527 +extern CORE_ADDR amd64dfly_sigtramp_start_addr;
3528 +extern CORE_ADDR amd64dfly_sigtramp_end_addr;
3529 +extern int amd64dfly_sc_reg_offset[];
3530  
3531  #endif /* amd64-tdep.h */
3532
3533
3534 [FILE:644:dragonfly/patch-gdb_bsd-kvm.c]
3535 --- gdb/bsd-kvm.c.orig  2020-09-13 02:33:41 UTC
3536 +++ gdb/bsd-kvm.c
3537 @@ -39,10 +39,10 @@
3538  #include <paths.h>
3539  #include "readline/readline.h"
3540  #include <sys/param.h>
3541 -#include <sys/proc.h>
3542  #ifdef HAVE_SYS_USER_H
3543  #include <sys/user.h>
3544  #endif
3545 +#include <sys/proc.h>
3546  
3547  #include "bsd-kvm.h"
3548  
3549 @@ -330,8 +330,10 @@ bsd_kvm_proc_cmd (const char *arg, int f
3550  #ifdef HAVE_STRUCT_LWP
3551    addr += offsetof (struct lwp, l_addr);
3552  #else
3553 +#ifndef __DragonFly__  /* XXX FIXME */
3554    addr += offsetof (struct proc, p_addr);
3555  #endif
3556 +#endif
3557  
3558    if (kvm_read (core_kd, addr, &bsd_kvm_paddr, sizeof bsd_kvm_paddr) == -1)
3559      error (("%s"), kvm_geterr (core_kd));
3560
3561
3562 [FILE:361:dragonfly/patch-gdb_configure.host]
3563 --- gdb/configure.host.orig     2020-09-13 02:33:41 UTC
3564 +++ gdb/configure.host
3565 @@ -173,6 +173,7 @@ vax-*-netbsdelf* | vax-*-knetbsd*-gnu)
3566  vax-*-openbsd*)                gdb_host=obsd ;;
3567  
3568  x86_64-*-linux*)       gdb_host=linux64 ;;
3569 +x86_64-*-dragonfly*)   gdb_host=dfly64 ;;
3570  x86_64-*-freebsd* | x86_64-*-kfreebsd*-gnu)
3571                         gdb_host=fbsd64 ;;
3572  x86_64-*-netbsd* | x86_64-*-knetbsd*-gnu)
3573
3574
3575 [FILE:786:dragonfly/patch-gdb_configure.nat]
3576 --- gdb/configure.nat.orig      2020-10-24 04:23:02 UTC
3577 +++ gdb/configure.nat
3578 @@ -62,6 +62,11 @@ case ${gdb_host} in
3579         NAT_CDEPS='$(srcdir)/proc-service.list'
3580         LOADLIBES='-ldl $(RDYNAMIC)'
3581         ;;
3582 +    dfly*)
3583 +       NATDEPFILES='fork-child.o nat/fork-inferior.o inf-ptrace.o dfly-nat.o'
3584 +       HAVE_NATIVE_GCORE_HOST=1
3585 +       LOADLIBES='-lkvm'
3586 +       ;;
3587      fbsd*)
3588         NATDEPFILES='fork-child.o nat/fork-inferior.o inf-ptrace.o fbsd-nat.o'
3589         HAVE_NATIVE_GCORE_HOST=1
3590 @@ -197,6 +202,16 @@ case ${gdb_host} in
3591                 x86-bsd-nat.o"
3592                 ;;
3593         esac
3594 +       ;;
3595 +    dfly64)
3596 +       case ${gdb_host_cpu} in
3597 +           i386)
3598 +               # Host: DragonFly/amd64
3599 +               NATDEPFILES="${NATDEPFILES} amd64-nat.o amd64-bsd-nat.o \
3600 +               amd64-dfly-nat.o bsd-kvm.o x86-nat.o nat/x86-dregs.o \
3601 +               x86-bsd-nat.o"
3602 +               ;;
3603 +       esac
3604         ;;
3605      go32)
3606         case ${gdb_host_cpu} in
3607
3608
3609 [FILE:993:dragonfly/patch-gdb_configure.tgt]
3610 --- gdb/configure.tgt.orig      2020-10-24 04:23:02 UTC
3611 +++ gdb/configure.tgt
3612 @@ -100,6 +100,8 @@ esac
3613  # 2. Get the objects per os in $TARG.
3614  
3615  case "${targ}" in
3616 +*-*-dragonfly*)
3617 +       os_obs="dfly-tdep.o solib-svr4.o";;
3618  *-*-freebsd* | *-*-kfreebsd*-gnu)
3619         os_obs="fbsd-tdep.o solib-svr4.o";;
3620  *-*-netbsd* | *-*-knetbsd*-gnu)
3621 @@ -733,6 +735,11 @@ x86_64-*-linux*)
3622                         i386-linux-tdep.o glibc-tdep.o \
3623                         solib-svr4.o symfile-mem.o linux-tdep.o linux-record.o"
3624         ;;
3625 +x86_64-*-dragonfly*)
3626 +       # Target: DragonFly/amd64
3627 +       gdb_target_obs="amd64-dfly-tdep.o ${i386_tobjs} \
3628 +                       i386-bsd-tdep.o i386-dfly-tdep.o"
3629 +       ;;
3630  x86_64-*-freebsd* | x86_64-*-kfreebsd*-gnu)
3631         # Target: FreeBSD/amd64
3632         gdb_target_obs="amd64-fbsd-tdep.o ${i386_tobjs} \
3633 @@ -771,6 +778,8 @@ gdb_target_obs="${cpu_obs} ${os_obs} ${g
3634  # map target onto default OS ABI
3635  
3636  case "${targ}" in
3637 +*-*-dragonfly*)
3638 +               gdb_osabi=GDB_OSABI_DRAGONFLY ;;
3639  *-*-freebsd* | *-*-kfreebsd*-gnu)
3640                 gdb_osabi=GDB_OSABI_FREEBSD ;;
3641  *-*-linux* | *-*-uclinux*)
3642
3643
3644 [FILE:344:dragonfly/patch-gdb_i386-bsd-nat.c]
3645 --- gdb/i386-bsd-nat.c.orig     2020-10-24 04:23:02 UTC
3646 +++ gdb/i386-bsd-nat.c
3647 @@ -360,6 +360,8 @@ _initialize_i386bsd_nat ()
3648  #define SC_REG_OFFSET i386nbsd_sc_reg_offset
3649  #elif defined (OpenBSD)
3650  #define SC_REG_OFFSET i386obsd_sc_reg_offset
3651 +#elif defined (DragonFly)
3652 +#define SC_REG_OFFSET i386dfly_sc_reg_offset
3653  #endif
3654  
3655  #ifdef SC_REG_OFFSET
3656
3657
3658 [FILE:773:dragonfly/patch-gdb_i386-tdep.h]
3659 --- gdb/i386-tdep.h.orig        2020-10-24 04:23:02 UTC
3660 +++ gdb/i386-tdep.h
3661 @@ -471,12 +471,11 @@ extern int i386_mpx_enabled (void);
3662  /* Functions and variables exported from i386-bsd-tdep.c.  */
3663  
3664  extern void i386bsd_init_abi (struct gdbarch_info, struct gdbarch *);
3665 -extern CORE_ADDR i386fbsd_sigtramp_start_addr;
3666 -extern CORE_ADDR i386fbsd_sigtramp_end_addr;
3667 +extern CORE_ADDR i386dfly_sigtramp_start_addr;
3668 +extern CORE_ADDR i386dfly_sigtramp_end_addr;
3669  extern CORE_ADDR i386obsd_sigtramp_start_addr;
3670  extern CORE_ADDR i386obsd_sigtramp_end_addr;
3671 -extern int i386fbsd4_sc_reg_offset[];
3672 -extern int i386fbsd_sc_reg_offset[];
3673 +extern int i386dfly_sc_reg_offset[];
3674  extern int i386nbsd_sc_reg_offset[];
3675  extern int i386obsd_sc_reg_offset[];
3676  extern int i386bsd_sc_reg_offset[];
3677
3678
3679 [FILE:728:dragonfly/patch-gdb_osabi.c]
3680 --- gdb/osabi.c.orig    2020-10-24 04:23:02 UTC
3681 +++ gdb/osabi.c
3682 @@ -68,6 +68,7 @@ static const struct osabi_names gdb_osab
3683    { "FreeBSD", NULL },
3684    { "NetBSD", NULL },
3685    { "OpenBSD", NULL },
3686 +  { "DragonFly", NULL },
3687    { "WindowsCE", NULL },
3688    { "DJGPP", NULL },
3689    { "QNX-Neutrino", NULL },
3690 @@ -497,6 +498,15 @@ generic_elf_osabi_sniff_abi_tag_sections
3691           return;
3692         }
3693  
3694 +      /* DragonFly.  */
3695 +      if (check_note (abfd, sect, note, &sectsize, "DragonFly", 4,
3696 +                     NT_DRAGONFLY_ABI_TAG))
3697 +       {
3698 +         /* There is no need to check the version yet.  */
3699 +         *osabi = GDB_OSABI_DRAGONFLY;
3700 +         return;
3701 +       }
3702 +
3703        /* FreeBSD.  */
3704        if (check_note (abfd, sect, note, &sectsize, "FreeBSD", 4,
3705                       NT_FREEBSD_ABI_TAG))
3706
3707
3708 [FILE:243:dragonfly/patch-gdb_osabi.h]
3709 --- gdb/osabi.h.orig    2020-10-24 04:23:02 UTC
3710 +++ gdb/osabi.h
3711 @@ -33,6 +33,7 @@ enum gdb_osabi
3712    GDB_OSABI_FREEBSD,
3713    GDB_OSABI_NETBSD,
3714    GDB_OSABI_OPENBSD,
3715 +  GDB_OSABI_DRAGONFLY,
3716    GDB_OSABI_WINCE,
3717    GDB_OSABI_GO32,
3718    GDB_OSABI_QNXNTO,
3719
3720
3721 [FILE:390:dragonfly/patch-include_elf_common.h]
3722 --- include/elf/common.h.orig   2020-10-24 04:23:02 UTC
3723 +++ include/elf/common.h
3724 @@ -882,6 +882,7 @@
3725  /* Values for FreeBSD .note.ABI-tag notes.  Note name is "FreeBSD".  */
3726  
3727  #define NT_FREEBSD_ABI_TAG     1
3728 +#define NT_DRAGONFLY_ABI_TAG   1
3729  
3730  /* These three macros disassemble and assemble a symbol table st_info field,
3731     which contains the symbol binding and symbol type.  The STB_ and STT_
3732
3733
3734 [FILE:740:sunos/patch-gdb_fbsd-tdep.c]
3735 --- gdb/fbsd-tdep.c.orig        2020-05-23 21:10:29 UTC
3736 +++ gdb/fbsd-tdep.c
3737 @@ -1018,12 +1018,12 @@ fbsd_info_proc_files_entry (int kf_type,
3738  
3739             /* For local sockets, print out the first non-nul path
3740                rather than both paths.  */
3741 -           const struct fbsd_sockaddr_un *sun
3742 +           const struct fbsd_sockaddr_un *xsunx
3743               = reinterpret_cast<const struct fbsd_sockaddr_un *> (kf_sa_local);
3744 -           if (sun->sun_path[0] == 0)
3745 -             sun = reinterpret_cast<const struct fbsd_sockaddr_un *>
3746 +           if (xsunx->sun_path[0] == 0)
3747 +             xsunx = reinterpret_cast<const struct fbsd_sockaddr_un *>
3748                 (kf_sa_peer);
3749 -           printf_filtered ("%s", sun->sun_path);
3750 +           printf_filtered ("%s", xsunx->sun_path);
3751             break;
3752           }
3753         case FBSD_AF_INET:
3754