retrieving line number in case of error - "simple debugger"
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.tcl archive

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

From: Nicolas Castagne <castagne@imag.fr>
Date: Thu Sep 29 2005 - 17:30:51 CEST

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
Received on Sat Oct 15 03:53:36 2005