retrieving line number in case of error - "simple debugger"



Hi all,

I will use tcl within a C/C++ application in order to execute scripts writen by users. The app starts a Tcl_Interp, and execute the file.

I would need to display basic information to the user in case an error occurs. Among these, the error line on which the error occured.

My two question are :
1/ Given a script, how can I retrieve the exact line on which the error occured ?
2/ Do you know a nice HOWTO or code sample for building basic debug features ?



In order to explain which point I have reached so far, here is a rather simple example then.


Suppose the script is :

 1	if 1 {
 2		set a 2
 3		set a 2 3
 4	}

The error is on line 3.

When evaluating this script, however, the error line registered by Tcl is "1" (ie : error of the 'first level' command called).

If, in the C master application, I write something like :

	result = Tcl_EvalEx(tclInterp, script, length,  TCL_EVAL_GLOBAL);
    	if (result != TCL_OK ) {
           Tcl_Obj *options = Tcl_GetReturnOptions(tclInterp, result);
           Tcl_Obj *key = Tcl_NewStringObj("-errorline", -1);
           Tcl_Obj *errorline;
           Tcl_DictObjGet(NULL, options, key, &errorline);
           printf(" ERROR line %s\n", Tcl_GetString(errorline));
	}

the output will be "ERROR line 1".

Basically, I am unable to retrieve the error line within the nested script of the "if" command.


Thanks for reading, and waiting for answer !

Dr Nicolas Castagne
http://acroe.imag.fr
.



Relevant Pages

  • Re: Key-passing from PHP to TCL CGI script - how is it done (web security issue)?
    ... TCL v.8.3 ... set hasEnteredTrivia 0 ... # NEW 8/7/2004 USE PHP (AS CGI) TO CHECK IF USER IS ATTEMPTING TO ENTER ... # USE REMOTE PHP SCRIPT TO CHECK FOR REPOSTING ...
    (comp.lang.tcl)
  • embedded Tcl performance -- how to make it faster?
    ... My application already provides a limited scripting language to our ... I set off to embed Tcl. ... (Embedded Ruby ... and then retrieve results back in the app once the script ...
    (comp.lang.tcl)
  • Expect: interact and buffering?
    ... with the tcl application and terminated it. ... remaining output would display and the Expect script would end. ... I have changed the interact in an attempt to make it process character ...
    (comp.lang.tcl)
  • Re: No argv, argc for worker thread
    ... I expected that a Tcl interpreter started in any manner would accept options ... This is how the interpreter works with command line options ... a "main" script processes command line ...
    (comp.lang.tcl)
  • Re: Functional programming versus TCL-like strings rant
    ... > Someone suggested that using combinations of custom-built control ... I assume you mean a script built up at ... In a language like Tcl, ... * Tcl uses a limited form of lexical/static scoping for commands ...
    (comp.lang.tcl)