119370Spst/* Simulate breakpoints by patching locations in the target system, for GDB. 2130803Smarcel 3130803Smarcel Copyright 1990, 1991, 1992, 1993, 1995, 1997, 1998, 1999, 2000, 4130803Smarcel 2002 Free Software Foundation, Inc. 5130803Smarcel 619370Spst Contributed by Cygnus Support. Written by John Gilmore. 719370Spst 898944Sobrien This file is part of GDB. 919370Spst 1098944Sobrien This program is free software; you can redistribute it and/or modify 1198944Sobrien it under the terms of the GNU General Public License as published by 1298944Sobrien the Free Software Foundation; either version 2 of the License, or 1398944Sobrien (at your option) any later version. 1419370Spst 1598944Sobrien This program is distributed in the hope that it will be useful, 1698944Sobrien but WITHOUT ANY WARRANTY; without even the implied warranty of 1798944Sobrien MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1898944Sobrien GNU General Public License for more details. 1919370Spst 2098944Sobrien You should have received a copy of the GNU General Public License 2198944Sobrien along with this program; if not, write to the Free Software 2298944Sobrien Foundation, Inc., 59 Temple Place - Suite 330, 2398944Sobrien Boston, MA 02111-1307, USA. */ 2419370Spst 2519370Spst#include "defs.h" 2619370Spst 27130803Smarcel/* This file is only useful if BREAKPOINT_FROM_PC is set. If not, we 28130803Smarcel punt. */ 2919370Spst 3019370Spst#include "symtab.h" 3119370Spst#include "breakpoint.h" 3219370Spst#include "inferior.h" 3319370Spst#include "target.h" 3419370Spst 3519370Spst 3619370Spst/* Insert a breakpoint on targets that don't have any better breakpoint 3719370Spst support. We read the contents of the target location and stash it, 3819370Spst then overwrite it with a breakpoint instruction. ADDR is the target 3919370Spst location in the target machine. CONTENTS_CACHE is a pointer to 4019370Spst memory allocated for saving the target contents. It is guaranteed 4119370Spst by the caller to be long enough to save BREAKPOINT_LEN bytes (this 4219370Spst is accomplished via BREAKPOINT_MAX). */ 4319370Spst 4419370Spstint 4598944Sobriendefault_memory_insert_breakpoint (CORE_ADDR addr, char *contents_cache) 4619370Spst{ 4719370Spst int val; 48130803Smarcel const unsigned char *bp; 4946283Sdfr int bplen; 5019370Spst 5146283Sdfr /* Determine appropriate breakpoint contents and size for this address. */ 5246283Sdfr bp = BREAKPOINT_FROM_PC (&addr, &bplen); 5346283Sdfr if (bp == NULL) 5446283Sdfr error ("Software breakpoints not implemented for this target."); 5519370Spst 5646283Sdfr /* Save the memory contents. */ 5746283Sdfr val = target_read_memory (addr, contents_cache, bplen); 5846283Sdfr 5946283Sdfr /* Write the breakpoint. */ 6019370Spst if (val == 0) 6198944Sobrien val = target_write_memory (addr, (char *) bp, bplen); 6219370Spst 6319370Spst return val; 6419370Spst} 6519370Spst 6619370Spst 6719370Spstint 6898944Sobriendefault_memory_remove_breakpoint (CORE_ADDR addr, char *contents_cache) 6919370Spst{ 70130803Smarcel const unsigned char *bp; 7146283Sdfr int bplen; 7219370Spst 7346283Sdfr /* Determine appropriate breakpoint contents and size for this address. */ 7446283Sdfr bp = BREAKPOINT_FROM_PC (&addr, &bplen); 7546283Sdfr if (bp == NULL) 7646283Sdfr error ("Software breakpoints not implemented for this target."); 7719370Spst 7846283Sdfr return target_write_memory (addr, contents_cache, bplen); 7919370Spst} 8098944Sobrien 8198944Sobrien 8298944Sobrienint 8398944Sobrienmemory_insert_breakpoint (CORE_ADDR addr, char *contents_cache) 8498944Sobrien{ 8598944Sobrien return MEMORY_INSERT_BREAKPOINT(addr, contents_cache); 8698944Sobrien} 8798944Sobrien 8898944Sobrienint 8998944Sobrienmemory_remove_breakpoint (CORE_ADDR addr, char *contents_cache) 9098944Sobrien{ 9198944Sobrien return MEMORY_REMOVE_BREAKPOINT(addr, contents_cache); 9298944Sobrien} 93