在尝试调试已内联的函数时、我会看到一些奇怪的问题。 我不会假装了解正在发生的情况、但我怀疑 CCS 调试器在代码被内联时会遇到一些问题。
为了让您了解我看到的内容、我生成了一个简单的逻辑位、加载上下文结构、然后将其传递到两个基本相同的函数、一个保留为可调用函数、另一个强制内联函数。 这两个函数都返回相同(正确)的结果、但通过调试器在函数执行中查看的结果肯定不正确。 我的演示逻辑如下所示、注释显示了我通过调试器看到的内容。
typedef struct { uint16_t integer1; } test_ctx_t; // inside main - removed bits that turn off watchdog etc test_ctx_t test_str; // This is located at 0x3BE8 uint16_t result; uint16_t result2; test_str.integer1 = 1234; // Set up some value in the test_str // Now return this value through inlined and callable code result = test (&test_str); // both return correctly as 1234 result2 = test2 (&test_str); .... // Now the two functions, which simply retrieve the value of the integer // from within the context structure, and returns ts. THe comments show what I // am seeing with the debugger inline uint16_t __attribute__((always_inline)) test (void *context_addr) { test_ctx_t *context; uint16_t some_integer; // the incoming context address is some gibberish value, and nothing like the // 0x3BE8 expected. context = (test_ctx_t *)context_addr; some_integer = context -> integer1; // Once cast to a test_ctx_t, it also contains gibberish. The value contained // in some_integer happens to be 16780, which should be what is returned??? return some_integer; // However, the value returned is the correct 1234 } uint16_t test2 (void *context_addr) { test_ctx_t *context; uint16_t some_integer; // the called function is debugged exactly as expected. The incoming address // is the 0x3BE8 as expected, containing the expected integer with a // value of 1234, which is returned context = (test_ctx_t *)context_addr; some_integer = context -> integer1; return some_integer; }
两个函数都返回正确的值这一事实表明编译器正在正确地管理内联函数。 但是、调试器 在函数本身内部跟踪该函数时似乎非常远。
是否有人可以对此添加任何见解? 我是否错过了它?
这一切都使用 MSP 5964上的 GCC 工具链。
谢谢- Andrew