简体   繁体   中英

How to debug code wrapped in __asm volatile modifier?

I am trying to debug why my FreeRTOS integration does not work. I am seeing that it breaks when vRestoreContextOfFirstTask is called. Inside this function, I see some code wrapped in __asm volatile modifier. Is there a way to step through this by printf debugging so I can tell which instruction breaks (I already have UART setup to dump some debug output).

An example of a function that I would like to debug:

void SVC_Handler( void ) /* __attribute__ (( naked )) PRIVILEGED_FUNCTION */

{

    __asm volatile    
    (    
        "   movs r0, #4                                     \n"
        "   mov r1, lr                                      \n"
        "   tst r0, r1                                      \n"
        "   beq stacking_used_msp                           \n"
        "   mrs r0, psp                                     \n"
        "   ldr r2, svchandler_address_const                \n"
        "   bx r2                                           \n"
        " stacking_used_msp:                                \n"
        "   mrs r0, msp                                     \n"
        "   ldr r2, svchandler_address_const                \n"
        "   bx r2                                           \n"
        "                                                   \n"
        "   .align 4                                        \n"
        "svchandler_address_const: .word vPortSVCHandler_C  \n"
    );
}

No, you cannot insert printf() s. It would break the intention of the asm volatile block as a kind of atomic sequence of instructions. It would change contents of registers, for example.

Use your debugger and single-step on assembly level, if you need to watch it. Or let it run and see what the debugger tells you about the exact location.

Actually the error should reveal the exact address of the breaking instruction.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM