Stack Overflow Question

This is a discussion on Stack Overflow Question within the Tech Board forums, part of the Community Boards category; With some of you guys with experience in embedded systems, I wanted to ask a question regarding overflowing the stack. ...

  1. #1
    Registered User carrotcake1029's Avatar
    Join Date
    Apr 2008
    Posts
    398

    Stack Overflow Question

    With some of you guys with experience in embedded systems, I wanted to ask a question regarding overflowing the stack.

    Typically, you define what areas of memory are used for in the linker directive. Now lets say you split up some memory for multiple uses. We currently have it so that if we overflow the stack, we run into memory regions we own already, however we are still getting a watchdog reset. The region that it happens to flow into isn't used for about 5KB so it has some space available.

    We have defined however in the linker directive how much space should be used for the stack. Are there internal protection operations going on within the controller that could cause us to get a reset even if we are still using space allocated to us? I ask this because we don't actually have access to the low level code of the microcontroller. We load executable code in other regions, and we have a less than cooperative vendor.

    FYI, we are using a MPC5566 if anyone happens to be familiar. I wouldn't even mind just having an explanation of what results are typical in a situation like this since I have no background in this field.

    Thanks.

  2. #2
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,246
    By looking at the reference manual for the MPC5566, I see it has an MMU and thus in theory could implement stack overflow protection if the boundaries of things are page-aligned in a certain way. Basically it's up to the "OS" which, sounds like is controlled by your vendor.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,588
    > The region that it happens to flow into isn't used for about 5KB so it has some space available.
    So is there any chance of filling this with zeros, and then seeing if it's been overwritten when you've caught the WDR.

    Do you have JTAG debuggers for this board?

    Is your code massively recursive, have large local arrays, or variable length arrays? If it has none of these things, then how would it cause stack overflow?

    Is there an RTOS on the board, or is it just your code on the bare metal?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User carrotcake1029's Avatar
    Join Date
    Apr 2008
    Posts
    398
    So is there any chance of filling this with zeros, and then seeing if it's been overwritten when you've caught the WDR.
    We have no doubts we are overflowing the stack, we just want to know the cause of the reset.
    Do you have JTAG debuggers for this board?
    We do have JTAG debuggers, however we may lack the expertise to use them. I'm sure I could read a manual and figure it out. The issue is mostly that we are having problems regarding things outside the scope of our skillset.
    Is your code massively recursive, have large local arrays, or variable length arrays? If it has none of these things, then how would it cause stack overflow?
    We have identified in the software using stack analysis tools that we are allocating too much stack space. We are fine with this since we have discovered this, but we are really concerned with what is causing the watchdog reset.
    Is there an RTOS on the board, or is it just your code on the bare metal?
    I'm fairly certain we have an RTOS, but am not entirely certain.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stack overflow
    By alperen1994 in forum C Programming
    Replies: 5
    Last Post: 04-06-2009, 11:11 AM
  2. Stack Overflow
    By ldb88 in forum C++ Programming
    Replies: 4
    Last Post: 07-24-2007, 09:07 AM
  3. stack overflow
    By TechHigh in forum C Programming
    Replies: 12
    Last Post: 01-11-2007, 12:49 PM
  4. Stack Overflow
    By madmardigan53 in forum C++ Programming
    Replies: 2
    Last Post: 08-10-2003, 12:32 PM
  5. stack overflow...need help
    By Unregistered in forum C Programming
    Replies: 12
    Last Post: 06-18-2002, 01:54 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21