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

OpenOCD return error when using GDB to hit hardware breakpoints on hardware that doesn't support them. #1034

Closed
Alan-19950616 opened this issue Mar 26, 2024 · 11 comments

Comments

@Alan-19950616
Copy link

I think it's better to report a warning when this behaviour is detected than to report an error outright.

reporting an error will cause GDB to disconnect

return ERROR_FAIL;

@en-sc
Copy link
Collaborator

en-sc commented Mar 26, 2024

You mention hardware breakpoints in the name of the issue. However, the line you are referring to is related to processing of software breakpoints:

if (target->rtos && bp_type == BKPT_SOFT) {

Are you sure you have determined the source of the issue correctly?

Please, attach OpenOCD -d3 log of the reproduction if it's not too much trouble.

@Alan-19950616
Copy link
Author

Sorry, I got the wrong line number.

retval = gdb_error(connection, retval);

@en-sc
Copy link
Collaborator

en-sc commented Mar 26, 2024

AFAIU, ERROR_NOT_IMPLEMENTED should be returned here by watchpoint_add().

Please, attach OpenOCD -d3 log so it is possible to figure out why watchpoint_add() does not return ERROR_NOT_IMPLEMENTED in the case in question.

@Alan-19950616
Copy link
Author

OpenOCD log

Info : [riscv.cpu] Found 0 triggers
Error: Couldn't find an available hardware trigger.
Error: can't add breakpoint: resource not available

OpenOCD -d3 log

84595 Error: 84593 31200 riscv.c:673 add_trigger(): Couldn't find an available hardware trigger.
84596 Error: 84594 31200 breakpoints.c:93 breakpoint_add_internal(): can't add breakpoint: resource not available
84597 Debug: 84595 31200 gdb_server.c:1495 gdb_error(): Reporting -308 to GDB as generic error

@aap-sc
Copy link
Collaborator

aap-sc commented Mar 27, 2024

ERROR_NOT_IMPLEMENTED is returned if OpenOCD does not implement something (not the target). Here the behavior is as expected. You try to set a HW breakpoint -> you have no available resources -> you get an error. GDB should not disconnect in such a case. Which GDB version are you using?

@Alan-19950616
Copy link
Author

GDB version GNU gdb (GDB) 13.2.90.20230712-git

I want to make sure that the error code is #define ERROR_TARGET_RESOURCE_NOT_AVAILABLE (-308) and not #define ERROR_NOT_IMPLEMENTED (-7).

@aap-sc
Copy link
Collaborator

aap-sc commented Mar 27, 2024

I want to make sure that the error code is 

Again, OpenOCD should return ERROR_TARGET_RESOURCE_NOT_AVAILABLE here since no HW resources available. ERROR_NOT_IMPLEMENTED is for the cases when something is not impleneted in OpenOCD itself.

Here is the debug session from gdb 13.2:

(gdb) watch *(int*)0x0
Hardware watchpoint 1: *(int*)0x0
(gdb) c
Continuing.
Warning:
Could not insert hardware watchpoint 1.
Could not insert hardware breakpoints:
You may have requested too many hardware breakpoints/watchpoints.

Command aborted.
(gdb) q

GDB is not disconnected. it simply aborts the "continue" command since it can't set HW watchpoint.

@Alan-19950616
Copy link
Author

That's the problem I'm having, and I'm not expressing it clearly.

At this point it is not possible to use commands such as continue or single-step unless the hardware breakpoint is removed, is it possible to just warn without returning an error?

@aap-sc
Copy link
Collaborator

aap-sc commented Mar 27, 2024

At this point it is not possible to use commands such as continue or single-step unless the hardware breakpoint is removed, is it possible to just warn without returning an error?

But that's the intended behavior for GDB. You've explicitly asked to set a HW watchpoint. GDB is unable to do so. GDB is unable to proceed unless you cancel this request.

@TommyMurphyTM1234
Copy link
Collaborator

TommyMurphyTM1234 commented Mar 27, 2024

If you're trying to report and analyse an OpenOCD issue then it might make more sense to use OpenOCD standalone and its Telnet interface to interact with the program/target obviating the need for GDB and thus simplifying the diagnosis?

Also, the code that you're referring to in gdb_server.c is target neutral code in OpenOCD so, almost certainly, should not be changed specifically for RISC-V. Such a modification is unlikely to be accepted upstream in any case.

@aap-sc
Copy link
Collaborator

aap-sc commented Jun 5, 2024

I presume that the question is answered. The behavior you have is the expected one. Let us know if you think that there is something that needs to be changed.

@aap-sc aap-sc closed this as completed Jun 5, 2024
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

No branches or pull requests

4 participants