OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [branches/] [oc/] [gdb-5.0/] [gdb/] [mem-break.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 104 markom
/* Simulate breakpoints by patching locations in the target system, for GDB.
2
   Copyright 1990, 1991, 1995 Free Software Foundation, Inc.
3
   Contributed by Cygnus Support.  Written by John Gilmore.
4
 
5
   This file is part of GDB.
6
 
7
   This program is free software; you can redistribute it and/or modify
8
   it under the terms of the GNU General Public License as published by
9
   the Free Software Foundation; either version 2 of the License, or
10
   (at your option) any later version.
11
 
12
   This program is distributed in the hope that it will be useful,
13
   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
   GNU General Public License for more details.
16
 
17
   You should have received a copy of the GNU General Public License
18
   along with this program; if not, write to the Free Software
19
   Foundation, Inc., 59 Temple Place - Suite 330,
20
   Boston, MA 02111-1307, USA.  */
21
 
22
#include "defs.h"
23
 
24
/* This file is only useful if BREAKPOINT is set.  If not, we punt.  */
25
 
26
#include "symtab.h"
27
#include "breakpoint.h"
28
#include "inferior.h"
29
#include "target.h"
30
 
31
 
32
/* Use the program counter to determine the contents and size
33
   of a breakpoint instruction.  If no target-dependent macro
34
   BREAKPOINT_FROM_PC has been defined to implement this function,
35
   assume that the breakpoint doesn't depend on the PC, and
36
   use the values of the BIG_BREAKPOINT and LITTLE_BREAKPOINT macros.
37
   Return a pointer to a string of bytes that encode a breakpoint
38
   instruction, stores the length of the string to *lenptr,
39
   and optionally adjust the pc to point to the correct memory location
40
   for inserting the breakpoint.  */
41
 
42
unsigned char *
43
memory_breakpoint_from_pc (pcptr, lenptr)
44
     CORE_ADDR *pcptr;
45
     int *lenptr;
46
{
47
  /* {BIG_,LITTLE_}BREAKPOINT is the sequence of bytes we insert for a
48
     breakpoint.  On some machines, breakpoints are handled by the
49
     target environment and we don't have to worry about them here.  */
50
#ifdef BIG_BREAKPOINT
51
  if (TARGET_BYTE_ORDER == BIG_ENDIAN)
52
    {
53
      static unsigned char big_break_insn[] = BIG_BREAKPOINT;
54
      *lenptr = sizeof (big_break_insn);
55
      return big_break_insn;
56
    }
57
#endif
58
#ifdef LITTLE_BREAKPOINT
59
  if (TARGET_BYTE_ORDER != BIG_ENDIAN)
60
    {
61
      static unsigned char little_break_insn[] = LITTLE_BREAKPOINT;
62
      *lenptr = sizeof (little_break_insn);
63
      return little_break_insn;
64
    }
65
#endif
66
#ifdef BREAKPOINT
67
  {
68
    static unsigned char break_insn[] = BREAKPOINT;
69
    *lenptr = sizeof (break_insn);
70
    return break_insn;
71
  }
72
#endif
73
  *lenptr = 0;
74
  return NULL;
75
}
76
 
77
 
78
/* Insert a breakpoint on targets that don't have any better breakpoint
79
   support.  We read the contents of the target location and stash it,
80
   then overwrite it with a breakpoint instruction.  ADDR is the target
81
   location in the target machine.  CONTENTS_CACHE is a pointer to
82
   memory allocated for saving the target contents.  It is guaranteed
83
   by the caller to be long enough to save BREAKPOINT_LEN bytes (this
84
   is accomplished via BREAKPOINT_MAX).  */
85
 
86
int
87
default_memory_insert_breakpoint (addr, contents_cache)
88
     CORE_ADDR addr;
89
     char *contents_cache;
90
{
91
  int val;
92
  unsigned char *bp;
93
  int bplen;
94
 
95
  /* Determine appropriate breakpoint contents and size for this address.  */
96
  bp = BREAKPOINT_FROM_PC (&addr, &bplen);
97
  if (bp == NULL)
98
    error ("Software breakpoints not implemented for this target.");
99
 
100
  /* Save the memory contents.  */
101
  val = target_read_memory (addr, contents_cache, bplen);
102
 
103
  /* Write the breakpoint.  */
104
  if (val == 0)
105
    val = target_write_memory (addr, (char *) bp, bplen);
106
 
107
  return val;
108
}
109
 
110
 
111
int
112
default_memory_remove_breakpoint (addr, contents_cache)
113
     CORE_ADDR addr;
114
     char *contents_cache;
115
{
116
  unsigned char *bp;
117
  int bplen;
118
 
119
  /* Determine appropriate breakpoint contents and size for this address.  */
120
  bp = BREAKPOINT_FROM_PC (&addr, &bplen);
121
  if (bp == NULL)
122
    error ("Software breakpoints not implemented for this target.");
123
 
124
  return target_write_memory (addr, contents_cache, bplen);
125
}
126
 
127
 
128
#if !defined(MEMORY_INSERT_BREAKPOINT)
129
#define MEMORY_INSERT_BREAKPOINT(addr, contents_cache) \
130
  default_memory_insert_breakpoint(addr, contents_cache)
131
#endif
132
int
133
memory_insert_breakpoint (addr, contents_cache)
134
     CORE_ADDR addr;
135
     char *contents_cache;
136
{
137
  return MEMORY_INSERT_BREAKPOINT(addr, contents_cache);
138
}
139
 
140
#if !defined(MEMORY_REMOVE_BREAKPOINT)
141
#define MEMORY_REMOVE_BREAKPOINT(addr, contents_cache) \
142
  default_memory_remove_breakpoint(addr, contents_cache)
143
#endif
144
int
145
memory_remove_breakpoint (addr, contents_cache)
146
     CORE_ADDR addr;
147
     char *contents_cache;
148
{
149
  return MEMORY_REMOVE_BREAKPOINT(addr, contents_cache);
150
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.