1 /* GNU/Linux/x86-64 specific low level interface, for the in-process
4 Copyright (C) 2010-2016 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #include "tracepoint.h"
24 #include "linux-x86-tdesc.h"
26 /* Defined in auto-generated file amd64-linux.c. */
27 void init_registers_amd64_linux (void);
28 extern const struct target_desc
*tdesc_amd64_linux
;
30 /* fast tracepoints collect registers. */
33 #define FT_CR_EFLAGS 1
51 static const int x86_64_ft_collect_regmap
[] = {
52 FT_CR_RAX
* 8, FT_CR_RBX
* 8, FT_CR_RCX
* 8, FT_CR_RDX
* 8,
53 FT_CR_RSI
* 8, FT_CR_RDI
* 8, FT_CR_RBP
* 8, FT_CR_RSP
* 8,
54 FT_CR_R8
* 8, FT_CR_R9
* 8, FT_CR_R10
* 8, FT_CR_R11
* 8,
55 FT_CR_R12
* 8, FT_CR_R13
* 8, FT_CR_R14
* 8, FT_CR_R15
* 8,
56 FT_CR_RIP
* 8, FT_CR_EFLAGS
* 8
59 #define X86_64_NUM_FT_COLLECT_GREGS \
60 (sizeof (x86_64_ft_collect_regmap) / sizeof(x86_64_ft_collect_regmap[0]))
63 supply_fast_tracepoint_registers (struct regcache
*regcache
,
64 const unsigned char *buf
)
68 for (i
= 0; i
< X86_64_NUM_FT_COLLECT_GREGS
; i
++)
69 supply_register (regcache
, i
,
70 ((char *) buf
) + x86_64_ft_collect_regmap
[i
]);
74 get_raw_reg (const unsigned char *raw_regs
, int regnum
)
76 if (regnum
>= X86_64_NUM_FT_COLLECT_GREGS
)
79 return *(ULONGEST
*) (raw_regs
+ x86_64_ft_collect_regmap
[regnum
]);
84 #include <ust/processor.h>
86 /* "struct registers" is the UST object type holding the registers at
87 the time of the static tracepoint marker call. This doesn't
88 contain RIP, but we know what it must have been (the marker
91 #define ST_REGENTRY(REG) \
93 offsetof (struct registers, REG), \
94 sizeof (((struct registers *) NULL)->REG) \
101 } x86_64_st_collect_regmap
[] =
125 #define X86_64_NUM_ST_COLLECT_GREGS \
126 (sizeof (x86_64_st_collect_regmap) / sizeof (x86_64_st_collect_regmap[0]))
128 /* GDB's RIP register number. */
129 #define AMD64_RIP_REGNUM 16
132 supply_static_tracepoint_registers (struct regcache
*regcache
,
133 const unsigned char *buf
,
137 unsigned long newpc
= pc
;
139 supply_register (regcache
, AMD64_RIP_REGNUM
, &newpc
);
141 for (i
= 0; i
< X86_64_NUM_ST_COLLECT_GREGS
; i
++)
142 if (x86_64_st_collect_regmap
[i
].offset
!= -1)
144 switch (x86_64_st_collect_regmap
[i
].size
)
147 supply_register (regcache
, i
,
149 + x86_64_st_collect_regmap
[i
].offset
);
154 = * (short *) (((char *) buf
)
155 + x86_64_st_collect_regmap
[i
].offset
);
157 supply_register (regcache
, i
, ®
);
161 internal_error (__FILE__
, __LINE__
,
162 "unhandled register size: %d",
163 x86_64_st_collect_regmap
[i
].size
);
169 #endif /* HAVE_UST */
171 /* Return target_desc to use for IPA, given the tdesc index passed by
174 const struct target_desc
*
175 get_ipa_tdesc (int idx
)
177 #if defined __ILP32__
181 return tdesc_x32_linux
;
183 return tdesc_x32_avx_linux
;
184 case X86_TDESC_AVX512
:
185 return tdesc_x32_avx512_linux
;
193 return tdesc_amd64_linux
;
195 return tdesc_amd64_avx_linux
;
197 return tdesc_amd64_mpx_linux
;
198 case X86_TDESC_AVX_MPX
:
199 return tdesc_amd64_avx_mpx_linux
;
200 case X86_TDESC_AVX512
:
201 return tdesc_amd64_avx512_linux
;
205 internal_error (__FILE__
, __LINE__
,
206 "unknown ipa tdesc index: %d", idx
);
209 /* Allocate buffer for the jump pads. Since we're using 32-bit jumps
210 to reach them, and the executable is at low addresses, MAP_32BIT
211 works just fine. Shared libraries, being allocated at the top,
212 are unfortunately out of luck. */
215 alloc_jump_pad_buffer (size_t size
)
217 void *res
= mmap (NULL
, size
, PROT_READ
| PROT_WRITE
| PROT_EXEC
,
218 MAP_PRIVATE
| MAP_ANONYMOUS
| MAP_32BIT
, -1, 0);
220 if (res
== MAP_FAILED
)
227 initialize_low_tracepoint (void)
229 #if defined __ILP32__
230 init_registers_x32_linux ();
231 init_registers_x32_avx_linux ();
232 init_registers_x32_avx512_linux ();
234 init_registers_amd64_linux ();
235 init_registers_amd64_avx_linux ();
236 init_registers_amd64_avx_mpx_linux ();
237 init_registers_amd64_mpx_linux ();
238 init_registers_amd64_avx512_linux ();