Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

target/riscv: report helpfull location during register decode #972

Merged
merged 2 commits into from
Dec 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/target/riscv/riscv-013.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,16 +297,23 @@ static riscv_debug_reg_ctx_t get_riscv_debug_reg_ctx(struct target *target)
}

static void log_debug_reg(struct target *target, enum riscv_debug_reg_ordinal reg,
riscv_reg_t value)
riscv_reg_t value, const char *file, unsigned int line, const char *func)
{
if (debug_level < LOG_LVL_DEBUG)
return;
const riscv_debug_reg_ctx_t context = get_riscv_debug_reg_ctx(target);
char buf[riscv_debug_reg_to_s(NULL, reg, context, value) + 1];
char * const buf = malloc(riscv_debug_reg_to_s(NULL, reg, context, value) + 1);
if (!buf) {
LOG_ERROR("Unable to allocate memory.");
return;
}
riscv_debug_reg_to_s(buf, reg, context, value);
LOG_TARGET_DEBUG(target, "%s", buf);
log_printf_lf(LOG_LVL_DEBUG, file, line, func, "[%s] %s", target_name(target), buf);
free(buf);
}

#define LOG_DEBUG_REG(t, r, v) log_debug_reg(t, r##_ORDINAL, v, __FILE__, __LINE__, __func__)

static uint32_t set_dmcontrol_hartsel(uint32_t initial, int hart_index)
{
assert(hart_index != HART_INDEX_UNKNOWN);
Expand Down Expand Up @@ -864,7 +871,7 @@ static int execute_abstract_command(struct target *target, uint32_t command)
if (debug_level >= LOG_LVL_DEBUG) {
switch (get_field(command, DM_COMMAND_CMDTYPE)) {
case 0:
log_debug_reg(target, AC_ACCESS_REGISTER_ORDINAL, command);
LOG_DEBUG_REG(target, AC_ACCESS_REGISTER, command);
break;
default:
LOG_TARGET_DEBUG(target, "command=0x%x", command);
Expand Down Expand Up @@ -1860,7 +1867,7 @@ static int examine(struct target *target)
}

LOG_TARGET_DEBUG(target, "dtmcontrol=0x%x", dtmcontrol);
log_debug_reg(target, DTM_DTMCS_ORDINAL, dtmcontrol);
LOG_DEBUG_REG(target, DTM_DTMCS, dtmcontrol);

if (get_field(dtmcontrol, DTM_DTMCS_VERSION) != 1) {
LOG_TARGET_ERROR(target, "Unsupported DTM version %" PRIu32 ". (dtmcontrol=0x%" PRIx32 ")",
Expand Down
Loading