GDB (API)
|
00001 /* Native-dependent code for GNU/Linux on MIPS processors. 00002 00003 Copyright (C) 2001-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 "command.h" 00022 #include "gdbcmd.h" 00023 #include "gdb_assert.h" 00024 #include "inferior.h" 00025 #include "mips-tdep.h" 00026 #include "target.h" 00027 #include "regcache.h" 00028 #include "linux-nat.h" 00029 #include "mips-linux-tdep.h" 00030 #include "target-descriptions.h" 00031 00032 #include "gdb_proc_service.h" 00033 #include "gregset.h" 00034 00035 #include <sgidefs.h> 00036 #include <sys/ptrace.h> 00037 #include <asm/ptrace.h> 00038 00039 #include "mips-linux-watch.h" 00040 00041 #include "features/mips-linux.c" 00042 #include "features/mips-dsp-linux.c" 00043 #include "features/mips64-linux.c" 00044 #include "features/mips64-dsp-linux.c" 00045 00046 #ifndef PTRACE_GET_THREAD_AREA 00047 #define PTRACE_GET_THREAD_AREA 25 00048 #endif 00049 00050 /* Assume that we have PTRACE_GETREGS et al. support. If we do not, 00051 we'll clear this and use PTRACE_PEEKUSER instead. */ 00052 static int have_ptrace_regsets = 1; 00053 00054 /* Whether or not to print the mirrored debug registers. */ 00055 00056 static int maint_show_dr; 00057 00058 /* Saved function pointers to fetch and store a single register using 00059 PTRACE_PEEKUSER and PTRACE_POKEUSER. */ 00060 00061 static void (*super_fetch_registers) (struct target_ops *, 00062 struct regcache *, int); 00063 static void (*super_store_registers) (struct target_ops *, 00064 struct regcache *, int); 00065 00066 static void (*super_close) (void); 00067 00068 /* Map gdb internal register number to ptrace ``address''. 00069 These ``addresses'' are normally defined in <asm/ptrace.h>. 00070 00071 ptrace does not provide a way to read (or set) MIPS_PS_REGNUM, 00072 and there's no point in reading or setting MIPS_ZERO_REGNUM. 00073 We also can not set BADVADDR, CAUSE, or FCRIR via ptrace(). */ 00074 00075 static CORE_ADDR 00076 mips_linux_register_addr (struct gdbarch *gdbarch, int regno, int store) 00077 { 00078 CORE_ADDR regaddr; 00079 00080 if (regno < 0 || regno >= gdbarch_num_regs (gdbarch)) 00081 error (_("Bogon register number %d."), regno); 00082 00083 if (regno > MIPS_ZERO_REGNUM && regno < MIPS_ZERO_REGNUM + 32) 00084 regaddr = regno; 00085 else if ((regno >= mips_regnum (gdbarch)->fp0) 00086 && (regno < mips_regnum (gdbarch)->fp0 + 32)) 00087 regaddr = FPR_BASE + (regno - mips_regnum (gdbarch)->fp0); 00088 else if (regno == mips_regnum (gdbarch)->pc) 00089 regaddr = PC; 00090 else if (regno == mips_regnum (gdbarch)->cause) 00091 regaddr = store? (CORE_ADDR) -1 : CAUSE; 00092 else if (regno == mips_regnum (gdbarch)->badvaddr) 00093 regaddr = store? (CORE_ADDR) -1 : BADVADDR; 00094 else if (regno == mips_regnum (gdbarch)->lo) 00095 regaddr = MMLO; 00096 else if (regno == mips_regnum (gdbarch)->hi) 00097 regaddr = MMHI; 00098 else if (regno == mips_regnum (gdbarch)->fp_control_status) 00099 regaddr = FPC_CSR; 00100 else if (regno == mips_regnum (gdbarch)->fp_implementation_revision) 00101 regaddr = store? (CORE_ADDR) -1 : FPC_EIR; 00102 else if (mips_regnum (gdbarch)->dspacc != -1 00103 && regno >= mips_regnum (gdbarch)->dspacc 00104 && regno < mips_regnum (gdbarch)->dspacc + 6) 00105 regaddr = DSP_BASE + (regno - mips_regnum (gdbarch)->dspacc); 00106 else if (regno == mips_regnum (gdbarch)->dspctl) 00107 regaddr = DSP_CONTROL; 00108 else if (mips_linux_restart_reg_p (gdbarch) && regno == MIPS_RESTART_REGNUM) 00109 regaddr = 0; 00110 else 00111 regaddr = (CORE_ADDR) -1; 00112 00113 return regaddr; 00114 } 00115 00116 static CORE_ADDR 00117 mips64_linux_register_addr (struct gdbarch *gdbarch, int regno, int store) 00118 { 00119 CORE_ADDR regaddr; 00120 00121 if (regno < 0 || regno >= gdbarch_num_regs (gdbarch)) 00122 error (_("Bogon register number %d."), regno); 00123 00124 if (regno > MIPS_ZERO_REGNUM && regno < MIPS_ZERO_REGNUM + 32) 00125 regaddr = regno; 00126 else if ((regno >= mips_regnum (gdbarch)->fp0) 00127 && (regno < mips_regnum (gdbarch)->fp0 + 32)) 00128 regaddr = MIPS64_FPR_BASE + (regno - gdbarch_fp0_regnum (gdbarch)); 00129 else if (regno == mips_regnum (gdbarch)->pc) 00130 regaddr = MIPS64_PC; 00131 else if (regno == mips_regnum (gdbarch)->cause) 00132 regaddr = store? (CORE_ADDR) -1 : MIPS64_CAUSE; 00133 else if (regno == mips_regnum (gdbarch)->badvaddr) 00134 regaddr = store? (CORE_ADDR) -1 : MIPS64_BADVADDR; 00135 else if (regno == mips_regnum (gdbarch)->lo) 00136 regaddr = MIPS64_MMLO; 00137 else if (regno == mips_regnum (gdbarch)->hi) 00138 regaddr = MIPS64_MMHI; 00139 else if (regno == mips_regnum (gdbarch)->fp_control_status) 00140 regaddr = MIPS64_FPC_CSR; 00141 else if (regno == mips_regnum (gdbarch)->fp_implementation_revision) 00142 regaddr = store? (CORE_ADDR) -1 : MIPS64_FPC_EIR; 00143 else if (mips_regnum (gdbarch)->dspacc != -1 00144 && regno >= mips_regnum (gdbarch)->dspacc 00145 && regno < mips_regnum (gdbarch)->dspacc + 6) 00146 regaddr = DSP_BASE + (regno - mips_regnum (gdbarch)->dspacc); 00147 else if (regno == mips_regnum (gdbarch)->dspctl) 00148 regaddr = DSP_CONTROL; 00149 else if (mips_linux_restart_reg_p (gdbarch) && regno == MIPS_RESTART_REGNUM) 00150 regaddr = 0; 00151 else 00152 regaddr = (CORE_ADDR) -1; 00153 00154 return regaddr; 00155 } 00156 00157 /* Fetch the thread-local storage pointer for libthread_db. */ 00158 00159 ps_err_e 00160 ps_get_thread_area (const struct ps_prochandle *ph, 00161 lwpid_t lwpid, int idx, void **base) 00162 { 00163 if (ptrace (PTRACE_GET_THREAD_AREA, lwpid, NULL, base) != 0) 00164 return PS_ERR; 00165 00166 /* IDX is the bias from the thread pointer to the beginning of the 00167 thread descriptor. It has to be subtracted due to implementation 00168 quirks in libthread_db. */ 00169 *base = (void *) ((char *)*base - idx); 00170 00171 return PS_OK; 00172 } 00173 00174 /* Wrapper functions. These are only used by libthread_db. */ 00175 00176 void 00177 supply_gregset (struct regcache *regcache, const gdb_gregset_t *gregsetp) 00178 { 00179 if (mips_isa_regsize (get_regcache_arch (regcache)) == 4) 00180 mips_supply_gregset (regcache, (const mips_elf_gregset_t *) gregsetp); 00181 else 00182 mips64_supply_gregset (regcache, (const mips64_elf_gregset_t *) gregsetp); 00183 } 00184 00185 void 00186 fill_gregset (const struct regcache *regcache, 00187 gdb_gregset_t *gregsetp, int regno) 00188 { 00189 if (mips_isa_regsize (get_regcache_arch (regcache)) == 4) 00190 mips_fill_gregset (regcache, (mips_elf_gregset_t *) gregsetp, regno); 00191 else 00192 mips64_fill_gregset (regcache, (mips64_elf_gregset_t *) gregsetp, regno); 00193 } 00194 00195 void 00196 supply_fpregset (struct regcache *regcache, const gdb_fpregset_t *fpregsetp) 00197 { 00198 if (mips_isa_regsize (get_regcache_arch (regcache)) == 4) 00199 mips_supply_fpregset (regcache, (const mips_elf_fpregset_t *) fpregsetp); 00200 else 00201 mips64_supply_fpregset (regcache, 00202 (const mips64_elf_fpregset_t *) fpregsetp); 00203 } 00204 00205 void 00206 fill_fpregset (const struct regcache *regcache, 00207 gdb_fpregset_t *fpregsetp, int regno) 00208 { 00209 if (mips_isa_regsize (get_regcache_arch (regcache)) == 4) 00210 mips_fill_fpregset (regcache, (mips_elf_fpregset_t *) fpregsetp, regno); 00211 else 00212 mips64_fill_fpregset (regcache, 00213 (mips64_elf_fpregset_t *) fpregsetp, regno); 00214 } 00215 00216 00217 /* Fetch REGNO (or all registers if REGNO == -1) from the target 00218 using PTRACE_GETREGS et al. */ 00219 00220 static void 00221 mips64_linux_regsets_fetch_registers (struct target_ops *ops, 00222 struct regcache *regcache, int regno) 00223 { 00224 struct gdbarch *gdbarch = get_regcache_arch (regcache); 00225 int is_fp, is_dsp; 00226 int have_dsp; 00227 int regi; 00228 int tid; 00229 00230 if (regno >= mips_regnum (gdbarch)->fp0 00231 && regno <= mips_regnum (gdbarch)->fp0 + 32) 00232 is_fp = 1; 00233 else if (regno == mips_regnum (gdbarch)->fp_control_status) 00234 is_fp = 1; 00235 else if (regno == mips_regnum (gdbarch)->fp_implementation_revision) 00236 is_fp = 1; 00237 else 00238 is_fp = 0; 00239 00240 /* DSP registers are optional and not a part of any set. */ 00241 have_dsp = mips_regnum (gdbarch)->dspctl != -1; 00242 if (!have_dsp) 00243 is_dsp = 0; 00244 else if (regno >= mips_regnum (gdbarch)->dspacc 00245 && regno < mips_regnum (gdbarch)->dspacc + 6) 00246 is_dsp = 1; 00247 else if (regno == mips_regnum (gdbarch)->dspctl) 00248 is_dsp = 1; 00249 else 00250 is_dsp = 0; 00251 00252 tid = ptid_get_lwp (inferior_ptid); 00253 if (tid == 0) 00254 tid = ptid_get_pid (inferior_ptid); 00255 00256 if (regno == -1 || (!is_fp && !is_dsp)) 00257 { 00258 mips64_elf_gregset_t regs; 00259 00260 if (ptrace (PTRACE_GETREGS, tid, 0L, (PTRACE_TYPE_ARG3) ®s) == -1) 00261 { 00262 if (errno == EIO) 00263 { 00264 have_ptrace_regsets = 0; 00265 return; 00266 } 00267 perror_with_name (_("Couldn't get registers")); 00268 } 00269 00270 mips64_supply_gregset (regcache, 00271 (const mips64_elf_gregset_t *) ®s); 00272 } 00273 00274 if (regno == -1 || is_fp) 00275 { 00276 mips64_elf_fpregset_t fp_regs; 00277 00278 if (ptrace (PTRACE_GETFPREGS, tid, 0L, 00279 (PTRACE_TYPE_ARG3) &fp_regs) == -1) 00280 { 00281 if (errno == EIO) 00282 { 00283 have_ptrace_regsets = 0; 00284 return; 00285 } 00286 perror_with_name (_("Couldn't get FP registers")); 00287 } 00288 00289 mips64_supply_fpregset (regcache, 00290 (const mips64_elf_fpregset_t *) &fp_regs); 00291 } 00292 00293 if (is_dsp) 00294 super_fetch_registers (ops, regcache, regno); 00295 else if (regno == -1 && have_dsp) 00296 { 00297 for (regi = mips_regnum (gdbarch)->dspacc; 00298 regi < mips_regnum (gdbarch)->dspacc + 6; 00299 regi++) 00300 super_fetch_registers (ops, regcache, regi); 00301 super_fetch_registers (ops, regcache, mips_regnum (gdbarch)->dspctl); 00302 } 00303 } 00304 00305 /* Store REGNO (or all registers if REGNO == -1) to the target 00306 using PTRACE_SETREGS et al. */ 00307 00308 static void 00309 mips64_linux_regsets_store_registers (struct target_ops *ops, 00310 struct regcache *regcache, int regno) 00311 { 00312 struct gdbarch *gdbarch = get_regcache_arch (regcache); 00313 int is_fp, is_dsp; 00314 int have_dsp; 00315 int regi; 00316 int tid; 00317 00318 if (regno >= mips_regnum (gdbarch)->fp0 00319 && regno <= mips_regnum (gdbarch)->fp0 + 32) 00320 is_fp = 1; 00321 else if (regno == mips_regnum (gdbarch)->fp_control_status) 00322 is_fp = 1; 00323 else if (regno == mips_regnum (gdbarch)->fp_implementation_revision) 00324 is_fp = 1; 00325 else 00326 is_fp = 0; 00327 00328 /* DSP registers are optional and not a part of any set. */ 00329 have_dsp = mips_regnum (gdbarch)->dspctl != -1; 00330 if (!have_dsp) 00331 is_dsp = 0; 00332 else if (regno >= mips_regnum (gdbarch)->dspacc 00333 && regno < mips_regnum (gdbarch)->dspacc + 6) 00334 is_dsp = 1; 00335 else if (regno == mips_regnum (gdbarch)->dspctl) 00336 is_dsp = 1; 00337 else 00338 is_dsp = 0; 00339 00340 tid = ptid_get_lwp (inferior_ptid); 00341 if (tid == 0) 00342 tid = ptid_get_pid (inferior_ptid); 00343 00344 if (regno == -1 || (!is_fp && !is_dsp)) 00345 { 00346 mips64_elf_gregset_t regs; 00347 00348 if (ptrace (PTRACE_GETREGS, tid, 0L, (PTRACE_TYPE_ARG3) ®s) == -1) 00349 perror_with_name (_("Couldn't get registers")); 00350 00351 mips64_fill_gregset (regcache, ®s, regno); 00352 00353 if (ptrace (PTRACE_SETREGS, tid, 0L, (PTRACE_TYPE_ARG3) ®s) == -1) 00354 perror_with_name (_("Couldn't set registers")); 00355 } 00356 00357 if (regno == -1 || is_fp) 00358 { 00359 mips64_elf_fpregset_t fp_regs; 00360 00361 if (ptrace (PTRACE_GETFPREGS, tid, 0L, 00362 (PTRACE_TYPE_ARG3) &fp_regs) == -1) 00363 perror_with_name (_("Couldn't get FP registers")); 00364 00365 mips64_fill_fpregset (regcache, &fp_regs, regno); 00366 00367 if (ptrace (PTRACE_SETFPREGS, tid, 0L, 00368 (PTRACE_TYPE_ARG3) &fp_regs) == -1) 00369 perror_with_name (_("Couldn't set FP registers")); 00370 } 00371 00372 if (is_dsp) 00373 super_store_registers (ops, regcache, regno); 00374 else if (regno == -1 && have_dsp) 00375 { 00376 for (regi = mips_regnum (gdbarch)->dspacc; 00377 regi < mips_regnum (gdbarch)->dspacc + 6; 00378 regi++) 00379 super_store_registers (ops, regcache, regi); 00380 super_store_registers (ops, regcache, mips_regnum (gdbarch)->dspctl); 00381 } 00382 } 00383 00384 /* Fetch REGNO (or all registers if REGNO == -1) from the target 00385 using any working method. */ 00386 00387 static void 00388 mips64_linux_fetch_registers (struct target_ops *ops, 00389 struct regcache *regcache, int regnum) 00390 { 00391 /* Unless we already know that PTRACE_GETREGS does not work, try it. */ 00392 if (have_ptrace_regsets) 00393 mips64_linux_regsets_fetch_registers (ops, regcache, regnum); 00394 00395 /* If we know, or just found out, that PTRACE_GETREGS does not work, fall 00396 back to PTRACE_PEEKUSER. */ 00397 if (!have_ptrace_regsets) 00398 super_fetch_registers (ops, regcache, regnum); 00399 } 00400 00401 /* Store REGNO (or all registers if REGNO == -1) to the target 00402 using any working method. */ 00403 00404 static void 00405 mips64_linux_store_registers (struct target_ops *ops, 00406 struct regcache *regcache, int regnum) 00407 { 00408 /* Unless we already know that PTRACE_GETREGS does not work, try it. */ 00409 if (have_ptrace_regsets) 00410 mips64_linux_regsets_store_registers (ops, regcache, regnum); 00411 00412 /* If we know, or just found out, that PTRACE_GETREGS does not work, fall 00413 back to PTRACE_PEEKUSER. */ 00414 if (!have_ptrace_regsets) 00415 super_store_registers (ops, regcache, regnum); 00416 } 00417 00418 /* Return the address in the core dump or inferior of register 00419 REGNO. */ 00420 00421 static CORE_ADDR 00422 mips_linux_register_u_offset (struct gdbarch *gdbarch, int regno, int store_p) 00423 { 00424 if (mips_abi_regsize (gdbarch) == 8) 00425 return mips64_linux_register_addr (gdbarch, regno, store_p); 00426 else 00427 return mips_linux_register_addr (gdbarch, regno, store_p); 00428 } 00429 00430 static const struct target_desc * 00431 mips_linux_read_description (struct target_ops *ops) 00432 { 00433 static int have_dsp = -1; 00434 00435 if (have_dsp < 0) 00436 { 00437 int tid; 00438 00439 tid = ptid_get_lwp (inferior_ptid); 00440 if (tid == 0) 00441 tid = ptid_get_pid (inferior_ptid); 00442 00443 ptrace (PTRACE_PEEKUSER, tid, DSP_CONTROL, 0); 00444 switch (errno) 00445 { 00446 case 0: 00447 have_dsp = 1; 00448 break; 00449 case EIO: 00450 have_dsp = 0; 00451 break; 00452 default: 00453 perror_with_name (_("Couldn't check DSP support")); 00454 break; 00455 } 00456 } 00457 00458 /* Report that target registers are a size we know for sure 00459 that we can get from ptrace. */ 00460 if (_MIPS_SIM == _ABIO32) 00461 return have_dsp ? tdesc_mips_dsp_linux : tdesc_mips_linux; 00462 else 00463 return have_dsp ? tdesc_mips64_dsp_linux : tdesc_mips64_linux; 00464 } 00465 00466 /* -1 if the kernel and/or CPU do not support watch registers. 00467 1 if watch_readback is valid and we can read style, num_valid 00468 and the masks. 00469 0 if we need to read the watch_readback. */ 00470 00471 static int watch_readback_valid; 00472 00473 /* Cached watch register read values. */ 00474 00475 static struct pt_watch_regs watch_readback; 00476 00477 static struct mips_watchpoint *current_watches; 00478 00479 /* The current set of watch register values for writing the 00480 registers. */ 00481 00482 static struct pt_watch_regs watch_mirror; 00483 00484 static void 00485 mips_show_dr (const char *func, CORE_ADDR addr, 00486 int len, enum target_hw_bp_type type) 00487 { 00488 int i; 00489 00490 puts_unfiltered (func); 00491 if (addr || len) 00492 printf_unfiltered (" (addr=%s, len=%d, type=%s)", 00493 paddress (target_gdbarch (), addr), len, 00494 type == hw_write ? "data-write" 00495 : (type == hw_read ? "data-read" 00496 : (type == hw_access ? "data-read/write" 00497 : (type == hw_execute ? "instruction-execute" 00498 : "??unknown??")))); 00499 puts_unfiltered (":\n"); 00500 00501 for (i = 0; i < MAX_DEBUG_REGISTER; i++) 00502 printf_unfiltered ("\tDR%d: lo=%s, hi=%s\n", i, 00503 paddress (target_gdbarch (), 00504 mips_linux_watch_get_watchlo (&watch_mirror, 00505 i)), 00506 paddress (target_gdbarch (), 00507 mips_linux_watch_get_watchhi (&watch_mirror, 00508 i))); 00509 } 00510 00511 /* Target to_can_use_hw_breakpoint implementation. Return 1 if we can 00512 handle the specified watch type. */ 00513 00514 static int 00515 mips_linux_can_use_hw_breakpoint (int type, int cnt, int ot) 00516 { 00517 int i; 00518 uint32_t wanted_mask, irw_mask; 00519 00520 if (!mips_linux_read_watch_registers (ptid_get_lwp (inferior_ptid), 00521 &watch_readback, 00522 &watch_readback_valid, 0)) 00523 return 0; 00524 00525 switch (type) 00526 { 00527 case bp_hardware_watchpoint: 00528 wanted_mask = W_MASK; 00529 break; 00530 case bp_read_watchpoint: 00531 wanted_mask = R_MASK; 00532 break; 00533 case bp_access_watchpoint: 00534 wanted_mask = R_MASK | W_MASK; 00535 break; 00536 default: 00537 return 0; 00538 } 00539 00540 for (i = 0; 00541 i < mips_linux_watch_get_num_valid (&watch_readback) && cnt; 00542 i++) 00543 { 00544 irw_mask = mips_linux_watch_get_irw_mask (&watch_readback, i); 00545 if ((irw_mask & wanted_mask) == wanted_mask) 00546 cnt--; 00547 } 00548 return (cnt == 0) ? 1 : 0; 00549 } 00550 00551 /* Target to_stopped_by_watchpoint implementation. Return 1 if 00552 stopped by watchpoint. The watchhi R and W bits indicate the watch 00553 register triggered. */ 00554 00555 static int 00556 mips_linux_stopped_by_watchpoint (void) 00557 { 00558 int n; 00559 int num_valid; 00560 00561 if (!mips_linux_read_watch_registers (ptid_get_lwp (inferior_ptid), 00562 &watch_readback, 00563 &watch_readback_valid, 1)) 00564 return 0; 00565 00566 num_valid = mips_linux_watch_get_num_valid (&watch_readback); 00567 00568 for (n = 0; n < MAX_DEBUG_REGISTER && n < num_valid; n++) 00569 if (mips_linux_watch_get_watchhi (&watch_readback, n) & (R_MASK | W_MASK)) 00570 return 1; 00571 00572 return 0; 00573 } 00574 00575 /* Target to_stopped_data_address implementation. Set the address 00576 where the watch triggered (if known). Return 1 if the address was 00577 known. */ 00578 00579 static int 00580 mips_linux_stopped_data_address (struct target_ops *t, CORE_ADDR *paddr) 00581 { 00582 /* On mips we don't know the low order 3 bits of the data address, 00583 so we must return false. */ 00584 return 0; 00585 } 00586 00587 /* Target to_region_ok_for_hw_watchpoint implementation. Return 1 if 00588 the specified region can be covered by the watch registers. */ 00589 00590 static int 00591 mips_linux_region_ok_for_hw_watchpoint (CORE_ADDR addr, int len) 00592 { 00593 struct pt_watch_regs dummy_regs; 00594 int i; 00595 00596 if (!mips_linux_read_watch_registers (ptid_get_lwp (inferior_ptid), 00597 &watch_readback, 00598 &watch_readback_valid, 0)) 00599 return 0; 00600 00601 dummy_regs = watch_readback; 00602 /* Clear them out. */ 00603 for (i = 0; i < mips_linux_watch_get_num_valid (&dummy_regs); i++) 00604 mips_linux_watch_set_watchlo (&dummy_regs, i, 0); 00605 return mips_linux_watch_try_one_watch (&dummy_regs, addr, len, 0); 00606 } 00607 00608 /* Write the mirrored watch register values for each thread. */ 00609 00610 static int 00611 write_watchpoint_regs (void) 00612 { 00613 struct lwp_info *lp; 00614 int tid; 00615 00616 ALL_LWPS (lp) 00617 { 00618 tid = ptid_get_lwp (lp->ptid); 00619 if (ptrace (PTRACE_SET_WATCH_REGS, tid, &watch_mirror) == -1) 00620 perror_with_name (_("Couldn't write debug register")); 00621 } 00622 return 0; 00623 } 00624 00625 /* linux_nat new_thread implementation. Write the mirrored watch 00626 register values for the new thread. */ 00627 00628 static void 00629 mips_linux_new_thread (struct lwp_info *lp) 00630 { 00631 int tid; 00632 00633 if (!mips_linux_read_watch_registers (ptid_get_lwp (inferior_ptid), 00634 &watch_readback, 00635 &watch_readback_valid, 0)) 00636 return; 00637 00638 tid = ptid_get_lwp (lp->ptid); 00639 if (ptrace (PTRACE_SET_WATCH_REGS, tid, &watch_mirror) == -1) 00640 perror_with_name (_("Couldn't write debug register")); 00641 } 00642 00643 /* Target to_insert_watchpoint implementation. Try to insert a new 00644 watch. Return zero on success. */ 00645 00646 static int 00647 mips_linux_insert_watchpoint (CORE_ADDR addr, int len, int type, 00648 struct expression *cond) 00649 { 00650 struct pt_watch_regs regs; 00651 struct mips_watchpoint *new_watch; 00652 struct mips_watchpoint **pw; 00653 00654 int i; 00655 int retval; 00656 00657 if (!mips_linux_read_watch_registers (ptid_get_lwp (inferior_ptid), 00658 &watch_readback, 00659 &watch_readback_valid, 0)) 00660 return -1; 00661 00662 if (len <= 0) 00663 return -1; 00664 00665 regs = watch_readback; 00666 /* Add the current watches. */ 00667 mips_linux_watch_populate_regs (current_watches, ®s); 00668 00669 /* Now try to add the new watch. */ 00670 if (!mips_linux_watch_try_one_watch (®s, addr, len, 00671 mips_linux_watch_type_to_irw (type))) 00672 return -1; 00673 00674 /* It fit. Stick it on the end of the list. */ 00675 new_watch = (struct mips_watchpoint *) 00676 xmalloc (sizeof (struct mips_watchpoint)); 00677 new_watch->addr = addr; 00678 new_watch->len = len; 00679 new_watch->type = type; 00680 new_watch->next = NULL; 00681 00682 pw = ¤t_watches; 00683 while (*pw != NULL) 00684 pw = &(*pw)->next; 00685 *pw = new_watch; 00686 00687 watch_mirror = regs; 00688 retval = write_watchpoint_regs (); 00689 00690 if (maint_show_dr) 00691 mips_show_dr ("insert_watchpoint", addr, len, type); 00692 00693 return retval; 00694 } 00695 00696 /* Target to_remove_watchpoint implementation. Try to remove a watch. 00697 Return zero on success. */ 00698 00699 static int 00700 mips_linux_remove_watchpoint (CORE_ADDR addr, int len, int type, 00701 struct expression *cond) 00702 { 00703 int retval; 00704 int deleted_one; 00705 00706 struct mips_watchpoint **pw; 00707 struct mips_watchpoint *w; 00708 00709 /* Search for a known watch that matches. Then unlink and free 00710 it. */ 00711 deleted_one = 0; 00712 pw = ¤t_watches; 00713 while ((w = *pw)) 00714 { 00715 if (w->addr == addr && w->len == len && w->type == type) 00716 { 00717 *pw = w->next; 00718 xfree (w); 00719 deleted_one = 1; 00720 break; 00721 } 00722 pw = &(w->next); 00723 } 00724 00725 if (!deleted_one) 00726 return -1; /* We don't know about it, fail doing nothing. */ 00727 00728 /* At this point watch_readback is known to be valid because we 00729 could not have added the watch without reading it. */ 00730 gdb_assert (watch_readback_valid == 1); 00731 00732 watch_mirror = watch_readback; 00733 mips_linux_watch_populate_regs (current_watches, &watch_mirror); 00734 00735 retval = write_watchpoint_regs (); 00736 00737 if (maint_show_dr) 00738 mips_show_dr ("remove_watchpoint", addr, len, type); 00739 00740 return retval; 00741 } 00742 00743 /* Target to_close implementation. Free any watches and call the 00744 super implementation. */ 00745 00746 static void 00747 mips_linux_close (void) 00748 { 00749 struct mips_watchpoint *w; 00750 struct mips_watchpoint *nw; 00751 00752 /* Clean out the current_watches list. */ 00753 w = current_watches; 00754 while (w) 00755 { 00756 nw = w->next; 00757 xfree (w); 00758 w = nw; 00759 } 00760 current_watches = NULL; 00761 00762 if (super_close) 00763 super_close (); 00764 } 00765 00766 void _initialize_mips_linux_nat (void); 00767 00768 void 00769 _initialize_mips_linux_nat (void) 00770 { 00771 struct target_ops *t; 00772 00773 add_setshow_boolean_cmd ("show-debug-regs", class_maintenance, 00774 &maint_show_dr, _("\ 00775 Set whether to show variables that mirror the mips debug registers."), _("\ 00776 Show whether to show variables that mirror the mips debug registers."), _("\ 00777 Use \"on\" to enable, \"off\" to disable.\n\ 00778 If enabled, the debug registers values are shown when GDB inserts\n\ 00779 or removes a hardware breakpoint or watchpoint, and when the inferior\n\ 00780 triggers a breakpoint or watchpoint."), 00781 NULL, 00782 NULL, 00783 &maintenance_set_cmdlist, 00784 &maintenance_show_cmdlist); 00785 00786 t = linux_trad_target (mips_linux_register_u_offset); 00787 00788 super_close = t->to_close; 00789 t->to_close = mips_linux_close; 00790 00791 super_fetch_registers = t->to_fetch_registers; 00792 super_store_registers = t->to_store_registers; 00793 00794 t->to_fetch_registers = mips64_linux_fetch_registers; 00795 t->to_store_registers = mips64_linux_store_registers; 00796 00797 t->to_can_use_hw_breakpoint = mips_linux_can_use_hw_breakpoint; 00798 t->to_remove_watchpoint = mips_linux_remove_watchpoint; 00799 t->to_insert_watchpoint = mips_linux_insert_watchpoint; 00800 t->to_stopped_by_watchpoint = mips_linux_stopped_by_watchpoint; 00801 t->to_stopped_data_address = mips_linux_stopped_data_address; 00802 t->to_region_ok_for_hw_watchpoint = mips_linux_region_ok_for_hw_watchpoint; 00803 00804 t->to_read_description = mips_linux_read_description; 00805 00806 linux_nat_add_target (t); 00807 linux_nat_set_new_thread (t, mips_linux_new_thread); 00808 00809 /* Initialize the standard target descriptions. */ 00810 initialize_tdesc_mips_linux (); 00811 initialize_tdesc_mips_dsp_linux (); 00812 initialize_tdesc_mips64_linux (); 00813 initialize_tdesc_mips64_dsp_linux (); 00814 }