Re: Functions & Procedure runing stak

new topic     » goto parent     » topic index » view thread      » older message » newer message

In Euphoria 4.1, you can get the current call stack at any time.

 
include std/io.e 
include std/sequence.e 
include euphoria/debug/debug.e 
 
constant CS_FORMAT_STRING = "routine '%s' called from %s:%d\n" 
 
procedure show_call_stack( integer start = 1 ) 
     
    sequence cs = call_stack() 
     
    if start <= length( cs ) then 
        cs = cs[start..$] 
    end if 
     
    for i = 1 to length( cs ) do 
         
        object routine_name, file_name, line_no 
        {routine_name,file_name,line_no} = cs[i] 
         
        if i > 1 then puts( STDOUT, ">>> " ) end if 
        printf( STDOUT, CS_FORMAT_STRING, {routine_name,file_name,line_no} ) 
         
    end for 
     
end procedure 
 
procedure main() 
     
    -- skip first line, which is the 
    -- call to 'call_stack()' itself 
    show_call_stack( 2 ) 
     
end procedure 
 
main() 

D:\Greg\Documents\Euphoria\Testing> eui call_stack.ex 
routine 'show_call_stack' called from D:\Greg\Documents\Euphoria\Testing\call_stack.ex:10 
>>> routine '<TopLevel>' called from D:\Greg\Documents\Euphoria\Testing\call_stack.ex:37 

Fun fact: main() got inlined, so it doesn't show up in the call stack. If you change its declaration to without inline procedure main() then it will show up in the call stack.

D:\Greg\Documents\Euphoria\Testing>eui call_stack.ex 
routine 'show_call_stack' called from D:\Greg\Documents\Euphoria\Testing\call_stack.ex:10 
>>> routine 'main' called from D:\Greg\Documents\Euphoria\Testing\call_stack.ex:35 
>>> routine '<TopLevel>' called from D:\Greg\Documents\Euphoria\Testing\call_stack.ex:37 

There's also functionality to use your own external debugger, but it doesn't seem well documented, so I'm still trying to figure out how to use it. I will provide a proper example when I do (but don't look for that any time soon).

-Greg

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu