Msg/FunctionNestCount: Difference between revisions
From CPUlator Wiki
< Msg
No edit summary |
No edit summary |
||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
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. | 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. | ||
Deep function call nesting isn't technically an error. If your program really uses more than 32 nested functions, disable this warning. If not, this is likely indicative of a bug. | |||
=== Examples === | |||
==== ARMv7 ==== | |||
<syntaxhighlight line lang="Asm" highlight="4"> | |||
.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 | |||
</syntaxhighlight> | |||
==== Nios II ==== | |||
<syntaxhighlight line lang="Asm" highlight="4"> | |||
.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 | |||
</syntaxhighlight> | |||
==== MIPS ==== | |||
<syntaxhighlight line lang="Asm" highlight="4"> | |||
.global _start | |||
_start: | |||
nop | |||
jal NotAFunction # This is a function call, but the target doesn't behave like a function (no return). | |||
nop | |||
NotAFunction: | |||
b _start | |||
</syntaxhighlight> | |||
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 === | === Debugging === |
Latest revision as of 04:06, 17 March 2019
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.
Deep function call nesting isn't technically an error. If your program really uses more than 32 nested functions, disable this warning. If not, this 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
MIPS
.global _start
_start:
nop
jal NotAFunction # This is a function call, but the target doesn't behave like a function (no return).
nop
NotAFunction:
b _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.