GDB (API)
|
00001 /* Functions specific to running gdb native on IA-64 running 00002 GNU/Linux. 00003 00004 Copyright (C) 1999-2013 Free Software Foundation, Inc. 00005 00006 This file is part of GDB. 00007 00008 This program is free software; you can redistribute it and/or modify 00009 it under the terms of the GNU General Public License as published by 00010 the Free Software Foundation; either version 3 of the License, or 00011 (at your option) any later version. 00012 00013 This program is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU General Public License for more details. 00017 00018 You should have received a copy of the GNU General Public License 00019 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 00020 00021 #include "defs.h" 00022 #include "gdb_string.h" 00023 #include "inferior.h" 00024 #include "target.h" 00025 #include "gdbcore.h" 00026 #include "regcache.h" 00027 #include "ia64-tdep.h" 00028 #include "linux-nat.h" 00029 00030 #include <signal.h> 00031 #include <sys/ptrace.h> 00032 #include "gdb_wait.h" 00033 #ifdef HAVE_SYS_REG_H 00034 #include <sys/reg.h> 00035 #endif 00036 #include <sys/syscall.h> 00037 #include <sys/user.h> 00038 00039 #include <asm/ptrace_offsets.h> 00040 #include <sys/procfs.h> 00041 00042 /* Prototypes for supply_gregset etc. */ 00043 #include "gregset.h" 00044 00045 /* These must match the order of the register names. 00046 00047 Some sort of lookup table is needed because the offsets associated 00048 with the registers are all over the board. */ 00049 00050 static int u_offsets[] = 00051 { 00052 /* general registers */ 00053 -1, /* gr0 not available; i.e, it's always zero. */ 00054 PT_R1, 00055 PT_R2, 00056 PT_R3, 00057 PT_R4, 00058 PT_R5, 00059 PT_R6, 00060 PT_R7, 00061 PT_R8, 00062 PT_R9, 00063 PT_R10, 00064 PT_R11, 00065 PT_R12, 00066 PT_R13, 00067 PT_R14, 00068 PT_R15, 00069 PT_R16, 00070 PT_R17, 00071 PT_R18, 00072 PT_R19, 00073 PT_R20, 00074 PT_R21, 00075 PT_R22, 00076 PT_R23, 00077 PT_R24, 00078 PT_R25, 00079 PT_R26, 00080 PT_R27, 00081 PT_R28, 00082 PT_R29, 00083 PT_R30, 00084 PT_R31, 00085 /* gr32 through gr127 not directly available via the ptrace interface. */ 00086 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 00087 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 00088 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 00089 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 00090 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 00091 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 00092 /* Floating point registers */ 00093 -1, -1, /* f0 and f1 not available (f0 is +0.0 and f1 is +1.0). */ 00094 PT_F2, 00095 PT_F3, 00096 PT_F4, 00097 PT_F5, 00098 PT_F6, 00099 PT_F7, 00100 PT_F8, 00101 PT_F9, 00102 PT_F10, 00103 PT_F11, 00104 PT_F12, 00105 PT_F13, 00106 PT_F14, 00107 PT_F15, 00108 PT_F16, 00109 PT_F17, 00110 PT_F18, 00111 PT_F19, 00112 PT_F20, 00113 PT_F21, 00114 PT_F22, 00115 PT_F23, 00116 PT_F24, 00117 PT_F25, 00118 PT_F26, 00119 PT_F27, 00120 PT_F28, 00121 PT_F29, 00122 PT_F30, 00123 PT_F31, 00124 PT_F32, 00125 PT_F33, 00126 PT_F34, 00127 PT_F35, 00128 PT_F36, 00129 PT_F37, 00130 PT_F38, 00131 PT_F39, 00132 PT_F40, 00133 PT_F41, 00134 PT_F42, 00135 PT_F43, 00136 PT_F44, 00137 PT_F45, 00138 PT_F46, 00139 PT_F47, 00140 PT_F48, 00141 PT_F49, 00142 PT_F50, 00143 PT_F51, 00144 PT_F52, 00145 PT_F53, 00146 PT_F54, 00147 PT_F55, 00148 PT_F56, 00149 PT_F57, 00150 PT_F58, 00151 PT_F59, 00152 PT_F60, 00153 PT_F61, 00154 PT_F62, 00155 PT_F63, 00156 PT_F64, 00157 PT_F65, 00158 PT_F66, 00159 PT_F67, 00160 PT_F68, 00161 PT_F69, 00162 PT_F70, 00163 PT_F71, 00164 PT_F72, 00165 PT_F73, 00166 PT_F74, 00167 PT_F75, 00168 PT_F76, 00169 PT_F77, 00170 PT_F78, 00171 PT_F79, 00172 PT_F80, 00173 PT_F81, 00174 PT_F82, 00175 PT_F83, 00176 PT_F84, 00177 PT_F85, 00178 PT_F86, 00179 PT_F87, 00180 PT_F88, 00181 PT_F89, 00182 PT_F90, 00183 PT_F91, 00184 PT_F92, 00185 PT_F93, 00186 PT_F94, 00187 PT_F95, 00188 PT_F96, 00189 PT_F97, 00190 PT_F98, 00191 PT_F99, 00192 PT_F100, 00193 PT_F101, 00194 PT_F102, 00195 PT_F103, 00196 PT_F104, 00197 PT_F105, 00198 PT_F106, 00199 PT_F107, 00200 PT_F108, 00201 PT_F109, 00202 PT_F110, 00203 PT_F111, 00204 PT_F112, 00205 PT_F113, 00206 PT_F114, 00207 PT_F115, 00208 PT_F116, 00209 PT_F117, 00210 PT_F118, 00211 PT_F119, 00212 PT_F120, 00213 PT_F121, 00214 PT_F122, 00215 PT_F123, 00216 PT_F124, 00217 PT_F125, 00218 PT_F126, 00219 PT_F127, 00220 /* Predicate registers - we don't fetch these individually. */ 00221 -1, -1, -1, -1, -1, -1, -1, -1, 00222 -1, -1, -1, -1, -1, -1, -1, -1, 00223 -1, -1, -1, -1, -1, -1, -1, -1, 00224 -1, -1, -1, -1, -1, -1, -1, -1, 00225 -1, -1, -1, -1, -1, -1, -1, -1, 00226 -1, -1, -1, -1, -1, -1, -1, -1, 00227 -1, -1, -1, -1, -1, -1, -1, -1, 00228 -1, -1, -1, -1, -1, -1, -1, -1, 00229 /* branch registers */ 00230 PT_B0, 00231 PT_B1, 00232 PT_B2, 00233 PT_B3, 00234 PT_B4, 00235 PT_B5, 00236 PT_B6, 00237 PT_B7, 00238 /* Virtual frame pointer and virtual return address pointer. */ 00239 -1, -1, 00240 /* other registers */ 00241 PT_PR, 00242 PT_CR_IIP, /* ip */ 00243 PT_CR_IPSR, /* psr */ 00244 PT_CFM, /* cfm */ 00245 /* kernel registers not visible via ptrace interface (?) */ 00246 -1, -1, -1, -1, -1, -1, -1, -1, 00247 /* hole */ 00248 -1, -1, -1, -1, -1, -1, -1, -1, 00249 PT_AR_RSC, 00250 PT_AR_BSP, 00251 PT_AR_BSPSTORE, 00252 PT_AR_RNAT, 00253 -1, 00254 -1, /* Not available: FCR, IA32 floating control register. */ 00255 -1, -1, 00256 -1, /* Not available: EFLAG */ 00257 -1, /* Not available: CSD */ 00258 -1, /* Not available: SSD */ 00259 -1, /* Not available: CFLG */ 00260 -1, /* Not available: FSR */ 00261 -1, /* Not available: FIR */ 00262 -1, /* Not available: FDR */ 00263 -1, 00264 PT_AR_CCV, 00265 -1, -1, -1, 00266 PT_AR_UNAT, 00267 -1, -1, -1, 00268 PT_AR_FPSR, 00269 -1, -1, -1, 00270 -1, /* Not available: ITC */ 00271 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 00272 -1, -1, -1, -1, -1, -1, -1, -1, -1, 00273 PT_AR_PFS, 00274 PT_AR_LC, 00275 PT_AR_EC, 00276 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 00277 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 00278 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 00279 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 00280 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 00281 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 00282 -1, 00283 /* nat bits - not fetched directly; instead we obtain these bits from 00284 either rnat or unat or from memory. */ 00285 -1, -1, -1, -1, -1, -1, -1, -1, 00286 -1, -1, -1, -1, -1, -1, -1, -1, 00287 -1, -1, -1, -1, -1, -1, -1, -1, 00288 -1, -1, -1, -1, -1, -1, -1, -1, 00289 -1, -1, -1, -1, -1, -1, -1, -1, 00290 -1, -1, -1, -1, -1, -1, -1, -1, 00291 -1, -1, -1, -1, -1, -1, -1, -1, 00292 -1, -1, -1, -1, -1, -1, -1, -1, 00293 -1, -1, -1, -1, -1, -1, -1, -1, 00294 -1, -1, -1, -1, -1, -1, -1, -1, 00295 -1, -1, -1, -1, -1, -1, -1, -1, 00296 -1, -1, -1, -1, -1, -1, -1, -1, 00297 -1, -1, -1, -1, -1, -1, -1, -1, 00298 -1, -1, -1, -1, -1, -1, -1, -1, 00299 -1, -1, -1, -1, -1, -1, -1, -1, 00300 -1, -1, -1, -1, -1, -1, -1, -1, 00301 }; 00302 00303 static CORE_ADDR 00304 ia64_register_addr (struct gdbarch *gdbarch, int regno) 00305 { 00306 CORE_ADDR addr; 00307 00308 if (regno < 0 || regno >= gdbarch_num_regs (gdbarch)) 00309 error (_("Invalid register number %d."), regno); 00310 00311 if (u_offsets[regno] == -1) 00312 addr = 0; 00313 else 00314 addr = (CORE_ADDR) u_offsets[regno]; 00315 00316 return addr; 00317 } 00318 00319 static int 00320 ia64_cannot_fetch_register (struct gdbarch *gdbarch, int regno) 00321 { 00322 return regno < 0 00323 || regno >= gdbarch_num_regs (gdbarch) 00324 || u_offsets[regno] == -1; 00325 } 00326 00327 static int 00328 ia64_cannot_store_register (struct gdbarch *gdbarch, int regno) 00329 { 00330 /* Rationale behind not permitting stores to bspstore... 00331 00332 The IA-64 architecture provides bspstore and bsp which refer 00333 memory locations in the RSE's backing store. bspstore is the 00334 next location which will be written when the RSE needs to write 00335 to memory. bsp is the address at which r32 in the current frame 00336 would be found if it were written to the backing store. 00337 00338 The IA-64 architecture provides read-only access to bsp and 00339 read/write access to bspstore (but only when the RSE is in 00340 the enforced lazy mode). It should be noted that stores 00341 to bspstore also affect the value of bsp. Changing bspstore 00342 does not affect the number of dirty entries between bspstore 00343 and bsp, so changing bspstore by N words will also cause bsp 00344 to be changed by (roughly) N as well. (It could be N-1 or N+1 00345 depending upon where the NaT collection bits fall.) 00346 00347 OTOH, the Linux kernel provides read/write access to bsp (and 00348 currently read/write access to bspstore as well). But it 00349 is definitely the case that if you change one, the other 00350 will change at the same time. It is more useful to gdb to 00351 be able to change bsp. So in order to prevent strange and 00352 undesirable things from happening when a dummy stack frame 00353 is popped (after calling an inferior function), we allow 00354 bspstore to be read, but not written. (Note that popping 00355 a (generic) dummy stack frame causes all registers that 00356 were previously read from the inferior process to be written 00357 back.) */ 00358 00359 return regno < 0 00360 || regno >= gdbarch_num_regs (gdbarch) 00361 || u_offsets[regno] == -1 00362 || regno == IA64_BSPSTORE_REGNUM; 00363 } 00364 00365 void 00366 supply_gregset (struct regcache *regcache, const gregset_t *gregsetp) 00367 { 00368 int regi; 00369 const greg_t *regp = (const greg_t *) gregsetp; 00370 00371 for (regi = IA64_GR0_REGNUM; regi <= IA64_GR31_REGNUM; regi++) 00372 { 00373 regcache_raw_supply (regcache, regi, regp + (regi - IA64_GR0_REGNUM)); 00374 } 00375 00376 /* FIXME: NAT collection bits are at index 32; gotta deal with these 00377 somehow... */ 00378 00379 regcache_raw_supply (regcache, IA64_PR_REGNUM, regp + 33); 00380 00381 for (regi = IA64_BR0_REGNUM; regi <= IA64_BR7_REGNUM; regi++) 00382 { 00383 regcache_raw_supply (regcache, regi, 00384 regp + 34 + (regi - IA64_BR0_REGNUM)); 00385 } 00386 00387 regcache_raw_supply (regcache, IA64_IP_REGNUM, regp + 42); 00388 regcache_raw_supply (regcache, IA64_CFM_REGNUM, regp + 43); 00389 regcache_raw_supply (regcache, IA64_PSR_REGNUM, regp + 44); 00390 regcache_raw_supply (regcache, IA64_RSC_REGNUM, regp + 45); 00391 regcache_raw_supply (regcache, IA64_BSP_REGNUM, regp + 46); 00392 regcache_raw_supply (regcache, IA64_BSPSTORE_REGNUM, regp + 47); 00393 regcache_raw_supply (regcache, IA64_RNAT_REGNUM, regp + 48); 00394 regcache_raw_supply (regcache, IA64_CCV_REGNUM, regp + 49); 00395 regcache_raw_supply (regcache, IA64_UNAT_REGNUM, regp + 50); 00396 regcache_raw_supply (regcache, IA64_FPSR_REGNUM, regp + 51); 00397 regcache_raw_supply (regcache, IA64_PFS_REGNUM, regp + 52); 00398 regcache_raw_supply (regcache, IA64_LC_REGNUM, regp + 53); 00399 regcache_raw_supply (regcache, IA64_EC_REGNUM, regp + 54); 00400 } 00401 00402 void 00403 fill_gregset (const struct regcache *regcache, gregset_t *gregsetp, int regno) 00404 { 00405 int regi; 00406 greg_t *regp = (greg_t *) gregsetp; 00407 00408 #define COPY_REG(_idx_,_regi_) \ 00409 if ((regno == -1) || regno == _regi_) \ 00410 regcache_raw_collect (regcache, _regi_, regp + _idx_) 00411 00412 for (regi = IA64_GR0_REGNUM; regi <= IA64_GR31_REGNUM; regi++) 00413 { 00414 COPY_REG (regi - IA64_GR0_REGNUM, regi); 00415 } 00416 00417 /* FIXME: NAT collection bits at index 32? */ 00418 00419 COPY_REG (33, IA64_PR_REGNUM); 00420 00421 for (regi = IA64_BR0_REGNUM; regi <= IA64_BR7_REGNUM; regi++) 00422 { 00423 COPY_REG (34 + (regi - IA64_BR0_REGNUM), regi); 00424 } 00425 00426 COPY_REG (42, IA64_IP_REGNUM); 00427 COPY_REG (43, IA64_CFM_REGNUM); 00428 COPY_REG (44, IA64_PSR_REGNUM); 00429 COPY_REG (45, IA64_RSC_REGNUM); 00430 COPY_REG (46, IA64_BSP_REGNUM); 00431 COPY_REG (47, IA64_BSPSTORE_REGNUM); 00432 COPY_REG (48, IA64_RNAT_REGNUM); 00433 COPY_REG (49, IA64_CCV_REGNUM); 00434 COPY_REG (50, IA64_UNAT_REGNUM); 00435 COPY_REG (51, IA64_FPSR_REGNUM); 00436 COPY_REG (52, IA64_PFS_REGNUM); 00437 COPY_REG (53, IA64_LC_REGNUM); 00438 COPY_REG (54, IA64_EC_REGNUM); 00439 } 00440 00441 /* Given a pointer to a floating point register set in /proc format 00442 (fpregset_t *), unpack the register contents and supply them as gdb's 00443 idea of the current floating point register values. */ 00444 00445 void 00446 supply_fpregset (struct regcache *regcache, const fpregset_t *fpregsetp) 00447 { 00448 int regi; 00449 const char *from; 00450 const gdb_byte f_zero[16] = { 0 }; 00451 const gdb_byte f_one[16] = 00452 { 0, 0, 0, 0, 0, 0, 0, 0x80, 0xff, 0xff, 0, 0, 0, 0, 0, 0 }; 00453 00454 /* Kernel generated cores have fr1==0 instead of 1.0. Older GDBs 00455 did the same. So ignore whatever might be recorded in fpregset_t 00456 for fr0/fr1 and always supply their expected values. */ 00457 00458 /* fr0 is always read as zero. */ 00459 regcache_raw_supply (regcache, IA64_FR0_REGNUM, f_zero); 00460 /* fr1 is always read as one (1.0). */ 00461 regcache_raw_supply (regcache, IA64_FR1_REGNUM, f_one); 00462 00463 for (regi = IA64_FR2_REGNUM; regi <= IA64_FR127_REGNUM; regi++) 00464 { 00465 from = (const char *) &((*fpregsetp)[regi - IA64_FR0_REGNUM]); 00466 regcache_raw_supply (regcache, regi, from); 00467 } 00468 } 00469 00470 /* Given a pointer to a floating point register set in /proc format 00471 (fpregset_t *), update the register specified by REGNO from gdb's idea 00472 of the current floating point register set. If REGNO is -1, update 00473 them all. */ 00474 00475 void 00476 fill_fpregset (const struct regcache *regcache, 00477 fpregset_t *fpregsetp, int regno) 00478 { 00479 int regi; 00480 00481 for (regi = IA64_FR0_REGNUM; regi <= IA64_FR127_REGNUM; regi++) 00482 { 00483 if ((regno == -1) || (regno == regi)) 00484 regcache_raw_collect (regcache, regi, 00485 &((*fpregsetp)[regi - IA64_FR0_REGNUM])); 00486 } 00487 } 00488 00489 #define IA64_PSR_DB (1UL << 24) 00490 #define IA64_PSR_DD (1UL << 39) 00491 00492 static void 00493 enable_watchpoints_in_psr (ptid_t ptid) 00494 { 00495 struct regcache *regcache = get_thread_regcache (ptid); 00496 ULONGEST psr; 00497 00498 regcache_cooked_read_unsigned (regcache, IA64_PSR_REGNUM, &psr); 00499 if (!(psr & IA64_PSR_DB)) 00500 { 00501 psr |= IA64_PSR_DB; /* Set the db bit - this enables hardware 00502 watchpoints and breakpoints. */ 00503 regcache_cooked_write_unsigned (regcache, IA64_PSR_REGNUM, psr); 00504 } 00505 } 00506 00507 static long debug_registers[8]; 00508 00509 static void 00510 store_debug_register (ptid_t ptid, int idx, long val) 00511 { 00512 int tid; 00513 00514 tid = ptid_get_lwp (ptid); 00515 if (tid == 0) 00516 tid = ptid_get_pid (ptid); 00517 00518 (void) ptrace (PT_WRITE_U, tid, (PTRACE_TYPE_ARG3) (PT_DBR + 8 * idx), val); 00519 } 00520 00521 static void 00522 store_debug_register_pair (ptid_t ptid, int idx, long *dbr_addr, 00523 long *dbr_mask) 00524 { 00525 if (dbr_addr) 00526 store_debug_register (ptid, 2 * idx, *dbr_addr); 00527 if (dbr_mask) 00528 store_debug_register (ptid, 2 * idx + 1, *dbr_mask); 00529 } 00530 00531 static int 00532 is_power_of_2 (int val) 00533 { 00534 int i, onecount; 00535 00536 onecount = 0; 00537 for (i = 0; i < 8 * sizeof (val); i++) 00538 if (val & (1 << i)) 00539 onecount++; 00540 00541 return onecount <= 1; 00542 } 00543 00544 static int 00545 ia64_linux_insert_watchpoint (CORE_ADDR addr, int len, int rw, 00546 struct expression *cond) 00547 { 00548 struct lwp_info *lp; 00549 int idx; 00550 long dbr_addr, dbr_mask; 00551 int max_watchpoints = 4; 00552 00553 if (len <= 0 || !is_power_of_2 (len)) 00554 return -1; 00555 00556 for (idx = 0; idx < max_watchpoints; idx++) 00557 { 00558 dbr_mask = debug_registers[idx * 2 + 1]; 00559 if ((dbr_mask & (0x3UL << 62)) == 0) 00560 { 00561 /* Exit loop if both r and w bits clear. */ 00562 break; 00563 } 00564 } 00565 00566 if (idx == max_watchpoints) 00567 return -1; 00568 00569 dbr_addr = (long) addr; 00570 dbr_mask = (~(len - 1) & 0x00ffffffffffffffL); /* construct mask to match */ 00571 dbr_mask |= 0x0800000000000000L; /* Only match privilege level 3 */ 00572 switch (rw) 00573 { 00574 case hw_write: 00575 dbr_mask |= (1L << 62); /* Set w bit */ 00576 break; 00577 case hw_read: 00578 dbr_mask |= (1L << 63); /* Set r bit */ 00579 break; 00580 case hw_access: 00581 dbr_mask |= (3L << 62); /* Set both r and w bits */ 00582 break; 00583 default: 00584 return -1; 00585 } 00586 00587 debug_registers[2 * idx] = dbr_addr; 00588 debug_registers[2 * idx + 1] = dbr_mask; 00589 ALL_LWPS (lp) 00590 { 00591 store_debug_register_pair (lp->ptid, idx, &dbr_addr, &dbr_mask); 00592 enable_watchpoints_in_psr (lp->ptid); 00593 } 00594 00595 return 0; 00596 } 00597 00598 static int 00599 ia64_linux_remove_watchpoint (CORE_ADDR addr, int len, int type, 00600 struct expression *cond) 00601 { 00602 int idx; 00603 long dbr_addr, dbr_mask; 00604 int max_watchpoints = 4; 00605 00606 if (len <= 0 || !is_power_of_2 (len)) 00607 return -1; 00608 00609 for (idx = 0; idx < max_watchpoints; idx++) 00610 { 00611 dbr_addr = debug_registers[2 * idx]; 00612 dbr_mask = debug_registers[2 * idx + 1]; 00613 if ((dbr_mask & (0x3UL << 62)) && addr == (CORE_ADDR) dbr_addr) 00614 { 00615 struct lwp_info *lp; 00616 00617 debug_registers[2 * idx] = 0; 00618 debug_registers[2 * idx + 1] = 0; 00619 dbr_addr = 0; 00620 dbr_mask = 0; 00621 00622 ALL_LWPS (lp) 00623 store_debug_register_pair (lp->ptid, idx, &dbr_addr, &dbr_mask); 00624 00625 return 0; 00626 } 00627 } 00628 return -1; 00629 } 00630 00631 static void 00632 ia64_linux_new_thread (struct lwp_info *lp) 00633 { 00634 int i, any; 00635 00636 any = 0; 00637 for (i = 0; i < 8; i++) 00638 { 00639 if (debug_registers[i] != 0) 00640 any = 1; 00641 store_debug_register (lp->ptid, i, debug_registers[i]); 00642 } 00643 00644 if (any) 00645 enable_watchpoints_in_psr (lp->ptid); 00646 } 00647 00648 static int 00649 ia64_linux_stopped_data_address (struct target_ops *ops, CORE_ADDR *addr_p) 00650 { 00651 CORE_ADDR psr; 00652 siginfo_t siginfo; 00653 struct regcache *regcache = get_current_regcache (); 00654 00655 if (!linux_nat_get_siginfo (inferior_ptid, &siginfo)) 00656 return 0; 00657 00658 if (siginfo.si_signo != SIGTRAP 00659 || (siginfo.si_code & 0xffff) != 0x0004 /* TRAP_HWBKPT */) 00660 return 0; 00661 00662 regcache_cooked_read_unsigned (regcache, IA64_PSR_REGNUM, &psr); 00663 psr |= IA64_PSR_DD; /* Set the dd bit - this will disable the watchpoint 00664 for the next instruction. */ 00665 regcache_cooked_write_unsigned (regcache, IA64_PSR_REGNUM, psr); 00666 00667 *addr_p = (CORE_ADDR) siginfo.si_addr; 00668 return 1; 00669 } 00670 00671 static int 00672 ia64_linux_stopped_by_watchpoint (void) 00673 { 00674 CORE_ADDR addr; 00675 return ia64_linux_stopped_data_address (¤t_target, &addr); 00676 } 00677 00678 static int 00679 ia64_linux_can_use_hw_breakpoint (int type, int cnt, int othertype) 00680 { 00681 return 1; 00682 } 00683 00684 00685 /* Fetch register REGNUM from the inferior. */ 00686 00687 static void 00688 ia64_linux_fetch_register (struct regcache *regcache, int regnum) 00689 { 00690 struct gdbarch *gdbarch = get_regcache_arch (regcache); 00691 CORE_ADDR addr; 00692 size_t size; 00693 PTRACE_TYPE_RET *buf; 00694 int pid, i; 00695 00696 /* r0 cannot be fetched but is always zero. */ 00697 if (regnum == IA64_GR0_REGNUM) 00698 { 00699 const gdb_byte zero[8] = { 0 }; 00700 00701 gdb_assert (sizeof (zero) == register_size (gdbarch, regnum)); 00702 regcache_raw_supply (regcache, regnum, zero); 00703 return; 00704 } 00705 00706 /* fr0 cannot be fetched but is always zero. */ 00707 if (regnum == IA64_FR0_REGNUM) 00708 { 00709 const gdb_byte f_zero[16] = { 0 }; 00710 00711 gdb_assert (sizeof (f_zero) == register_size (gdbarch, regnum)); 00712 regcache_raw_supply (regcache, regnum, f_zero); 00713 return; 00714 } 00715 00716 /* fr1 cannot be fetched but is always one (1.0). */ 00717 if (regnum == IA64_FR1_REGNUM) 00718 { 00719 const gdb_byte f_one[16] = 00720 { 0, 0, 0, 0, 0, 0, 0, 0x80, 0xff, 0xff, 0, 0, 0, 0, 0, 0 }; 00721 00722 gdb_assert (sizeof (f_one) == register_size (gdbarch, regnum)); 00723 regcache_raw_supply (regcache, regnum, f_one); 00724 return; 00725 } 00726 00727 if (ia64_cannot_fetch_register (gdbarch, regnum)) 00728 { 00729 regcache_raw_supply (regcache, regnum, NULL); 00730 return; 00731 } 00732 00733 /* Cater for systems like GNU/Linux, that implement threads as 00734 separate processes. */ 00735 pid = ptid_get_lwp (inferior_ptid); 00736 if (pid == 0) 00737 pid = ptid_get_pid (inferior_ptid); 00738 00739 /* This isn't really an address, but ptrace thinks of it as one. */ 00740 addr = ia64_register_addr (gdbarch, regnum); 00741 size = register_size (gdbarch, regnum); 00742 00743 gdb_assert ((size % sizeof (PTRACE_TYPE_RET)) == 0); 00744 buf = alloca (size); 00745 00746 /* Read the register contents from the inferior a chunk at a time. */ 00747 for (i = 0; i < size / sizeof (PTRACE_TYPE_RET); i++) 00748 { 00749 errno = 0; 00750 buf[i] = ptrace (PT_READ_U, pid, (PTRACE_TYPE_ARG3)addr, 0); 00751 if (errno != 0) 00752 error (_("Couldn't read register %s (#%d): %s."), 00753 gdbarch_register_name (gdbarch, regnum), 00754 regnum, safe_strerror (errno)); 00755 00756 addr += sizeof (PTRACE_TYPE_RET); 00757 } 00758 regcache_raw_supply (regcache, regnum, buf); 00759 } 00760 00761 /* Fetch register REGNUM from the inferior. If REGNUM is -1, do this 00762 for all registers. */ 00763 00764 static void 00765 ia64_linux_fetch_registers (struct target_ops *ops, 00766 struct regcache *regcache, int regnum) 00767 { 00768 if (regnum == -1) 00769 for (regnum = 0; 00770 regnum < gdbarch_num_regs (get_regcache_arch (regcache)); 00771 regnum++) 00772 ia64_linux_fetch_register (regcache, regnum); 00773 else 00774 ia64_linux_fetch_register (regcache, regnum); 00775 } 00776 00777 /* Store register REGNUM into the inferior. */ 00778 00779 static void 00780 ia64_linux_store_register (const struct regcache *regcache, int regnum) 00781 { 00782 struct gdbarch *gdbarch = get_regcache_arch (regcache); 00783 CORE_ADDR addr; 00784 size_t size; 00785 PTRACE_TYPE_RET *buf; 00786 int pid, i; 00787 00788 if (ia64_cannot_store_register (gdbarch, regnum)) 00789 return; 00790 00791 /* Cater for systems like GNU/Linux, that implement threads as 00792 separate processes. */ 00793 pid = ptid_get_lwp (inferior_ptid); 00794 if (pid == 0) 00795 pid = ptid_get_pid (inferior_ptid); 00796 00797 /* This isn't really an address, but ptrace thinks of it as one. */ 00798 addr = ia64_register_addr (gdbarch, regnum); 00799 size = register_size (gdbarch, regnum); 00800 00801 gdb_assert ((size % sizeof (PTRACE_TYPE_RET)) == 0); 00802 buf = alloca (size); 00803 00804 /* Write the register contents into the inferior a chunk at a time. */ 00805 regcache_raw_collect (regcache, regnum, buf); 00806 for (i = 0; i < size / sizeof (PTRACE_TYPE_RET); i++) 00807 { 00808 errno = 0; 00809 ptrace (PT_WRITE_U, pid, (PTRACE_TYPE_ARG3)addr, buf[i]); 00810 if (errno != 0) 00811 error (_("Couldn't write register %s (#%d): %s."), 00812 gdbarch_register_name (gdbarch, regnum), 00813 regnum, safe_strerror (errno)); 00814 00815 addr += sizeof (PTRACE_TYPE_RET); 00816 } 00817 } 00818 00819 /* Store register REGNUM back into the inferior. If REGNUM is -1, do 00820 this for all registers. */ 00821 00822 static void 00823 ia64_linux_store_registers (struct target_ops *ops, 00824 struct regcache *regcache, int regnum) 00825 { 00826 if (regnum == -1) 00827 for (regnum = 0; 00828 regnum < gdbarch_num_regs (get_regcache_arch (regcache)); 00829 regnum++) 00830 ia64_linux_store_register (regcache, regnum); 00831 else 00832 ia64_linux_store_register (regcache, regnum); 00833 } 00834 00835 00836 static LONGEST (*super_xfer_partial) (struct target_ops *, enum target_object, 00837 const char *, gdb_byte *, 00838 const gdb_byte *, ULONGEST, LONGEST); 00839 00840 static LONGEST 00841 ia64_linux_xfer_partial (struct target_ops *ops, 00842 enum target_object object, 00843 const char *annex, 00844 gdb_byte *readbuf, const gdb_byte *writebuf, 00845 ULONGEST offset, LONGEST len) 00846 { 00847 if (object == TARGET_OBJECT_UNWIND_TABLE && writebuf == NULL && offset == 0) 00848 return syscall (__NR_getunwind, readbuf, len); 00849 00850 return super_xfer_partial (ops, object, annex, readbuf, writebuf, 00851 offset, len); 00852 } 00853 00854 /* For break.b instruction ia64 CPU forgets the immediate value and generates 00855 SIGILL with ILL_ILLOPC instead of more common SIGTRAP with TRAP_BRKPT. 00856 ia64 does not use gdbarch_decr_pc_after_break so we do not have to make any 00857 difference for the signals here. */ 00858 00859 static int 00860 ia64_linux_status_is_event (int status) 00861 { 00862 return WIFSTOPPED (status) && (WSTOPSIG (status) == SIGTRAP 00863 || WSTOPSIG (status) == SIGILL); 00864 } 00865 00866 void _initialize_ia64_linux_nat (void); 00867 00868 void 00869 _initialize_ia64_linux_nat (void) 00870 { 00871 struct target_ops *t; 00872 00873 /* Fill in the generic GNU/Linux methods. */ 00874 t = linux_target (); 00875 00876 /* Override the default fetch/store register routines. */ 00877 t->to_fetch_registers = ia64_linux_fetch_registers; 00878 t->to_store_registers = ia64_linux_store_registers; 00879 00880 /* Override the default to_xfer_partial. */ 00881 super_xfer_partial = t->to_xfer_partial; 00882 t->to_xfer_partial = ia64_linux_xfer_partial; 00883 00884 /* Override watchpoint routines. */ 00885 00886 /* The IA-64 architecture can step over a watch point (without triggering 00887 it again) if the "dd" (data debug fault disable) bit in the processor 00888 status word is set. 00889 00890 This PSR bit is set in ia64_linux_stopped_by_watchpoint when the 00891 code there has determined that a hardware watchpoint has indeed 00892 been hit. The CPU will then be able to execute one instruction 00893 without triggering a watchpoint. */ 00894 00895 t->to_have_steppable_watchpoint = 1; 00896 t->to_can_use_hw_breakpoint = ia64_linux_can_use_hw_breakpoint; 00897 t->to_stopped_by_watchpoint = ia64_linux_stopped_by_watchpoint; 00898 t->to_stopped_data_address = ia64_linux_stopped_data_address; 00899 t->to_insert_watchpoint = ia64_linux_insert_watchpoint; 00900 t->to_remove_watchpoint = ia64_linux_remove_watchpoint; 00901 00902 /* Register the target. */ 00903 linux_nat_add_target (t); 00904 linux_nat_set_new_thread (t, ia64_linux_new_thread); 00905 linux_nat_set_status_is_event (t, ia64_linux_status_is_event); 00906 }