blob: 712f1a535d3214cb9e1f23fe793a8e21c99435e6 [file] [log] [blame]
Juan Cespedesa4850832002-03-03 02:37:50 +01001#if HAVE_CONFIG_H
2#include "config.h"
3#endif
4
5#include <sys/ptrace.h>
Ian Wienand5570a772006-02-17 02:00:00 +01006#include <string.h>
Juan Cespedesa4850832002-03-03 02:37:50 +01007#include "arch.h"
8#include "options.h"
9#include "output.h"
Ian Wienand9a2ad352006-02-20 22:44:45 +010010#include "debug.h"
Juan Cespedesa4850832002-03-03 02:37:50 +010011
12static unsigned char break_insn[] = BREAKPOINT_VALUE;
13
Ian Wienand5570a772006-02-17 02:00:00 +010014#ifdef ARCH_HAVE_ENABLE_BREAKPOINT
15extern void arch_enable_breakpoint(pid_t, struct breakpoint*);
16void enable_breakpoint(pid_t pid, struct breakpoint *sbp)
17{
Ian Wienand9a2ad352006-02-20 22:44:45 +010018 arch_enable_breakpoint(pid, sbp);
Ian Wienand5570a772006-02-17 02:00:00 +010019}
20#else
Ian Wienand9a2ad352006-02-20 22:44:45 +010021void
22enable_breakpoint(pid_t pid, struct breakpoint * sbp) {
23 int i,j;
Juan Cespedesa4850832002-03-03 02:37:50 +010024
Ian Wienand9a2ad352006-02-20 22:44:45 +010025 debug(1, "enable_breakpoint(%d,%p)", pid, sbp->addr);
Juan Cespedesa4850832002-03-03 02:37:50 +010026
Ian Wienand9a2ad352006-02-20 22:44:45 +010027 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 Cespedesa4850832002-03-03 02:37:50 +010031
Ian Wienand9a2ad352006-02-20 22:44:45 +010032 sbp->orig_value[i*sizeof(long)+j] = bytes[+j];
33 bytes[j] = break_insn[i*sizeof(long)+j];
Juan Cespedesa4850832002-03-03 02:37:50 +010034 }
Ian Wienand9a2ad352006-02-20 22:44:45 +010035 ptrace(PTRACE_POKETEXT, pid, sbp->addr + i*sizeof(long), a);
Juan Cespedesa4850832002-03-03 02:37:50 +010036 }
37}
Ian Wienand5570a772006-02-17 02:00:00 +010038#endif /* ARCH_HAVE_ENABLE_BREAKPOINT */
Juan Cespedesa4850832002-03-03 02:37:50 +010039
Ian Wienand5570a772006-02-17 02:00:00 +010040#ifdef ARCH_HAVE_DISABLE_BREAKPOINT
41extern void arch_disable_breakpoint(pid_t, const struct breakpoint * sbp);
42void
43disable_breakpoint(pid_t pid, const struct breakpoint * sbp) {
44 arch_disable_breakpoint(pid, sbp);
45}
46#else
Ian Wienand9a2ad352006-02-20 22:44:45 +010047void
48disable_breakpoint(pid_t pid, const struct breakpoint * sbp) {
49 int i,j;
Juan Cespedesa4850832002-03-03 02:37:50 +010050
Ian Wienand9a2ad352006-02-20 22:44:45 +010051 if (opt_d>1) {
Juan Cespedesefe85f02004-04-04 01:31:38 +020052 output_line(0, "disable_breakpoint(%d,%p)", pid, sbp->addr);
Juan Cespedesa4850832002-03-03 02:37:50 +010053 }
54
Ian Wienand9a2ad352006-02-20 22:44:45 +010055 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 Cespedesa4850832002-03-03 02:37:50 +010059
Ian Wienand9a2ad352006-02-20 22:44:45 +010060 bytes[j] = sbp->orig_value[i*sizeof(long)+j];
Juan Cespedesa4850832002-03-03 02:37:50 +010061 }
Ian Wienand9a2ad352006-02-20 22:44:45 +010062 ptrace(PTRACE_POKETEXT, pid, sbp->addr + i*sizeof(long), a);
Juan Cespedesa4850832002-03-03 02:37:50 +010063 }
64}
Ian Wienand5570a772006-02-17 02:00:00 +010065#endif /* ARCH_HAVE_DISABLE_BREAKPOINT */