Forums

Stacktraces

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

Stacktraces

Postby Necoro » Wed Apr 08, 2009 12:50 pm

Hi,

I played around a bit with the last informal release. And I tried to get reasonable stack-traces. Therefore I modified the hello.cobra to look as follows:

Code: Select all
class Program

    def bla is shared
        print 'Bla [1+1]'
        throw Exception()

    def test is shared
        print 'Test'
        .bla

    def main is shared
        .test
        print 'Hello, world.'


Now when I run ./cobra -d hello I get:

Code: Select all
Test
Bla 2

Unhandled Exception: System.Exception: Exception of type 'System.Exception' was thrown.
  at Program.Bla () [0x0003d] in /home/necoro/cobra/Cobra-Informal-Release-2009-04-07/Source/hello.cobra:5
  at Program.Test () [0x00014] in /home/necoro/cobra/Cobra-Informal-Release-2009-04-07/Source/hello.cobra:9
  at Program.Main () [0x00005] in /home/necoro/cobra/Cobra-Informal-Release-2009-04-07/Source/hello.cobra:12


- which looks very much like what I expected. But now I tried to add detailed stack traces ... et voilà ... nothing works ;)
./cobra -d -dst hello
Code: Select all
Test
Bla 2

Unhandled Exception: System.Exception: Exception of type 'System.Exception' was thrown.
  at Program.Bla () [0x0006e] in /home/necoro/cobra/Cobra-Informal-Release-2009-04-07/Source/hello.cobra:5

Not very detailed ... is this wanted?
Necoro
 
Posts: 7

Re: Stacktraces

Postby Charles » Wed Apr 08, 2009 9:37 pm

The option -detailed-stack-trace (-dst) only makes sense (1) in the context of -exception-report (-er) or (2) if your program takes the dst information and does something with it. You'll see instructions if you run without -d:
Code: Select all
...
An unhandled exception has occurred.

Cobra debugging tips:
    To get file name and line number information for the stack frames, use:
        cobra -debug foo.cobra
    To get a post-mortem, HTML-formatted report with more details about your objects:
        cobra -debug -exception-report foo.cobra
    For even more information, try:
        cobra -debug -exception-report -detailed-stack-trace foo.cobra
    Or use the abbreviations:
        cobra -d -er -dst foo.cobra

And the cobra -h for -dst mentions using -er too.

Why doesn't cobra.exe detect -dst without -er and warn you? Well you could take over the detailed stack trace information yourself as I do with the Cobra compiler. Check out wincomp.bat's contents:

Snapshot\cobra.exe -out:cobra-win.exe -compile -color -debug -dst -ert:yes -timeit -t:exe -ref:System.Windows.Forms -ref
:System.Drawing %* -files:files-to-compile-win.text

You can see there is a -dst but no -er (-ert is for -embed-run-time). However, if you look at files-to-compile-win.text, you'll see two extra files at the bottom compared to the normal files-to-compile.text:

CobraMain-ObjectExplorer-WinForms.cobra
ObjectExplorer-WinForms.cobra

The first is a specific "def main" that catches uncaught exceptions and creates an instance of ObjectExplorer defined in the second file.

I ended up preferring this technique over the HTML output of -exception-report/-er because -er churns out a bunch of uninteresting objects. Also, the ObjectExplorer is interactive and you can easily drill down on stack frames, args, locals, objects, collections, etc.

In short, add -er, or explore the GUI/ObjectExplorer way.

I've enhanced cobra -h to mention the GUI approach:

-detailed-stack-trace, -dst
Enable a detailed stack trace which gives great postmortem information for uncaught exceptions, but slows execution. Works in combination with -exception-report, or see ObjectExplorer-WinForms.cobra and its doc string for ideas on how to present this information graphically.

-exception-report, -exc-rpt, -er
Turn on an informative HTML report that will be generated if the program throws an uncaught exception. Also, see ObjectExplorer-WinForms.cobra and its doc string for an alternative, GUI approach.

Thanks for bringing this up.
Charles
 
Posts: 2515
Location: Los Angeles, CA


Return to Discussion

Who is online

Users browsing this forum: No registered users and 45 guests