| OLD | NEW |
| 1 /* Simulate breakpoints by patching locations in the target system, for GDB. | 1 /* Simulate breakpoints by patching locations in the target system, for GDB. |
| 2 | 2 |
| 3 Copyright (C) 1990-1993, 1995, 1997-2000, 2002, 2007-2012 Free | 3 Copyright (C) 1990-1993, 1995, 1997-2000, 2002, 2007-2012 Free |
| 4 Software Foundation, Inc. | 4 Software Foundation, Inc. |
| 5 | 5 |
| 6 Contributed by Cygnus Support. Written by John Gilmore. | 6 Contributed by Cygnus Support. Written by John Gilmore. |
| 7 | 7 |
| 8 This file is part of GDB. | 8 This file is part of GDB. |
| 9 | 9 |
| 10 This program is free software; you can redistribute it and/or modify | 10 This program is free software; you can redistribute it and/or modify |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 | 22 |
| 23 #include "defs.h" | 23 #include "defs.h" |
| 24 | 24 |
| 25 /* This file is only useful if BREAKPOINT_FROM_PC is set. If not, we | 25 /* This file is only useful if BREAKPOINT_FROM_PC is set. If not, we |
| 26 punt. */ | 26 punt. */ |
| 27 | 27 |
| 28 #include "symtab.h" | 28 #include "symtab.h" |
| 29 #include "breakpoint.h" | 29 #include "breakpoint.h" |
| 30 #include "inferior.h" | 30 #include "inferior.h" |
| 31 #include "target.h" | 31 #include "target.h" |
| 32 #include "gdb_string.h" |
| 32 | 33 |
| 33 | 34 |
| 34 /* Insert a breakpoint on targets that don't have any better | 35 /* Insert a breakpoint on targets that don't have any better |
| 35 breakpoint support. We read the contents of the target location | 36 breakpoint support. We read the contents of the target location |
| 36 and stash it, then overwrite it with a breakpoint instruction. | 37 and stash it, then overwrite it with a breakpoint instruction. |
| 37 BP_TGT->placed_address is the target location in the target | 38 BP_TGT->placed_address is the target location in the target |
| 38 machine. BP_TGT->shadow_contents is some memory allocated for | 39 machine. BP_TGT->shadow_contents is some memory allocated for |
| 39 saving the target contents. It is guaranteed by the caller to be | 40 saving the target contents. It is guaranteed by the caller to be |
| 40 long enough to save BREAKPOINT_LEN bytes (this is accomplished via | 41 long enough to save BREAKPOINT_LEN bytes (this is accomplished via |
| 41 BREAKPOINT_MAX). */ | 42 BREAKPOINT_MAX). */ |
| 42 | 43 |
| 43 int | 44 int |
| 44 default_memory_insert_breakpoint (struct gdbarch *gdbarch, | 45 default_memory_insert_breakpoint (struct gdbarch *gdbarch, |
| 45 struct bp_target_info *bp_tgt) | 46 struct bp_target_info *bp_tgt) |
| 46 { | 47 { |
| 47 int val; | 48 int val; |
| 48 const unsigned char *bp; | 49 const unsigned char *bp; |
| 50 gdb_byte *readbuf; |
| 49 | 51 |
| 50 /* Determine appropriate breakpoint contents and size for this address. */ | 52 /* Determine appropriate breakpoint contents and size for this address. */ |
| 51 bp = gdbarch_breakpoint_from_pc | 53 bp = gdbarch_breakpoint_from_pc |
| 52 (gdbarch, &bp_tgt->placed_address, &bp_tgt->placed_size); | 54 (gdbarch, &bp_tgt->placed_address, &bp_tgt->placed_size); |
| 53 if (bp == NULL) | 55 if (bp == NULL) |
| 54 error (_("Software breakpoints not implemented for this target.")); | 56 error (_("Software breakpoints not implemented for this target.")); |
| 55 | 57 |
| 56 /* Save the memory contents. */ | 58 /* Save the memory contents in the shadow_contents buffer and then |
| 59 write the breakpoint instruction. */ |
| 57 bp_tgt->shadow_len = bp_tgt->placed_size; | 60 bp_tgt->shadow_len = bp_tgt->placed_size; |
| 58 val = target_read_memory (bp_tgt->placed_address, bp_tgt->shadow_contents, | 61 readbuf = alloca (bp_tgt->placed_size); |
| 62 val = target_read_memory (bp_tgt->placed_address, readbuf, |
| 59 bp_tgt->placed_size); | 63 bp_tgt->placed_size); |
| 60 | |
| 61 /* Write the breakpoint. */ | |
| 62 if (val == 0) | 64 if (val == 0) |
| 63 val = target_write_raw_memory (bp_tgt->placed_address, bp, | 65 { |
| 64 » » » » bp_tgt->placed_size); | 66 memcpy (bp_tgt->shadow_contents, readbuf, bp_tgt->placed_size); |
| 67 val = target_write_raw_memory (bp_tgt->placed_address, bp, |
| 68 » » » » bp_tgt->placed_size); |
| 69 } |
| 65 | 70 |
| 66 return val; | 71 return val; |
| 67 } | 72 } |
| 68 | 73 |
| 69 | 74 |
| 70 int | 75 int |
| 71 default_memory_remove_breakpoint (struct gdbarch *gdbarch, | 76 default_memory_remove_breakpoint (struct gdbarch *gdbarch, |
| 72 struct bp_target_info *bp_tgt) | 77 struct bp_target_info *bp_tgt) |
| 73 { | 78 { |
| 74 return target_write_raw_memory (bp_tgt->placed_address, bp_tgt->shadow_content
s, | 79 return target_write_raw_memory (bp_tgt->placed_address, bp_tgt->shadow_content
s, |
| 75 bp_tgt->placed_size); | 80 bp_tgt->placed_size); |
| 76 } | 81 } |
| 77 | 82 |
| 78 | 83 |
| 79 int | 84 int |
| 80 memory_insert_breakpoint (struct gdbarch *gdbarch, | 85 memory_insert_breakpoint (struct gdbarch *gdbarch, |
| 81 struct bp_target_info *bp_tgt) | 86 struct bp_target_info *bp_tgt) |
| 82 { | 87 { |
| 83 return gdbarch_memory_insert_breakpoint (gdbarch, bp_tgt); | 88 return gdbarch_memory_insert_breakpoint (gdbarch, bp_tgt); |
| 84 } | 89 } |
| 85 | 90 |
| 86 int | 91 int |
| 87 memory_remove_breakpoint (struct gdbarch *gdbarch, | 92 memory_remove_breakpoint (struct gdbarch *gdbarch, |
| 88 struct bp_target_info *bp_tgt) | 93 struct bp_target_info *bp_tgt) |
| 89 { | 94 { |
| 90 return gdbarch_memory_remove_breakpoint (gdbarch, bp_tgt); | 95 return gdbarch_memory_remove_breakpoint (gdbarch, bp_tgt); |
| 91 } | 96 } |
| OLD | NEW |