Msg/FunctionNestCount

From CPUlator Wiki

< Msg
Revision as of 08:47, 11 March 2019 by Henry (talk | contribs)

A function is called from a caller, runs some code, and then returns to its caller. Although a function may call other functions (possibly recursively), it is unusual for the function call depth to be very large. This warning tells you that you have exceeded 32 nested function calls.

This isn't technically an error, but if this behaviour is not expected, it is likely indicative of a bug.

Examples

ARMv7

.global _start
_start:
	nop
	bl NotAFunction		// This is a function call, but the target doesn't behave like a function (no return).
    nop
NotAFunction:	
    b _start

Nios II

.global _start
_start:
	nop
	call NotAFunction		# This is a function call, but the target doesn't behave like a function (no return).
    nop
NotAFunction:	
    br _start

The call at line 4 repeatedly calls a function that never returns. The function call depth increases by one every time the call is executed. The Call stack will show a stack of calls originating from line 4.

Debugging

  • Make sure functions are returning, not stuck in an unending recursion.
  • Make sure you do not use a call (or branch-and-link) instruction when the intention is to use a regular branch instruction.
  • Use the Call stack window (located in the same panel as the registers window) to see where the function calls are occurring. The top entry is the current PC. Each entry below that is the location of the call instruction in the function one nesting level up.
  • The Trace window may also be useful to see the last 200 instructions executed.

Implementation

The simulator tracks idiomatic call and return instructions and counts the function call nesting depth. This message is generated at a call instruction when the new call depth exceeds 32.

Disabling this message

This debugging check can be disabled in the Debugging Checks section of the Settings box: Function nesting too deep.