1 /* GNU/Linux/x86 specific low level interface, for the in-process
4 Copyright (C) 2010, 2011 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/>. */
25 /* GDB register numbers. */
29 I386_EAX_REGNUM, /* %eax */
30 I386_ECX_REGNUM, /* %ecx */
31 I386_EDX_REGNUM, /* %edx */
32 I386_EBX_REGNUM, /* %ebx */
33 I386_ESP_REGNUM, /* %esp */
34 I386_EBP_REGNUM, /* %ebp */
35 I386_ESI_REGNUM, /* %esi */
36 I386_EDI_REGNUM, /* %edi */
37 I386_EIP_REGNUM, /* %eip */
38 I386_EFLAGS_REGNUM, /* %eflags */
39 I386_CS_REGNUM, /* %cs */
40 I386_SS_REGNUM, /* %ss */
41 I386_DS_REGNUM, /* %ds */
42 I386_ES_REGNUM, /* %es */
43 I386_FS_REGNUM, /* %fs */
44 I386_GS_REGNUM, /* %gs */
45 I386_ST0_REGNUM /* %st(0) */
48 #define i386_num_regs 16
50 /* Defined in auto-generated file i386-linux.c. */
51 void init_registers_i386_linux (void);
70 /* Mapping between the general-purpose registers in jump tracepoint
71 format and GDB's register array layout. */
73 static const int i386_ft_collect_regmap[] =
75 FT_CR_EAX * 4, FT_CR_ECX * 4, FT_CR_EDX * 4, FT_CR_EBX * 4,
76 FT_CR_UESP * 4, FT_CR_EBP * 4, FT_CR_ESI * 4, FT_CR_EDI * 4,
77 FT_CR_EIP * 4, FT_CR_EFL * 4, FT_CR_CS * 4, FT_CR_SS * 4,
78 FT_CR_DS * 4, FT_CR_ES * 4, FT_CR_FS * 4, FT_CR_GS * 4
82 supply_fast_tracepoint_registers (struct regcache *regcache,
83 const unsigned char *buf)
87 for (i = 0; i < i386_num_regs; i++)
91 if (i >= I386_CS_REGNUM && i <= I386_GS_REGNUM)
92 regval = *(short *) (((char *) buf) + i386_ft_collect_regmap[i]);
94 regval = *(int *) (((char *) buf) + i386_ft_collect_regmap[i]);
96 supply_register (regcache, i, ®val);
100 ULONGEST __attribute__ ((visibility("default"), used))
101 gdb_agent_get_raw_reg (unsigned char *raw_regs, int regnum)
103 /* This should maybe be allowed to return an error code, or perhaps
104 better, have the emit_reg detect this, and emit a constant zero,
107 if (regnum > i386_num_regs)
109 else if (regnum >= I386_CS_REGNUM && regnum <= I386_GS_REGNUM)
110 return *(short *) (raw_regs + i386_ft_collect_regmap[regnum]);
112 return *(int *) (raw_regs + i386_ft_collect_regmap[regnum]);
117 #include <ust/processor.h>
119 /* "struct registers" is the UST object type holding the registers at
120 the time of the static tracepoint marker call. This doesn't
121 contain EIP, but we know what it must have been (the marker
124 #define ST_REGENTRY(REG) \
126 offsetof (struct registers, REG), \
127 sizeof (((struct registers *) NULL)->REG) \
134 } i386_st_collect_regmap[] =
150 #define i386_NUM_ST_COLLECT_GREGS \
151 (sizeof (i386_st_collect_regmap) / sizeof (i386_st_collect_regmap[0]))
154 supply_static_tracepoint_registers (struct regcache *regcache,
155 const unsigned char *buf,
159 unsigned int newpc = pc;
161 supply_register (regcache, I386_EIP_REGNUM, &newpc);
163 for (i = 0; i < i386_NUM_ST_COLLECT_GREGS; i++)
164 if (i386_st_collect_regmap[i].offset != -1)
166 switch (i386_st_collect_regmap[i].size)
169 supply_register (regcache, i,
171 + i386_st_collect_regmap[i].offset);
176 = * (short *) (((char *) buf)
177 + i386_st_collect_regmap[i].offset);
179 supply_register (regcache, i, ®);
183 internal_error (__FILE__, __LINE__, "unhandled register size: %d",
184 i386_st_collect_regmap[i].size);
189 #endif /* HAVE_UST */
192 /* This is only needed because reg-i386-linux-lib.o references it. We
193 may use it proper at some point. */
194 const char *gdbserver_xmltarget;
196 /* Attempt to allocate memory for trampolines in the first 64 KiB of
197 memory to enable smaller jump patches. */
200 initialize_fast_tracepoint_trampoline_buffer (void)
202 const CORE_ADDR buffer_end = 64 * 1024;
203 /* Ensure that the buffer will be at least 1 KiB in size, which is
204 enough space for over 200 fast tracepoints. */
205 const int min_buffer_size = 1024;
206 char buf[IPA_BUFSIZ];
207 CORE_ADDR mmap_min_addr = buffer_end + 1;
208 ULONGEST buffer_size;
209 FILE *f = fopen ("/proc/sys/vm/mmap_min_addr", "r");
213 snprintf (buf, sizeof (buf), "mmap_min_addr open failed: %s",
215 set_trampoline_buffer_space (0, 0, buf);
219 if (fgets (buf, IPA_BUFSIZ, f))
220 sscanf (buf, "%llu", &mmap_min_addr);
224 buffer_size = buffer_end - mmap_min_addr;
226 if (buffer_size >= min_buffer_size)
228 if (mmap ((void *) (uintptr_t) mmap_min_addr, buffer_size,
229 PROT_READ | PROT_EXEC | PROT_WRITE,
230 MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS,
233 set_trampoline_buffer_space (mmap_min_addr, buffer_end, NULL);
236 snprintf (buf, IPA_BUFSIZ, "low-64K-buffer mmap() failed: %s",
238 set_trampoline_buffer_space (0, 0, buf);
243 snprintf (buf, IPA_BUFSIZ, "mmap_min_addr is %d, must be %d or less",
244 (int) mmap_min_addr, (int) buffer_end - min_buffer_size);
245 set_trampoline_buffer_space (0, 0, buf);
250 initialize_low_tracepoint (void)
252 init_registers_i386_linux ();
253 initialize_fast_tracepoint_trampoline_buffer ();