-
Notifications
You must be signed in to change notification settings - Fork 3k
Change behaviour of mbed_asert to use mbed_error instead of mbed_die #8255
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
Conversation
CC @SenRamakri |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @SenRamakri,
Could you confirm is MBED_ERROR_INVALID_ARGUMENT
the correct error status to be used in this case?
If not, could you suggest one?
Everything else looks OK to me.
@MateuszMaz - Please define a new error code for "assertion failed" in mbed_error.h as below - |
The output now is:
|
platform/mbed_assert.c
Outdated
|
||
const char error_description[] = "Mbed assertation failed "; | ||
unsigned error_message_length = strlen(error_description) + strlen(expr) + 1; | ||
char error_message[error_message_length]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does anyone know if variable-length arrays are totally safe in IRQ-disabled context? Possibly are, but a bit wary about potential heap fallback rather than using the stack.
Even then, using the stack is possibly hairy if big - would it be possible to reuse the static buffer that mbed_error_printf uses?
Or do we even need a buffer? Could mbed_error be persuaded to print something about assertion failure itself from the error code, so we just pass expr
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kjbracey-arm - I think that make sense, lets have mbed_error.c handle creating the message in print_error_report() function. We already do that for few special error codes. That way mbed_assert_internal() can just pass the expr.
Also print_error_report() is wrapped with right flags.
@MateuszMaz - Can you please make these changes to just pass the expr into mbed_error and have print_error_report() function cook the message(Eg:- "Assertion failed", no need to prepend that with Mbed) for assertion fails.
platform/mbed_error.h
Outdated
@@ -780,7 +780,8 @@ typedef enum _mbed_error_code { | |||
MBED_DEFINE_SYSTEM_ERROR(BLE_NO_FRAME_INITIALIZED, 65), /* 321 BLE No frame initialized */ | |||
MBED_DEFINE_SYSTEM_ERROR(BLE_BACKEND_CREATION_FAILED, 66), /* 322 BLE Backend creation failed */ | |||
MBED_DEFINE_SYSTEM_ERROR(BLE_BACKEND_NOT_INITIALIZED, 67), /* 323 BLE Backend not initialized */ | |||
|
|||
MBED_DEFINE_SYSTEM_ERROR(ASSERTATION_FAILED, 68), /* 324 Assertation Failed */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Assertation" is barely a word - could you correct it to "assertion" before baking it into API?
( I've already got a PR pending which corrects the text: #8076 . Been sitting unreviewed for over 3 weeks though. )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you update the GitHub message to show the final output?
platform/mbed_error.c
Outdated
@@ -349,6 +349,10 @@ static void print_error_report(mbed_error_ctx *ctx, const char *error_msg) | |||
mbed_error_printf("MessageQueue: 0x%X, ", ctx->error_value); | |||
break; | |||
|
|||
case MBED_ERROR_CODE_ASSERTION_FAILED: | |||
mbed_error_printf("Assertion failed, ", ctx->error_value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You want to have :
here not ,
, so the output is Asssertion failed: expression
.
The comma was to separate the error_value
, which has been left in - drop it.
This should resolve #6850 |
Making sure I understand, this PR needs to come in before #8076 (comment), correct? |
platform/mbed_error.c
Outdated
@@ -349,6 +349,10 @@ static void print_error_report(mbed_error_ctx *ctx, const char *error_msg) | |||
mbed_error_printf("MessageQueue: 0x%X, ", ctx->error_value); | |||
break; | |||
|
|||
case MBED_ERROR_CODE_ASSERTION_FAILED: | |||
mbed_error_printf("Assertion failed: ", ctx->error_value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still has the stray ctx->error_value
.
(You should ideally be getting a warning about that, but unfortunately there's no format checking directives on mbed_error_printf
. I am intending to add some to all the local printf
-type functions).
It should now be independent - I've revised #8076 to avoid collision. |
|
||
void mbed_assert_internal(const char *expr, const char *file, int line) | ||
{ | ||
core_util_critical_section_enter(); | ||
mbed_error_printf("mbed assertation failed: %s, file: %s, line %d \n", expr, file, line); | ||
mbed_die(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this function no longer need mbed_die()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nvm, looked over the PR again and it looks ok.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mbed_die is called but after error processing, just like any other error, next addition to removal is mbed_error()
Line 200 in e6ae3d2
WEAK mbed_error_status_t mbed_error(mbed_error_status_t error_status, const char *error_msg, unsigned int error_value, const char *filename, int line_number) |
|
||
void mbed_assert_internal(const char *expr, const char *file, int line) | ||
{ | ||
core_util_critical_section_enter(); | ||
mbed_error_printf("mbed assertation failed: %s, file: %s, line %d \n", expr, file, line); | ||
mbed_die(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nvm, looked over the PR again and it looks ok.
/morph build |
It's just come to my attention that there is a significant functional change here - this is going to only output filenames if I don't think that's a reason to block this PR - I think the PR is sound. The problem is in the way mbed_error works - it should be accepting and printing filenames and line numbers even if it isn't "storing" them. I think we'll need to follow that up after #8255 and #8076. The filename conditions for "assert" should not be inherently the same as the filename conditions for "error" or "warning", as assert otherwise only has a not-fully-identifying expression, whereas "error" and "warning" can be expected to have identifying text, making the filename redundant. |
@SenRamakri Fyi ^^^ /morph build |
Build : SUCCESSBuild number : 3358 Triggering tests/morph test |
Exporter Build : SUCCESSBuild number : 2993 |
Test : SUCCESSBuild number : 3163 |
Created #8441 to make sure full filename is always shown by MBED_ASSERT, plus more fixes. |
/morph mbed2-build |
/morph mbed2-build |
Bringing this in, but it makes me a but uneasy that I can't rerun the unittest due to it's age (build 140). |
Description
@jamesbeyond @0xc0170 @mprse
Task: IOTCORE-378
This PR changes behaviour of mbed_assert to use mbed_error, instead of mbed_die that goes around new error reporting mechanism.
The output of following example when flag MBED_CONF_PLATFORM_ERROR_FILENAME_CAPTURE_ENABLED = 1:
is:
Pull request type