gdb/i386nbsd-nat.c - gdb

Functions defined

Source code

  1. /* Native-dependent code for NetBSD/i386.

  2.    Copyright (C) 2004-2015 Free Software Foundation, Inc.

  3.    This file is part of GDB.

  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 3 of the License, or
  7.    (at your option) any later version.

  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.

  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  14. #include "defs.h"
  15. #include "gdbcore.h"
  16. #include "regcache.h"
  17. #include "target.h"

  18. #include "i386-tdep.h"
  19. #include "i386bsd-nat.h"

  20. /* Support for debugging kernel virtual memory images.  */

  21. #include <sys/types.h>
  22. #include <machine/frame.h>
  23. #include <machine/pcb.h>

  24. #include "nbsd-nat.h"
  25. #include "bsd-kvm.h"

  26. static int
  27. i386nbsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
  28. {
  29.   struct switchframe sf;

  30.   /* The following is true for NetBSD 1.6.2:

  31.      The pcb contains %esp and %ebp at the point of the context switch
  32.      in cpu_switch().  At that point we have a stack frame as
  33.      described by `struct switchframe', which for NetBSD 1.6.2 has the
  34.      following layout:

  35.      interrupt level
  36.      %edi
  37.      %esi
  38.      %ebx
  39.      %eip

  40.      we reconstruct the register state as it would look when we just
  41.      returned from cpu_switch().  */

  42.   /* The stack pointer shouldn't be zero.  */
  43.   if (pcb->pcb_esp == 0)
  44.     return 0;

  45.   read_memory (pcb->pcb_esp, (gdb_byte *)&sf, sizeof sf);
  46.   pcb->pcb_esp += sizeof (struct switchframe);
  47.   regcache_raw_supply (regcache, I386_EDI_REGNUM, &sf.sf_edi);
  48.   regcache_raw_supply (regcache, I386_ESI_REGNUM, &sf.sf_esi);
  49.   regcache_raw_supply (regcache, I386_EBP_REGNUM, &pcb->pcb_ebp);
  50.   regcache_raw_supply (regcache, I386_ESP_REGNUM, &pcb->pcb_esp);
  51.   regcache_raw_supply (regcache, I386_EBX_REGNUM, &sf.sf_ebx);
  52.   regcache_raw_supply (regcache, I386_EIP_REGNUM, &sf.sf_eip);

  53.   return 1;
  54. }


  55. /* Provide a prototype to silence -Wmissing-prototypes.  */
  56. void _initialize_i386nbsd_nat (void);

  57. void
  58. _initialize_i386nbsd_nat (void)
  59. {
  60.   struct target_ops *t;

  61.   /* Add some extra features to the common *BSD/i386 target.  */
  62.   t = i386bsd_target ();
  63.   t->to_pid_to_exec_file = nbsd_pid_to_exec_file;
  64.   add_target (t);

  65.   /* Support debugging kernel virtual memory images.  */
  66.   bsd_kvm_add_target (i386nbsd_supply_pcb);
  67. }