GDB (API)
/home/stan/gdb/src/gdb/mem-break.c
Go to the documentation of this file.
00001 /* Simulate breakpoints by patching locations in the target system, for GDB.
00002 
00003    Copyright (C) 1990-2013 Free Software Foundation, Inc.
00004 
00005    Contributed by Cygnus Support.  Written by John Gilmore.
00006 
00007    This file is part of GDB.
00008 
00009    This program is free software; you can redistribute it and/or modify
00010    it under the terms of the GNU General Public License as published by
00011    the Free Software Foundation; either version 3 of the License, or
00012    (at your option) any later version.
00013 
00014    This program is distributed in the hope that it will be useful,
00015    but WITHOUT ANY WARRANTY; without even the implied warranty of
00016    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017    GNU General Public License for more details.
00018 
00019    You should have received a copy of the GNU General Public License
00020    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00021 
00022 #include "defs.h"
00023 #include "symtab.h"
00024 #include "breakpoint.h"
00025 #include "inferior.h"
00026 #include "target.h"
00027 #include "gdb_string.h"
00028 
00029 
00030 /* Insert a breakpoint on targets that don't have any better
00031    breakpoint support.  We read the contents of the target location
00032    and stash it, then overwrite it with a breakpoint instruction.
00033    BP_TGT->placed_address is the target location in the target
00034    machine.  BP_TGT->shadow_contents is some memory allocated for
00035    saving the target contents.  It is guaranteed by the caller to be
00036    long enough to save BREAKPOINT_LEN bytes (this is accomplished via
00037    BREAKPOINT_MAX).  */
00038 
00039 int
00040 default_memory_insert_breakpoint (struct gdbarch *gdbarch,
00041                                   struct bp_target_info *bp_tgt)
00042 {
00043   int val;
00044   const unsigned char *bp;
00045   gdb_byte *readbuf;
00046 
00047   /* Determine appropriate breakpoint contents and size for this address.  */
00048   bp = gdbarch_breakpoint_from_pc
00049        (gdbarch, &bp_tgt->placed_address, &bp_tgt->placed_size);
00050   if (bp == NULL)
00051     error (_("Software breakpoints not implemented for this target."));
00052 
00053   /* Save the memory contents in the shadow_contents buffer and then
00054      write the breakpoint instruction.  */
00055   bp_tgt->shadow_len = bp_tgt->placed_size;
00056   readbuf = alloca (bp_tgt->placed_size);
00057   val = target_read_memory (bp_tgt->placed_address, readbuf,
00058                             bp_tgt->placed_size);
00059   if (val == 0)
00060     {
00061       memcpy (bp_tgt->shadow_contents, readbuf, bp_tgt->placed_size);
00062       val = target_write_raw_memory (bp_tgt->placed_address, bp,
00063                                      bp_tgt->placed_size);
00064     }
00065 
00066   return val;
00067 }
00068 
00069 
00070 int
00071 default_memory_remove_breakpoint (struct gdbarch *gdbarch,
00072                                   struct bp_target_info *bp_tgt)
00073 {
00074   return target_write_raw_memory (bp_tgt->placed_address, bp_tgt->shadow_contents,
00075                                   bp_tgt->placed_size);
00076 }
00077 
00078 
00079 int
00080 memory_insert_breakpoint (struct gdbarch *gdbarch,
00081                           struct bp_target_info *bp_tgt)
00082 {
00083   return gdbarch_memory_insert_breakpoint (gdbarch, bp_tgt);
00084 }
00085 
00086 int
00087 memory_remove_breakpoint (struct gdbarch *gdbarch,
00088                           struct bp_target_info *bp_tgt)
00089 {
00090   return gdbarch_memory_remove_breakpoint (gdbarch, bp_tgt);
00091 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines