Juan Cespedes | a485083 | 2002-03-03 02:37:50 +0100 | [diff] [blame] | 1 | #if HAVE_CONFIG_H |
| 2 | #include "config.h" |
| 3 | #endif |
| 4 | |
| 5 | #include <sys/ptrace.h> |
| 6 | #include "arch.h" |
| 7 | #include "options.h" |
| 8 | #include "output.h" |
| 9 | |
| 10 | static unsigned char break_insn[] = BREAKPOINT_VALUE; |
| 11 | |
| 12 | void |
| 13 | enable_breakpoint(pid_t pid, struct breakpoint * sbp) { |
| 14 | int i,j; |
| 15 | |
| 16 | if (opt_d>1) { |
Juan Cespedes | efe85f0 | 2004-04-04 01:31:38 +0200 | [diff] [blame^] | 17 | output_line(0, "enable_breakpoint(%d,%p)", pid, sbp->addr); |
Juan Cespedes | a485083 | 2002-03-03 02:37:50 +0100 | [diff] [blame] | 18 | } |
| 19 | |
| 20 | for(i=0; i < 1+((BREAKPOINT_LENGTH-1)/sizeof(long)); i++) { |
| 21 | long a = ptrace(PTRACE_PEEKTEXT, pid, sbp->addr + i*sizeof(long), 0); |
| 22 | for(j=0; j<sizeof(long) && i*sizeof(long)+j < BREAKPOINT_LENGTH; j++) { |
| 23 | unsigned char * bytes = (unsigned char *)&a; |
| 24 | |
| 25 | sbp->orig_value[i*sizeof(long)+j] = bytes[i*sizeof(long)+j]; |
| 26 | bytes[i*sizeof(long)+j] = break_insn[i*sizeof(long)+j]; |
| 27 | } |
| 28 | ptrace(PTRACE_POKETEXT, pid, sbp->addr + i*sizeof(long), a); |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | void |
| 33 | disable_breakpoint(pid_t pid, const struct breakpoint * sbp) { |
| 34 | int i,j; |
| 35 | |
| 36 | if (opt_d>1) { |
Juan Cespedes | efe85f0 | 2004-04-04 01:31:38 +0200 | [diff] [blame^] | 37 | output_line(0, "disable_breakpoint(%d,%p)", pid, sbp->addr); |
Juan Cespedes | a485083 | 2002-03-03 02:37:50 +0100 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | for(i=0; i < 1+((BREAKPOINT_LENGTH-1)/sizeof(long)); i++) { |
| 41 | long a = ptrace(PTRACE_PEEKTEXT, pid, sbp->addr + i*sizeof(long), 0); |
| 42 | for(j=0; j<sizeof(long) && i*sizeof(long)+j < BREAKPOINT_LENGTH; j++) { |
| 43 | unsigned char * bytes = (unsigned char *)&a; |
| 44 | |
| 45 | bytes[i*sizeof(long)+j] = sbp->orig_value[i*sizeof(long)+j]; |
| 46 | } |
| 47 | ptrace(PTRACE_POKETEXT, pid, sbp->addr + i*sizeof(long), a); |
| 48 | } |
| 49 | } |