GDB (xrefs)

/tmp/gdb-8.1/gdb/i386-nbsd-nat.c
Go to the documentation of this file.
1 /* Native-dependent code for NetBSD/i386.
2
3 Copyright (C) 2004-2018 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 #include "defs.h"
21 #include "gdbcore.h"
22 #include "regcache.h"
23 #include "target.h"
24
25 #include "i386-tdep.h"
26 #include "i386-bsd-nat.h"
27
28 /* Support for debugging kernel virtual memory images. */
29
30 #include <sys/types.h>
31 #include <machine/frame.h>
32 #include <machine/pcb.h>
33
34 #include "nbsd-nat.h"
35 #include "bsd-kvm.h"
36
37 static int
38 i386nbsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
39 {
40 struct switchframe sf;
41
42 /* The following is true for NetBSD 1.6.2:
43
44 The pcb contains %esp and %ebp at the point of the context switch
45 in cpu_switch(). At that point we have a stack frame as
46 described by `struct switchframe', which for NetBSD 1.6.2 has the
47 following layout:
48
49 interrupt level
50 %edi
51 %esi
52 %ebx
53 %eip
54
55 we reconstruct the register state as it would look when we just
56 returned from cpu_switch(). */
57
58 /* The stack pointer shouldn't be zero. */
59 if (pcb->pcb_esp == 0)
60 return 0;
61
62 read_memory (pcb->pcb_esp, (gdb_byte *)&sf, sizeof sf);
63 pcb->pcb_esp += sizeof (struct switchframe);
64 regcache_raw_supply (regcache, I386_EDI_REGNUM, &sf.sf_edi);
65 regcache_raw_supply (regcache, I386_ESI_REGNUM, &sf.sf_esi);
66 regcache_raw_supply (regcache, I386_EBP_REGNUM, &pcb->pcb_ebp);
67 regcache_raw_supply (regcache, I386_ESP_REGNUM, &pcb->pcb_esp);
68 regcache_raw_supply (regcache, I386_EBX_REGNUM, &sf.sf_ebx);
69 regcache_raw_supply (regcache, I386_EIP_REGNUM, &sf.sf_eip);
70
71 return 1;
72 }
73
74 void
75 _initialize_i386nbsd_nat (void)
76 {
77 struct target_ops *t;
78
79 /* Add some extra features to the common *BSD/i386 target. */
80 t = i386bsd_target ();
81 t->to_pid_to_exec_file = nbsd_pid_to_exec_file;
82 add_target (t);
83
84 /* Support debugging kernel virtual memory images. */
85 bsd_kvm_add_target (i386nbsd_supply_pcb);
86 }
add_target
void add_target(struct target_ops *t)
Definition: target.c:395
nbsd_pid_to_exec_file
char * nbsd_pid_to_exec_file(struct target_ops *self, int pid)
Definition: nbsd-nat.c:28
defs.h
I386_EBX_REGNUM
Definition: i386-tdep.h:274
I386_EIP_REGNUM
Definition: i386-tdep.h:279
target_ops
Definition: target.h:412
regcache.h
bsd-kvm.h
I386_ESP_REGNUM
Definition: i386-tdep.h:275
i386-bsd-nat.h
I386_ESI_REGNUM
Definition: i386-tdep.h:277
read_memory
void read_memory(CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
Definition: corefile.c:258
target_ops::to_pid_to_exec_file
char *(* to_pid_to_exec_file)(struct target_ops *, int pid) TARGET_DEFAULT_RETURN(NULL)
Definition: target.h:650
nbsd-nat.h
gdb_byte
bfd_byte gdb_byte
Definition: common-types.h:38
_initialize_i386nbsd_nat
void _initialize_i386nbsd_nat(void)
Definition: i386-nbsd-nat.c:75
gdbcore.h
I386_EDI_REGNUM
Definition: i386-tdep.h:278
target.h
i386bsd_target
struct target_ops * i386bsd_target(void)
Definition: i386-bsd-nat.c:274
regcache_raw_supply
void regcache_raw_supply(struct regcache *regcache, int regnum, const void *buf)
Definition: regcache.c:1004
i386nbsd_supply_pcb
static int i386nbsd_supply_pcb(struct regcache *regcache, struct pcb *pcb)
Definition: i386-nbsd-nat.c:38
regcache
Definition: regcache.h:232
bsd_kvm_add_target
void bsd_kvm_add_target(int(*supply_pcb)(struct regcache *, struct pcb *))
Definition: bsd-kvm.c:354
i386-tdep.h
I386_EBP_REGNUM
Definition: i386-tdep.h:276