简体   繁体   English

如何调试包装在 __asm volatile 修饰符中的代码?

[英]How to debug code wrapped in __asm volatile modifier?

I am trying to debug why my FreeRTOS integration does not work.我正在尝试调试为什么我的 FreeRTOS 集成不起作用。 I am seeing that it breaks when vRestoreContextOfFirstTask is called.我看到调用vRestoreContextOfFirstTask时它会中断。 Inside this function, I see some code wrapped in __asm volatile modifier.在这个 function 中,我看到一些代码包含在__asm volatile修饰符中。 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).有没有办法通过 printf 调试来逐步解决这个问题,这样我就可以知道哪些指令中断(我已经有 UART 设置来转储一些调试输出)。

An example of a function that I would like to debug:我想调试的 function 示例:

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.不,您不能插入printf() It would break the intention of the asm volatile block as a kind of atomic sequence of instructions.它会破坏asm volatile块作为一种原子指令序列的意图。 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.实际上,错误应该显示中断指令的确切地址。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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