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

RISC-V Semihosting 3 of 3: Warn if encountered but disabled #1200

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
26 changes: 19 additions & 7 deletions src/target/riscv/riscv_semihosting.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,32 +110,44 @@ enum semihosting_result riscv_semihosting(struct target *target, int *retval)
struct semihosting *semihosting = target->semihosting;
assert(semihosting);

if (!semihosting->is_active) {
LOG_TARGET_DEBUG(target, "Semihosting outcome: NONE (semihosting not enabled)");
return SEMIHOSTING_NONE;
}

riscv_reg_t pc;
int result = riscv_reg_get(target, &pc, GDB_REGNO_PC);
if (result != ERROR_OK) {
LOG_TARGET_DEBUG(target, "Semihosting outcome: ERROR (failed to read PC)");
return SEMIHOSTING_ERROR;
}

bool sequence_found;
bool sequence_found = false;
*retval = riscv_semihosting_detect_magic_sequence(target, pc, &sequence_found);
if (*retval != ERROR_OK) {
LOG_TARGET_DEBUG(target, "Semihosting outcome: ERROR (during magic seq. detection)");
return SEMIHOSTING_ERROR;
}

if (!semihosting->is_active) {
if (sequence_found) {
// If semihositing is encountered but disabled, provide an additional hint to the user.
LOG_TARGET_WARNING(target, "RISC-V semihosting call encountered in the program "
"but semihosting is disabled!");
LOG_TARGET_WARNING(target, "The target will remain halted (PC = 0x%" TARGET_PRIxADDR ").", pc);
LOG_TARGET_WARNING(target, "Hint: Restart your debug session and enable semihosting "
"by command 'arm semihosting enable'.");
// TODO: This can be improved: The ebreak halt cause detection and riscv_semihosting() call
// can be added also to "arm semihosting enable", which would allow the user to continue
// without restart of the debug session.
}

LOG_TARGET_DEBUG(target, "Semihosting outcome: NONE (semihosting not enabled)");
return SEMIHOSTING_NONE;
}

if (!sequence_found) {
LOG_TARGET_DEBUG(target, "Semihosting outcome: NONE (no magic sequence)");
return SEMIHOSTING_NONE;
}

/* Otherwise we have a semihosting call (and semihosting is enabled).
* Proceed with the semihosting. */
* Proceed with the handling of semihosting. */

/*
* Perform semihosting call if we are not waiting on a fileio
Expand Down
Loading