2006-06-02 05:36:31 -05:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2005 by Dominic Rath *
|
|
|
|
* Dominic.Rath@gmx.de *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the *
|
|
|
|
* Free Software Foundation, Inc., *
|
|
|
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
|
|
|
***************************************************************************/
|
2006-07-17 09:13:27 -05:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2006-06-02 05:36:31 -05:00
|
|
|
#include "config.h"
|
2006-07-17 09:13:27 -05:00
|
|
|
#endif
|
2006-06-02 05:36:31 -05:00
|
|
|
|
|
|
|
#include "target.h"
|
2009-12-03 06:14:28 -06:00
|
|
|
#include <helper/log.h>
|
2006-06-02 05:36:31 -05:00
|
|
|
#include "breakpoints.h"
|
|
|
|
|
2009-05-10 23:56:37 -05:00
|
|
|
|
2009-04-30 04:49:38 -05:00
|
|
|
static char *breakpoint_type_strings[] =
|
2006-06-02 05:36:31 -05:00
|
|
|
{
|
|
|
|
"hardware",
|
|
|
|
"software"
|
|
|
|
};
|
|
|
|
|
2009-04-30 04:49:38 -05:00
|
|
|
static char *watchpoint_rw_strings[] =
|
2006-06-02 05:36:31 -05:00
|
|
|
{
|
|
|
|
"read",
|
|
|
|
"write",
|
|
|
|
"access"
|
|
|
|
};
|
|
|
|
|
2009-06-27 12:25:07 -05:00
|
|
|
// monotonic counter/id-number for breakpoints and watch points
|
|
|
|
static int bpwp_unique_id;
|
|
|
|
|
2009-11-13 12:11:13 -06:00
|
|
|
int breakpoint_add(struct target *target, uint32_t address, uint32_t length, enum breakpoint_type type)
|
2006-06-02 05:36:31 -05:00
|
|
|
{
|
2009-11-13 11:15:32 -06:00
|
|
|
struct breakpoint *breakpoint = target->breakpoints;
|
|
|
|
struct breakpoint **breakpoint_p = &target->breakpoints;
|
2009-11-24 02:13:43 -06:00
|
|
|
char *reason;
|
2006-06-02 05:36:31 -05:00
|
|
|
int retval;
|
2009-06-27 12:25:07 -05:00
|
|
|
int n;
|
2009-06-23 17:49:23 -05:00
|
|
|
|
2009-06-27 12:25:07 -05:00
|
|
|
n = 0;
|
2006-06-02 05:36:31 -05:00
|
|
|
while (breakpoint)
|
|
|
|
{
|
2009-06-27 12:25:07 -05:00
|
|
|
n++;
|
2009-11-24 02:13:43 -06:00
|
|
|
if (breakpoint->address == address) {
|
|
|
|
/* FIXME don't assume "same address" means "same
|
|
|
|
* breakpoint" ... check all the parameters before
|
|
|
|
* succeeding.
|
|
|
|
*/
|
2009-09-21 13:40:55 -05:00
|
|
|
LOG_DEBUG("Duplicate Breakpoint address: 0x%08" PRIx32 " (BP %d)",
|
2009-06-27 12:25:07 -05:00
|
|
|
address, breakpoint->unique_id );
|
2006-06-02 05:36:31 -05:00
|
|
|
return ERROR_OK;
|
2009-06-27 12:25:07 -05:00
|
|
|
}
|
2006-06-02 05:36:31 -05:00
|
|
|
breakpoint_p = &breakpoint->next;
|
|
|
|
breakpoint = breakpoint->next;
|
|
|
|
}
|
2009-06-23 17:49:23 -05:00
|
|
|
|
2009-11-13 11:15:32 -06:00
|
|
|
(*breakpoint_p) = malloc(sizeof(struct breakpoint));
|
2006-11-07 04:54:19 -06:00
|
|
|
(*breakpoint_p)->address = address;
|
|
|
|
(*breakpoint_p)->length = length;
|
|
|
|
(*breakpoint_p)->type = type;
|
|
|
|
(*breakpoint_p)->set = 0;
|
2007-10-01 03:31:30 -05:00
|
|
|
(*breakpoint_p)->orig_instr = malloc(length);
|
2006-11-07 04:54:19 -06:00
|
|
|
(*breakpoint_p)->next = NULL;
|
2009-06-27 12:25:07 -05:00
|
|
|
(*breakpoint_p)->unique_id = bpwp_unique_id++;
|
2009-06-23 17:49:23 -05:00
|
|
|
|
2009-11-24 02:13:43 -06:00
|
|
|
retval = target_add_breakpoint(target, *breakpoint_p);
|
|
|
|
switch (retval) {
|
|
|
|
case ERROR_OK:
|
|
|
|
break;
|
|
|
|
case ERROR_TARGET_RESOURCE_NOT_AVAILABLE:
|
|
|
|
reason = "resource not available";
|
|
|
|
goto fail;
|
|
|
|
case ERROR_TARGET_NOT_HALTED:
|
|
|
|
reason = "target running";
|
|
|
|
goto fail;
|
|
|
|
default:
|
|
|
|
reason = "unknown reason";
|
|
|
|
fail:
|
|
|
|
LOG_ERROR("can't add breakpoint: %s", reason);
|
|
|
|
free((*breakpoint_p)->orig_instr);
|
|
|
|
free(*breakpoint_p);
|
|
|
|
*breakpoint_p = NULL;
|
|
|
|
return retval;
|
2006-06-02 05:36:31 -05:00
|
|
|
}
|
2009-06-23 17:49:23 -05:00
|
|
|
|
2009-06-27 12:25:07 -05:00
|
|
|
LOG_DEBUG("added %s breakpoint at 0x%8.8" PRIx32 " of length 0x%8.8x, (BPID: %d)",
|
|
|
|
breakpoint_type_strings[(*breakpoint_p)->type],
|
|
|
|
(*breakpoint_p)->address, (*breakpoint_p)->length,
|
|
|
|
(*breakpoint_p)->unique_id );
|
2009-06-23 17:49:23 -05:00
|
|
|
|
2006-06-02 05:36:31 -05:00
|
|
|
return ERROR_OK;
|
|
|
|
}
|
|
|
|
|
2008-08-13 10:05:15 -05:00
|
|
|
/* free up a breakpoint */
|
2010-06-15 16:04:22 -05:00
|
|
|
static void breakpoint_free(struct target *target, struct breakpoint *breakpoint_to_remove)
|
2008-08-13 10:05:15 -05:00
|
|
|
{
|
2009-11-13 11:15:32 -06:00
|
|
|
struct breakpoint *breakpoint = target->breakpoints;
|
|
|
|
struct breakpoint **breakpoint_p = &target->breakpoints;
|
2009-11-28 12:40:26 -06:00
|
|
|
int retval;
|
2009-06-23 17:49:23 -05:00
|
|
|
|
2008-08-13 10:05:15 -05:00
|
|
|
while (breakpoint)
|
|
|
|
{
|
2010-06-15 16:04:22 -05:00
|
|
|
if (breakpoint == breakpoint_to_remove)
|
2008-08-13 10:05:15 -05:00
|
|
|
break;
|
|
|
|
breakpoint_p = &breakpoint->next;
|
|
|
|
breakpoint = breakpoint->next;
|
|
|
|
}
|
2009-06-23 17:49:23 -05:00
|
|
|
|
2009-06-23 17:42:03 -05:00
|
|
|
if (breakpoint == NULL)
|
2008-08-13 10:05:15 -05:00
|
|
|
return;
|
2009-06-23 17:49:23 -05:00
|
|
|
|
2009-11-28 12:40:26 -06:00
|
|
|
retval = target_remove_breakpoint(target, breakpoint);
|
2009-06-23 17:49:23 -05:00
|
|
|
|
2009-11-28 12:40:26 -06:00
|
|
|
LOG_DEBUG("free BPID: %d --> %d", breakpoint->unique_id, retval);
|
2008-08-13 10:05:15 -05:00
|
|
|
(*breakpoint_p) = breakpoint->next;
|
|
|
|
free(breakpoint->orig_instr);
|
|
|
|
free(breakpoint);
|
|
|
|
}
|
|
|
|
|
2009-11-13 12:11:13 -06:00
|
|
|
void breakpoint_remove(struct target *target, uint32_t address)
|
2006-06-02 05:36:31 -05:00
|
|
|
{
|
2009-11-13 11:15:32 -06:00
|
|
|
struct breakpoint *breakpoint = target->breakpoints;
|
|
|
|
struct breakpoint **breakpoint_p = &target->breakpoints;
|
2009-06-23 17:49:23 -05:00
|
|
|
|
2006-06-02 05:36:31 -05:00
|
|
|
while (breakpoint)
|
|
|
|
{
|
|
|
|
if (breakpoint->address == address)
|
|
|
|
break;
|
|
|
|
breakpoint_p = &breakpoint->next;
|
|
|
|
breakpoint = breakpoint->next;
|
|
|
|
}
|
2009-06-23 17:49:23 -05:00
|
|
|
|
2006-06-02 05:36:31 -05:00
|
|
|
if (breakpoint)
|
|
|
|
{
|
2008-08-13 10:05:15 -05:00
|
|
|
breakpoint_free(target, breakpoint);
|
2006-06-02 05:36:31 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-06-20 22:16:09 -05:00
|
|
|
LOG_ERROR("no breakpoint at address 0x%8.8" PRIx32 " found", address);
|
2006-06-02 05:36:31 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-13 12:11:13 -06:00
|
|
|
void breakpoint_clear_target(struct target *target)
|
2008-08-13 10:05:15 -05:00
|
|
|
{
|
2009-11-13 11:15:32 -06:00
|
|
|
struct breakpoint *breakpoint;
|
2009-11-25 18:38:08 -06:00
|
|
|
|
|
|
|
LOG_DEBUG("Delete all breakpoints for target: %s",
|
2009-11-25 18:38:08 -06:00
|
|
|
target_name(target));
|
2009-06-23 17:38:12 -05:00
|
|
|
while ((breakpoint = target->breakpoints) != NULL)
|
2008-08-13 10:05:15 -05:00
|
|
|
{
|
|
|
|
breakpoint_free(target, breakpoint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-13 12:11:13 -06:00
|
|
|
struct breakpoint* breakpoint_find(struct target *target, uint32_t address)
|
2006-06-02 05:36:31 -05:00
|
|
|
{
|
2009-11-13 11:15:32 -06:00
|
|
|
struct breakpoint *breakpoint = target->breakpoints;
|
2009-06-23 17:49:23 -05:00
|
|
|
|
2006-06-02 05:36:31 -05:00
|
|
|
while (breakpoint)
|
|
|
|
{
|
|
|
|
if (breakpoint->address == address)
|
|
|
|
return breakpoint;
|
|
|
|
breakpoint = breakpoint->next;
|
|
|
|
}
|
2009-06-23 17:49:23 -05:00
|
|
|
|
2006-06-02 05:36:31 -05:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-11-13 12:11:13 -06:00
|
|
|
int watchpoint_add(struct target *target, uint32_t address, uint32_t length,
|
2009-11-05 03:47:44 -06:00
|
|
|
enum watchpoint_rw rw, uint32_t value, uint32_t mask)
|
2006-06-02 05:36:31 -05:00
|
|
|
{
|
2009-11-13 10:42:06 -06:00
|
|
|
struct watchpoint *watchpoint = target->watchpoints;
|
|
|
|
struct watchpoint **watchpoint_p = &target->watchpoints;
|
2006-06-02 05:36:31 -05:00
|
|
|
int retval;
|
2009-11-05 03:47:44 -06:00
|
|
|
char *reason;
|
2009-06-23 17:49:23 -05:00
|
|
|
|
2006-06-02 05:36:31 -05:00
|
|
|
while (watchpoint)
|
|
|
|
{
|
2009-11-05 03:47:44 -06:00
|
|
|
if (watchpoint->address == address) {
|
|
|
|
if (watchpoint->length != length
|
|
|
|
|| watchpoint->value != value
|
|
|
|
|| watchpoint->mask != mask
|
|
|
|
|| watchpoint->rw != rw) {
|
|
|
|
LOG_ERROR("address 0x%8.8" PRIx32
|
|
|
|
"already has watchpoint %d",
|
|
|
|
address, watchpoint->unique_id);
|
|
|
|
return ERROR_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ignore duplicate watchpoint */
|
2006-06-02 05:36:31 -05:00
|
|
|
return ERROR_OK;
|
2009-11-05 03:47:44 -06:00
|
|
|
}
|
2006-06-02 05:36:31 -05:00
|
|
|
watchpoint_p = &watchpoint->next;
|
|
|
|
watchpoint = watchpoint->next;
|
|
|
|
}
|
2009-06-23 17:49:23 -05:00
|
|
|
|
2009-11-13 10:42:06 -06:00
|
|
|
(*watchpoint_p) = calloc(1, sizeof(struct watchpoint));
|
2006-11-07 04:54:19 -06:00
|
|
|
(*watchpoint_p)->address = address;
|
|
|
|
(*watchpoint_p)->length = length;
|
|
|
|
(*watchpoint_p)->value = value;
|
|
|
|
(*watchpoint_p)->mask = mask;
|
|
|
|
(*watchpoint_p)->rw = rw;
|
2009-06-27 12:25:07 -05:00
|
|
|
(*watchpoint_p)->unique_id = bpwp_unique_id++;
|
2009-06-23 17:49:23 -05:00
|
|
|
|
2009-11-05 03:47:44 -06:00
|
|
|
retval = target_add_watchpoint(target, *watchpoint_p);
|
|
|
|
switch (retval) {
|
|
|
|
case ERROR_OK:
|
|
|
|
break;
|
|
|
|
case ERROR_TARGET_RESOURCE_NOT_AVAILABLE:
|
|
|
|
reason = "resource not available";
|
|
|
|
goto bye;
|
|
|
|
case ERROR_TARGET_NOT_HALTED:
|
|
|
|
reason = "target running";
|
|
|
|
goto bye;
|
|
|
|
default:
|
|
|
|
reason = "unrecognized error";
|
|
|
|
bye:
|
|
|
|
LOG_ERROR("can't add %s watchpoint at 0x%8.8" PRIx32 ", %s",
|
|
|
|
watchpoint_rw_strings[(*watchpoint_p)->rw],
|
|
|
|
address, reason);
|
|
|
|
free (*watchpoint_p);
|
|
|
|
*watchpoint_p = NULL;
|
|
|
|
return retval;
|
2006-06-02 05:36:31 -05:00
|
|
|
}
|
2009-06-23 17:49:23 -05:00
|
|
|
|
2009-11-12 16:21:33 -06:00
|
|
|
LOG_DEBUG("added %s watchpoint at 0x%8.8" PRIx32
|
|
|
|
" of length 0x%8.8" PRIx32 " (WPID: %d)",
|
|
|
|
watchpoint_rw_strings[(*watchpoint_p)->rw],
|
|
|
|
(*watchpoint_p)->address,
|
|
|
|
(*watchpoint_p)->length,
|
|
|
|
(*watchpoint_p)->unique_id );
|
2009-06-23 17:49:23 -05:00
|
|
|
|
2006-06-02 05:36:31 -05:00
|
|
|
return ERROR_OK;
|
|
|
|
}
|
|
|
|
|
2010-06-15 16:04:22 -05:00
|
|
|
static void watchpoint_free(struct target *target, struct watchpoint *watchpoint_to_remove)
|
2008-08-13 10:05:15 -05:00
|
|
|
{
|
2009-11-13 10:42:06 -06:00
|
|
|
struct watchpoint *watchpoint = target->watchpoints;
|
|
|
|
struct watchpoint **watchpoint_p = &target->watchpoints;
|
2009-11-28 12:40:26 -06:00
|
|
|
int retval;
|
2008-08-13 10:05:15 -05:00
|
|
|
|
|
|
|
while (watchpoint)
|
|
|
|
{
|
2010-06-15 16:04:22 -05:00
|
|
|
if (watchpoint == watchpoint_to_remove)
|
2008-08-13 10:05:15 -05:00
|
|
|
break;
|
|
|
|
watchpoint_p = &watchpoint->next;
|
|
|
|
watchpoint = watchpoint->next;
|
|
|
|
}
|
2009-06-23 17:49:23 -05:00
|
|
|
|
2009-06-23 17:42:03 -05:00
|
|
|
if (watchpoint == NULL)
|
2008-08-13 10:05:15 -05:00
|
|
|
return;
|
2009-11-28 12:40:26 -06:00
|
|
|
retval = target_remove_watchpoint(target, watchpoint);
|
|
|
|
LOG_DEBUG("free WPID: %d --> %d", watchpoint->unique_id, retval);
|
2008-08-13 10:05:15 -05:00
|
|
|
(*watchpoint_p) = watchpoint->next;
|
|
|
|
free(watchpoint);
|
|
|
|
}
|
|
|
|
|
2009-11-13 12:11:13 -06:00
|
|
|
void watchpoint_remove(struct target *target, uint32_t address)
|
2006-06-02 05:36:31 -05:00
|
|
|
{
|
2009-11-13 10:42:06 -06:00
|
|
|
struct watchpoint *watchpoint = target->watchpoints;
|
|
|
|
struct watchpoint **watchpoint_p = &target->watchpoints;
|
2009-06-23 17:49:23 -05:00
|
|
|
|
2006-06-02 05:36:31 -05:00
|
|
|
while (watchpoint)
|
|
|
|
{
|
|
|
|
if (watchpoint->address == address)
|
|
|
|
break;
|
|
|
|
watchpoint_p = &watchpoint->next;
|
|
|
|
watchpoint = watchpoint->next;
|
|
|
|
}
|
2009-06-23 17:49:23 -05:00
|
|
|
|
2006-06-02 05:36:31 -05:00
|
|
|
if (watchpoint)
|
|
|
|
{
|
2008-08-13 10:05:15 -05:00
|
|
|
watchpoint_free(target, watchpoint);
|
2006-06-02 05:36:31 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-06-20 22:16:09 -05:00
|
|
|
LOG_ERROR("no watchpoint at address 0x%8.8" PRIx32 " found", address);
|
2006-06-02 05:36:31 -05:00
|
|
|
}
|
|
|
|
}
|
2008-08-13 10:05:15 -05:00
|
|
|
|
2009-11-13 12:11:13 -06:00
|
|
|
void watchpoint_clear_target(struct target *target)
|
2008-08-13 10:05:15 -05:00
|
|
|
{
|
2009-11-13 10:42:06 -06:00
|
|
|
struct watchpoint *watchpoint;
|
2009-11-25 18:38:08 -06:00
|
|
|
|
|
|
|
LOG_DEBUG("Delete all watchpoints for target: %s",
|
2009-11-25 18:38:08 -06:00
|
|
|
target_name(target));
|
2009-06-23 17:38:12 -05:00
|
|
|
while ((watchpoint = target->watchpoints) != NULL)
|
2008-08-13 10:05:15 -05:00
|
|
|
{
|
|
|
|
watchpoint_free(target, watchpoint);
|
|
|
|
}
|
|
|
|
}
|