1*5796c8dcSSimon Schubert /* Simulate breakpoints by patching locations in the target system, for GDB. 2*5796c8dcSSimon Schubert 3*5796c8dcSSimon Schubert Copyright (C) 1990, 1991, 1992, 1993, 1995, 1997, 1998, 1999, 2000, 2002, 4*5796c8dcSSimon Schubert 2007, 2008, 2009 Free Software Foundation, Inc. 5*5796c8dcSSimon Schubert 6*5796c8dcSSimon Schubert Contributed by Cygnus Support. Written by John Gilmore. 7*5796c8dcSSimon Schubert 8*5796c8dcSSimon Schubert This file is part of GDB. 9*5796c8dcSSimon Schubert 10*5796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify 11*5796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by 12*5796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or 13*5796c8dcSSimon Schubert (at your option) any later version. 14*5796c8dcSSimon Schubert 15*5796c8dcSSimon Schubert This program is distributed in the hope that it will be useful, 16*5796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of 17*5796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*5796c8dcSSimon Schubert GNU General Public License for more details. 19*5796c8dcSSimon Schubert 20*5796c8dcSSimon Schubert You should have received a copy of the GNU General Public License 21*5796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */ 22*5796c8dcSSimon Schubert 23*5796c8dcSSimon Schubert #include "defs.h" 24*5796c8dcSSimon Schubert 25*5796c8dcSSimon Schubert /* This file is only useful if BREAKPOINT_FROM_PC is set. If not, we 26*5796c8dcSSimon Schubert punt. */ 27*5796c8dcSSimon Schubert 28*5796c8dcSSimon Schubert #include "symtab.h" 29*5796c8dcSSimon Schubert #include "breakpoint.h" 30*5796c8dcSSimon Schubert #include "inferior.h" 31*5796c8dcSSimon Schubert #include "target.h" 32*5796c8dcSSimon Schubert 33*5796c8dcSSimon Schubert 34*5796c8dcSSimon Schubert /* Insert a breakpoint on targets that don't have any better 35*5796c8dcSSimon Schubert breakpoint support. We read the contents of the target location 36*5796c8dcSSimon Schubert and stash it, then overwrite it with a breakpoint instruction. 37*5796c8dcSSimon Schubert BP_TGT->placed_address is the target location in the target 38*5796c8dcSSimon Schubert machine. BP_TGT->shadow_contents is some memory allocated for 39*5796c8dcSSimon Schubert saving the target contents. It is guaranteed by the caller to be 40*5796c8dcSSimon Schubert long enough to save BREAKPOINT_LEN bytes (this is accomplished via 41*5796c8dcSSimon Schubert BREAKPOINT_MAX). */ 42*5796c8dcSSimon Schubert 43*5796c8dcSSimon Schubert int 44*5796c8dcSSimon Schubert default_memory_insert_breakpoint (struct gdbarch *gdbarch, 45*5796c8dcSSimon Schubert struct bp_target_info *bp_tgt) 46*5796c8dcSSimon Schubert { 47*5796c8dcSSimon Schubert int val; 48*5796c8dcSSimon Schubert const unsigned char *bp; 49*5796c8dcSSimon Schubert int bplen; 50*5796c8dcSSimon Schubert 51*5796c8dcSSimon Schubert /* Determine appropriate breakpoint contents and size for this address. */ 52*5796c8dcSSimon Schubert bp = gdbarch_breakpoint_from_pc 53*5796c8dcSSimon Schubert (gdbarch, &bp_tgt->placed_address, &bp_tgt->placed_size); 54*5796c8dcSSimon Schubert if (bp == NULL) 55*5796c8dcSSimon Schubert error (_("Software breakpoints not implemented for this target.")); 56*5796c8dcSSimon Schubert 57*5796c8dcSSimon Schubert /* Save the memory contents. */ 58*5796c8dcSSimon Schubert bp_tgt->shadow_len = bp_tgt->placed_size; 59*5796c8dcSSimon Schubert val = target_read_memory (bp_tgt->placed_address, bp_tgt->shadow_contents, 60*5796c8dcSSimon Schubert bp_tgt->placed_size); 61*5796c8dcSSimon Schubert 62*5796c8dcSSimon Schubert /* Write the breakpoint. */ 63*5796c8dcSSimon Schubert if (val == 0) 64*5796c8dcSSimon Schubert val = target_write_memory (bp_tgt->placed_address, bp, 65*5796c8dcSSimon Schubert bp_tgt->placed_size); 66*5796c8dcSSimon Schubert 67*5796c8dcSSimon Schubert return val; 68*5796c8dcSSimon Schubert } 69*5796c8dcSSimon Schubert 70*5796c8dcSSimon Schubert 71*5796c8dcSSimon Schubert int 72*5796c8dcSSimon Schubert default_memory_remove_breakpoint (struct gdbarch *gdbarch, 73*5796c8dcSSimon Schubert struct bp_target_info *bp_tgt) 74*5796c8dcSSimon Schubert { 75*5796c8dcSSimon Schubert return target_write_memory (bp_tgt->placed_address, bp_tgt->shadow_contents, 76*5796c8dcSSimon Schubert bp_tgt->placed_size); 77*5796c8dcSSimon Schubert } 78*5796c8dcSSimon Schubert 79*5796c8dcSSimon Schubert 80*5796c8dcSSimon Schubert int 81*5796c8dcSSimon Schubert memory_insert_breakpoint (struct gdbarch *gdbarch, 82*5796c8dcSSimon Schubert struct bp_target_info *bp_tgt) 83*5796c8dcSSimon Schubert { 84*5796c8dcSSimon Schubert return gdbarch_memory_insert_breakpoint (gdbarch, bp_tgt); 85*5796c8dcSSimon Schubert } 86*5796c8dcSSimon Schubert 87*5796c8dcSSimon Schubert int 88*5796c8dcSSimon Schubert memory_remove_breakpoint (struct gdbarch *gdbarch, 89*5796c8dcSSimon Schubert struct bp_target_info *bp_tgt) 90*5796c8dcSSimon Schubert { 91*5796c8dcSSimon Schubert return gdbarch_memory_remove_breakpoint (gdbarch, bp_tgt); 92*5796c8dcSSimon Schubert } 93