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

core/lib: make the use of DEBUG_BREAKPOINT on assert optional #19766

Merged
merged 2 commits into from
Jun 28, 2023

Conversation

gschorcht
Copy link
Contributor

Contribution description

This PR makes the use of DEBUG_BREAKPOINT on failed assertion optional.

The behavior of assert has been changed with PR #19368. Instead of printing some useful information, either a breakpoint is inserted and the execution of the MCU stops in debugger or a endless while loop is executed.

Before PR #19368 the user got on failed assertion:

Starting ESP32x with ID: 7cdfa1e36a34
ESP-IDF SDK Version v4.4.1-0-g1329b19fe49
...
*** RIOT kernel panic:
FAILED ASSERTION.

*** halted.

This was very helpful during development, especially to identify quickly the cause of problems with DEBUG_ASSERT_VERBOSE enabled, e.g. when misconfiguration led to failed assertions.

With PR #19368 the user gets an address in best case (or even 0 on platforms like ESP32), in worst case the MCU seems to stuck, e.g.

Starting ESP32x with ID: 7cdfa1e36a34
ESP-IDF SDK Version v4.4.1-0-g1329b19fe49
...
0

The problem with the new behavior is that

  • a user doesn't get a quick indication of what happened
  • there is not always an easy way to attach a debugger

This PR therefore makes the use of DEBUG_BREAKPOINT optional using DEBUG_ASSERT_BREAKPOINT define.

Testing procedure

Add assert(0) in examples/hello-world/main.c and compile with and w/o CFLAGS='-DDEBUG_ASSERT_BREAKPOINT'.

With DEBUG_ASSERT_BREAKPOINT the execution should stop in assert_failue. Without DEBUG_ASSERT_BREAKPOINT, the information as generated before PR #19368 and the execution should stop in panic_arch.

Issues/PRs references

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@gschorcht gschorcht requested a review from kaspar030 as a code owner June 27, 2023 15:25
@github-actions github-actions bot added the Area: core Area: RIOT kernel. Handle PRs marked with this with care! label Jun 27, 2023
@gschorcht gschorcht 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 labels Jun 27, 2023
@gschorcht gschorcht requested review from benpicco and maribu June 27, 2023 15:26
@riot-ci
Copy link

riot-ci commented Jun 27, 2023

Murdock results

✔️ PASSED

6eb358b tests/sys/sema_inv: boards with insufficient RAM

Success Failures Total Runtime
6930 0 6930 12m:17s

Artifacts

Copy link
Member

@maribu maribu left a comment

Choose a reason for hiding this comment

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

Makes sense. I think the reason this got in was that behavior on a break instruction when no debugger is attached is platform dependent. Some just treat the break instruction as a nop without a debugger attached, which would be fine here

@maribu
Copy link
Member

maribu commented Jun 27, 2023

bors merge

bors bot added a commit that referenced this pull request Jun 27, 2023
19766: core/lib: make the use of DEBUG_BREAKPOINT on assert optional r=maribu a=gschorcht

### Contribution description

This PR makes the use of `DEBUG_BREAKPOINT` on failed assertion optional.

The behavior of `assert` has been changed with PR #19368. Instead of printing some useful information, either a breakpoint is inserted and the execution of the MCU stops in debugger or a endless while loop is executed.

Before PR #19368 the user got on failed assertion:
```
Starting ESP32x with ID: 7cdfa1e36a34
ESP-IDF SDK Version v4.4.1-0-g1329b19fe49
...
*** RIOT kernel panic:
FAILED ASSERTION.

*** halted.
```
This was very helpful during development, especially to identify quickly the cause of problems with `DEBUG_ASSERT_VERBOSE` enabled, e.g. when misconfiguration led to failed assertions.

With PR #19368 the user gets an address in best case (or even `0` on platforms like ESP32), in worst case the MCU seems to stuck, e.g.
```
Starting ESP32x with ID: 7cdfa1e36a34
ESP-IDF SDK Version v4.4.1-0-g1329b19fe49
...
0
```
The problem with the new behavior is that
- a user doesn't get a quick indication of what happened
- there is not always an easy way to attach a debugger

This PR therefore makes the use of `DEBUG_BREAKPOINT` optional using `DEBUG_ASSERT_BREAKPOINT` define.

