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