Skip to content

Commit 07a6ab0

Browse files
committed
Fix for filename capture not working
1 parent dbc42f6 commit 07a6ab0

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

platform/mbed_error.c

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -129,16 +129,10 @@ mbed_error_status_t handle_error(mbed_error_status_t error_status, const char *e
129129

130130
#ifdef MBED_CONF_ERROR_FILENAME_CAPTURE_ENABLED
131131
//Capture filename/linenumber if provided
132-
//Index for tracking error_filename
133-
int idx = 0;
134-
135-
if(NULL != filename) {
136-
while(idx < MBED_CONF_MAX_ERROR_FILENAME_LEN && (filename[idx] != '\0')) {
137-
current_error_ctx.error_filename[idx] = filename[idx];
138-
idx++;
139-
}
140-
current_error_ctx.error_line_number = line_number;
141-
}
132+
//Index for tracking error_filename
133+
memset(&current_error_ctx.error_filename, 0, MBED_CONF_MAX_ERROR_FILENAME_LEN);
134+
strncpy(current_error_ctx.error_filename, filename, MBED_CONF_MAX_ERROR_FILENAME_LEN);
135+
current_error_ctx.error_line_number = line_number;
142136
#endif
143137

144138
//Capture the fist system error and store it
@@ -359,7 +353,7 @@ static void print_error_report(mbed_error_ctx *ctx, const char *error_msg)
359353
uint32_t error_code = MBED_GET_ERROR_CODE(ctx->error_status);
360354
uint32_t error_module = MBED_GET_ERROR_MODULE(ctx->error_status);
361355

362-
mbed_error_printf("\n\n++ MbedOS Error Info ++\nError Status: 0x%x Code: %d Entity: %d\nError Message: ", ctx->error_status, error_code, error_module);
356+
mbed_error_printf("\n\n++ MbedOS Error Info ++\nError Status: 0x%x Code: %d Module: %d\nError Message: ", ctx->error_status, error_code, error_module);
363357

364358
//Report error info based on error code, some errors require different
365359
//error_vals[1] contains the error code
@@ -410,12 +404,10 @@ static void print_error_report(mbed_error_ctx *ctx, const char *error_msg)
410404
}
411405
mbed_error_printf(error_msg, NULL);
412406
mbed_error_printf("\nLocation: 0x%x", ctx->error_address);
413-
#ifdef MBED_CONF_ERROR_FILENAME_CAPTURE_ENABLED
414-
if(NULL != error_ctx->error_filename) {
407+
#if defined(MBED_CONF_ERROR_FILENAME_CAPTURE_ENABLED) && !defined(NDEBUG)
408+
if(NULL != ctx->error_filename) {
415409
//for string, we must pass address of a ptr which has the address of the string
416-
uint32_t *file_name = (uint32_t *)&error_ctx->error_filename[0];
417-
mbed_error_printf("\nFile:%s", &file_name);
418-
mbed_error_printf("+0x%x", ctx->error_line_number);
410+
mbed_error_printf("\nFile:%s+%d", ctx->error_filename, ctx->error_line_number);
419411
}
420412
#endif
421413

0 commit comments

Comments
 (0)