12 retrieving the call stack, 13 viewing global variables, Retrieving the call stack -33 – ElmoMC SimplIQ Software Manual User Manual

Page 95: Viewing global variables -33

Advertising
background image

SimplIQ

Software Manual

Program Development and Execution

MAN-SIMSW (Ver. 1.4)

6-33

6.7.12 Retrieving the Call Stack

There is no direct command for retrieving a call stack. The IDE manager executes all debug
analysis.

Example (more details provided in

section 8.2

):

Stack Pointer
Relative to
Base Pointer



Meaning



Remarks

BP-5

Saved previous BP

BP is 0 for first called function

BP-4

Return address

Program counter of next
program line after function call

BP-3

Index of current function in
Function Symbol table

See section

A.5.5

.

BP-2

Number of input arguments

BP-1

Number of actual output arguments Number of left-hand values

during function call

This information can assist in restoring a call stack as follows:
When the first function is called, its BP is zero. Every subsequent function during its call saves
the previous base pointer in the stack at BP-5, so that it can restore BP upon return from the
function. To get the entire call stack, the previous base pointer must be rolled back in the loop
until BP becomes zero. The process to restore the call stack is as follows:
ƒ DB##PS[N];

Get

current

status

ƒ

Check current status: if it is not halted, return an error.

ƒ BP_last = BP;

Get current BP from data returned by DB##PS

ƒ N1 = 0;

Index of the bottom of the stack

ƒ N2 = SP;

Index of the top of the stack

ƒ DB##GS=N1,N2;

Get

entire

stack

ƒ do

Start

do-while loop until BP_last is not 0

ƒ funcIndex = BP_last - 3 ;

Get called function index in Symbol table and insert

in call stack

ƒ if (BP_last == 0) break ;

This is the first called function

ƒ BP_last = BP_last - 5 :

Update

BP_last

ƒ while (1)

End

of

do-while loop

6.7.13 Viewing Global Variables

Global variables may be accessed through the Interpreter; there is no need for a special
debug command.

Advertising