Setting up heap and stack size

Sysprogs forums Forums VisualGDB Setting up heap and stack size

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #7793
    bernardofca
    Participant

    What is the right way to setup the size of the heap and stack in a VisualGDB project? (STM32 processor).

    I am getting conflicting information from Google!

    #7794
    support
    Keymaster

    Hi,

    The default implementation of malloc()/free() that comes with GCC starts the heap immediately after the end of the data segment and extends it dynamically until it intersects with the stack pointer at the moment of the extension.

    If you want to set the explicit heap limit, you can do this by providing your own implementation to the _sbrk() function that will stop growing the heap once it reaches the given address. Let us know if you need more details.

    #7801
    bernardofca
    Participant

    Thanks for the response. Yes, I have seen the information regarding _sbrk()…

    I am trying to debug a problem whereby global variables are overwritten when jumping to a function. With the debugger I see that the corruption has occurred during the jump. It looks like a stack corruption but I cannot find the problem (yet!).

    #7802
    support
    Keymaster

    Hi,

    You can try setting a memory breakpoint via the Breakpoints window. It will trigger once any code writes to that variable.

    #7819
    bernardofca
    Participant

    For the record in case someone looks at this thread:

    I agree that the default setting of the heap and stack works well (this is really an issue if one is running an OS). My problem was caused by a function that had local variables that were consuming a huge amount of stack space. The problem was not easy to find because the data corruption was happening randomly on function calls (but not necessarily on the offending one). I was able to find the problem by stepping through the program and monitoring the stack pointer. When I stepped in the offending function, I saw a huge jump in the stack.

    #7821
    support
    Keymaster

    Hi,

    Thanks for letting us know. We will consider adding a feature to monitor the stack pointer validity to VisualGDB 5.2.

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.