Skip to content

Commit e307df1

Browse files
target/riscv/riscv.c: support auto-selection of software breakpoint size
Add auto-selection of breakpoint size for RISC-V targets. The new length depends on C extension. If the C extension is used, the auto-selected length is 2 bytes. Otherwise, the default length is 4 bytes. Change-Id: Ie3473514beace15b76714aa6d5441122cd3262aa Signed-off-by: Kulyatskaya Alexandra <a.kulyatskaya@syntacore.com>
1 parent 6f84e90 commit e307df1

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/target/riscv/riscv.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,6 +1609,16 @@ static int riscv_add_breakpoint(struct target *target, struct breakpoint *breakp
16091609
LOG_TARGET_DEBUG(target, "@0x%" TARGET_PRIxADDR, breakpoint->address);
16101610
assert(breakpoint);
16111611
if (breakpoint->type == BKPT_SOFT) {
1612+
if (breakpoint->length == 0) {
1613+
breakpoint->length = riscv_supports_extension(target, 'c') ? 2 : 4;
1614+
uint8_t *instr_buffer = (uint8_t *)realloc (breakpoint->orig_instr, breakpoint->length);
1615+
if (!instr_buffer) {
1616+
LOG_ERROR("Fail to realloc memory with original instruction");
1617+
return ERROR_FAIL;
1618+
}
1619+
breakpoint->orig_instr = instr_buffer;
1620+
}
1621+
16121622
/** @todo check RVC for size/alignment */
16131623
if (!(breakpoint->length == 4 || breakpoint->length == 2)) {
16141624
LOG_TARGET_ERROR(target, "Invalid breakpoint length %d", breakpoint->length);

0 commit comments

Comments
 (0)