Debugging TRPL¶
Introduction¶
Unfortunately, TRPL is not yet enabled for source-level debugging. We have a plan to switch TRPL to a Scala based environment, but until that time we must make do. The following tips are intended to help with this process.
Connecting a Debugger¶
You can add the following to the ConversionDriver
command line:
-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=2080,server=y,suspend=y
You can choose a different port than 2080. The conversion process will block (suspend=y
) until you connect. Set your breakpoints and debug as you normally would.
Useful Techniques¶
Understanding Error Output¶
See Understanding TRPL Error Output.
How to Find Failing Statements¶
See How to Find Failing TRPL Statements.
Tracing Execution¶
When you run the conversion driver with -Drules.tracing=true
as a JVM argument, the .jast
will have an annotation recording the TRPL rule which added that node. This is a way to 'backtrack' and find the TRPL code responsible for the generation of some resulting Java code.
Output Statements¶
If you are trying to debug the TRPL rules, a good starting point is to put debug output statements in the TRPL itself where you can co-locate with problem rules, output state and only conditionally output something.- The global
printf()
function is especially useful. - Besides
printf()
, a temporary<action>putNote("foo", "bar")</action>
is also very useful, to get your debugging strings inside the tree ("Let the tree work for you"), in the writtenAST
xml. - A more elaborate
putNote
example: (depth
will be invoked asAast.getDepth()
, seeAast
for other functionality):<action>putNote("foo_tree", sprintf("%s %d '%s'", "Hello world", this.depth, this.dumpTree()))</action>
Breakpoint Locations¶
In the com.goldencode.p2j.pattern
package there are the Rule
, RuleSet
and RuleContainer
classes which are used by the PatternEngine
to execute the TRPL rules. Each expression is compiled using the com.goldencode.expr
package.
If you want to see the state of the conversion environment in the debugger at a particular line of TRPL code, you can set a conditional breakpoint in com.goldencode.expr.Expression.java
, at the top of the execute()
method. Set a condition like:
return infix.equals("some TRPL expression");
Of course, you can use any String
method here... startsWith()
, endsWith()
, etc.
This will be very slow, since it is doing a lot of string processing in the breakpoint. However, it can be useful on occasion.
© 2004-2022 Golden Code Development Corporation. ALL RIGHTS RESERVED.