[antlr-interest] Issues Remote Debugging when using C Target and ASTs

Kurt Otte kurtotte at gmail.com
Wed Aug 6 12:43:27 PDT 2008

I am new to antlr so maybe these are known issues, but I am running
into trouble trying to get AntlrWorks to remote debug a grammar which
is targeted at C and generates ASTs.  I have found several issues
which I wondered if anyone had some thoughts on how to resolve.

#1 - It appears that code generation with the C target and ASTs
enabled is broken if the debug option is set.
For example, with a simple example like this (foo.g)

    grammar foo;

      language = C;

    bar : 'A'..'Z' ;

I get the following error

    java org.antlr.Tool -debug foo.g

    ANTLR Parser Generator  Version 3.1b2 (July 17, 2008)  1989-2008

    Generating fooParser.c
    error(10):  internal error: foo.g :
java.lang.IllegalArgumentException: Can't find template
parserCtorBody.st; group hierarchy is [C]

Debugging this a bit, I found that 'parserCtorBody() ::= <<   >>' is
missing from the file C.stg.  I am not sure if this is where it is
expected to be found it in the C code generation case, but I notice it
was defined there for java.  If I stub out this section in the C.stg
file with a blank section for parserCtorBody(), the error goes away
but I don't know enough about the code to propose a proper fix.

#2 – If I disable AST generation, I can get the grammar to generate
and compile in my C app.  This app will launch and hang waiting on the
debugger as it is supposed to.  Then when I try to connect the
debugger, it claims the source has changed.  An easy way to replicate
this error is to take the 'C' example in the examples-v3/C directory
and compile it with –debug enabled.  Then try to connect ANTLRWorks to
it.  When I do this, I get this error:  'Warning: the grammar used by
the remote parser is not the same (C.g")'.  Is this maybe a problem
with picking up an extra quote in the file name?  I have tried several
examples and so far I am unable to anything to remote connect.

#3 – I seems the default remote debug port in C is different than the
ANTLRWorks default.  It took me some digging through the code to find
it, but I guess C expects the port to be 4100
(antlr3debugeventlistener.h:  #define DEFAULT_DEBUGGER_PORT   0xBFCC)
and AltlrWorks expects it to be 49153
(http://www.antlr.org/wiki/pages/viewpage.action?pageId=4554898).  I
am not sure if makes since to line these up or update the docs, but I
thought I would pass it along for the next guy since it took some time
to track down.

Any thoughts on how to fix or work around these issues would be much



More information about the antlr-interest mailing list