### Testing procedure

Add `assert(0)` in `examples/hello-world/main.c` and compile with and w/o `CFLAGS='-DDEBUG_ASSERT_BREAKPOINT'`.

With `DEBUG_ASSERT_BREAKPOINT` the execution should stop in `assert_failue`. Without `DEBUG_ASSERT_BREAKPOINT`, the information as generated before PR #19368 and the execution should stop in `panic_arch`.

### Issues/PRs references



Co-authored-by: Gunar Schorcht <[email protected]>
@bors
Copy link
Contributor

bors bot commented Jun 27, 2023

Build failed:

@maribu
Copy link
Member

maribu commented Jun 28, 2023

The CI failure is quite unexpected and interesting

@gschorcht
Copy link
Contributor Author

gschorcht commented Jun 28, 2023

The CI failure is quite unexpected and interesting

Compilation works with DEBUG_ASSERT_BREAKPOINT defined. So I guess that the compiler optimizes out something in assert so that the RAM is sufficient.

No wonder, you removed Atmega328p boards in Makefile.ci with 7e58bea 😉

@maribu
Copy link
Member

maribu commented Jun 28, 2023

No wonder, you removed Atmega328p boards in Makefile.ci with 7e58bea 😉

That one is not related. The commit allowing it to compile there was storing string literals (the first argument to printf() to be nore precise) in flash rather than in RAM for AVR, which requires some extra effort to do so.

@maribu
Copy link
Member

maribu commented Jun 28, 2023

Ahh, AVR doesn't implement ARCHITECTURE_BREAKPOINT() and the fallback is a spinning endless loop. That yields some optimization potential.

@gschorcht
Copy link
Contributor Author

gschorcht commented Jun 28, 2023

That one is not related. The commit allowing it to compile there was storing string literals (the first argument to printf() to be nore precise) in flash rather than in RAM for AVR,

OK 🤔 then the RAM usage has been increased after PR #19368 but we didn't notice that because it was previously reduced by PR #19368:

                   data   bss    total
Before PR #19368   212    1835   2047
After PR #19368    194    1835   2029

That is, without PR #19368 there was only one byte left 😎 With PR #19368 we had 19 Bytes left, but now we have only 7 bytes left, too less to reenable assert output 😟

                   data   bss    total
Current master     194	  1847   2041

@maribu
Copy link
Member

maribu commented Jun 28, 2023

Sorry if I made the impression that bumping Makefile.ci is an issue to me. It is not.

I just was confused as to why it was needed and thought that this may trigger (but not cause) an unrelated issue. But now that the reason is obvious, I can sleep well again.

@gschorcht
Copy link
Contributor Author

gschorcht commented Jun 28, 2023

That one is not related. The commit allowing it to compile there was storing string literals (the first argument to printf() to be nore precise) in flash rather than in RAM for AVR, which requires some extra effort to do so.

Indeed, reducing the string in this call reduces the RAM usage

core_panic(PANIC_ASSERT_FAIL, "FAILED ASSERTION.");

@github-actions github-actions bot added the Area: tests Area: tests and testing framework label Jun 28, 2023
@maribu
Copy link
Member

maribu commented Jun 28, 2023

bors retry

@bors
Copy link
Contributor

bors bot commented Jun 28, 2023

🕐 Waiting for PR status (GitHub check) to be set, probably by CI. Bors will automatically try to run when all required PR statuses are set.

@gschorcht
Copy link
Contributor Author

bors merge

@bors
Copy link
Contributor

bors bot commented Jun 28, 2023

Build succeeded!

The publicly hosted instance of bors-ng is deprecated and will go away soon.

If you want to self-host your own instance, instructions are here.
For more help, visit the forum.

If you want to switch to GitHub's built-in merge queue, visit their help page.

@bors bors bot merged commit d339984 into RIOT-OS:master Jun 28, 2023
@maribu
Copy link
Member

maribu commented Jun 28, 2023

Thx for the fix :)

@benpicco benpicco added this to the Release 2023.07 milestone Aug 2, 2023
@gschorcht gschorcht deleted the core/lib/assert_debug_breakpoint branch September 10, 2023 11:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: core Area: RIOT kernel. Handle PRs marked with this with care! Area: tests Area: tests and testing framework CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR 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.

None yet

4 participants