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