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

Error print improvements #10358

Merged
merged 4 commits into from Apr 17, 2019

Conversation

Projects
None yet
5 participants
@kjbracey-arm
Copy link
Contributor

commented Apr 9, 2019

Description

Fixes two key problems:

  • mbed_error or MBED_ASSERT failure could fail to output if the console had not previously been used
  • mbed_error or MBED_ASSERT failure would be garbled if platform.stdio-buffered-serial was true but platform.stdio-convert-newlines was false.

Getting the console initialized for the first time in a fatal crash situation is always going to be potentially dicey, but we can make a better effort.

(If a platform is really serious about getting crash information out of the serial port, they should make an effort to get it ready in advance. But we don't necessarily want to initialise it if they're not planning to use it in normal operation.)

Fixes #10344, fixes #10242.

Pull request type

[X] Fix
[ ] Refactor
[ ] Target update
[ ] Functionality change
[ ] Docs update
[ ] Test update
[ ] Breaking change

kjbracey-arm added some commits Apr 9, 2019

Fix UARTSerial emergency unbuffered write
The length calculation in UARTSerial::write_unbuffered was wrong,
meaning it would truncate output data to half length.

This would show up if `platform.stdio-buffered-serial` was configured to
true, `platform.stdio-convert-newlines` was still false - `mbed_error`
crashes would be garbled.

This wasn't usually spotted because applications generally have both
settings false or both true, and if newline conversion is on, then
`mbed_error_puts` writes 1 character at a time to FileHandle::write,
avoiding the length error.
mbed_assert_failure: Don't take critical section
Assert failure took a critical section before calling `mbed_error`.

There's no need to take a critical section on assert failure -
mbed_error does not do this, and is designed to operate from normal
contexts.

Avoiding the critical section will improve the chances of console
initialisation due to assert failure working nicely.
mbed_error_puts: Prime STDERR_FILENO before writing
Prime the console outside the critical section, improving the chances of
nice initialisation.

@ciarmcom ciarmcom requested review from ARMmbed/mbed-os-maintainers Apr 9, 2019

@ciarmcom

This comment has been minimized.

Copy link
Member

commented Apr 9, 2019

@kjbracey-arm, thank you for your changes.
@ARMmbed/mbed-os-core @ARMmbed/mbed-os-maintainers please review.

Show resolved Hide resolved rtos/TARGET_CORTEX/mbed_rtx_handlers.c
Show resolved Hide resolved rtos/TARGET_CORTEX/mbed_rtx_handlers.c Outdated
Don't trap RTX errors or mutex errors during errors
Once a fatal error is in progress, it's not useful to trap RTX errors
or mutex problems, so short-circuit the checks.

This makes it more likely that we may be able to get the console
initialised if it is being written to for the first time by `mbed_error`
in a difficult context - such as an RTX error callback from inside an
SVCall.

For example, the one-line program

   osMutexAcquire(NULL, 0);

will generate an RTX error trap, then `mbed_error` will try to call
`write(STDERR_FILENO)` to print the error, which will prompt mbed_retarget to
construct a singleton `UARTSerial`. This would trap in the mutex
for the singleton or the construction of the UARTSerial itself, if
we didn't allow this leniency. If we clear the mutex checks, then
`UARTSerial::write_unbuffered` will work.

@kjbracey-arm kjbracey-arm force-pushed the kjbracey-arm:error_print_improvements branch from 67cfca4 to b8e80dd Apr 15, 2019

@mbed-ci

This comment has been minimized.

Copy link

commented Apr 17, 2019

Test run: SUCCESS

Summary: 11 of 11 test jobs passed
Build number : 1
Build artifacts

@0xc0170 0xc0170 added ready for merge and removed needs: CI labels Apr 17, 2019

@0xc0170 0xc0170 merged commit 94898a1 into ARMmbed:master Apr 17, 2019

26 checks passed

continuous-integration/jenkins/pr-head This commit looks good
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
jenkins-ci/build-ARM Success
Details
jenkins-ci/build-GCC_ARM Success
Details
jenkins-ci/build-IAR Success
Details
jenkins-ci/cloud-client-test Success
Details
jenkins-ci/dynamic-memory-usage Success
Details
jenkins-ci/exporter Success
Details
jenkins-ci/greentea-test Success
Details
jenkins-ci/mbed2-build-ARM Success
Details
jenkins-ci/mbed2-build-GCC_ARM Success
Details
jenkins-ci/mbed2-build-IAR Success
Details
jenkins-ci/unittests Success
Details
travis-ci/astyle Success!
Details
travis-ci/docs Success!
Details
travis-ci/doxy-spellcheck Success!
Details
travis-ci/events Success! Runtime is 9440 cycles.
Details
travis-ci/gitattributestest Success!
Details
travis-ci/include_check Success!
Details
travis-ci/licence_check Success!
Details
travis-ci/littlefs Success! Code size is 8448B.
Details
travis-ci/psa-autogen Success!
Details
travis-ci/tools-py2.7 Success!
Details
travis-ci/tools-py3.5 Success!
Details
travis-ci/tools-py3.6 Success!
Details
travis-ci/tools-py3.7 Success!
Details

@kjbracey-arm kjbracey-arm deleted the kjbracey-arm:error_print_improvements branch Apr 17, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.