GDB (xrefs)
/tmp/gdb-8.1/gdb/amd64-nat.c
Go to the documentation of this file.
1 /* Native-dependent code for AMD64.
2 
3  Copyright (C) 2003-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 "gdbarch.h"
22 #include "regcache.h"
23 
24 #include "i386-tdep.h"
25 #include "amd64-tdep.h"
26 #include "amd64-nat.h"
27 
28 /* The following bits of code help with implementing debugging 32-bit
29  code natively on AMD64. The idea is to define two mappings between
30  the register number as used by GDB and the register set used by the
31  host to represent the general-purpose registers; one for 32-bit
32  code and one for 64-bit code. The mappings are specified by the
33  follwing variables and consist of an array of offsets within the
34  register set indexed by register number, and the number of
35  registers supported by the mapping. We don't need mappings for the
36  floating-point and SSE registers, since the difference between
37  64-bit and 32-bit variants are negligable. The difference in the
38  number of SSE registers is already handled by the target code. */
39 
40 /* General-purpose register mapping for native 32-bit code. */
43 
44 /* General-purpose register mapping for native 64-bit code. */
47 
48 /* Return the offset of REGNUM within the appropriate native
49  general-purpose register set. */
50 
51 static int
53 {
56 
57  gdb_assert (regnum >= 0);
58 
59  if (gdbarch_bfd_arch_info (gdbarch)->bits_per_word == 32)
60  {
63  }
64 
67 
68  if (regnum >= num_regs)
69  return -1;
70 
71  /* Kernels that predate Linux 2.6.25 don't provide access to
72  these segment registers in user_regs_struct. */
73 #ifndef HAVE_STRUCT_USER_REGS_STRUCT_FS_BASE
75  return -1;
76 #endif
77 
78  return reg_offset[regnum];
79 }
80 
81 /* Return whether the native general-purpose register set supplies
82  register REGNUM. */
83 
84 int
86 {
88 }
89 
90 
91 /* Supply register REGNUM, whose contents are stored in GREGS, to
92  REGCACHE. If REGNUM is -1, supply all appropriate registers. */
93 
94 void
96  const void *gregs, int regnum)
97 {
98  const char *regs = (const char *) gregs;
99  struct gdbarch *gdbarch = regcache->arch ();
101  int i;
102 
103  if (gdbarch_bfd_arch_info (gdbarch)->bits_per_word == 32)
105 
108 
109  for (i = 0; i < num_regs; i++)
110  {
111  if (regnum == -1 || regnum == i)
112  {
114 
115  if (offset != -1)
116  regcache_raw_supply (regcache, i, regs + offset);
117  }
118  }
119 }
120 
121 /* Collect register REGNUM from REGCACHE and store its contents in
122  GREGS. If REGNUM is -1, collect and store all appropriate
123  registers. */
124 
125 void
127  void *gregs, int regnum)
128 {
129  char *regs = (char *) gregs;
130  struct gdbarch *gdbarch = regcache->arch ();
132  int i;
133 
134  if (gdbarch_bfd_arch_info (gdbarch)->bits_per_word == 32)
135  {
137 
138  /* Make sure %eax, %ebx, %ecx, %edx, %esi, %edi, %ebp, %esp and
139  %eip get zero-extended to 64 bits. */
140  for (i = 0; i <= I386_EIP_REGNUM; i++)
141  {
142  if (regnum == -1 || regnum == i)
143  memset (regs + amd64_native_gregset_reg_offset (gdbarch, i), 0, 8);
144  }
145  /* Ditto for %cs, %ss, %ds, %es, %fs, and %gs. */
146  for (i = I386_CS_REGNUM; i <= I386_GS_REGNUM; i++)
147  {
148  if (regnum == -1 || regnum == i)
149  memset (regs + amd64_native_gregset_reg_offset (gdbarch, i), 0, 8);
150  }
151  }
152 
155 
156  for (i = 0; i < num_regs; i++)
157  {
158  if (regnum == -1 || regnum == i)
159  {
161 
162  if (offset != -1)
163  regcache_raw_collect (regcache, i, regs + offset);
164  }
165  }
166 }
#define I386_NUM_GREGS
Definition: i386-tdep.h:332
static int reg_offset[]
Definition: i386-gnu-nat.c:46
int num_regs
Definition: gdbarch.c:200
void amd64_collect_native_gregset(const struct regcache *regcache, void *gregs, int regnum)
Definition: amd64-nat.c:126
int amd64_native_gregset32_num_regs
Definition: amd64-nat.c:42
void * memset(T *s, int c, size_t n)=delete
int gdbarch_num_regs(struct gdbarch *gdbarch)
Definition: gdbarch.c:2039
int amd64_native_gregset64_num_regs
Definition: amd64-nat.c:46
void amd64_supply_native_gregset(struct regcache *regcache, const void *gregs, int regnum)
Definition: amd64-nat.c:95
int * amd64_native_gregset32_reg_offset
Definition: amd64-nat.c:41
int * amd64_native_gregset64_reg_offset
Definition: amd64-nat.c:45
#define AMD64_NUM_GREGS
Definition: amd64-tdep.h:86
int regnum
Definition: aarch64-tdep.c:77
#define gdb_assert(expr)
Definition: gdb_assert.h:32
static int amd64_native_gregset_reg_offset(struct gdbarch *gdbarch, int regnum)
Definition: amd64-nat.c:52
int amd64_native_gregset_supplies_p(struct gdbarch *gdbarch, int regnum)
Definition: amd64-nat.c:85
int offset
Definition: agent.c:65
gdbarch * arch() const
Definition: regcache.c:221
void regcache_raw_supply(struct regcache *regcache, int regnum, const void *buf)
Definition: regcache.c:1004
const struct bfd_arch_info * gdbarch_bfd_arch_info(struct gdbarch *gdbarch)
Definition: gdbarch.c:1500
void regcache_raw_collect(const struct regcache *regcache, int regnum, void *buf)
Definition: regcache.c:1085