1 /***************************************************************************
2 * Copyright (C) 2005 by Dominic Rath *
3 * Dominic.Rath@gmx.de *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
24 #include "binarybuffer.h"
29 #include "breakpoints.h"
31 char *breakpoint_type_strings[] =
37 char *watchpoint_rw_strings[] =
44 int breakpoint_add(target_t *target, u32 address, u32 length, enum breakpoint_type type)
46 breakpoint_t *breakpoint = target->breakpoints;
47 breakpoint_t **breakpoint_p = &target->breakpoints;
52 if (breakpoint->address == address)
54 breakpoint_p = &breakpoint->next;
55 breakpoint = breakpoint->next;
58 if ((retval = target->type->add_breakpoint(target, address, length, type)) != ERROR_OK)
62 case ERROR_TARGET_RESOURCE_NOT_AVAILABLE:
63 INFO("can't add %s breakpoint, resource not available", breakpoint_type_strings[type]);
66 case ERROR_TARGET_NOT_HALTED:
67 INFO("can't add breakpoint while target is running");
71 ERROR("unknown error");
77 (*breakpoint_p) = malloc(sizeof(breakpoint_t));
78 (*breakpoint_p)->address = address;
79 (*breakpoint_p)->length = length;
80 (*breakpoint_p)->type = type;
81 (*breakpoint_p)->set = 0;
82 (*breakpoint_p)->orig_instr = malloc(CEIL(length, 8));
83 (*breakpoint_p)->next = NULL;
85 DEBUG("added %s breakpoint at 0x%8.8x of length 0x%8.8x", breakpoint_type_strings[type], address, length);
90 int breakpoint_remove(target_t *target, u32 address)
92 breakpoint_t *breakpoint = target->breakpoints;
93 breakpoint_t **breakpoint_p = &target->breakpoints;
98 if (breakpoint->address == address)
100 breakpoint_p = &breakpoint->next;
101 breakpoint = breakpoint->next;
106 if ((retval = target->type->remove_breakpoint(target, breakpoint)) != ERROR_OK)
110 case ERROR_TARGET_NOT_HALTED:
111 INFO("can't remove breakpoint while target is running");
115 ERROR("unknown error");
120 (*breakpoint_p) = breakpoint->next;
121 free(breakpoint->orig_instr);
126 ERROR("no breakpoint at address 0x%8.8x found", address);
132 breakpoint_t* breakpoint_find(target_t *target, u32 address)
134 breakpoint_t *breakpoint = target->breakpoints;
138 if (breakpoint->address == address)
140 breakpoint = breakpoint->next;
146 int watchpoint_add(target_t *target, u32 address, u32 length, enum watchpoint_rw rw, u32 value, u32 mask)
148 watchpoint_t *watchpoint = target->watchpoints;
149 watchpoint_t **watchpoint_p = &target->watchpoints;
154 if (watchpoint->address == address)
156 watchpoint_p = &watchpoint->next;
157 watchpoint = watchpoint->next;
160 if ((retval = target->type->add_watchpoint(target, address, length, rw)) != ERROR_OK)
164 case ERROR_TARGET_RESOURCE_NOT_AVAILABLE:
165 INFO("can't add %s watchpoint, resource not available", watchpoint_rw_strings[rw]);
169 ERROR("unknown error");
175 (*watchpoint_p) = malloc(sizeof(watchpoint_t));
176 (*watchpoint_p)->address = address;
177 (*watchpoint_p)->length = length;
178 (*watchpoint_p)->value = value;
179 (*watchpoint_p)->mask = mask;
180 (*watchpoint_p)->rw = rw;
181 (*watchpoint_p)->set = 0;
182 (*watchpoint_p)->next = NULL;
184 DEBUG("added %s watchpoint at 0x%8.8x of length 0x%8.8x", watchpoint_rw_strings[rw], address, length);
189 int watchpoint_remove(target_t *target, u32 address)
191 watchpoint_t *watchpoint = target->watchpoints;
192 watchpoint_t **watchpoint_p = &target->watchpoints;
197 if (watchpoint->address == address)
199 watchpoint_p = &watchpoint->next;
200 watchpoint = watchpoint->next;
205 if ((retval = target->type->remove_watchpoint(target, watchpoint)) != ERROR_OK)
207 ERROR("BUG: can't remove watchpoint");
210 (*watchpoint_p) = watchpoint->next;
215 ERROR("no watchpoint at address 0x%8.8x found", address);