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

gdb_server,rtos: Differentiate rtos_get_gdb_reg failing and not imple… #925

Merged
merged 2 commits into from
Oct 11, 2023

Conversation

timsifive
Copy link
Collaborator

…mented

If it fails, then pass that failure on. If it's simply not implemented, then we can fall through and try target_get_gdb_reg_list_noread().

This difference matters when the target representing the current hwthread is unavailable, but the target that is linked to the gdb connection is available. In that case we want the operation to return an error to gdb, instead of reading the register from the target that is available.

Change-Id: I9c84ca556f818c5580e25ab349a34a226fcf0f43

…mented

If it fails, then pass that failure on. If it's simply not implemented,
then we can fall through and try target_get_gdb_reg_list_noread().

This difference matters when the target representing the current
hwthread is unavailable, but the target that is linked to the gdb
connection is available. In that case we want the operation to return an
error to gdb, instead of reading the register from the target that is
available.

Change-Id: I9c84ca556f818c5580e25ab349a34a226fcf0f43
Signed-off-by: Tim Newsome <tim@sifive.com>
@JanMatCodasip
Copy link
Collaborator

I will be able to review this one (and also #926, #927) tomorrow morning.

src/rtos/rtos.c Outdated
@@ -591,7 +591,7 @@ int rtos_get_gdb_reg(struct connection *connection, int reg_num)

free(reg_list);
}
return ERROR_FAIL;
return ERROR_NOT_IMPLEMENTED;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, this looks all right to me. I have just two suggestions:

  1. Code style: For readability, I'd recommend to use here the early-return code structure, as shown below.

  2. What should be returned at the very end of the function, that is if the reg_num is not found in reg_list? I believe it should be ERROR_FAIL.

int rtos_get_gdb_reg(...)
{
    if ( (!target->rtos) || 
        current_threadid == -1 ||
        current_threadid == 0 ||
        /* ... */ ) {
        /* early return */
        return ERROR_NOT_IMPLEMENTED;
    }

    /* The rest of the algorithm continues here */
    /* ... */
    /* ... */

    /* What should be returned if we reach the end? */
    LOG_ERROR("Did not find register number %d in RTOS register list", reg_num);
    return ERROR_FAIL; 
    
    /* or */

    return ERROR_NOT_IMPLEMENTED;
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Thanks.

Exit early if conditions aren't satisfied, instead of putting the core
code inside an if().

Also return ERROR_FAIL if conditions are satisfied but no matching
registers were found.

Change-Id: I77aa63d9f707bc38d1a71899275ba603914b52c9
Signed-off-by: Tim Newsome <tim@sifive.com>
@timsifive timsifive merged commit 6f4b90a into riscv Oct 11, 2023
5 checks passed
@timsifive timsifive deleted the unavailable_reg branch October 11, 2023 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants