home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 9 / FreshFishVol9-CD2.bin / bbs / gnu / gdb-4.14-src.lha / gdb-4.14 / gdb / mem-break.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-14  |  3.0 KB  |  105 lines

  1. /* Simulate breakpoints by patching locations in the target system, for GDB.
  2.    Copyright 1990, 1991 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., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. #include "defs.h"
  22.  
  23. #ifdef BREAKPOINT
  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. /* This is the sequence of bytes we insert for a breakpoint.  On some
  32.    machines, breakpoints are handled by the target environment and we
  33.    don't have to worry about them here.  */
  34.  
  35. static unsigned char break_insn[] = BREAKPOINT;
  36.  
  37. /* This is only to check that BREAKPOINT fits in BREAKPOINT_MAX bytes.  */
  38.  
  39. static unsigned char check_break_insn_size[BREAKPOINT_MAX] = BREAKPOINT;
  40.  
  41. /* Insert a breakpoint on targets that don't have any better breakpoint
  42.    support.  We read the contents of the target location and stash it,
  43.    then overwrite it with a breakpoint instruction.  ADDR is the target
  44.    location in the target machine.  CONTENTS_CACHE is a pointer to 
  45.    memory allocated for saving the target contents.  It is guaranteed
  46.    by the caller to be long enough to save sizeof BREAKPOINT bytes (this
  47.    is accomplished via BREAKPOINT_MAX).  */
  48.  
  49. int
  50. memory_insert_breakpoint (addr, contents_cache)
  51.      CORE_ADDR addr;
  52.      char *contents_cache;
  53. {
  54.   int val;
  55.  
  56.   val = target_read_memory (addr, contents_cache, sizeof break_insn);
  57.  
  58.   if (val == 0)
  59.     val = target_write_memory (addr, (char *)break_insn, sizeof break_insn);
  60.  
  61.   return val;
  62. }
  63.  
  64.  
  65. int
  66. memory_remove_breakpoint (addr, contents_cache)
  67.      CORE_ADDR addr;
  68.      char *contents_cache;
  69. {
  70.   return target_write_memory (addr, contents_cache, sizeof break_insn);
  71. }
  72.  
  73.  
  74. /* FIXME: This is a hack and should depend on the debugging target.
  75.    See comment in breakpoint.c where this is used.  */
  76.  
  77. int memory_breakpoint_size = sizeof (break_insn);
  78.  
  79.  
  80. #else  /* BREAKPOINT */
  81.  
  82. char nogo[] = "Breakpoints not implemented for this target.";
  83.  
  84. int
  85. memory_insert_breakpoint (addr, contents_cache)
  86.      CORE_ADDR addr;
  87.      char *contents_cache;
  88. {
  89.   error (nogo);
  90.   return 0;    /* lint */
  91. }
  92.  
  93. int
  94. memory_remove_breakpoint (addr, contents_cache)
  95.      CORE_ADDR addr;
  96.      char *contents_cache;
  97. {
  98.   error (nogo);
  99.   return 0;    /* lint */
  100. }
  101.  
  102. int memory_breakpoint_size = -1;
  103.  
  104. #endif /* BREAKPOINT */
  105.