<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to Debugging</title><link>https://sourceforge.net/p/jburg/wiki/Debugging/</link><description>Recent changes to Debugging</description><atom:link href="https://sourceforge.net/p/jburg/wiki/Debugging/feed" rel="self"/><language>en</language><lastBuildDate>Tue, 19 Mar 2013 21:25:16 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/jburg/wiki/Debugging/feed" rel="self" type="application/rss+xml"/><item><title>WikiPage Debugging modified by Tom Harwood</title><link>https://sourceforge.net/p/jburg/wiki/Debugging/</link><description>&lt;div class="markdown_content"&gt;&lt;pre&gt;--- v1
+++ v2
@@ -62,6 +62,6 @@
 }
 &lt;/code&gt;

-The [`UnknownTreeHandler`](http://svn.apache.org/viewvc/flex/falcon/trunk/compiler/src/org/apache/flex/compiler/internal/as/codegen/UnknownTreeHandler.java?view=markup) is an Apache Falcon subsystem that explores the annotated AST and attempts to diagnose the problem.
+The [`UnknownTreeHandler`](http://svn.apache.org/viewvc/flex/falcon/trunk/compiler/src/org/apache/flex/compiler/internal/as/codegen/UnknownTreeHandler.java?view=markup) 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.

&lt;/pre&gt;
&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Tom Harwood</dc:creator><pubDate>Tue, 19 Mar 2013 21:25:16 -0000</pubDate><guid>https://sourceforge.net26d698266a612b7c85c1effe72e34025b3a962de</guid></item><item><title>WikiPage Debugging modified by Tom Harwood</title><link>https://sourceforge.net/p/jburg/wiki/Debugging/</link><description>&lt;div class="markdown_content"&gt;&lt;h1 id="debugging-jburg-generated-burms"&gt;Debugging JBurg-Generated BURMS&lt;/h1&gt;
&lt;h2 id="basic-principles"&gt;Basic Principles&lt;/h2&gt;
&lt;p&gt;JBurg generated code can fail in two ways that are particular to it:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The pattern matcher may fail to find a valid sequence of reductions to cover the entire tree.&lt;/li&gt;
&lt;li&gt;The sequence of reductions selected may not be what the programmer thought it would be.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="failure-to-find-a-valid-cover"&gt;Failure to Find a Valid Cover&lt;/h3&gt;
&lt;p&gt;The first problem, failing to find a valid sequence of reductions to cover the tree, is often caused by one of these problems:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The specification may not have the tree shape correctly specified. This is often the case when the specification is under development.&lt;/li&gt;
&lt;li&gt;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 &lt;code&gt;statment&lt;/code&gt; instead of &lt;code&gt;statement&lt;/code&gt; will cause a pattern match to fail.&lt;/li&gt;
&lt;li&gt;The front end may have loose error handling that allows badly formed trees into the code generator.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="compiler-compile-time-options"&gt;Compiler-Compile Time Options&lt;/h2&gt;
&lt;p&gt;Specify &lt;code&gt;-g&lt;/code&gt; on the command line to build debugging code into your BURM.&lt;/p&gt;
&lt;h2 id="compile-time-techniques"&gt;Compile Time Techniques&lt;/h2&gt;
&lt;h3 id="intercepting-burm-errors"&gt;Intercepting BURM errors&lt;/h3&gt;
&lt;p&gt;[Java target specific] When the BURM cannot find a valid cover for a tree, it throws an &lt;code&gt;IllegalStateException&lt;/code&gt;.  Your driver can catch this exception and dump an annotated AST for analysis in JBurg's debugger, and/or otherwise fix up the error:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span class="n"&gt;private&lt;/span&gt; &lt;span class="n"&gt;static&lt;/span&gt; &lt;span class="n"&gt;Object&lt;/span&gt; &lt;span class="n"&gt;generateCode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;CommonTree&lt;/span&gt; &lt;span class="n"&gt;tree&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;throws&lt;/span&gt; &lt;span class="n"&gt;Exception&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;SecondTreeParser&lt;/span&gt; &lt;span class="n"&gt;burm&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;new&lt;/span&gt; &lt;span class="n"&gt;SecondTreeParser&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;burm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;burm&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tree&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;burm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;getResult&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="n"&gt;IllegalStateException&lt;/span&gt; &lt;span class="n"&gt;ex&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;burm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;dump&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tree&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;new&lt;/span&gt; &lt;span class="n"&gt;PrintWriter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&amp;quot;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;tmp&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;failedBurm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;xml&lt;/span&gt;&amp;quot;&lt;span class="p"&gt;));&lt;/span&gt;
        &lt;span class="n"&gt;throw&lt;/span&gt; &lt;span class="n"&gt;ex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;h2 id="using-the-debugger"&gt;Using the Debugger&lt;/h2&gt;
&lt;p&gt;JBurg's debugger is part of the source distribution; build it via &lt;code&gt;ant ErrorAnalyzer.jar&lt;/code&gt; and invoke it... TBD&lt;/p&gt;
&lt;h3 id="advanced-error-analysis-in-the-burm"&gt;Advanced Error Analysis in the BURM&lt;/h3&gt;
&lt;p&gt;Use the &lt;code&gt;DefaultErrorHandler&lt;/code&gt; directive to add code that gets control when the BURM cannot generate a valid cover of the input AST:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&lt;br /&gt;
/&lt;em&gt;&lt;br /&gt;
 *  Error recovery routine: deduce what we can from the problem&lt;br /&gt;
 *  tree, then abort this BURM with an exception that the caller&lt;br /&gt;
 *  can catch and ignore.&lt;br /&gt;
&lt;/em&gt;/&lt;br /&gt;
DefaultErrorHandler&lt;br /&gt;
{&lt;br /&gt;
    new UnknownTreeHandler(reducer.getProblems()).analyze(p);&lt;br /&gt;
    BURMAbortException.abort();&lt;br /&gt;
}&lt;br /&gt;
&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;The &lt;a class="" href="http://svn.apache.org/viewvc/flex/falcon/trunk/compiler/src/org/apache/flex/compiler/internal/as/codegen/UnknownTreeHandler.java?view=markup"&gt;&lt;code&gt;UnknownTreeHandler&lt;/code&gt;&lt;/a&gt; is an Apache Falcon subsystem that explores the annotated AST and attempts to diagnose the problem.&lt;/p&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Tom Harwood</dc:creator><pubDate>Tue, 19 Mar 2013 20:59:17 -0000</pubDate><guid>https://sourceforge.net1963c865a484a01cf219c2edb147ef9bb3733e75</guid></item></channel></rss>