UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Visitor vgimonkar
Visitor
641 Views
Registered: ‎07-06-2018

Debugging Microblaze for stack overflow

Jump to solution

Hello,

I am running a program on microblaze and I suspect that my stack is getting overflowed causing a crash in microblaze.

While building the microblaze we didnt add any exception flags and also we dont have access to printf.

The way I am debugging this crash is getting the stack pointer from via register int *stack_ptr asm("r1");

and from a MAP file generated while building the microblaze, I get the stack start address. 

eg: .stack          0x00008c50      0x400

I know the stack end address based on the size of the stack. So stackSize/4 gives me the total pointers it can store.

I am calculating the percentageStackUsed = ((float)((void *)stack_ptr - (void*)stackStartAddr)*(stackSize/4))*100;

I am passing this variable percentageStackUsed to a common location were we can read out the number every other second. But I am not seeing any reasonable values.

I am not sure if this is a correct way to debug stackOverflow in microblaze. If this community has some suggestions please let me know

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
Visitor vgimonkar
Visitor
570 Views
Registered: ‎07-06-2018

Re: Debugging Microblaze for stack overflow

Jump to solution

Hi Johnmcd,

thank you for your reply,

do you think using the stack_ptr ("r1") will give me the current location of stack? I was thinking my approach should tell me if the stack overflowed?

I will try your approach 2. next

0 Kudos
3 Replies
Xilinx Employee
Xilinx Employee
569 Views
Registered: ‎02-01-2008

Re: Debugging Microblaze for stack overflow

Jump to solution

A few thoughts:

  1. enable the microblaze 'Enable Stack Protection' option in the microblaze 'Exception' tab
  2. fill stack memory with a known value, after running app for a while, stop and review how much memory was changed from known value
  3. Use chipscope to monitor the axi or lmb addresses used
  4. connect chipscope to the microblaze trace port and set appropriate triggers
0 Kudos
Visitor vgimonkar
Visitor
571 Views
Registered: ‎07-06-2018

Re: Debugging Microblaze for stack overflow

Jump to solution

Hi Johnmcd,

thank you for your reply,

do you think using the stack_ptr ("r1") will give me the current location of stack? I was thinking my approach should tell me if the stack overflowed?

I will try your approach 2. next

0 Kudos
Xilinx Employee
Xilinx Employee
539 Views
Registered: ‎02-01-2008

Re: Debugging Microblaze for stack overflow

Jump to solution

I've never tried using asm("r1") so did a quick test and it appears to work for me.

1.png

0 Kudos