Menu

Debugging

Tom Harwood

Debugging JBurg-Generated BURMS

Basic Principles

JBurg generated code can fail in two ways that are particular to it:

  1. The pattern matcher may fail to find a valid sequence of reductions to cover the entire tree.
  2. The sequence of reductions selected may not be what the programmer thought it would be.

Failure to Find a Valid Cover

The first problem, failing to find a valid sequence of reductions to cover the tree, is often caused by one of these problems:

  • The specification may not have the tree shape correctly specified. This is often the case when the specification is under development.
  • There may be a typo in the specification; unless the specification uses an enumeration to provide nonterminal names, JBurg will create nonterminals as it sees them, and typing statment instead of statement will cause a pattern match to fail.
  • The front end may have loose error handling that allows badly formed trees into the code generator.

Compiler-Compile Time Options

Specify -g on the command line to build debugging code into your BURM.

Compile Time Techniques

Intercepting BURM errors

[Java target specific] When the BURM cannot find a valid cover for a tree, it throws an IllegalStateException. Your driver can catch this exception and dump an annotated AST for analysis in JBurg's debugger, and/or otherwise fix up the error:

private static Object generateCode(CommonTree tree)
throws Exception
{
    SecondTreeParser burm = new SecondTreeParser();
    try
    {
        burm.burm(tree);
        return burm.getResult();
    }
    catch ( IllegalStateException ex )
    {
        burm.dump(tree, new PrintWriter("/tmp/failedBurm.xml"));
        throw ex;
    }
}

Using the Debugger

JBurg's debugger is part of the source distribution; build it via ant ErrorAnalyzer.jar and invoke it... TBD

Advanced Error Analysis in the BURM

Use the DefaultErrorHandler directive to add code that gets control when the BURM cannot generate a valid cover of the input AST:


/
* Error recovery routine: deduce what we can from the problem
* tree, then abort this BURM with an exception that the caller
* can catch and ignore.
/
DefaultErrorHandler
{
new UnknownTreeHandler(reducer.getProblems()).analyze(p);
BURMAbortException.abort();
}

The UnknownTreeHandler is an Apache Falcon subsystem that explores the annotated AST and attempts to diagnose the problem. Because failure to match a subtree causes the parent tree to also fail to match, the UnknownTreeHandler recursively explores the tree and attempts to identify the most deeply nested subtree that failed to match.


Related

Wiki: CommandLineOptions
Wiki: DirectivesGuide
Wiki: JBurg Reference
Wiki: JBurg2 Reference
Wiki: JBurg2 Syntax