GDB (API)
/home/stan/gdb/src/gdb/i386nbsd-nat.c
Go to the documentation of this file.
00001 /* Native-dependent code for NetBSD/i386.
00002 
00003    Copyright (C) 2004-2013 Free Software Foundation, Inc.
00004 
00005    This file is part of GDB.
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 3 of the License, or
00010    (at your option) any later version.
00011 
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016 
00017    You should have received a copy of the GNU General Public License
00018    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00019 
00020 #include "defs.h"
00021 #include "gdbcore.h"
00022 #include "regcache.h"
00023 #include "target.h"
00024 
00025 #include "i386-tdep.h"
00026 #include "i386bsd-nat.h"
00027 
00028 /* Support for debugging kernel virtual memory images.  */
00029 
00030 #include <sys/types.h>
00031 #include <machine/frame.h>
00032 #include <machine/pcb.h>
00033 
00034 #include "nbsd-nat.h"
00035 #include "bsd-kvm.h"
00036 
00037 static int
00038 i386nbsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
00039 {
00040   struct switchframe sf;
00041 
00042   /* The following is true for NetBSD 1.6.2:
00043 
00044      The pcb contains %esp and %ebp at the point of the context switch
00045      in cpu_switch().  At that point we have a stack frame as
00046      described by `struct switchframe', which for NetBSD 1.6.2 has the
00047      following layout:
00048 
00049      interrupt level
00050      %edi
00051      %esi
00052      %ebx
00053      %eip
00054 
00055      we reconstruct the register state as it would look when we just
00056      returned from cpu_switch().  */
00057 
00058   /* The stack pointer shouldn't be zero.  */
00059   if (pcb->pcb_esp == 0)
00060     return 0;
00061 
00062   read_memory (pcb->pcb_esp, (gdb_byte *)&sf, sizeof sf);
00063   pcb->pcb_esp += sizeof (struct switchframe);
00064   regcache_raw_supply (regcache, I386_EDI_REGNUM, &sf.sf_edi);
00065   regcache_raw_supply (regcache, I386_ESI_REGNUM, &sf.sf_esi);
00066   regcache_raw_supply (regcache, I386_EBP_REGNUM, &pcb->pcb_ebp);
00067   regcache_raw_supply (regcache, I386_ESP_REGNUM, &pcb->pcb_esp);
00068   regcache_raw_supply (regcache, I386_EBX_REGNUM, &sf.sf_ebx);
00069   regcache_raw_supply (regcache, I386_EIP_REGNUM, &sf.sf_eip);
00070 
00071   return 1;
00072 }
00073 
00074 
00075 /* Provide a prototype to silence -Wmissing-prototypes.  */
00076 void _initialize_i386nbsd_nat (void);
00077 
00078 void
00079 _initialize_i386nbsd_nat (void)
00080 {
00081   struct target_ops *t;
00082 
00083   /* Add some extra features to the common *BSD/i386 target.  */
00084   t = i386bsd_target ();
00085   t->to_pid_to_exec_file = nbsd_pid_to_exec_file;
00086   add_target (t);
00087  
00088   /* Support debugging kernel virtual memory images.  */
00089   bsd_kvm_add_target (i386nbsd_supply_pcb);
00090 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines