Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Simple debugging tool

 [1/1] from: Christophe::Coussement::mil::be at: 14-Nov-2003 15:42


Hi list, [Warning: long post] Although debugging in REBOL stays simple (think about '?, '?? and other probe), we had the need to add some functionalities to it for our project developments. I did hack in this 'debug function this morning, which is pretty simple to use and did help us to debug a long script in the afternoon. One of the big advantage is that the debugging instructions do not interfear with the normal evaluation of the script. Given the simplistic script: ;=== begin script ====================== rebol [] ;$debug a: 1 ;$debug b: 2 a: "test" ;$debug/stop v: 10 ;$debug/var 'a ask "done" ;=== end script ====================== the 'debug output will be: ;=== begin output ====================== --- DEBUG CALL # 1 at 14-Nov-2003/15:33:13+1:00 --- No user word defined --- DEBUG CALL # 2 at 14-Nov-2003/15:33:13+1:00 --- A is an integer of value: 1 --- DEBUG CALL # 3 at 14-Nov-2003/15:33:13+1:00 --- A is a string of value: "test" B is an integer of value: 2 - Pause requested - Press any key to continue ... --- DEBUG CALL # 4 at 14-Nov-2003/15:33:16+1:00 --- A is a string of value: "test" done ;=== end output ====================== Here is the 'debug script. The "special" coding style has been developped by us to make possible the utilisation of an style-checker, wich enforce the standardisation of the script produced within out projects. So don't pay too much attention to it ;) ;=== begin script ===================== rebol [ title: "Debug" purpose: "provide an easy way to examine user word contents" history: [ 0.1.2 [14-nov-03 "initial" "cou"] ] usage: { 1. your script... at the place you want a examination of word content: ;$debug => gives value of all user words ;$debug/var 'var1 => gives only value of var1 ;$debug/var [var1 var2] => gives only value of var1 & var2 ;$debug/stop => request pause after displaying var value 2. calling the debug script... from the console: do/args %debug.r %yourscript.r or do %debug.r => the file to debug will be requested } ] debug_ctx: context [ do [ pri_debug_count: 0 ] ;--------------------------------------------------------------------------- set 'debug func [ {=== TASK X.X === [COU] print value of the choosen user words (all by default) RETURN: true = all OK / false = error} /var aany_var [word! block!] "word or block of words to get value for" /stop "pause after each debug call" /local lerr_result ][ either error? lerr_result: try [ print [newline "--- DEBUG CALL #" pri_debug_count: pri_debug_count + 1 "at" now "---"] either var [ either word? aany_var [ either find query system/words :aany_var [ help :aany_var ][ print [aany_var "is undefined"] ] ][ foreach ew_user sort aany_var [ either find query system/words :ew_user [ help :ew_user ][ print [ew_user "is undefined"] ] ] ] ][ either [pri_debug_count] = query system/words [ print "No user word defined" ][ foreach ew_user sort query system/words [ if all [ :ew_user <> 'type-name :ew_user <> 'pri_debug_count ] [ help :ew_user ] ] ] ] if stop [ask "- Pause requested - Press any key to continue ..."] ][ ;--- error handling probe disarm lerr_result return false ][ ;--- return if all ok return true ] ] do [ either prs_arg: system/script/args [ prfile_arg: to-rebol-file prs_arg prs_to_debug: replace/all read prfile_arg ";$debug" "debug" query/clear system/words do load prs_to_debug ][ if not prfile_arg: request-file/title/filter "Select file to debug" "Select" "*.r" [quit] prfile_arg: first prfile_arg prs_to_debug: replace/all read prfile_arg ";$debug" "debug" query/clear system/words do load prs_to_debug ] print "----------------------------------------" ask "End of script. Press any key to quit ..." ] ] ;=== end script ======================= Hopes this can be usefull to someone. Anyway, do not hesitate to criticise or give remark about it ;) ==christophe