Normally I invoke my tcl script under shell like this.
> tclsh8.5 mytest.tcl -opt1 foo -opt2 bar
In case need to launch gdb to debug due to some modules implemented in C++. I have to launch tclsh via gdb. So the question is how to execute my script in tcl sh with arguments.
I need something like:
tclsh> run mytest.tcl -opt1 foo -opt2 bar
Using exec is not ideal as it folks another process and losses my breakpoints settings.
tclsh> exec mytest.tcl -opt1 foo -opt2 bar
I would think something like the following should work for you:
set argv [list -opt1 foo -opt2 bar]
set argc 4
source mytest.tcl
So set argv and argc to get the arguments correct and then just source in your Tcl code to execute.
Alternatively the gdb run command allows you to pass command line arguments to the executable to be debugged. So if your debugging tclsh then the what is the problem with the run command as follows?
run mytest.tcl -opt1 foo -opt2 bar
For example under cygwin I'm able to do the following:
$ tclsh test.tcl
This is a test
$ gdb -q tclsh.exe
(no debugging symbols found)
(gdb) run test.tcl
Starting program: /usr/bin/tclsh.exe test.tcl