GDB (API)
|
00001 /* GNU/Linux on ARM target support. 00002 00003 Copyright (C) 1999-2013 Free Software Foundation, Inc. 00004 00005 This file is part of GDB. 00006 00007 This program is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; either version 3 of the License, or 00010 (at your option) any later version. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 00019 00020 #include "defs.h" 00021 #include "target.h" 00022 #include "value.h" 00023 #include "gdbtypes.h" 00024 #include "floatformat.h" 00025 #include "gdbcore.h" 00026 #include "frame.h" 00027 #include "regcache.h" 00028 #include "doublest.h" 00029 #include "solib-svr4.h" 00030 #include "osabi.h" 00031 #include "regset.h" 00032 #include "trad-frame.h" 00033 #include "tramp-frame.h" 00034 #include "breakpoint.h" 00035 #include "auxv.h" 00036 #include "xml-syscall.h" 00037 00038 #include "arm-tdep.h" 00039 #include "arm-linux-tdep.h" 00040 #include "linux-tdep.h" 00041 #include "glibc-tdep.h" 00042 #include "arch-utils.h" 00043 #include "inferior.h" 00044 #include "gdbthread.h" 00045 #include "symfile.h" 00046 00047 #include "cli/cli-utils.h" 00048 #include "stap-probe.h" 00049 #include "parser-defs.h" 00050 #include "user-regs.h" 00051 #include <ctype.h> 00052 #include "elf/common.h" 00053 #include "gdb_string.h" 00054 00055 extern int arm_apcs_32; 00056 00057 /* Under ARM GNU/Linux the traditional way of performing a breakpoint 00058 is to execute a particular software interrupt, rather than use a 00059 particular undefined instruction to provoke a trap. Upon exection 00060 of the software interrupt the kernel stops the inferior with a 00061 SIGTRAP, and wakes the debugger. */ 00062 00063 static const gdb_byte arm_linux_arm_le_breakpoint[] = { 0x01, 0x00, 0x9f, 0xef }; 00064 00065 static const gdb_byte arm_linux_arm_be_breakpoint[] = { 0xef, 0x9f, 0x00, 0x01 }; 00066 00067 /* However, the EABI syscall interface (new in Nov. 2005) does not look at 00068 the operand of the swi if old-ABI compatibility is disabled. Therefore, 00069 use an undefined instruction instead. This is supported as of kernel 00070 version 2.5.70 (May 2003), so should be a safe assumption for EABI 00071 binaries. */ 00072 00073 static const gdb_byte eabi_linux_arm_le_breakpoint[] = { 0xf0, 0x01, 0xf0, 0xe7 }; 00074 00075 static const gdb_byte eabi_linux_arm_be_breakpoint[] = { 0xe7, 0xf0, 0x01, 0xf0 }; 00076 00077 /* All the kernels which support Thumb support using a specific undefined 00078 instruction for the Thumb breakpoint. */ 00079 00080 static const gdb_byte arm_linux_thumb_be_breakpoint[] = {0xde, 0x01}; 00081 00082 static const gdb_byte arm_linux_thumb_le_breakpoint[] = {0x01, 0xde}; 00083 00084 /* Because the 16-bit Thumb breakpoint is affected by Thumb-2 IT blocks, 00085 we must use a length-appropriate breakpoint for 32-bit Thumb 00086 instructions. See also thumb_get_next_pc. */ 00087 00088 static const gdb_byte arm_linux_thumb2_be_breakpoint[] = { 0xf7, 0xf0, 0xa0, 0x00 }; 00089 00090 static const gdb_byte arm_linux_thumb2_le_breakpoint[] = { 0xf0, 0xf7, 0x00, 0xa0 }; 00091 00092 /* Description of the longjmp buffer. The buffer is treated as an array of 00093 elements of size ARM_LINUX_JB_ELEMENT_SIZE. 00094 00095 The location of saved registers in this buffer (in particular the PC 00096 to use after longjmp is called) varies depending on the ABI (in 00097 particular the FP model) and also (possibly) the C Library. 00098 00099 For glibc, eglibc, and uclibc the following holds: If the FP model is 00100 SoftVFP or VFP (which implies EABI) then the PC is at offset 9 in the 00101 buffer. This is also true for the SoftFPA model. However, for the FPA 00102 model the PC is at offset 21 in the buffer. */ 00103 #define ARM_LINUX_JB_ELEMENT_SIZE INT_REGISTER_SIZE 00104 #define ARM_LINUX_JB_PC_FPA 21 00105 #define ARM_LINUX_JB_PC_EABI 9 00106 00107 /* 00108 Dynamic Linking on ARM GNU/Linux 00109 -------------------------------- 00110 00111 Note: PLT = procedure linkage table 00112 GOT = global offset table 00113 00114 As much as possible, ELF dynamic linking defers the resolution of 00115 jump/call addresses until the last minute. The technique used is 00116 inspired by the i386 ELF design, and is based on the following 00117 constraints. 00118 00119 1) The calling technique should not force a change in the assembly 00120 code produced for apps; it MAY cause changes in the way assembly 00121 code is produced for position independent code (i.e. shared 00122 libraries). 00123 00124 2) The technique must be such that all executable areas must not be 00125 modified; and any modified areas must not be executed. 00126 00127 To do this, there are three steps involved in a typical jump: 00128 00129 1) in the code 00130 2) through the PLT 00131 3) using a pointer from the GOT 00132 00133 When the executable or library is first loaded, each GOT entry is 00134 initialized to point to the code which implements dynamic name 00135 resolution and code finding. This is normally a function in the 00136 program interpreter (on ARM GNU/Linux this is usually 00137 ld-linux.so.2, but it does not have to be). On the first 00138 invocation, the function is located and the GOT entry is replaced 00139 with the real function address. Subsequent calls go through steps 00140 1, 2 and 3 and end up calling the real code. 00141 00142 1) In the code: 00143 00144 b function_call 00145 bl function_call 00146 00147 This is typical ARM code using the 26 bit relative branch or branch 00148 and link instructions. The target of the instruction 00149 (function_call is usually the address of the function to be called. 00150 In position independent code, the target of the instruction is 00151 actually an entry in the PLT when calling functions in a shared 00152 library. Note that this call is identical to a normal function 00153 call, only the target differs. 00154 00155 2) In the PLT: 00156 00157 The PLT is a synthetic area, created by the linker. It exists in 00158 both executables and libraries. It is an array of stubs, one per 00159 imported function call. It looks like this: 00160 00161 PLT[0]: 00162 str lr, [sp, #-4]! @push the return address (lr) 00163 ldr lr, [pc, #16] @load from 6 words ahead 00164 add lr, pc, lr @form an address for GOT[0] 00165 ldr pc, [lr, #8]! @jump to the contents of that addr 00166 00167 The return address (lr) is pushed on the stack and used for 00168 calculations. The load on the second line loads the lr with 00169 &GOT[3] - . - 20. The addition on the third leaves: 00170 00171 lr = (&GOT[3] - . - 20) + (. + 8) 00172 lr = (&GOT[3] - 12) 00173 lr = &GOT[0] 00174 00175 On the fourth line, the pc and lr are both updated, so that: 00176 00177 pc = GOT[2] 00178 lr = &GOT[0] + 8 00179 = &GOT[2] 00180 00181 NOTE: PLT[0] borrows an offset .word from PLT[1]. This is a little 00182 "tight", but allows us to keep all the PLT entries the same size. 00183 00184 PLT[n+1]: 00185 ldr ip, [pc, #4] @load offset from gotoff 00186 add ip, pc, ip @add the offset to the pc 00187 ldr pc, [ip] @jump to that address 00188 gotoff: .word GOT[n+3] - . 00189 00190 The load on the first line, gets an offset from the fourth word of 00191 the PLT entry. The add on the second line makes ip = &GOT[n+3], 00192 which contains either a pointer to PLT[0] (the fixup trampoline) or 00193 a pointer to the actual code. 00194 00195 3) In the GOT: 00196 00197 The GOT contains helper pointers for both code (PLT) fixups and 00198 data fixups. The first 3 entries of the GOT are special. The next 00199 M entries (where M is the number of entries in the PLT) belong to 00200 the PLT fixups. The next D (all remaining) entries belong to 00201 various data fixups. The actual size of the GOT is 3 + M + D. 00202 00203 The GOT is also a synthetic area, created by the linker. It exists 00204 in both executables and libraries. When the GOT is first 00205 initialized , all the GOT entries relating to PLT fixups are 00206 pointing to code back at PLT[0]. 00207 00208 The special entries in the GOT are: 00209 00210 GOT[0] = linked list pointer used by the dynamic loader 00211 GOT[1] = pointer to the reloc table for this module 00212 GOT[2] = pointer to the fixup/resolver code 00213 00214 The first invocation of function call comes through and uses the 00215 fixup/resolver code. On the entry to the fixup/resolver code: 00216 00217 ip = &GOT[n+3] 00218 lr = &GOT[2] 00219 stack[0] = return address (lr) of the function call 00220 [r0, r1, r2, r3] are still the arguments to the function call 00221 00222 This is enough information for the fixup/resolver code to work 00223 with. Before the fixup/resolver code returns, it actually calls 00224 the requested function and repairs &GOT[n+3]. */ 00225 00226 /* The constants below were determined by examining the following files 00227 in the linux kernel sources: 00228 00229 arch/arm/kernel/signal.c 00230 - see SWI_SYS_SIGRETURN and SWI_SYS_RT_SIGRETURN 00231 include/asm-arm/unistd.h 00232 - see __NR_sigreturn, __NR_rt_sigreturn, and __NR_SYSCALL_BASE */ 00233 00234 #define ARM_LINUX_SIGRETURN_INSTR 0xef900077 00235 #define ARM_LINUX_RT_SIGRETURN_INSTR 0xef9000ad 00236 00237 /* For ARM EABI, the syscall number is not in the SWI instruction 00238 (instead it is loaded into r7). We recognize the pattern that 00239 glibc uses... alternatively, we could arrange to do this by 00240 function name, but they are not always exported. */ 00241 #define ARM_SET_R7_SIGRETURN 0xe3a07077 00242 #define ARM_SET_R7_RT_SIGRETURN 0xe3a070ad 00243 #define ARM_EABI_SYSCALL 0xef000000 00244 00245 /* OABI syscall restart trampoline, used for EABI executables too 00246 whenever OABI support has been enabled in the kernel. */ 00247 #define ARM_OABI_SYSCALL_RESTART_SYSCALL 0xef900000 00248 #define ARM_LDR_PC_SP_12 0xe49df00c 00249 #define ARM_LDR_PC_SP_4 0xe49df004 00250 00251 static void 00252 arm_linux_sigtramp_cache (struct frame_info *this_frame, 00253 struct trad_frame_cache *this_cache, 00254 CORE_ADDR func, int regs_offset) 00255 { 00256 CORE_ADDR sp = get_frame_register_unsigned (this_frame, ARM_SP_REGNUM); 00257 CORE_ADDR base = sp + regs_offset; 00258 int i; 00259 00260 for (i = 0; i < 16; i++) 00261 trad_frame_set_reg_addr (this_cache, i, base + i * 4); 00262 00263 trad_frame_set_reg_addr (this_cache, ARM_PS_REGNUM, base + 16 * 4); 00264 00265 /* The VFP or iWMMXt registers may be saved on the stack, but there's 00266 no reliable way to restore them (yet). */ 00267 00268 /* Save a frame ID. */ 00269 trad_frame_set_id (this_cache, frame_id_build (sp, func)); 00270 } 00271 00272 /* There are a couple of different possible stack layouts that 00273 we need to support. 00274 00275 Before version 2.6.18, the kernel used completely independent 00276 layouts for non-RT and RT signals. For non-RT signals the stack 00277 began directly with a struct sigcontext. For RT signals the stack 00278 began with two redundant pointers (to the siginfo and ucontext), 00279 and then the siginfo and ucontext. 00280 00281 As of version 2.6.18, the non-RT signal frame layout starts with 00282 a ucontext and the RT signal frame starts with a siginfo and then 00283 a ucontext. Also, the ucontext now has a designated save area 00284 for coprocessor registers. 00285 00286 For RT signals, it's easy to tell the difference: we look for 00287 pinfo, the pointer to the siginfo. If it has the expected 00288 value, we have an old layout. If it doesn't, we have the new 00289 layout. 00290 00291 For non-RT signals, it's a bit harder. We need something in one 00292 layout or the other with a recognizable offset and value. We can't 00293 use the return trampoline, because ARM usually uses SA_RESTORER, 00294 in which case the stack return trampoline is not filled in. 00295 We can't use the saved stack pointer, because sigaltstack might 00296 be in use. So for now we guess the new layout... */ 00297 00298 /* There are three words (trap_no, error_code, oldmask) in 00299 struct sigcontext before r0. */ 00300 #define ARM_SIGCONTEXT_R0 0xc 00301 00302 /* There are five words (uc_flags, uc_link, and three for uc_stack) 00303 in the ucontext_t before the sigcontext. */ 00304 #define ARM_UCONTEXT_SIGCONTEXT 0x14 00305 00306 /* There are three elements in an rt_sigframe before the ucontext: 00307 pinfo, puc, and info. The first two are pointers and the third 00308 is a struct siginfo, with size 128 bytes. We could follow puc 00309 to the ucontext, but it's simpler to skip the whole thing. */ 00310 #define ARM_OLD_RT_SIGFRAME_SIGINFO 0x8 00311 #define ARM_OLD_RT_SIGFRAME_UCONTEXT 0x88 00312 00313 #define ARM_NEW_RT_SIGFRAME_UCONTEXT 0x80 00314 00315 #define ARM_NEW_SIGFRAME_MAGIC 0x5ac3c35a 00316 00317 static void 00318 arm_linux_sigreturn_init (const struct tramp_frame *self, 00319 struct frame_info *this_frame, 00320 struct trad_frame_cache *this_cache, 00321 CORE_ADDR func) 00322 { 00323 struct gdbarch *gdbarch = get_frame_arch (this_frame); 00324 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 00325 CORE_ADDR sp = get_frame_register_unsigned (this_frame, ARM_SP_REGNUM); 00326 ULONGEST uc_flags = read_memory_unsigned_integer (sp, 4, byte_order); 00327 00328 if (uc_flags == ARM_NEW_SIGFRAME_MAGIC) 00329 arm_linux_sigtramp_cache (this_frame, this_cache, func, 00330 ARM_UCONTEXT_SIGCONTEXT 00331 + ARM_SIGCONTEXT_R0); 00332 else 00333 arm_linux_sigtramp_cache (this_frame, this_cache, func, 00334 ARM_SIGCONTEXT_R0); 00335 } 00336 00337 static void 00338 arm_linux_rt_sigreturn_init (const struct tramp_frame *self, 00339 struct frame_info *this_frame, 00340 struct trad_frame_cache *this_cache, 00341 CORE_ADDR func) 00342 { 00343 struct gdbarch *gdbarch = get_frame_arch (this_frame); 00344 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 00345 CORE_ADDR sp = get_frame_register_unsigned (this_frame, ARM_SP_REGNUM); 00346 ULONGEST pinfo = read_memory_unsigned_integer (sp, 4, byte_order); 00347 00348 if (pinfo == sp + ARM_OLD_RT_SIGFRAME_SIGINFO) 00349 arm_linux_sigtramp_cache (this_frame, this_cache, func, 00350 ARM_OLD_RT_SIGFRAME_UCONTEXT 00351 + ARM_UCONTEXT_SIGCONTEXT 00352 + ARM_SIGCONTEXT_R0); 00353 else 00354 arm_linux_sigtramp_cache (this_frame, this_cache, func, 00355 ARM_NEW_RT_SIGFRAME_UCONTEXT 00356 + ARM_UCONTEXT_SIGCONTEXT 00357 + ARM_SIGCONTEXT_R0); 00358 } 00359 00360 static void 00361 arm_linux_restart_syscall_init (const struct tramp_frame *self, 00362 struct frame_info *this_frame, 00363 struct trad_frame_cache *this_cache, 00364 CORE_ADDR func) 00365 { 00366 struct gdbarch *gdbarch = get_frame_arch (this_frame); 00367 CORE_ADDR sp = get_frame_register_unsigned (this_frame, ARM_SP_REGNUM); 00368 CORE_ADDR pc = get_frame_memory_unsigned (this_frame, sp, 4); 00369 CORE_ADDR cpsr = get_frame_register_unsigned (this_frame, ARM_PS_REGNUM); 00370 ULONGEST t_bit = arm_psr_thumb_bit (gdbarch); 00371 int sp_offset; 00372 00373 /* There are two variants of this trampoline; with older kernels, the 00374 stub is placed on the stack, while newer kernels use the stub from 00375 the vector page. They are identical except that the older version 00376 increments SP by 12 (to skip stored PC and the stub itself), while 00377 the newer version increments SP only by 4 (just the stored PC). */ 00378 if (self->insn[1].bytes == ARM_LDR_PC_SP_4) 00379 sp_offset = 4; 00380 else 00381 sp_offset = 12; 00382 00383 /* Update Thumb bit in CPSR. */ 00384 if (pc & 1) 00385 cpsr |= t_bit; 00386 else 00387 cpsr &= ~t_bit; 00388 00389 /* Remove Thumb bit from PC. */ 00390 pc = gdbarch_addr_bits_remove (gdbarch, pc); 00391 00392 /* Save previous register values. */ 00393 trad_frame_set_reg_value (this_cache, ARM_SP_REGNUM, sp + sp_offset); 00394 trad_frame_set_reg_value (this_cache, ARM_PC_REGNUM, pc); 00395 trad_frame_set_reg_value (this_cache, ARM_PS_REGNUM, cpsr); 00396 00397 /* Save a frame ID. */ 00398 trad_frame_set_id (this_cache, frame_id_build (sp, func)); 00399 } 00400 00401 static struct tramp_frame arm_linux_sigreturn_tramp_frame = { 00402 SIGTRAMP_FRAME, 00403 4, 00404 { 00405 { ARM_LINUX_SIGRETURN_INSTR, -1 }, 00406 { TRAMP_SENTINEL_INSN } 00407 }, 00408 arm_linux_sigreturn_init 00409 }; 00410 00411 static struct tramp_frame arm_linux_rt_sigreturn_tramp_frame = { 00412 SIGTRAMP_FRAME, 00413 4, 00414 { 00415 { ARM_LINUX_RT_SIGRETURN_INSTR, -1 }, 00416 { TRAMP_SENTINEL_INSN } 00417 }, 00418 arm_linux_rt_sigreturn_init 00419 }; 00420 00421 static struct tramp_frame arm_eabi_linux_sigreturn_tramp_frame = { 00422 SIGTRAMP_FRAME, 00423 4, 00424 { 00425 { ARM_SET_R7_SIGRETURN, -1 }, 00426 { ARM_EABI_SYSCALL, -1 }, 00427 { TRAMP_SENTINEL_INSN } 00428 }, 00429 arm_linux_sigreturn_init 00430 }; 00431 00432 static struct tramp_frame arm_eabi_linux_rt_sigreturn_tramp_frame = { 00433 SIGTRAMP_FRAME, 00434 4, 00435 { 00436 { ARM_SET_R7_RT_SIGRETURN, -1 }, 00437 { ARM_EABI_SYSCALL, -1 }, 00438 { TRAMP_SENTINEL_INSN } 00439 }, 00440 arm_linux_rt_sigreturn_init 00441 }; 00442 00443 static struct tramp_frame arm_linux_restart_syscall_tramp_frame = { 00444 NORMAL_FRAME, 00445 4, 00446 { 00447 { ARM_OABI_SYSCALL_RESTART_SYSCALL, -1 }, 00448 { ARM_LDR_PC_SP_12, -1 }, 00449 { TRAMP_SENTINEL_INSN } 00450 }, 00451 arm_linux_restart_syscall_init 00452 }; 00453 00454 static struct tramp_frame arm_kernel_linux_restart_syscall_tramp_frame = { 00455 NORMAL_FRAME, 00456 4, 00457 { 00458 { ARM_OABI_SYSCALL_RESTART_SYSCALL, -1 }, 00459 { ARM_LDR_PC_SP_4, -1 }, 00460 { TRAMP_SENTINEL_INSN } 00461 }, 00462 arm_linux_restart_syscall_init 00463 }; 00464 00465 /* Core file and register set support. */ 00466 00467 #define ARM_LINUX_SIZEOF_GREGSET (18 * INT_REGISTER_SIZE) 00468 00469 void 00470 arm_linux_supply_gregset (const struct regset *regset, 00471 struct regcache *regcache, 00472 int regnum, const void *gregs_buf, size_t len) 00473 { 00474 struct gdbarch *gdbarch = get_regcache_arch (regcache); 00475 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 00476 const gdb_byte *gregs = gregs_buf; 00477 int regno; 00478 CORE_ADDR reg_pc; 00479 gdb_byte pc_buf[INT_REGISTER_SIZE]; 00480 00481 for (regno = ARM_A1_REGNUM; regno < ARM_PC_REGNUM; regno++) 00482 if (regnum == -1 || regnum == regno) 00483 regcache_raw_supply (regcache, regno, 00484 gregs + INT_REGISTER_SIZE * regno); 00485 00486 if (regnum == ARM_PS_REGNUM || regnum == -1) 00487 { 00488 if (arm_apcs_32) 00489 regcache_raw_supply (regcache, ARM_PS_REGNUM, 00490 gregs + INT_REGISTER_SIZE * ARM_CPSR_GREGNUM); 00491 else 00492 regcache_raw_supply (regcache, ARM_PS_REGNUM, 00493 gregs + INT_REGISTER_SIZE * ARM_PC_REGNUM); 00494 } 00495 00496 if (regnum == ARM_PC_REGNUM || regnum == -1) 00497 { 00498 reg_pc = extract_unsigned_integer (gregs 00499 + INT_REGISTER_SIZE * ARM_PC_REGNUM, 00500 INT_REGISTER_SIZE, byte_order); 00501 reg_pc = gdbarch_addr_bits_remove (gdbarch, reg_pc); 00502 store_unsigned_integer (pc_buf, INT_REGISTER_SIZE, byte_order, reg_pc); 00503 regcache_raw_supply (regcache, ARM_PC_REGNUM, pc_buf); 00504 } 00505 } 00506 00507 void 00508 arm_linux_collect_gregset (const struct regset *regset, 00509 const struct regcache *regcache, 00510 int regnum, void *gregs_buf, size_t len) 00511 { 00512 gdb_byte *gregs = gregs_buf; 00513 int regno; 00514 00515 for (regno = ARM_A1_REGNUM; regno < ARM_PC_REGNUM; regno++) 00516 if (regnum == -1 || regnum == regno) 00517 regcache_raw_collect (regcache, regno, 00518 gregs + INT_REGISTER_SIZE * regno); 00519 00520 if (regnum == ARM_PS_REGNUM || regnum == -1) 00521 { 00522 if (arm_apcs_32) 00523 regcache_raw_collect (regcache, ARM_PS_REGNUM, 00524 gregs + INT_REGISTER_SIZE * ARM_CPSR_GREGNUM); 00525 else 00526 regcache_raw_collect (regcache, ARM_PS_REGNUM, 00527 gregs + INT_REGISTER_SIZE * ARM_PC_REGNUM); 00528 } 00529 00530 if (regnum == ARM_PC_REGNUM || regnum == -1) 00531 regcache_raw_collect (regcache, ARM_PC_REGNUM, 00532 gregs + INT_REGISTER_SIZE * ARM_PC_REGNUM); 00533 } 00534 00535 /* Support for register format used by the NWFPE FPA emulator. */ 00536 00537 #define typeNone 0x00 00538 #define typeSingle 0x01 00539 #define typeDouble 0x02 00540 #define typeExtended 0x03 00541 00542 void 00543 supply_nwfpe_register (struct regcache *regcache, int regno, 00544 const gdb_byte *regs) 00545 { 00546 const gdb_byte *reg_data; 00547 gdb_byte reg_tag; 00548 gdb_byte buf[FP_REGISTER_SIZE]; 00549 00550 reg_data = regs + (regno - ARM_F0_REGNUM) * FP_REGISTER_SIZE; 00551 reg_tag = regs[(regno - ARM_F0_REGNUM) + NWFPE_TAGS_OFFSET]; 00552 memset (buf, 0, FP_REGISTER_SIZE); 00553 00554 switch (reg_tag) 00555 { 00556 case typeSingle: 00557 memcpy (buf, reg_data, 4); 00558 break; 00559 case typeDouble: 00560 memcpy (buf, reg_data + 4, 4); 00561 memcpy (buf + 4, reg_data, 4); 00562 break; 00563 case typeExtended: 00564 /* We want sign and exponent, then least significant bits, 00565 then most significant. NWFPE does sign, most, least. */ 00566 memcpy (buf, reg_data, 4); 00567 memcpy (buf + 4, reg_data + 8, 4); 00568 memcpy (buf + 8, reg_data + 4, 4); 00569 break; 00570 default: 00571 break; 00572 } 00573 00574 regcache_raw_supply (regcache, regno, buf); 00575 } 00576 00577 void 00578 collect_nwfpe_register (const struct regcache *regcache, int regno, 00579 gdb_byte *regs) 00580 { 00581 gdb_byte *reg_data; 00582 gdb_byte reg_tag; 00583 gdb_byte buf[FP_REGISTER_SIZE]; 00584 00585 regcache_raw_collect (regcache, regno, buf); 00586 00587 /* NOTE drow/2006-06-07: This code uses the tag already in the 00588 register buffer. I've preserved that when moving the code 00589 from the native file to the target file. But this doesn't 00590 always make sense. */ 00591 00592 reg_data = regs + (regno - ARM_F0_REGNUM) * FP_REGISTER_SIZE; 00593 reg_tag = regs[(regno - ARM_F0_REGNUM) + NWFPE_TAGS_OFFSET]; 00594 00595 switch (reg_tag) 00596 { 00597 case typeSingle: 00598 memcpy (reg_data, buf, 4); 00599 break; 00600 case typeDouble: 00601 memcpy (reg_data, buf + 4, 4); 00602 memcpy (reg_data + 4, buf, 4); 00603 break; 00604 case typeExtended: 00605 memcpy (reg_data, buf, 4); 00606 memcpy (reg_data + 4, buf + 8, 4); 00607 memcpy (reg_data + 8, buf + 4, 4); 00608 break; 00609 default: 00610 break; 00611 } 00612 } 00613 00614 void 00615 arm_linux_supply_nwfpe (const struct regset *regset, 00616 struct regcache *regcache, 00617 int regnum, const void *regs_buf, size_t len) 00618 { 00619 const gdb_byte *regs = regs_buf; 00620 int regno; 00621 00622 if (regnum == ARM_FPS_REGNUM || regnum == -1) 00623 regcache_raw_supply (regcache, ARM_FPS_REGNUM, 00624 regs + NWFPE_FPSR_OFFSET); 00625 00626 for (regno = ARM_F0_REGNUM; regno <= ARM_F7_REGNUM; regno++) 00627 if (regnum == -1 || regnum == regno) 00628 supply_nwfpe_register (regcache, regno, regs); 00629 } 00630 00631 void 00632 arm_linux_collect_nwfpe (const struct regset *regset, 00633 const struct regcache *regcache, 00634 int regnum, void *regs_buf, size_t len) 00635 { 00636 gdb_byte *regs = regs_buf; 00637 int regno; 00638 00639 for (regno = ARM_F0_REGNUM; regno <= ARM_F7_REGNUM; regno++) 00640 if (regnum == -1 || regnum == regno) 00641 collect_nwfpe_register (regcache, regno, regs); 00642 00643 if (regnum == ARM_FPS_REGNUM || regnum == -1) 00644 regcache_raw_collect (regcache, ARM_FPS_REGNUM, 00645 regs + INT_REGISTER_SIZE * ARM_FPS_REGNUM); 00646 } 00647 00648 /* Support VFP register format. */ 00649 00650 #define ARM_LINUX_SIZEOF_VFP (32 * 8 + 4) 00651 00652 static void 00653 arm_linux_supply_vfp (const struct regset *regset, 00654 struct regcache *regcache, 00655 int regnum, const void *regs_buf, size_t len) 00656 { 00657 const gdb_byte *regs = regs_buf; 00658 int regno; 00659 00660 if (regnum == ARM_FPSCR_REGNUM || regnum == -1) 00661 regcache_raw_supply (regcache, ARM_FPSCR_REGNUM, regs + 32 * 8); 00662 00663 for (regno = ARM_D0_REGNUM; regno <= ARM_D31_REGNUM; regno++) 00664 if (regnum == -1 || regnum == regno) 00665 regcache_raw_supply (regcache, regno, 00666 regs + (regno - ARM_D0_REGNUM) * 8); 00667 } 00668 00669 static void 00670 arm_linux_collect_vfp (const struct regset *regset, 00671 const struct regcache *regcache, 00672 int regnum, void *regs_buf, size_t len) 00673 { 00674 gdb_byte *regs = regs_buf; 00675 int regno; 00676 00677 if (regnum == ARM_FPSCR_REGNUM || regnum == -1) 00678 regcache_raw_collect (regcache, ARM_FPSCR_REGNUM, regs + 32 * 8); 00679 00680 for (regno = ARM_D0_REGNUM; regno <= ARM_D31_REGNUM; regno++) 00681 if (regnum == -1 || regnum == regno) 00682 regcache_raw_collect (regcache, regno, 00683 regs + (regno - ARM_D0_REGNUM) * 8); 00684 } 00685 00686 /* Return the appropriate register set for the core section identified 00687 by SECT_NAME and SECT_SIZE. */ 00688 00689 static const struct regset * 00690 arm_linux_regset_from_core_section (struct gdbarch *gdbarch, 00691 const char *sect_name, size_t sect_size) 00692 { 00693 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); 00694 00695 if (strcmp (sect_name, ".reg") == 0 00696 && sect_size == ARM_LINUX_SIZEOF_GREGSET) 00697 { 00698 if (tdep->gregset == NULL) 00699 tdep->gregset = regset_alloc (gdbarch, arm_linux_supply_gregset, 00700 arm_linux_collect_gregset); 00701 return tdep->gregset; 00702 } 00703 00704 if (strcmp (sect_name, ".reg2") == 0 00705 && sect_size == ARM_LINUX_SIZEOF_NWFPE) 00706 { 00707 if (tdep->fpregset == NULL) 00708 tdep->fpregset = regset_alloc (gdbarch, arm_linux_supply_nwfpe, 00709 arm_linux_collect_nwfpe); 00710 return tdep->fpregset; 00711 } 00712 00713 if (strcmp (sect_name, ".reg-arm-vfp") == 0 00714 && sect_size == ARM_LINUX_SIZEOF_VFP) 00715 { 00716 if (tdep->vfpregset == NULL) 00717 tdep->vfpregset = regset_alloc (gdbarch, arm_linux_supply_vfp, 00718 arm_linux_collect_vfp); 00719 return tdep->vfpregset; 00720 } 00721 00722 return NULL; 00723 } 00724 00725 /* Core file register set sections. */ 00726 00727 static struct core_regset_section arm_linux_fpa_regset_sections[] = 00728 { 00729 { ".reg", ARM_LINUX_SIZEOF_GREGSET, "general-purpose" }, 00730 { ".reg2", ARM_LINUX_SIZEOF_NWFPE, "FPA floating-point" }, 00731 { NULL, 0} 00732 }; 00733 00734 static struct core_regset_section arm_linux_vfp_regset_sections[] = 00735 { 00736 { ".reg", ARM_LINUX_SIZEOF_GREGSET, "general-purpose" }, 00737 { ".reg-arm-vfp", ARM_LINUX_SIZEOF_VFP, "VFP floating-point" }, 00738 { NULL, 0} 00739 }; 00740 00741 /* Determine target description from core file. */ 00742 00743 static const struct target_desc * 00744 arm_linux_core_read_description (struct gdbarch *gdbarch, 00745 struct target_ops *target, 00746 bfd *abfd) 00747 { 00748 CORE_ADDR arm_hwcap = 0; 00749 00750 if (target_auxv_search (target, AT_HWCAP, &arm_hwcap) != 1) 00751 return NULL; 00752 00753 if (arm_hwcap & HWCAP_VFP) 00754 { 00755 /* NEON implies VFPv3-D32 or no-VFP unit. Say that we only support 00756 Neon with VFPv3-D32. */ 00757 if (arm_hwcap & HWCAP_NEON) 00758 return tdesc_arm_with_neon; 00759 else if ((arm_hwcap & (HWCAP_VFPv3 | HWCAP_VFPv3D16)) == HWCAP_VFPv3) 00760 return tdesc_arm_with_vfpv3; 00761 else 00762 return tdesc_arm_with_vfpv2; 00763 } 00764 00765 return NULL; 00766 } 00767 00768 00769 /* Copy the value of next pc of sigreturn and rt_sigrturn into PC, 00770 return 1. In addition, set IS_THUMB depending on whether we 00771 will return to ARM or Thumb code. Return 0 if it is not a 00772 rt_sigreturn/sigreturn syscall. */ 00773 static int 00774 arm_linux_sigreturn_return_addr (struct frame_info *frame, 00775 unsigned long svc_number, 00776 CORE_ADDR *pc, int *is_thumb) 00777 { 00778 /* Is this a sigreturn or rt_sigreturn syscall? */ 00779 if (svc_number == 119 || svc_number == 173) 00780 { 00781 if (get_frame_type (frame) == SIGTRAMP_FRAME) 00782 { 00783 ULONGEST t_bit = arm_psr_thumb_bit (frame_unwind_arch (frame)); 00784 CORE_ADDR cpsr 00785 = frame_unwind_register_unsigned (frame, ARM_PS_REGNUM); 00786 00787 *is_thumb = (cpsr & t_bit) != 0; 00788 *pc = frame_unwind_caller_pc (frame); 00789 return 1; 00790 } 00791 } 00792 return 0; 00793 } 00794 00795 /* At a ptrace syscall-stop, return the syscall number. This either 00796 comes from the SWI instruction (OABI) or from r7 (EABI). 00797 00798 When the function fails, it should return -1. */ 00799 00800 static LONGEST 00801 arm_linux_get_syscall_number (struct gdbarch *gdbarch, 00802 ptid_t ptid) 00803 { 00804 struct regcache *regs = get_thread_regcache (ptid); 00805 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); 00806 00807 ULONGEST pc; 00808 ULONGEST cpsr; 00809 ULONGEST t_bit = arm_psr_thumb_bit (gdbarch); 00810 int is_thumb; 00811 ULONGEST svc_number = -1; 00812 00813 regcache_cooked_read_unsigned (regs, ARM_PC_REGNUM, &pc); 00814 regcache_cooked_read_unsigned (regs, ARM_PS_REGNUM, &cpsr); 00815 is_thumb = (cpsr & t_bit) != 0; 00816 00817 if (is_thumb) 00818 { 00819 regcache_cooked_read_unsigned (regs, 7, &svc_number); 00820 } 00821 else 00822 { 00823 enum bfd_endian byte_order_for_code = 00824 gdbarch_byte_order_for_code (gdbarch); 00825 00826 /* PC gets incremented before the syscall-stop, so read the 00827 previous instruction. */ 00828 unsigned long this_instr = 00829 read_memory_unsigned_integer (pc - 4, 4, byte_order_for_code); 00830 00831 unsigned long svc_operand = (0x00ffffff & this_instr); 00832 00833 if (svc_operand) 00834 { 00835 /* OABI */ 00836 svc_number = svc_operand - 0x900000; 00837 } 00838 else 00839 { 00840 /* EABI */ 00841 regcache_cooked_read_unsigned (regs, 7, &svc_number); 00842 } 00843 } 00844 00845 return svc_number; 00846 } 00847 00848 /* When FRAME is at a syscall instruction, return the PC of the next 00849 instruction to be executed. */ 00850 00851 static CORE_ADDR 00852 arm_linux_syscall_next_pc (struct frame_info *frame) 00853 { 00854 CORE_ADDR pc = get_frame_pc (frame); 00855 CORE_ADDR return_addr = 0; 00856 int is_thumb = arm_frame_is_thumb (frame); 00857 ULONGEST svc_number = 0; 00858 00859 if (is_thumb) 00860 { 00861 svc_number = get_frame_register_unsigned (frame, 7); 00862 return_addr = pc + 2; 00863 } 00864 else 00865 { 00866 struct gdbarch *gdbarch = get_frame_arch (frame); 00867 enum bfd_endian byte_order_for_code = 00868 gdbarch_byte_order_for_code (gdbarch); 00869 unsigned long this_instr = 00870 read_memory_unsigned_integer (pc, 4, byte_order_for_code); 00871 00872 unsigned long svc_operand = (0x00ffffff & this_instr); 00873 if (svc_operand) /* OABI. */ 00874 { 00875 svc_number = svc_operand - 0x900000; 00876 } 00877 else /* EABI. */ 00878 { 00879 svc_number = get_frame_register_unsigned (frame, 7); 00880 } 00881 00882 return_addr = pc + 4; 00883 } 00884 00885 arm_linux_sigreturn_return_addr (frame, svc_number, &return_addr, &is_thumb); 00886 00887 /* Addresses for calling Thumb functions have the bit 0 set. */ 00888 if (is_thumb) 00889 return_addr |= 1; 00890 00891 return return_addr; 00892 } 00893 00894 00895 /* Insert a single step breakpoint at the next executed instruction. */ 00896 00897 static int 00898 arm_linux_software_single_step (struct frame_info *frame) 00899 { 00900 struct gdbarch *gdbarch = get_frame_arch (frame); 00901 struct address_space *aspace = get_frame_address_space (frame); 00902 CORE_ADDR next_pc; 00903 00904 if (arm_deal_with_atomic_sequence (frame)) 00905 return 1; 00906 00907 next_pc = arm_get_next_pc (frame, get_frame_pc (frame)); 00908 00909 /* The Linux kernel offers some user-mode helpers in a high page. We can 00910 not read this page (as of 2.6.23), and even if we could then we couldn't 00911 set breakpoints in it, and even if we could then the atomic operations 00912 would fail when interrupted. They are all called as functions and return 00913 to the address in LR, so step to there instead. */ 00914 if (next_pc > 0xffff0000) 00915 next_pc = get_frame_register_unsigned (frame, ARM_LR_REGNUM); 00916 00917 arm_insert_single_step_breakpoint (gdbarch, aspace, next_pc); 00918 00919 return 1; 00920 } 00921 00922 /* Support for displaced stepping of Linux SVC instructions. */ 00923 00924 static void 00925 arm_linux_cleanup_svc (struct gdbarch *gdbarch, 00926 struct regcache *regs, 00927 struct displaced_step_closure *dsc) 00928 { 00929 CORE_ADDR from = dsc->insn_addr; 00930 ULONGEST apparent_pc; 00931 int within_scratch; 00932 00933 regcache_cooked_read_unsigned (regs, ARM_PC_REGNUM, &apparent_pc); 00934 00935 within_scratch = (apparent_pc >= dsc->scratch_base 00936 && apparent_pc < (dsc->scratch_base 00937 + DISPLACED_MODIFIED_INSNS * 4 + 4)); 00938 00939 if (debug_displaced) 00940 { 00941 fprintf_unfiltered (gdb_stdlog, "displaced: PC is apparently %.8lx after " 00942 "SVC step ", (unsigned long) apparent_pc); 00943 if (within_scratch) 00944 fprintf_unfiltered (gdb_stdlog, "(within scratch space)\n"); 00945 else 00946 fprintf_unfiltered (gdb_stdlog, "(outside scratch space)\n"); 00947 } 00948 00949 if (within_scratch) 00950 displaced_write_reg (regs, dsc, ARM_PC_REGNUM, from + 4, BRANCH_WRITE_PC); 00951 } 00952 00953 static int 00954 arm_linux_copy_svc (struct gdbarch *gdbarch, struct regcache *regs, 00955 struct displaced_step_closure *dsc) 00956 { 00957 CORE_ADDR return_to = 0; 00958 00959 struct frame_info *frame; 00960 unsigned int svc_number = displaced_read_reg (regs, dsc, 7); 00961 int is_sigreturn = 0; 00962 int is_thumb; 00963 00964 frame = get_current_frame (); 00965 00966 is_sigreturn = arm_linux_sigreturn_return_addr(frame, svc_number, 00967 &return_to, &is_thumb); 00968 if (is_sigreturn) 00969 { 00970 struct symtab_and_line sal; 00971 00972 if (debug_displaced) 00973 fprintf_unfiltered (gdb_stdlog, "displaced: found " 00974 "sigreturn/rt_sigreturn SVC call. PC in frame = %lx\n", 00975 (unsigned long) get_frame_pc (frame)); 00976 00977 if (debug_displaced) 00978 fprintf_unfiltered (gdb_stdlog, "displaced: unwind pc = %lx. " 00979 "Setting momentary breakpoint.\n", (unsigned long) return_to); 00980 00981 gdb_assert (inferior_thread ()->control.step_resume_breakpoint 00982 == NULL); 00983 00984 sal = find_pc_line (return_to, 0); 00985 sal.pc = return_to; 00986 sal.section = find_pc_overlay (return_to); 00987 sal.explicit_pc = 1; 00988 00989 frame = get_prev_frame (frame); 00990 00991 if (frame) 00992 { 00993 inferior_thread ()->control.step_resume_breakpoint 00994 = set_momentary_breakpoint (gdbarch, sal, get_frame_id (frame), 00995 bp_step_resume); 00996 00997 /* set_momentary_breakpoint invalidates FRAME. */ 00998 frame = NULL; 00999 01000 /* We need to make sure we actually insert the momentary 01001 breakpoint set above. */ 01002 insert_breakpoints (); 01003 } 01004 else if (debug_displaced) 01005 fprintf_unfiltered (gdb_stderr, "displaced: couldn't find previous " 01006 "frame to set momentary breakpoint for " 01007 "sigreturn/rt_sigreturn\n"); 01008 } 01009 else if (debug_displaced) 01010 fprintf_unfiltered (gdb_stdlog, "displaced: sigreturn/rt_sigreturn " 01011 "SVC call not in signal trampoline frame\n"); 01012 01013 01014 /* Preparation: If we detect sigreturn, set momentary breakpoint at resume 01015 location, else nothing. 01016 Insn: unmodified svc. 01017 Cleanup: if pc lands in scratch space, pc <- insn_addr + 4 01018 else leave pc alone. */ 01019 01020 01021 dsc->cleanup = &arm_linux_cleanup_svc; 01022 /* Pretend we wrote to the PC, so cleanup doesn't set PC to the next 01023 instruction. */ 01024 dsc->wrote_to_pc = 1; 01025 01026 return 0; 01027 } 01028 01029 01030 /* The following two functions implement single-stepping over calls to Linux 01031 kernel helper routines, which perform e.g. atomic operations on architecture 01032 variants which don't support them natively. 01033 01034 When this function is called, the PC will be pointing at the kernel helper 01035 (at an address inaccessible to GDB), and r14 will point to the return 01036 address. Displaced stepping always executes code in the copy area: 01037 so, make the copy-area instruction branch back to the kernel helper (the 01038 "from" address), and make r14 point to the breakpoint in the copy area. In 01039 that way, we regain control once the kernel helper returns, and can clean 01040 up appropriately (as if we had just returned from the kernel helper as it 01041 would have been called from the non-displaced location). */ 01042 01043 static void 01044 cleanup_kernel_helper_return (struct gdbarch *gdbarch, 01045 struct regcache *regs, 01046 struct displaced_step_closure *dsc) 01047 { 01048 displaced_write_reg (regs, dsc, ARM_LR_REGNUM, dsc->tmp[0], CANNOT_WRITE_PC); 01049 displaced_write_reg (regs, dsc, ARM_PC_REGNUM, dsc->tmp[0], BRANCH_WRITE_PC); 01050 } 01051 01052 static void 01053 arm_catch_kernel_helper_return (struct gdbarch *gdbarch, CORE_ADDR from, 01054 CORE_ADDR to, struct regcache *regs, 01055 struct displaced_step_closure *dsc) 01056 { 01057 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 01058 01059 dsc->numinsns = 1; 01060 dsc->insn_addr = from; 01061 dsc->cleanup = &cleanup_kernel_helper_return; 01062 /* Say we wrote to the PC, else cleanup will set PC to the next 01063 instruction in the helper, which isn't helpful. */ 01064 dsc->wrote_to_pc = 1; 01065 01066 /* Preparation: tmp[0] <- r14 01067 r14 <- <scratch space>+4 01068 *(<scratch space>+8) <- from 01069 Insn: ldr pc, [r14, #4] 01070 Cleanup: r14 <- tmp[0], pc <- tmp[0]. */ 01071 01072 dsc->tmp[0] = displaced_read_reg (regs, dsc, ARM_LR_REGNUM); 01073 displaced_write_reg (regs, dsc, ARM_LR_REGNUM, (ULONGEST) to + 4, 01074 CANNOT_WRITE_PC); 01075 write_memory_unsigned_integer (to + 8, 4, byte_order, from); 01076 01077 dsc->modinsn[0] = 0xe59ef004; /* ldr pc, [lr, #4]. */ 01078 } 01079 01080 /* Linux-specific displaced step instruction copying function. Detects when 01081 the program has stepped into a Linux kernel helper routine (which must be 01082 handled as a special case), falling back to arm_displaced_step_copy_insn() 01083 if it hasn't. */ 01084 01085 static struct displaced_step_closure * 01086 arm_linux_displaced_step_copy_insn (struct gdbarch *gdbarch, 01087 CORE_ADDR from, CORE_ADDR to, 01088 struct regcache *regs) 01089 { 01090 struct displaced_step_closure *dsc 01091 = xmalloc (sizeof (struct displaced_step_closure)); 01092 01093 /* Detect when we enter an (inaccessible by GDB) Linux kernel helper, and 01094 stop at the return location. */ 01095 if (from > 0xffff0000) 01096 { 01097 if (debug_displaced) 01098 fprintf_unfiltered (gdb_stdlog, "displaced: detected kernel helper " 01099 "at %.8lx\n", (unsigned long) from); 01100 01101 arm_catch_kernel_helper_return (gdbarch, from, to, regs, dsc); 01102 } 01103 else 01104 { 01105 /* Override the default handling of SVC instructions. */ 01106 dsc->u.svc.copy_svc_os = arm_linux_copy_svc; 01107 01108 arm_process_displaced_insn (gdbarch, from, to, regs, dsc); 01109 } 01110 01111 arm_displaced_init_closure (gdbarch, from, to, dsc); 01112 01113 return dsc; 01114 } 01115 01116 static int 01117 arm_stap_is_single_operand (struct gdbarch *gdbarch, const char *s) 01118 { 01119 return (*s == '#' /* Literal number. */ 01120 || *s == '[' /* Register indirection or 01121 displacement. */ 01122 || isalpha (*s)); /* Register value. */ 01123 } 01124 01125 /* This routine is used to parse a special token in ARM's assembly. 01126 01127 The special tokens parsed by it are: 01128 01129 - Register displacement (e.g, [fp, #-8]) 01130 01131 It returns one if the special token has been parsed successfully, 01132 or zero if the current token is not considered special. */ 01133 01134 static int 01135 arm_stap_parse_special_token (struct gdbarch *gdbarch, 01136 struct stap_parse_info *p) 01137 { 01138 if (*p->arg == '[') 01139 { 01140 /* Temporary holder for lookahead. */ 01141 const char *tmp = p->arg; 01142 char *endp; 01143 /* Used to save the register name. */ 01144 const char *start; 01145 char *regname; 01146 int len, offset; 01147 int got_minus = 0; 01148 long displacement; 01149 struct stoken str; 01150 01151 ++tmp; 01152 start = tmp; 01153 01154 /* Register name. */ 01155 while (isalnum (*tmp)) 01156 ++tmp; 01157 01158 if (*tmp != ',') 01159 return 0; 01160 01161 len = tmp - start; 01162 regname = alloca (len + 2); 01163 01164 offset = 0; 01165 if (isdigit (*start)) 01166 { 01167 /* If we are dealing with a register whose name begins with a 01168 digit, it means we should prefix the name with the letter 01169 `r', because GDB expects this name pattern. Otherwise (e.g., 01170 we are dealing with the register `fp'), we don't need to 01171 add such a prefix. */ 01172 regname[0] = 'r'; 01173 offset = 1; 01174 } 01175 01176 strncpy (regname + offset, start, len); 01177 len += offset; 01178 regname[len] = '\0'; 01179 01180 if (user_reg_map_name_to_regnum (gdbarch, regname, len) == -1) 01181 error (_("Invalid register name `%s' on expression `%s'."), 01182 regname, p->saved_arg); 01183 01184 ++tmp; 01185 tmp = skip_spaces_const (tmp); 01186 if (*tmp++ != '#') 01187 return 0; 01188 01189 if (*tmp == '-') 01190 { 01191 ++tmp; 01192 got_minus = 1; 01193 } 01194 01195 displacement = strtol (tmp, &endp, 10); 01196 tmp = endp; 01197 01198 /* Skipping last `]'. */ 01199 if (*tmp++ != ']') 01200 return 0; 01201 01202 /* The displacement. */ 01203 write_exp_elt_opcode (OP_LONG); 01204 write_exp_elt_type (builtin_type (gdbarch)->builtin_long); 01205 write_exp_elt_longcst (displacement); 01206 write_exp_elt_opcode (OP_LONG); 01207 if (got_minus) 01208 write_exp_elt_opcode (UNOP_NEG); 01209 01210 /* The register name. */ 01211 write_exp_elt_opcode (OP_REGISTER); 01212 str.ptr = regname; 01213 str.length = len; 01214 write_exp_string (str); 01215 write_exp_elt_opcode (OP_REGISTER); 01216 01217 write_exp_elt_opcode (BINOP_ADD); 01218 01219 /* Casting to the expected type. */ 01220 write_exp_elt_opcode (UNOP_CAST); 01221 write_exp_elt_type (lookup_pointer_type (p->arg_type)); 01222 write_exp_elt_opcode (UNOP_CAST); 01223 01224 write_exp_elt_opcode (UNOP_IND); 01225 01226 p->arg = tmp; 01227 } 01228 else 01229 return 0; 01230 01231 return 1; 01232 } 01233 01234 static void 01235 arm_linux_init_abi (struct gdbarch_info info, 01236 struct gdbarch *gdbarch) 01237 { 01238 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); 01239 01240 linux_init_abi (info, gdbarch); 01241 01242 tdep->lowest_pc = 0x8000; 01243 if (info.byte_order == BFD_ENDIAN_BIG) 01244 { 01245 if (tdep->arm_abi == ARM_ABI_AAPCS) 01246 tdep->arm_breakpoint = eabi_linux_arm_be_breakpoint; 01247 else 01248 tdep->arm_breakpoint = arm_linux_arm_be_breakpoint; 01249 tdep->thumb_breakpoint = arm_linux_thumb_be_breakpoint; 01250 tdep->thumb2_breakpoint = arm_linux_thumb2_be_breakpoint; 01251 } 01252 else 01253 { 01254 if (tdep->arm_abi == ARM_ABI_AAPCS) 01255 tdep->arm_breakpoint = eabi_linux_arm_le_breakpoint; 01256 else 01257 tdep->arm_breakpoint = arm_linux_arm_le_breakpoint; 01258 tdep->thumb_breakpoint = arm_linux_thumb_le_breakpoint; 01259 tdep->thumb2_breakpoint = arm_linux_thumb2_le_breakpoint; 01260 } 01261 tdep->arm_breakpoint_size = sizeof (arm_linux_arm_le_breakpoint); 01262 tdep->thumb_breakpoint_size = sizeof (arm_linux_thumb_le_breakpoint); 01263 tdep->thumb2_breakpoint_size = sizeof (arm_linux_thumb2_le_breakpoint); 01264 01265 if (tdep->fp_model == ARM_FLOAT_AUTO) 01266 tdep->fp_model = ARM_FLOAT_FPA; 01267 01268 switch (tdep->fp_model) 01269 { 01270 case ARM_FLOAT_FPA: 01271 tdep->jb_pc = ARM_LINUX_JB_PC_FPA; 01272 break; 01273 case ARM_FLOAT_SOFT_FPA: 01274 case ARM_FLOAT_SOFT_VFP: 01275 case ARM_FLOAT_VFP: 01276 tdep->jb_pc = ARM_LINUX_JB_PC_EABI; 01277 break; 01278 default: 01279 internal_error 01280 (__FILE__, __LINE__, 01281 _("arm_linux_init_abi: Floating point model not supported")); 01282 break; 01283 } 01284 tdep->jb_elt_size = ARM_LINUX_JB_ELEMENT_SIZE; 01285 01286 set_solib_svr4_fetch_link_map_offsets 01287 (gdbarch, svr4_ilp32_fetch_link_map_offsets); 01288 01289 /* Single stepping. */ 01290 set_gdbarch_software_single_step (gdbarch, arm_linux_software_single_step); 01291 01292 /* Shared library handling. */ 01293 set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target); 01294 set_gdbarch_skip_solib_resolver (gdbarch, glibc_skip_solib_resolver); 01295 01296 /* Enable TLS support. */ 01297 set_gdbarch_fetch_tls_load_module_address (gdbarch, 01298 svr4_fetch_objfile_link_map); 01299 01300 tramp_frame_prepend_unwinder (gdbarch, 01301 &arm_linux_sigreturn_tramp_frame); 01302 tramp_frame_prepend_unwinder (gdbarch, 01303 &arm_linux_rt_sigreturn_tramp_frame); 01304 tramp_frame_prepend_unwinder (gdbarch, 01305 &arm_eabi_linux_sigreturn_tramp_frame); 01306 tramp_frame_prepend_unwinder (gdbarch, 01307 &arm_eabi_linux_rt_sigreturn_tramp_frame); 01308 tramp_frame_prepend_unwinder (gdbarch, 01309 &arm_linux_restart_syscall_tramp_frame); 01310 tramp_frame_prepend_unwinder (gdbarch, 01311 &arm_kernel_linux_restart_syscall_tramp_frame); 01312 01313 /* Core file support. */ 01314 set_gdbarch_regset_from_core_section (gdbarch, 01315 arm_linux_regset_from_core_section); 01316 set_gdbarch_core_read_description (gdbarch, arm_linux_core_read_description); 01317 01318 if (tdep->have_vfp_registers) 01319 set_gdbarch_core_regset_sections (gdbarch, arm_linux_vfp_regset_sections); 01320 else if (tdep->have_fpa_registers) 01321 set_gdbarch_core_regset_sections (gdbarch, arm_linux_fpa_regset_sections); 01322 01323 set_gdbarch_get_siginfo_type (gdbarch, linux_get_siginfo_type); 01324 01325 /* Displaced stepping. */ 01326 set_gdbarch_displaced_step_copy_insn (gdbarch, 01327 arm_linux_displaced_step_copy_insn); 01328 set_gdbarch_displaced_step_fixup (gdbarch, arm_displaced_step_fixup); 01329 set_gdbarch_displaced_step_free_closure (gdbarch, 01330 simple_displaced_step_free_closure); 01331 set_gdbarch_displaced_step_location (gdbarch, displaced_step_at_entry_point); 01332 01333 /* Reversible debugging, process record. */ 01334 set_gdbarch_process_record (gdbarch, arm_process_record); 01335 01336 /* SystemTap functions. */ 01337 set_gdbarch_stap_integer_prefix (gdbarch, "#"); 01338 set_gdbarch_stap_register_prefix (gdbarch, "r"); 01339 set_gdbarch_stap_register_indirection_prefix (gdbarch, "["); 01340 set_gdbarch_stap_register_indirection_suffix (gdbarch, "]"); 01341 set_gdbarch_stap_gdb_register_prefix (gdbarch, "r"); 01342 set_gdbarch_stap_is_single_operand (gdbarch, arm_stap_is_single_operand); 01343 set_gdbarch_stap_parse_special_token (gdbarch, 01344 arm_stap_parse_special_token); 01345 01346 tdep->syscall_next_pc = arm_linux_syscall_next_pc; 01347 01348 /* `catch syscall' */ 01349 set_xml_syscall_file_name ("syscalls/arm-linux.xml"); 01350 set_gdbarch_get_syscall_number (gdbarch, arm_linux_get_syscall_number); 01351 01352 /* Syscall record. */ 01353 tdep->arm_swi_record = NULL; 01354 } 01355 01356 /* Provide a prototype to silence -Wmissing-prototypes. */ 01357 extern initialize_file_ftype _initialize_arm_linux_tdep; 01358 01359 void 01360 _initialize_arm_linux_tdep (void) 01361 { 01362 gdbarch_register_osabi (bfd_arch_arm, 0, GDB_OSABI_LINUX, 01363 arm_linux_init_abi); 01364 }