]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/gdbserver/linux-amd64-ipa.c
[GDBserver] Multi-process + multi-arch
[thirdparty/binutils-gdb.git] / gdb / gdbserver / linux-amd64-ipa.c
1 /* GNU/Linux/x86-64 specific low level interface, for the in-process
2 agent library for GDB.
3
4 Copyright (C) 2010-2013 Free Software Foundation, Inc.
5
6 This file is part of GDB.
7
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.
12
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.
17
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/>. */
20
21 #include "server.h"
22
23 /* Defined in auto-generated file amd64-linux.c. */
24 void init_registers_amd64_linux (void);
25 extern const struct target_desc *tdesc_amd64_linux;
26
27 /* fast tracepoints collect registers. */
28
29 #define FT_CR_RIP 0
30 #define FT_CR_EFLAGS 1
31 #define FT_CR_R8 2
32 #define FT_CR_R9 3
33 #define FT_CR_R10 4
34 #define FT_CR_R11 5
35 #define FT_CR_R12 6
36 #define FT_CR_R13 7
37 #define FT_CR_R14 8
38 #define FT_CR_R15 9
39 #define FT_CR_RAX 10
40 #define FT_CR_RBX 11
41 #define FT_CR_RCX 12
42 #define FT_CR_RDX 13
43 #define FT_CR_RSI 14
44 #define FT_CR_RDI 15
45 #define FT_CR_RBP 16
46 #define FT_CR_RSP 17
47
48 static const int x86_64_ft_collect_regmap[] = {
49 FT_CR_RAX * 8, FT_CR_RBX * 8, FT_CR_RCX * 8, FT_CR_RDX * 8,
50 FT_CR_RSI * 8, FT_CR_RDI * 8, FT_CR_RBP * 8, FT_CR_RSP * 8,
51 FT_CR_R8 * 8, FT_CR_R9 * 8, FT_CR_R10 * 8, FT_CR_R11 * 8,
52 FT_CR_R12 * 8, FT_CR_R13 * 8, FT_CR_R14 * 8, FT_CR_R15 * 8,
53 FT_CR_RIP * 8, FT_CR_EFLAGS * 8
54 };
55
56 #define X86_64_NUM_FT_COLLECT_GREGS \
57 (sizeof (x86_64_ft_collect_regmap) / sizeof(x86_64_ft_collect_regmap[0]))
58
59 void
60 supply_fast_tracepoint_registers (struct regcache *regcache,
61 const unsigned char *buf)
62 {
63 int i;
64
65 for (i = 0; i < X86_64_NUM_FT_COLLECT_GREGS; i++)
66 supply_register (regcache, i,
67 ((char *) buf) + x86_64_ft_collect_regmap[i]);
68 }
69
70 ULONGEST __attribute__ ((visibility("default"), used))
71 gdb_agent_get_raw_reg (const unsigned char *raw_regs, int regnum)
72 {
73 if (regnum >= X86_64_NUM_FT_COLLECT_GREGS)
74 return 0;
75
76 return *(ULONGEST *) (raw_regs + x86_64_ft_collect_regmap[regnum]);
77 }
78
79 #ifdef HAVE_UST
80
81 #include <ust/processor.h>
82
83 /* "struct registers" is the UST object type holding the registers at
84 the time of the static tracepoint marker call. This doesn't
85 contain RIP, but we know what it must have been (the marker
86 address). */
87
88 #define ST_REGENTRY(REG) \
89 { \
90 offsetof (struct registers, REG), \
91 sizeof (((struct registers *) NULL)->REG) \
92 }
93
94 static struct
95 {
96 int offset;
97 int size;
98 } x86_64_st_collect_regmap[] =
99 {
100 ST_REGENTRY(rax),
101 ST_REGENTRY(rbx),
102 ST_REGENTRY(rcx),
103 ST_REGENTRY(rdx),
104 ST_REGENTRY(rsi),
105 ST_REGENTRY(rdi),
106 ST_REGENTRY(rbp),
107 ST_REGENTRY(rsp),
108 ST_REGENTRY(r8),
109 ST_REGENTRY(r9),
110 ST_REGENTRY(r10),
111 ST_REGENTRY(r11),
112 ST_REGENTRY(r12),
113 ST_REGENTRY(r13),
114 ST_REGENTRY(r14),
115 ST_REGENTRY(r15),
116 { -1, 0 },
117 ST_REGENTRY(rflags),
118 ST_REGENTRY(cs),
119 ST_REGENTRY(ss),
120 };
121
122 #define X86_64_NUM_ST_COLLECT_GREGS \
123 (sizeof (x86_64_st_collect_regmap) / sizeof (x86_64_st_collect_regmap[0]))
124
125 /* GDB's RIP register number. */
126 #define AMD64_RIP_REGNUM 16
127
128 void
129 supply_static_tracepoint_registers (struct regcache *regcache,
130 const unsigned char *buf,
131 CORE_ADDR pc)
132 {
133 int i;
134 unsigned long newpc = pc;
135
136 supply_register (regcache, AMD64_RIP_REGNUM, &newpc);
137
138 for (i = 0; i < X86_64_NUM_ST_COLLECT_GREGS; i++)
139 if (x86_64_st_collect_regmap[i].offset != -1)
140 {
141 switch (x86_64_st_collect_regmap[i].size)
142 {
143 case 8:
144 supply_register (regcache, i,
145 ((char *) buf)
146 + x86_64_st_collect_regmap[i].offset);
147 break;
148 case 2:
149 {
150 unsigned long reg
151 = * (short *) (((char *) buf)
152 + x86_64_st_collect_regmap[i].offset);
153 reg &= 0xffff;
154 supply_register (regcache, i, &reg);
155 }
156 break;
157 default:
158 internal_error (__FILE__, __LINE__,
159 "unhandled register size: %d",
160 x86_64_st_collect_regmap[i].size);
161 break;
162 }
163 }
164 }
165
166 #endif /* HAVE_UST */
167
168 void
169 initialize_low_tracepoint (void)
170 {
171 init_registers_amd64_linux ();
172 ipa_tdesc = tdesc_amd64_linux;
173 }