From f18fd83ac7219cd1e5e62a121e6cd6474e5f53dc Mon Sep 17 00:00:00 2001
From: Tim Newsome <tim@sifive.com>
Date: Mon, 3 Jul 2017 11:52:35 -0700
Subject: [PATCH] Fix trigger set/clear bug.

---
 src/target/riscv/riscv-013.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/target/riscv/riscv-013.c b/src/target/riscv/riscv-013.c
index 86f5f1b42..ab5b993ce 100644
--- a/src/target/riscv/riscv-013.c
+++ b/src/target/riscv/riscv-013.c
@@ -832,7 +832,7 @@ static int add_trigger(struct target *target, struct trigger *trigger)
 
 		uint64_t tdata1_rb;
 		for (int hartid = 0; hartid < riscv_count_harts(target); ++hartid) {
-			if (!riscv_hart_enabled(target, i))
+			if (!riscv_hart_enabled(target, hartid))
 				continue;
 
 			riscv_set_current_hartid(target, hartid);
@@ -921,7 +921,7 @@ static int remove_trigger(struct target *target, struct trigger *trigger)
 	}
 	LOG_DEBUG("Stop using resource %d for bp %d", i, trigger->unique_id);
 	for (int hartid = 0; hartid < riscv_count_harts(target); ++hartid) {
-		if (!riscv_hart_enabled(target, i))
+		if (!riscv_hart_enabled(target, hartid))
 			continue;
 
 		riscv_set_current_hartid(target, hartid);