REBOL 3.0

Comments on: Backtrace

Carl Sassenrath, CTO
REBOL Technologies
17-Jul-2009 1:00 GMT

Article #0224
Main page || Index || Prior Article [0223] || Next Article [0225] || 5 Comments || Send feedback

Note: the trace function document has been updated.

Have you ever had a script run fine for a moment then crash? You decide to add a trace to see what happened in the area of the crash... but you don't want to see 24000 lines of output it's just the last 20 lines you really need to know?

As we test R3, and as we port R2 scripts to it, we'll have that situation happen. So, in A75, there is a solution: TRACE/back. This is a simple refinement to trace that redirects its output to an internal buffer that you can examine later.

To enable backtrace:

>> trace/back on

Then, run your code. When your crash occurs, type:

>> trace/back 20

to see the last 20 lines (or however many lines you want to see.)

The internal backtrace buffer is 100KB, so it can hold quite a few lines of history.

You can also modify your trace depth as you would normally. For example:

>> trace/back on
>> trace 5

will only trace down five levels of code.

Here is an example session:

>> trace/back on
>> test: func [a] [if integer? a [loop a [bug]]]
>> test 10
** Script error: bug has no value
** Where: loop if test
** Near: loop a [bug]

>> trace/back 20
]
 1: test : function! [a]
 2: 10
--> test
     1: if : native! [condition then-block /else else-block]
     2: integer? : action! [value]
     3: a : 10
    --> integer?
    <-- integer? => true
     4: [loop a [bug]]
    --> if
         1: loop : native! [count block]
         2: a : 10
         3: [bug]
        --> loop
             1: bug : unset!
            **: error : Script no-value
 1: trace/back
 2: 20
--> trace

So, it's not hard to see what was going on when the script crashed. Backtrace can be quite handy when you need it.

I wrote a short document on how to read the trace output. It's pretty easy, once you "get the format". (Although, I should probably revisit and refresh that doc a bit.)

There are probably a few improvements that could be made. For example, it's often enough just to see the function call history, skipping all the evaluation details (as in R2). So, that can be added as a refinement.

Anyway, give it a try... and I should note: it's not going to handle Unicode as of yet. More work to do on that.

5 Comments

Comments:

-pekr-
18-Jul-2009 1:20:40
So if I understand it correctly, without the /back refinement, you use trace during the action, but when using /back refinement, you are able to use trace "afterwards", after some event already happened?

Two questions now:

1) What is the difference in?:

trace on ; and
trace/back on

2) What is relation of trace/back to stack function, as in http://www.rebol.net/r3blogs/0075.html ? Is stack function still valid?

Shadwolf
18-Jul-2009 4:41:26
yeaaaaaaaaaaaaaaaaaah !!!! I say yeaaaaaaaaaaaaaah !!!

Thank you Carl for this looking awsome trace capability !!

I'm happy for the month to come ^^

Paul
18-Jul-2009 11:51:57
I'm a big fan of this addition. This is going to make debugging much easier.
Gregg Irwin
19-Jul-2009 20:44:09
I second shadwolf's comment.
Shawolf
1-Aug-2009 2:14:34
I'm impatient to see how I can play and integrate to viva-rebol IDE the backtracking thing :P

Post a Comment:

You can post a comment here. Keep it on-topic.

Name:

Blog id:

R3-0224


Comment:


 Note: HTML tags allowed for: b i u li ol ul font span div a p br pre tt blockquote
 
 

This is a technical blog related to the above topic. We reserve the right to remove comments that are off-topic, irrelevant links, advertisements, spams, personal attacks, politics, religion, etc.

REBOL 3.0
Updated 19-Aug-2017 - Edit - Copyright REBOL Technologies - REBOL.net