Stack traces: Difference between revisions
Content added Content deleted
(Added Wren) |
m (→{{header|Phix}}: added syntax colouring the hard way) |
||
Line 1,491: | Line 1,491: | ||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
There no standard method of obtaining a stack trace mid-run (as yet, non-fatally that is), but we can quickly cobble something together: |
There no standard method of obtaining a stack trace mid-run (as yet, non-fatally that is), but we can quickly cobble something together: |
||
<lang Phix> |
<!--<lang Phix>--> |
||
<span style="color: #008080;">constant</span> <span style="color: #000000;">W</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">machine_word</span><span style="color: #0000FF;">(),</span> |
|||
{RTN,PREVEBP} = iff(W=4?{8,20}:{16,40}) |
|||
<span style="color: #0000FF;">{</span><span style="color: #000000;">RTN</span><span style="color: #0000FF;">,</span><span style="color: #000000;">PREVEBP</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #000000;">W</span><span style="color: #0000FF;">=</span><span style="color: #000000;">4</span><span style="color: #0000FF;">?{</span><span style="color: #000000;">8</span><span style="color: #0000FF;">,</span><span style="color: #000000;">20</span><span style="color: #0000FF;">}:{</span><span style="color: #000000;">16</span><span style="color: #0000FF;">,</span><span style="color: #000000;">40</span><span style="color: #0000FF;">})</span> |
|||
procedure show_stack() |
|||
<span style="color: #008080;">procedure</span> <span style="color: #000000;">show_stack</span><span style="color: #0000FF;">()</span> |
|||
sequence symtab, symtabN |
|||
<span style="color: #004080;">sequence</span> <span style="color: #000000;">symtab</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">symtabN</span> |
|||
integer rtn |
|||
<span style="color: #004080;">integer</span> <span style="color: #000000;">rtn</span> |
|||
atom prev_ebp |
|||
<span style="color: #004080;">atom</span> <span style="color: #000000;">prev_ebp</span> |
|||
#ilASM{ |
|||
#ilASM{ |
|||
[32] |
|||
lea edi,[symtab] |
|||
call :%opGetST -- [edi]=symtab (ie our local:=the real symtab) |
|||
call :%opGetST -- [edi]=symtab (ie our local:=the real symtab) |
|||
mov |
mov edi,[ebp+20] -- prev_ebp |
||
mov [ |
mov eax,[edi+8] -- calling routine no |
||
mov |
mov [rtn],eax |
||
mov eax,edi |
|||
lea edi,[prev_ebp] |
|||
call :%pStoreMint |
|||
[64] |
|||
lea rdi,[symtab] |
|||
call :%opGetST -- [rdi]=symtab (ie our local:=the real symtab) |
|||
call :%opGetST -- [rdi]=symtab (ie our local:=the real symtab) |
|||
mov |
mov rdi,[rbp+40] -- prev_ebp |
||
mov [ |
mov rax,[rdi+16] -- calling routine no |
||
mov |
mov [rtn],rax |
||
mov rax,rdi |
|||
lea rdi,[prev_ebp] |
|||
call :%pStoreMint |
|||
[] |
|||
⚫ | |||
while rtn!=21 do -- (T_maintls, main top level routine, always present) |
|||
<span style="color: #008080;">while</span> <span style="color: #000000;">rtn</span><span style="color: #0000FF;">!=</span><span style="color: #000000;">21</span> <span style="color: #008080;">do</span> <span style="color: #000080;font-style:italic;">-- (T_maintls, main top level routine, always present)</span> |
|||
symtabN = symtab[rtn] |
|||
<span style="color: #000000;">symtabN</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">symtab</span><span style="color: #0000FF;">[</span><span style="color: #000000;">rtn</span><span style="color: #0000FF;">]</span> |
|||
?symtabN[1] |
|||
<span style="color: #0000FF;">?</span><span style="color: #000000;">symtabN</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span> |
|||
prev_ebp = peekNS(prev_ebp+PREVEBP,W,0) |
|||
<span style="color: #000000;">prev_ebp</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">peekNS</span><span style="color: #0000FF;">(</span><span style="color: #000000;">prev_ebp</span><span style="color: #0000FF;">+</span><span style="color: #000000;">PREVEBP</span><span style="color: #0000FF;">,</span><span style="color: #000000;">W</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0</span><span style="color: #0000FF;">)</span> |
|||
rtn = peekNS(prev_ebp+RTN,W,0) |
|||
<span style="color: #000000;">rtn</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">peekNS</span><span style="color: #0000FF;">(</span><span style="color: #000000;">prev_ebp</span><span style="color: #0000FF;">+</span><span style="color: #000000;">RTN</span><span style="color: #0000FF;">,</span><span style="color: #000000;">W</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0</span><span style="color: #0000FF;">)</span> |
|||
end while |
|||
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span> |
|||
end procedure |
|||
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span> |
|||
procedure three(bool die) |
|||
<span style="color: #008080;">procedure</span> <span style="color: #000000;">three</span><span style="color: #0000FF;">(</span><span style="color: #004080;">bool</span> <span style="color: #000000;">die</span><span style="color: #0000FF;">)</span> |
|||
if die then |
|||
<span style="color: #008080;">if</span> <span style="color: #000000;">die</span> <span style="color: #008080;">then</span> |
|||
⚫ | |||
<span style="color: #0000FF;">?</span><span style="color: #000000;">9</span><span style="color: #0000FF;">/</span><span style="color: #000000;">0</span> |
|||
else |
|||
<span style="color: #008080;">else</span> |
|||
show_stack() |
|||
<span style="color: #000000;">show_stack</span><span style="color: #0000FF;">()</span> |
|||
end if |
|||
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span> |
|||
end procedure |
|||
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span> |
|||
procedure two(bool die) |
|||
<span style="color: #008080;">procedure</span> <span style="color: #000000;">two</span><span style="color: #0000FF;">(</span><span style="color: #004080;">bool</span> <span style="color: #000000;">die</span><span style="color: #0000FF;">)</span> |
|||
three(die) |
|||
<span style="color: #000000;">three</span><span style="color: #0000FF;">(</span><span style="color: #000000;">die</span><span style="color: #0000FF;">)</span> |
|||
end procedure |
|||
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span> |
|||
procedure one(bool die) |
|||
<span style="color: #008080;">procedure</span> <span style="color: #000000;">one</span><span style="color: #0000FF;">(</span><span style="color: #004080;">bool</span> <span style="color: #000000;">die</span><span style="color: #0000FF;">)</span> |
|||
two(die) |
|||
<span style="color: #000000;">two</span><span style="color: #0000FF;">(</span><span style="color: #000000;">die</span><span style="color: #0000FF;">)</span> |
|||
end procedure |
|||
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span> |
|||
one(0) |
|||
<span style="color: #000000;">one</span><span style="color: #0000FF;">(</span><span style="color: #000000;">0</span><span style="color: #0000FF;">)</span> |
|||
?routine_id("dummy") -- see note below |
|||
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">routine_id</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"dummy"</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- see note below</span> |
|||
⚫ | |||
<span style="color: #000000;">one</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)</span> |
|||
⚫ | |||
During compilation, the symbol table entries hold an integer ternary tree index rather than a string name, and normally |
During compilation, the symbol table entries hold an integer ternary tree index rather than a string name, and normally |
||
things are left like that during interpretation (the proper string names are always written out when an executable is |
things are left like that during interpretation (the proper string names are always written out when an executable is |
||
Line 1,579: | Line 1,581: | ||
Alternatively, but only when interpreting (whereas the above works as shown both when interpreting and pre-compiled), the debugger is |
Alternatively, but only when interpreting (whereas the above works as shown both when interpreting and pre-compiled), the debugger is |
||
started with the much saner |
started with the much saner |
||
<lang Phix> |
<!--<lang Phix>--> |
||
<span style="color: #008080;">trace</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)</span> |
|||
<!--</lang>--> |
|||
though as yet it offers no means of examining the stack trace (resume-ably), the above suggests it should be relative easy to add. |
though as yet it offers no means of examining the stack trace (resume-ably), the above suggests it should be relative easy to add. |
||