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