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> |
Ian Wienand | 5570a77 | 2006-02-17 02:00:00 +0100 | [diff] [blame] | 6 | #include <string.h> |
Juan Cespedes | a485083 | 2002-03-03 02:37:50 +0100 | [diff] [blame] | 7 | #include "arch.h" |
| 8 | #include "options.h" |
| 9 | #include "output.h" |
Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame^] | 10 | #include "debug.h" |
Juan Cespedes | a485083 | 2002-03-03 02:37:50 +0100 | [diff] [blame] | 11 | |
| 12 | static unsigned char break_insn[] = BREAKPOINT_VALUE; |
| 13 | |
Ian Wienand | 5570a77 | 2006-02-17 02:00:00 +0100 | [diff] [blame] | 14 | #ifdef ARCH_HAVE_ENABLE_BREAKPOINT |
| 15 | extern void arch_enable_breakpoint(pid_t, struct breakpoint*); |
| 16 | void enable_breakpoint(pid_t pid, struct breakpoint *sbp) |
| 17 | { |
Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame^] | 18 | arch_enable_breakpoint(pid, sbp); |
Ian Wienand | 5570a77 | 2006-02-17 02:00:00 +0100 | [diff] [blame] | 19 | } |
| 20 | #else |
Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame^] | 21 | void |
| 22 | enable_breakpoint(pid_t pid, struct breakpoint * sbp) { |
| 23 | int i,j; |
Juan Cespedes | a485083 | 2002-03-03 02:37:50 +0100 | [diff] [blame] | 24 | |
Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame^] | 25 | debug(1, "enable_breakpoint(%d,%p)", pid, sbp->addr); |
Juan Cespedes | a485083 | 2002-03-03 02:37:50 +0100 | [diff] [blame] | 26 | |
Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame^] | 27 | for(i=0; i < 1+((BREAKPOINT_LENGTH-1)/sizeof(long)); i++) { |
| 28 | long a = ptrace(PTRACE_PEEKTEXT, pid, sbp->addr + i*sizeof(long), 0); |
| 29 | for(j=0; j<sizeof(long) && i*sizeof(long)+j < BREAKPOINT_LENGTH; j++) { |
| 30 | unsigned char * bytes = (unsigned char *)&a; |
Juan Cespedes | a485083 | 2002-03-03 02:37:50 +0100 | [diff] [blame] | 31 | |
Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame^] | 32 | sbp->orig_value[i*sizeof(long)+j] = bytes[+j]; |
| 33 | bytes[j] = break_insn[i*sizeof(long)+j]; |
Juan Cespedes | a485083 | 2002-03-03 02:37:50 +0100 | [diff] [blame] | 34 | } |
Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame^] | 35 | ptrace(PTRACE_POKETEXT, pid, sbp->addr + i*sizeof(long), a); |
Juan Cespedes | a485083 | 2002-03-03 02:37:50 +0100 | [diff] [blame] | 36 | } |
| 37 | } |
Ian Wienand | 5570a77 | 2006-02-17 02:00:00 +0100 | [diff] [blame] | 38 | #endif /* ARCH_HAVE_ENABLE_BREAKPOINT */ |
Juan Cespedes | a485083 | 2002-03-03 02:37:50 +0100 | [diff] [blame] | 39 | |
Ian Wienand | 5570a77 | 2006-02-17 02:00:00 +0100 | [diff] [blame] | 40 | #ifdef ARCH_HAVE_DISABLE_BREAKPOINT |
| 41 | extern void arch_disable_breakpoint(pid_t, const struct breakpoint * sbp); |
| 42 | void |
| 43 | disable_breakpoint(pid_t pid, const struct breakpoint * sbp) { |
| 44 | arch_disable_breakpoint(pid, sbp); |
| 45 | } |
| 46 | #else |
Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame^] | 47 | void |
| 48 | disable_breakpoint(pid_t pid, const struct breakpoint * sbp) { |
| 49 | int i,j; |
Juan Cespedes | a485083 | 2002-03-03 02:37:50 +0100 | [diff] [blame] | 50 | |
Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame^] | 51 | if (opt_d>1) { |
Juan Cespedes | efe85f0 | 2004-04-04 01:31:38 +0200 | [diff] [blame] | 52 | output_line(0, "disable_breakpoint(%d,%p)", pid, sbp->addr); |
Juan Cespedes | a485083 | 2002-03-03 02:37:50 +0100 | [diff] [blame] | 53 | } |
| 54 | |
Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame^] | 55 | for(i=0; i < 1+((BREAKPOINT_LENGTH-1)/sizeof(long)); i++) { |
| 56 | long a = ptrace(PTRACE_PEEKTEXT, pid, sbp->addr + i*sizeof(long), 0); |
| 57 | for(j=0; j<sizeof(long) && i*sizeof(long)+j < BREAKPOINT_LENGTH; j++) { |
| 58 | unsigned char * bytes = (unsigned char *)&a; |
Juan Cespedes | a485083 | 2002-03-03 02:37:50 +0100 | [diff] [blame] | 59 | |
Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame^] | 60 | bytes[j] = sbp->orig_value[i*sizeof(long)+j]; |
Juan Cespedes | a485083 | 2002-03-03 02:37:50 +0100 | [diff] [blame] | 61 | } |
Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame^] | 62 | ptrace(PTRACE_POKETEXT, pid, sbp->addr + i*sizeof(long), a); |
Juan Cespedes | a485083 | 2002-03-03 02:37:50 +0100 | [diff] [blame] | 63 | } |
| 64 | } |
Ian Wienand | 5570a77 | 2006-02-17 02:00:00 +0100 | [diff] [blame] | 65 | #endif /* ARCH_HAVE_DISABLE_BREAKPOINT */ |