2 * This file is part of ltrace.
4 * Copyright (C) 2007 by Instituto Nokia de Tecnologia (INdT)
6 * Author: Anderson Lizardo <anderson.lizardo@indt.org.br>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22 * Modified from sysdeps/linux-gnu/breakpoint.c and added ARM Thumb support.
25 #include <sys/ptrace.h>
33 arch_enable_breakpoint(pid_t pid, Breakpoint *sbp) {
35 const unsigned char break_insn[] = BREAKPOINT_VALUE;
36 const unsigned char thumb_break_insn[] = THUMB_BREAKPOINT_VALUE;
38 debug(1, "arch_enable_breakpoint(%d,%p)", pid, sbp->addr);
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 unsigned char *bytes = (unsigned char *)&a;
44 debug(2, "current = 0x%lx, orig_value = 0x%lx, thumb_mode = %d", a, *(long *)&sbp->orig_value, sbp->thumb_mode);
45 for (j = 0; j < sizeof(long) && i * sizeof(long) + j < BREAKPOINT_LENGTH; j++) {
47 sbp->orig_value[i * sizeof(long) + j] = bytes[j];
48 if (!sbp->thumb_mode) {
49 bytes[j] = break_insn[i * sizeof(long) + j];
51 else if (j < THUMB_BREAKPOINT_LENGTH) {
52 bytes[j] = thumb_break_insn[i * sizeof(long) + j];
55 ptrace(PTRACE_POKETEXT, pid, sbp->addr + i * sizeof(long), a);
60 arch_disable_breakpoint(pid_t pid, const Breakpoint *sbp) {
62 const unsigned char break_insn[] = BREAKPOINT_VALUE;
63 const unsigned char thumb_break_insn[] = THUMB_BREAKPOINT_VALUE;
65 debug(1, "arch_disable_breakpoint(%d,%p)", pid, sbp->addr);
67 for (i = 0; i < 1 + ((BREAKPOINT_LENGTH - 1) / sizeof(long)); i++) {
68 long a = ptrace(PTRACE_PEEKTEXT, pid, sbp->addr + i * sizeof(long), 0);
69 unsigned char *bytes = (unsigned char *)&a;
71 debug(2, "current = 0x%lx, orig_value = 0x%lx, thumb_mode = %d", a, *(long *)&sbp->orig_value, sbp->thumb_mode);
72 for (j = 0; j < sizeof(long) && i * sizeof(long) + j < BREAKPOINT_LENGTH; j++) {
73 bytes[j] = sbp->orig_value[i * sizeof(long) + j];
75 ptrace(PTRACE_POKETEXT, pid, sbp->addr + i * sizeof(long), a);