Skip to content

openocd: Use reset halt when starting debug-server#10479

Closed
jnohlgard wants to merge 2 commits intoRIOT-OS:masterfrom
jnohlgard:openocd/debug-server-reset
Closed

openocd: Use reset halt when starting debug-server#10479
jnohlgard wants to merge 2 commits intoRIOT-OS:masterfrom
jnohlgard:openocd/debug-server-reset

Conversation

@jnohlgard
Copy link
Copy Markdown
Member

Contribution description

Makes the debug-server start up more robust, especially when combined with reset_config connect_assert_srst in the OpenOCD configuration.

Testing procedure

With any board with an onboard debugger interface and using OpenOCD:

make debug-server

Verify that the OpenOCD instance can connect to the board and that the application running is halted (e.g. does not respond to UART shell commands anymore, software controlled LEDs stop blinking etc.)

in a different terminal:

make debug

(This will attempt to start another instance of openocd, but that will fail since the same UDP port is already used by the running debug-server instance)

See that GDB works as expected:

continue

Verify that the application is running.

Press CTRL+C in GDB, verify that GDB has managed to halt the application.

Issues/PRs references

@jnohlgard jnohlgard added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Area: tools Area: Supplementary tools labels Nov 27, 2018
@jnohlgard jnohlgard added this to the Release 2019.01 milestone Nov 27, 2018
@jnohlgard jnohlgard requested a review from aabadie November 27, 2018 14:46
-c 'init' \
-c 'targets' \
-c 'halt'"
-c 'reset halt'"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Instead of this, maybe we could reuse ${OPENOCD_DBG_START_CMD} like in do_debug. This allows boards requiring this to override start command.

@jnohlgard jnohlgard force-pushed the openocd/debug-server-reset branch from 4d65bbd to 761726d Compare November 27, 2018 22:07
@jnohlgard
Copy link
Copy Markdown
Member Author

Modified to reuse OPENOCD_DBG_START_CMD for both debug and debug-server. Changed the default command to be reset halt instead of only halt

# the target when starting a debug session. 'reset halt' can also be used
# depending on the type of target.
: ${OPENOCD_DBG_START_CMD:=-c 'halt'}
: ${OPENOCD_DBG_START_CMD:=-c \'reset halt\'}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This needs to be discussed a bit more. See #8976 where I tried to set this default to boards using st-link.
The problem with this change is that by default one cannot attach to the current state of a running application.

Makes the OpenOCD start up more robust, especially when combined
with reset_config connect_assert_srst in the target configuration.
@aabadie aabadie force-pushed the openocd/debug-server-reset branch from 731cdcd to df08a86 Compare March 14, 2019 09:28
'reset halt' is now the default value for OpenOCD
@aabadie
Copy link
Copy Markdown
Contributor

aabadie commented Mar 14, 2019

To move forward on this, I allowed myself to rebase this PR and slightly update it: variable documentation is updated in openocd.sh and the default value used for this variable in a some boards (f1 based + b-l072Z-lrwan1 boards) is removed from the makefile, since now it's using the openocd default value.

@cladmi, are you interested in having a look ?

@cladmi
Copy link
Copy Markdown
Contributor

cladmi commented Mar 14, 2019

I can try on a few boards indeed.

Is this saying we are indeed going toward putting connect_assert_srst by default ?
I have some waiting commits to enable it on some boards https://github.com/RIOT-OS/RIOT/pull/10870/commits
If you have an easy way (even arch specific) to put a board into a non flashable mode without this option, I would gladly add a test for it. I know the tests/driver_adt7310 test was a good one to break some of the mentioned boards.

@kaspar030
Copy link
Copy Markdown
Contributor

This means running "make debug" would always reset a board? do we want that?

I sometimes realize a board is stuck somewhere, then connect the debugger to see where it got stuck.

@aabadie
Copy link
Copy Markdown
Contributor

aabadie commented Mar 14, 2019

This means running "make debug" would always reset a board? do we want that?

By default yes, but one can still have the non reset behaviour by passing OPENOCD_DBG_START_CMD="-c 'halt'" to the command line.

@cladmi
Copy link
Copy Markdown
Contributor

cladmi commented Mar 14, 2019

@kaspar030 currently there are many cases where doing make flash does not flash because the CPU is in an un-handled state. This breaks all testing possibilities and I would put it with a bigger priority even if our default configuration also resets when debugging.

@kaspar030
Copy link
Copy Markdown
Contributor

@kaspar030 currently there are many cases where doing make flash does not flash because the CPU is in an un-handled state.

Then add the corresponding reset halt to the flash command. I don't understand what that has to do with starting the gdb server.

@aabadie
Copy link
Copy Markdown
Contributor

aabadie commented Mar 14, 2019

There is a confusion here. This PR is just about debug. Having reset halt before starting the debug-server fixes gdb connection when connect_assert_srst is used by the openocd configuration. This option is useful when the CPU is in sleep mode (otherwise OpenOCD is not able to reflash it without manual interaction)

@aabadie aabadie self-requested a review March 15, 2019 06:48
@fjmolinas
Copy link
Copy Markdown
Contributor

Is this one still relevant? with OPENOCD_RESET_USE_CONNECT_ASSERT_SRST there is no issue when launching make debug, @aabadie do you agree?

@fjmolinas
Copy link
Copy Markdown
Contributor

ping @aabadie!

@leandrolanzieri
Copy link
Copy Markdown
Contributor

ping!

@benpicco
Copy link
Copy Markdown
Contributor

benpicco commented Apr 1, 2020

I agree with @kaspar030 here. I too will use make debug to see where the code got stuck, the default behavior shouldn't be to reset the CPU here.

If you want to start debugging in a defined state, how about adding a reset-debug target instead?

@leandrolanzieri leandrolanzieri removed this from the Release 2020.04 milestone Apr 8, 2020
@stale
Copy link
Copy Markdown

stale bot commented Oct 10, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions.

@stale stale bot added the State: stale State: The issue / PR has no activity for >185 days label Oct 10, 2020
@stale stale bot closed this Nov 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: tools Area: Supplementary tools CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR State: stale State: The issue / PR has no activity for >185 days Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants