1 /* Low level interface to valgrind, for the remote server for GDB integrated
4 Free Software Foundation, Inc.
6 This file is part of VALGRIND.
7 It has been inspired from a file from gdbserver in gdb 6.6.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 Boston, MA 02110-1301, USA. */
29 #include "pub_core_machine.h"
30 #include "pub_core_threadstate.h"
31 #include "pub_core_transtab.h"
32 #include "pub_core_gdbserver.h"
33 #include "pub_core_debuginfo.h"
35 #include "valgrind_low.h"
37 #include "libvex_guest_arm.h"
39 static struct reg regs
[] = {
56 { "", 512, 0 }, // It seems these entries are needed
57 { "", 512, 0 }, // as previous versions of arm <-> gdb placed
58 { "", 512, 0 }, // some floating point registers here. So, cpsr
59 { "", 512, 0 }, // must be register 25.
100 static const char *expedite_regs
[] = { "r11", "sp", "pc", 0 };
101 #define num_regs (sizeof (regs) / sizeof (regs[0]))
104 CORE_ADDR
get_pc (void)
108 collect_register_by_name ("pc", &pc
);
110 dlog(1, "stop pc is %p\n", (void *) pc
);
115 void set_pc (CORE_ADDR newpc
)
118 supply_register_by_name ("pc", &newpc
, &mod
);
120 dlog(1, "set pc to %p\n", C2v (newpc
));
122 dlog(1, "set pc not changed %p\n", C2v (newpc
));
125 Addr
thumb_pc (Addr pc
)
127 // If the thumb bit (bit 0) is already set, we trust it.
129 dlog (1, "%p = thumb (bit0 is set)\n", C2v (pc
));
133 // Here, bit 0 is not set.
134 // For a pc aligned on 4 bytes, we have to use the debug
135 // info to determine the thumb-ness.
136 // else (aligned on 2 bytes), we trust this is a thumb
137 // address and we set the thumb bit.
140 dlog (1, "bit0 not set, bit1 set => %p = thumb\n", C2v (pc
));
144 // pc aligned on 4 bytes. We need to use debug info.
148 // If this is a thumb instruction, we need to ask
149 // the debug info with the bit0 set
150 // (why can't debug info do that for us ???)
151 // (why if this is a 4 bytes thumb instruction ???)
153 // Used to check if the instruction is a thumb instruction,
154 // typically for a live address, so cur_ep is a reasonable choice.
155 const DiEpoch cur_ep
= VG_(current_DiEpoch
)();
157 if (VG_(get_fnname_raw
) (cur_ep
, pc
| 1, &fnname
)) {
158 if (VG_(lookup_symbol_SLOW
)( cur_ep
, "*", fnname
, &avmas
)) {
159 dlog (1, "fnname %s lookupsym %p => %p %s.\n",
160 fnname
, C2v(avmas
.main
), C2v(pc
),
161 (avmas
.main
& 1 ? "thumb" : "arm"));
168 dlog (1, "%p fnname %s lookupsym failed?. Assume arm\n",
173 // Can't find function name. We assume this is arm
174 dlog (1, "%p unknown fnname?. Assume arm\n", C2v (pc
));
180 /* store registers in the guest state (gdbserver_to_valgrind)
181 or fetch register from the guest state (valgrind_to_gdbserver). */
183 void transfer_register (ThreadId tid
, int abs_regno
, void * buf
,
184 transfer_direction dir
, int size
, Bool
*mod
)
186 ThreadState
* tst
= VG_(get_ThreadState
)(tid
);
187 int set
= abs_regno
/ num_regs
;
188 int regno
= abs_regno
% num_regs
;
191 VexGuestARMState
* arm
= (VexGuestARMState
*) get_arch (set
, tst
);
194 // numbers here have to match the order of regs above
195 // Attention: gdb order does not match valgrind order.
196 case 0: VG_(transfer
) (&arm
->guest_R0
, buf
, dir
, size
, mod
); break;
197 case 1: VG_(transfer
) (&arm
->guest_R1
, buf
, dir
, size
, mod
); break;
198 case 2: VG_(transfer
) (&arm
->guest_R2
, buf
, dir
, size
, mod
); break;
199 case 3: VG_(transfer
) (&arm
->guest_R3
, buf
, dir
, size
, mod
); break;
200 case 4: VG_(transfer
) (&arm
->guest_R4
, buf
, dir
, size
, mod
); break;
201 case 5: VG_(transfer
) (&arm
->guest_R5
, buf
, dir
, size
, mod
); break;
202 case 6: VG_(transfer
) (&arm
->guest_R6
, buf
, dir
, size
, mod
); break;
203 case 7: VG_(transfer
) (&arm
->guest_R7
, buf
, dir
, size
, mod
); break;
204 case 8: VG_(transfer
) (&arm
->guest_R8
, buf
, dir
, size
, mod
); break;
205 case 9: VG_(transfer
) (&arm
->guest_R9
, buf
, dir
, size
, mod
); break;
206 case 10: VG_(transfer
) (&arm
->guest_R10
, buf
, dir
, size
, mod
); break;
207 case 11: VG_(transfer
) (&arm
->guest_R11
, buf
, dir
, size
, mod
); break;
208 case 12: VG_(transfer
) (&arm
->guest_R12
, buf
, dir
, size
, mod
); break;
209 case 13: VG_(transfer
) (&arm
->guest_R13
, buf
, dir
, size
, mod
); break;
210 case 14: VG_(transfer
) (&arm
->guest_R14
, buf
, dir
, size
, mod
); break;
212 VG_(transfer
) (&arm
->guest_R15T
, buf
, dir
, size
, mod
);
213 if (dir
== gdbserver_to_valgrind
&& *mod
) {
214 // If gdb is changing the PC, we have to set the thumb bit
216 arm
->guest_R15T
= thumb_pc(arm
->guest_R15T
);
224 case 20: /* 9 "empty registers". See struct reg regs above. */
228 case 24: *mod
= False
; break;
230 UInt cpsr
= LibVEX_GuestARM_get_cpsr (arm
);
231 if (dir
== valgrind_to_gdbserver
) {
232 VG_(transfer
) (&cpsr
, buf
, dir
, size
, mod
);
236 VG_(transfer
) (&newcpsr
, buf
, dir
, size
, mod
);
237 *mod
= newcpsr
!= cpsr
;
238 // GDBTD ???? see FIXME in guest_arm_helpers.c
239 LibVEX_GuestARM_put_flags (newcpsr
, arm
);
246 case 26: VG_(transfer
) (&arm
->guest_D0
, buf
, dir
, size
, mod
); break;
247 case 27: VG_(transfer
) (&arm
->guest_D1
, buf
, dir
, size
, mod
); break;
248 case 28: VG_(transfer
) (&arm
->guest_D2
, buf
, dir
, size
, mod
); break;
249 case 29: VG_(transfer
) (&arm
->guest_D3
, buf
, dir
, size
, mod
); break;
250 case 30: VG_(transfer
) (&arm
->guest_D4
, buf
, dir
, size
, mod
); break;
251 case 31: VG_(transfer
) (&arm
->guest_D5
, buf
, dir
, size
, mod
); break;
252 case 32: VG_(transfer
) (&arm
->guest_D6
, buf
, dir
, size
, mod
); break;
253 case 33: VG_(transfer
) (&arm
->guest_D7
, buf
, dir
, size
, mod
); break;
254 case 34: VG_(transfer
) (&arm
->guest_D8
, buf
, dir
, size
, mod
); break;
255 case 35: VG_(transfer
) (&arm
->guest_D9
, buf
, dir
, size
, mod
); break;
256 case 36: VG_(transfer
) (&arm
->guest_D10
, buf
, dir
, size
, mod
); break;
257 case 37: VG_(transfer
) (&arm
->guest_D11
, buf
, dir
, size
, mod
); break;
258 case 38: VG_(transfer
) (&arm
->guest_D12
, buf
, dir
, size
, mod
); break;
259 case 39: VG_(transfer
) (&arm
->guest_D13
, buf
, dir
, size
, mod
); break;
260 case 40: VG_(transfer
) (&arm
->guest_D14
, buf
, dir
, size
, mod
); break;
261 case 41: VG_(transfer
) (&arm
->guest_D15
, buf
, dir
, size
, mod
); break;
262 case 42: VG_(transfer
) (&arm
->guest_D16
, buf
, dir
, size
, mod
); break;
263 case 43: VG_(transfer
) (&arm
->guest_D17
, buf
, dir
, size
, mod
); break;
264 case 44: VG_(transfer
) (&arm
->guest_D18
, buf
, dir
, size
, mod
); break;
265 case 45: VG_(transfer
) (&arm
->guest_D19
, buf
, dir
, size
, mod
); break;
266 case 46: VG_(transfer
) (&arm
->guest_D20
, buf
, dir
, size
, mod
); break;
267 case 47: VG_(transfer
) (&arm
->guest_D21
, buf
, dir
, size
, mod
); break;
268 case 48: VG_(transfer
) (&arm
->guest_D22
, buf
, dir
, size
, mod
); break;
269 case 49: VG_(transfer
) (&arm
->guest_D23
, buf
, dir
, size
, mod
); break;
270 case 50: VG_(transfer
) (&arm
->guest_D24
, buf
, dir
, size
, mod
); break;
271 case 51: VG_(transfer
) (&arm
->guest_D25
, buf
, dir
, size
, mod
); break;
272 case 52: VG_(transfer
) (&arm
->guest_D26
, buf
, dir
, size
, mod
); break;
273 case 53: VG_(transfer
) (&arm
->guest_D27
, buf
, dir
, size
, mod
); break;
274 case 54: VG_(transfer
) (&arm
->guest_D28
, buf
, dir
, size
, mod
); break;
275 case 55: VG_(transfer
) (&arm
->guest_D29
, buf
, dir
, size
, mod
); break;
276 case 56: VG_(transfer
) (&arm
->guest_D30
, buf
, dir
, size
, mod
); break;
277 case 57: VG_(transfer
) (&arm
->guest_D31
, buf
, dir
, size
, mod
); break;
278 case 58: VG_(transfer
) (&arm
->guest_FPSCR
, buf
, dir
, size
, mod
); break;
279 default: vg_assert(0);
284 const char* target_xml (Bool shadow_mode
)
287 return "arm-with-vfpv3-valgrind.xml";
289 return "arm-with-vfpv3.xml";
293 static CORE_ADDR
** target_get_dtv (ThreadState
*tst
)
295 VexGuestARMState
* arm
= (VexGuestARMState
*)&tst
->arch
.vex
;
296 // arm dtv is pointed to by TPIDRURO
297 return (CORE_ADDR
**)((CORE_ADDR
)arm
->guest_TPIDRURO
);
300 static struct valgrind_target_ops low_target
= {
312 void arm_init_architecture (struct valgrind_target_ops
*target
)
314 *target
= low_target
;
315 set_register_cache (regs
, num_regs
);
316 gdbserver_expedite_regs
= expedite_regs
;