This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
Remove noreturn attribute for __assert_func on embedded build
- From: PaweÅ <pawelwod at wp dot pl>
- To: newlib at sourceware dot org
- Date: Thu, 06 Feb 2014 08:19:12 +0100
- Subject: Remove noreturn attribute for __assert_func on embedded build
- Authentication-results: sourceware.org; auth=none
On my Cortex M I implemented simple __assert_func() as bellow
void __assert_func(const char *_file, int _line, const char *_func,
const char *_expr )
{
(void)_file;
(void)_line;
(void)_func;
(void)_expr;
volatile int loop = 1;
__asm volatile ("bkpt 0");
do { ; } while( loop );
}
And when some assert expression fails I get debbuger attentions. After
program stops I can return from this function. This is handy when assert
fails in ISR but I have spotted that sometimes debuger shows broken
backtrace.
I had replaced assert() with
if( !( ... ) )
__asm volatile ("bkpt 0");
and this works so I suppose that noreturn attribute is a problem. In
disassembly I see that compiler does not generates proper code:
void HardFault_Handler( void )
{
/*volatile int do_exit = 0;
while( !do_exit )
__asm volatile ( "bkpt 0" );
*/
assert( 0 );
}
void BusFault_Handler( void )
{
assert( 0 );
}
HardFault_Handler:
08006a48: push {r7, lr}
08006a4a: add r7, sp, #0
396 assert( 0 );
08006a4c: movw r0, #52476 ; 0xccfc
08006a50: movt r0, #2049 ; 0x801
08006a54: mov.w r1, #396 ; 0x18c
08006a58: movw r2, #52588 ; 0xcd6c
08006a5c: movt r2, #2049 ; 0x801
08006a60: movw r3, #52528 ; 0xcd30
08006a64: movt r3, #2049 ; 0x801
08006a68: bl 0x8006b10 <__assert_func>
400 {
BusFault_Handler:
08006a6c: push {r7, lr}
08006a6e: add r7, sp, #0
401 assert( 0 );
08006a70: movw r0, #52476 ; 0xccfc
08006a74: movt r0, #2049 ; 0x801
08006a78: movw r1, #401 ; 0x191
08006a7c: movw r2, #52568 ; 0xcd58
08006a80: movt r2, #2049 ; 0x801
08006a84: movw r3, #52528 ; 0xcd30
08006a88: movt r3, #2049 ; 0x801
08006a8c: bl 0x8006b10 <__assert_func>
405 {
UsageFault_Handler:
08006a90: push {r7, lr}
08006a92: add r7, sp, #0