I have a bit of a puzzle. My code has a stack guard that should call "error_shutdown" function if stack is corrupted (-fstack-protector gcc option), but somehow it seems it's called when it should not have been according to ETM trace.
The error_shutdown is declared as no-return function with the "noreturn" attribute (source link if you want to look at full code):
Display All
The issue is that that ETM trace shows instructions from the "error_shutdown" are executed, which should make the program halt. See piece of pasted trace below and also the attached screenshot. For some reason "error_shutdown" shows up in the ETM trace a lot.
Even if I put breakpoints at the instructions of "error_shutdown" shown in screenshot, the breakpoint never occurs, but it's still shown in ETM trace.
Part of CSV exported from the ETM trace (read from bottom to up, this is the ordering in the export) - you can see branch to the error_shutdown function:
Display All
The question is: how is this possible? May it be some optimizations? I use -Og for the debugging which should be suitable for debugging. There is obvious branching to the error_shutdown function, yet no breakpoint catches it and somehow the program recoveres from it. Is there some speculative execution that this could be? I am at loss and I spent days on trying to find out what is going on.
The error_shutdown is declared as no-return function with the "noreturn" attribute (source link if you want to look at full code):
C Source Code
The issue is that that ETM trace shows instructions from the "error_shutdown" are executed, which should make the program halt. See piece of pasted trace below and also the attached screenshot. For some reason "error_shutdown" shows up in the ETM trace a lot.
Even if I put breakpoints at the instructions of "error_shutdown" shown in screenshot, the breakpoint never occurs, but it's still shown in ETM trace.
Part of CSV exported from the ETM trace (read from bottom to up, this is the ordering in the export) - you can see branch to the error_shutdown function:
Source Code
- 953122,08097200,F7FFFB6A,4,$Thumb,BL,"SDMMC_GetCmdResp2 ; 0x080968D8",,
- 953121,080971FE,4628,2,$Thumb,MOV,"R0, R5",,
- 953120,0809835C,10004006,4,$Data,DC32,"0x40061000",,"}"
- 953119,0806DB52,D102,2,$Thumb,BNE,"0x0806DB5A",,"return DISPLAY_ORIENTATION;"
- 953118,0806DB4E,681B,2,$Thumb,LDR,"R3, [R3]",,
- 953117,0806DB4A,9A01,2,$Thumb,LDR,"R2, [SP, #4]",,
- 953116,0806DB48,6818,2,$Thumb,LDR,"R0, [R3]",,
- 953115,0806DB46,4B07,2,$Thumb,LDR,"R3, =DISPLAY_ORIENTATION ; [0x0806DB64] =0x20000010",,
- 953114,0806DB44,FD514B07,2,$Thumb,,"",,"display_set_orientation(degrees);"
- 953113,0806DB42,F7FEFD51,4,$Thumb,BL,"display_set_orientation ; 0x0806C5E8",,
- 953112,0806DB40,6018,2,$Thumb,STR,"R0, [R3]",,"DISPLAY_ORIENTATION = degrees;"
- 953111,0806DB3E,4B09,2,$Thumb,LDR,"R3, =DISPLAY_ORIENTATION ; [0x0806DB64] =0x20000010",,
- 953110,0806DB24,9301,2,$Thumb,STR,"R3, [SP, #4]",,"int display_orientation(int degrees) {"
- 953109,0806DB22,681B,2,$Thumb,LDR,"R3, [R3]",,
- 953108,0806DB20,4B0F,2,$Thumb,LDR,"R3, =__stack_chk_guard ; [0x0806DB60] =0x20002AA4",,
- 953107,0806DB1E,B083,2,$Thumb,SUB,"SP, SP, #12",,
- 953106,0806DB1C,B500,2,$Thumb,PUSH,"{LR}",display_orientation,
- 953105,080981F4,F7D5FC92,4,$Thumb,BL,"display_orientation ; 0x0806DB1C",,"display_orientation(0);"
- 953104,080981F2,2000,2,$Thumb,MOVS,"R0, #0",,
- 953103,080981F0,9305,2,$Thumb,STR,"R3, [SP, #20]",,"const char *line4) {"
- 953102,080981EE,681B,2,$Thumb,LDR,"R3, [R3]",,
- 953101,080981EC,4B34,2,$Thumb,LDR,"R3, =__stack_chk_guard ; [0x080982C0] =0x20002AA4",,
- 953100,080981EA,461D,2,$Thumb,MOV,"R5, R3",,
- 953099,080981E8,4616,2,$Thumb,MOV,"R6, R2",,
- 953098,080981E6,460F,2,$Thumb,MOV,"R7, R1",,
- 953097,080981E4,4604,2,$Thumb,MOV,"R4, R0",,
- 953096,080981E2,B086,2,$Thumb,SUB,"SP, SP, #24",,
- 953095,080981E0,B580,2,$Thumb,PUSH,"{R7, LR}",error_shutdown,
- 953094,08098376,F7FFFF33,4,$Thumb,BL,"error_shutdown ; 0x080981E0",,"error_shutdown("Internal error", "(SS)", NULL, NULL);"
The question is: how is this possible? May it be some optimizations? I use -Og for the debugging which should be suitable for debugging. There is obvious branching to the error_shutdown function, yet no breakpoint catches it and somehow the program recoveres from it. Is there some speculative execution that this could be? I am at loss and I spent days on trying to find out what is going on.