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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [gdb/] [mem-break.c] - Blame information for rev 1770

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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