i386-netbsd-nat.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* Native-dependent code for NetBSD/i386.
  2. Copyright (C) 2004-2022 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 "i386-bsd-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 "netbsd-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 (I386_EDI_REGNUM, &sf.sf_edi);
  48. regcache->raw_supply (I386_ESI_REGNUM, &sf.sf_esi);
  49. regcache->raw_supply (I386_EBP_REGNUM, &pcb->pcb_ebp);
  50. regcache->raw_supply (I386_ESP_REGNUM, &pcb->pcb_esp);
  51. regcache->raw_supply (I386_EBX_REGNUM, &sf.sf_ebx);
  52. regcache->raw_supply (I386_EIP_REGNUM, &sf.sf_eip);
  53. return 1;
  54. }
  55. static i386_bsd_nat_target<nbsd_nat_target> the_i386_nbsd_nat_target;
  56. void _initialize_i386nbsd_nat ();
  57. void
  58. _initialize_i386nbsd_nat ()
  59. {
  60. add_inf_child_target (&the_i386_nbsd_nat_target);
  61. /* Support debugging kernel virtual memory images. */
  62. bsd_kvm_add_target (i386nbsd_supply_pcb);
  63. }