This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Get call stack problem

Hi,master:

   platform:nrf52840

   IDE:keil compiler version 5

  tool chain: armcc

     There are multiple calls to a function in the product. I suspect that there is a problem with this function in some cases. When a condition is met in this function, I add a log. The log information includes who is calling this function at this time. I want to use lr to analyze, but in this environment, I wrote some assembly code and couldn't get lr, because the compilation failed:

Is there any way to achieve who is calling this function when there is a problem?

Thanks

  • Hi,

    With Keil you can do something like this to get the LR,PC and SP:

    Another approach, is to add a extra context variable in the function call.

    Pseudo code:

  • Not sure if it helps, but you can use cmsis_gcc.h to get info  __get_PSP() and __get_MSP() for process and main stack pointers, plus other stuff.

  • Hi,

             Thank you very much for sharing. This is the answer I want. In addition, I would like to ask, is there any way to know the calling method of a function through code implementation in software? Similar to keil's call stack.

    Thanks.

  • Hi, 

      Thank you for your answer,Others gave me the answer

  • You can try looking up where the function is located with arm-none-eabi-addr2line, and with the LR value and .axf file as input (.axf is generated when you compile the Keil project)

    You will then get the name of the .c file and line-number.

    e.g. ..\..\..\..\..\..\components\libraries\queue\/nrf_queue.c:451

1 2