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 | |
Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame^] | 12 | void enable_breakpoint(pid_t pid, struct breakpoint *sbp) |
| 13 | { |
| 14 | int i, j; |
Juan Cespedes | a485083 | 2002-03-03 02:37:50 +0100 | [diff] [blame] | 15 | |
Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame^] | 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 | |
Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame^] | 20 | for (i = 0; i < 1 + ((BREAKPOINT_LENGTH - 1) / sizeof(long)); i++) { |
| 21 | long a = |
| 22 | ptrace(PTRACE_PEEKTEXT, pid, sbp->addr + i * sizeof(long), |
| 23 | 0); |
| 24 | for (j = 0; |
| 25 | j < sizeof(long) |
| 26 | && i * sizeof(long) + j < BREAKPOINT_LENGTH; j++) { |
| 27 | unsigned char *bytes = (unsigned char *)&a; |
Juan Cespedes | a485083 | 2002-03-03 02:37:50 +0100 | [diff] [blame] | 28 | |
Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame^] | 29 | sbp->orig_value[i * sizeof(long) + j] = bytes[+j]; |
| 30 | bytes[j] = break_insn[i * sizeof(long) + j]; |
Juan Cespedes | a485083 | 2002-03-03 02:37:50 +0100 | [diff] [blame] | 31 | } |
Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame^] | 32 | ptrace(PTRACE_POKETEXT, pid, sbp->addr + i * sizeof(long), a); |
Juan Cespedes | a485083 | 2002-03-03 02:37:50 +0100 | [diff] [blame] | 33 | } |
| 34 | } |
| 35 | |
Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame^] | 36 | void disable_breakpoint(pid_t pid, const struct breakpoint *sbp) |
| 37 | { |
| 38 | int i, j; |
Juan Cespedes | a485083 | 2002-03-03 02:37:50 +0100 | [diff] [blame] | 39 | |
Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame^] | 40 | if (opt_d > 1) { |
Juan Cespedes | efe85f0 | 2004-04-04 01:31:38 +0200 | [diff] [blame] | 41 | output_line(0, "disable_breakpoint(%d,%p)", pid, sbp->addr); |
Juan Cespedes | a485083 | 2002-03-03 02:37:50 +0100 | [diff] [blame] | 42 | } |
| 43 | |
Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame^] | 44 | for (i = 0; i < 1 + ((BREAKPOINT_LENGTH - 1) / sizeof(long)); i++) { |
| 45 | long a = |
| 46 | ptrace(PTRACE_PEEKTEXT, pid, sbp->addr + i * sizeof(long), |
| 47 | 0); |
| 48 | for (j = 0; |
| 49 | j < sizeof(long) |
| 50 | && i * sizeof(long) + j < BREAKPOINT_LENGTH; j++) { |
| 51 | unsigned char *bytes = (unsigned char *)&a; |
Juan Cespedes | a485083 | 2002-03-03 02:37:50 +0100 | [diff] [blame] | 52 | |
Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame^] | 53 | bytes[j] = sbp->orig_value[i * sizeof(long) + j]; |
Juan Cespedes | a485083 | 2002-03-03 02:37:50 +0100 | [diff] [blame] | 54 | } |
Ian Wienand | 3219f32 | 2006-02-16 06:00:00 +0100 | [diff] [blame^] | 55 | ptrace(PTRACE_POKETEXT, pid, sbp->addr + i * sizeof(long), a); |
Juan Cespedes | a485083 | 2002-03-03 02:37:50 +0100 | [diff] [blame] | 56 | } |
| 57 | } |