@echo off
cd ..
echo Together includes a debug feature that helps you to debug your code.  Debugging
echo of Together component modules (formerly called scripts) requires some special
echo tricks. This is another example of debugging Together  from  Together  by using
echo the socket connection. This example is destined for WINDOWS NT or  2000. If you
echo use WIN95/98, provide sufficient environment space and place  start.exe command
echo (from WIN95/COMMAND or WIN98/COMMAND) be in the path.
echo This is the batch-file for WIN32 platform.  However,  the same commands can be
echo called on the other platforms: for example one can run the debugger on WIN NT,
echo and the debugged application on Solaris.
echo Note that for the classic java VM (without Hot Spot) it is necessary to disable
echo the JIT compiler (-Djava.compiler=NONE).
echo.
echo To start java VM,  the java VM parameters should be defined in this batch file.
echo.

SET TGH=..
SET TGL=..\lib
SET JDK=..\jdk

SET PATH=%PATH%;"%TGH%\bin\win32";"%JDK%\bin"

set CLASSPT1=%TGL%\together.jar;%TGL%\openapi.jar;%TGH%\modules;%TGL%\gifs.zip
set CLASSPT2=%TGH%\out;%TGL%\i18n;%TGL%\jgl.zip;%TGL%\jacl.jar;%TGL%\coroutine
set CLASSPT3=%TGL%\xml4j.jar;%TGL%\tcljava.jar;%TGL%\jcvs\application\jcvs.jar
set CLASSPT4=%TGL%\misclib.zip;%TGL%\javax.jar;%TGL%\jhall.jar
set CLASSPATH=%CLASSPT1%;%CLASSPT2%;%CLASSPT3%;%CLASSPT4%;..\jdk\lib\tools.jar

echo TGH=%TGH%
echo TGL=%TGL%
echo JDK=%JDK%
echo CLASSPATH=%CLASSPATH%
echo.

set PARAM=-Xms32m -Xmx512m -Xdebug -Xnoagent
rem Disable JIT compiler if you use the classic java VM (without Hot Spot)
rem set NOJIT=-Djava.compiler=NONE
set TRANSPORT=dt_socket
set TRANSPORT=%TRANSPORT%,address=8787

set PARAM=%PARAM% %NOJIT% -Xrunjdwp:transport=%TRANSPORT%,server=y,suspend=n

echo For java debug connection you must define the additional parameters
echo.
echo PARAM=%PARAM%
echo.
echo You can directly define the address for the socket connection port or wait for
echo the message "Listening for transport dt_socket at address: ... ".
echo To skip debugging by loading  of a debugged Together instance  (this can take
echo several minutes) select "suspend=n". This allows for the java VM with debugged
echo application to begin executing before the debugger application attaches. The
echo default value "suspend=y" can only be used for the short programs or in some
echo special cases. With the "suspend=y", the application being debugged waits for
echo the socket connection prior to start running. This run is in the debug mode,
echo which is about 20-30 times slower than the normal mode.
echo.
echo Let us start debugging.
echo 1) Start the Together instance as the debugger.  Use  Together launcher
echo (Together.exe) or Together.bat file. Press any key to do this and wait for the
echo 1st Together instance with the project TestModule to load.
@echo on
rem THIS IS TOGETHER INSTANCE OF DEBUGGER
set PROJ1=../modules/com/togethersoft/modules/testModule/TestModule.tpr
start Together.exe %PROJ1%
@echo off
echo Wait for Together project TestModule to load . . .
pause
echo.
echo 2) Load the second instance for debugging. Use additional parameters to use
echo socket connection (if the address is not defined, the message
echo       "Listening for transport dt_socket at address: ... "
echo will be received in the second console after loading the Java VM.
echo Wait for the 2nd instance of Together with the project CashSales to load.
echo Next, press Enter.
echo.
@echo on
rem THIS IS TOGETHER INSTANCE FOR DEBUG
set PROJ2=../samples/java/CashSales/CashSales.tpr
set CLASS_AND_PROJ2=com.togethersoft.together.Main %PROJ2%
start %JDK%\bin\java %PARAM% -cp %CLASSPATH% %CLASS_AND_PROJ2%
@echo off
echo.
echo Wait for Together project CashSales to load . . .
pause
echo.
echo 3) Now we have two instances of Together and can debug 2nd instance of Together
echo from the 1st instance.
echo In the 1st instance of Together, select  "Tools":"Run/Debug":"Attach to remote
echo process". In the "Attach to remote process" pane enter:
echo   Host:       localHost
echo   Transport:  dt_socket
echo   Address:    8787      (or address received from java VM)
echo.
echo 4) In the MessagePane of the Debugger select Breakpoints tab,  right click  the
echo line with breakpoints and select in context menu "Add class breakpoint". In the
echo "Add Class Breakpoint" pane type:
echo   Class:  com.togethersoft.modules.testModule.TestModule
echo and check "Stop execution" and "Log message". Next, press enter.
echo.
echo 5) Select any element in the diagram in the 2nd instance of together (for
echo example interface CashSales), expand Modules tab, find module TestModule,
echo right click this module and select "Run".
echo.
echo 6) In the  debugger console you will see the text "Hit breakpoint  in class
echo com.togethersoft.modules.testModule.TestModule" and in the text editor pane
echo the text of the same class with the selected first line of the method "run()".
echo Now you can trace (F8/F7) blocks, methods, classes, watch variables and classes
echo etc. To stop the debugger select "Resume program".
echo.
pause
echo Now type "exit", if you have loaded this bat file in a separate window.
