Skip to content

Commit 52ca5d1

Browse files
authored
Ask the RTOS which target to set swbp on. (#673)
This lets the RTOS pick the "current" target, which matters if address translation differs between threads. Change-Id: I5b5510ab6a06621589c902f42a91562055817dc4 Signed-off-by: Tim Newsome <tim@sifive.com>
1 parent 6f3daf3 commit 52ca5d1

File tree

4 files changed

+35
-6
lines changed

4 files changed

+35
-6
lines changed

src/rtos/hwthread.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ static int hwthread_read_buffer(struct rtos *rtos, target_addr_t address,
4343
uint32_t size, uint8_t *buffer);
4444
static int hwthread_write_buffer(struct rtos *rtos, target_addr_t address,
4545
uint32_t size, const uint8_t *buffer);
46+
struct target *hwthread_swbp_target(struct rtos *rtos, target_addr_t address,
47+
uint32_t length, enum breakpoint_type type);
4648

4749
#define HW_THREAD_NAME_STR_SIZE (32)
4850

@@ -66,6 +68,7 @@ const struct rtos_type hwthread_rtos = {
6668
.needs_fake_step = hwthread_needs_fake_step,
6769
.read_buffer = hwthread_read_buffer,
6870
.write_buffer = hwthread_write_buffer,
71+
.swbp_target = hwthread_swbp_target
6972
};
7073

7174
struct hwthread_params {
@@ -444,3 +447,9 @@ static int hwthread_write_buffer(struct rtos *rtos, target_addr_t address,
444447

445448
return target_write_buffer(curr, address, size, buffer);
446449
}
450+
451+
struct target *hwthread_swbp_target(struct rtos *rtos, target_addr_t address,
452+
uint32_t length, enum breakpoint_type type)
453+
{
454+
return hwthread_find_thread(rtos->target, rtos->current_thread);
455+
}

src/rtos/rtos.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,3 +836,11 @@ int rtos_write_buffer(struct target *target, target_addr_t address,
836836
return target->rtos->type->write_buffer(target->rtos, address, size, buffer);
837837
return ERROR_NOT_IMPLEMENTED;
838838
}
839+
840+
struct target *rtos_swbp_target(struct target *target, target_addr_t address,
841+
uint32_t length, enum breakpoint_type type)
842+
{
843+
if (target->rtos->type->swbp_target)
844+
return target->rtos->type->swbp_target(target->rtos, address, length, type);
845+
return target;
846+
}

src/rtos/rtos.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#define OPENOCD_RTOS_RTOS_H
2121

2222
#include "server/server.h"
23+
#include "target/breakpoints.h"
2324
#include "target/target.h"
2425
#include <helper/jim-nvp.h>
2526

@@ -103,6 +104,12 @@ struct rtos_type {
103104
uint8_t *buffer);
104105
int (*write_buffer)(struct rtos *rtos, target_addr_t address, uint32_t size,
105106
const uint8_t *buffer);
107+
/* When a software breakpoint is set, it is set on only one target,
108+
* because we assume memory is shared across them. By default this is the
109+
* first target in the SMP group. Override this function to have
110+
* breakpoint_add() use a different target. */
111+
struct target * (*swbp_target)(struct rtos *rtos, target_addr_t address,
112+
uint32_t length, enum breakpoint_type type);
106113
};
107114

108115
struct stack_register_offset {
@@ -166,5 +173,7 @@ int rtos_read_buffer(struct target *target, target_addr_t address,
166173
uint32_t size, uint8_t *buffer);
167174
int rtos_write_buffer(struct target *target, target_addr_t address,
168175
uint32_t size, const uint8_t *buffer);
176+
struct target *rtos_swbp_target(struct target *target, target_addr_t address,
177+
uint32_t length, enum breakpoint_type type);
169178

170179
#endif /* OPENOCD_RTOS_RTOS_H */

src/target/breakpoints.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "target.h"
2727
#include <helper/log.h>
2828
#include "breakpoints.h"
29+
#include "rtos/rtos.h"
2930

3031
static const char * const breakpoint_type_strings[] = {
3132
"hardware",
@@ -218,14 +219,16 @@ int breakpoint_add(struct target *target,
218219
{
219220
int retval = ERROR_OK;
220221
if (target->smp) {
221-
struct target_list *head;
222-
struct target *curr;
223-
head = target->head;
224-
if (type == BKPT_SOFT)
225-
return breakpoint_add_internal(head->target, address, length, type);
222+
struct target_list *head = target->head;
223+
if (type == BKPT_SOFT) {
224+
struct target *curr = head->target;
225+
if (target->rtos)
226+
curr = rtos_swbp_target(target, address, length, type);
227+
return breakpoint_add_internal(curr, address, length, type);
228+
}
226229

227230
while (head) {
228-
curr = head->target;
231+
struct target *curr = head->target;
229232
retval = breakpoint_add_internal(curr, address, length, type);
230233
if (retval != ERROR_OK)
231234
return retval;

0 commit comments

Comments
 (0)