C++ runtime debugging howto?

36 views
Skip to first unread message

azr...@googlemail.com

unread,
Apr 2, 2018, 4:52:03 PM4/2/18
to antlr-discussion
Hi!

I have a very huge (20kLOC) ANTLR4 grammar (converted by a script from Coco/R) which generates fine[1] & the C++ builds without warning, but whatever I feed the parser (even an empty file) I get:
> terminate called after throwing an instance of 'std::out_of_range'
>  what():  bitset::set: __position (which is 1051)1047) >= _Nb (which is 1024)

with a backtrace deep in antlr4::atn::LL1Analyzer::_LOOK()

The Java runtime seems to have a setTrace() method, but the C++ runtime doesn't. How would I debug such problems? Is it likely a problem with my grammar [due to above warnings?] or a runtime bug / limitation?

First I thought it might be a bug in my grammar actions, but the behaviour persists if I omit actions & rule attributes completely from the grammar.

Thank you for any hints
  azrdev


[1] Just a handfull of "rule contains an optional block with at least one alternative that can match an empty string" warnings

Mike Lischke

unread,
Apr 3, 2018, 2:57:06 AM4/3/18
to antlr-di...@googlegroups.com
Hi,

I have a very huge (20kLOC) ANTLR4 grammar (converted by a script from Coco/R) which generates fine[1] & the C++ builds without warning, but whatever I feed the parser (even an empty file) I get:
> terminate called after throwing an instance of 'std::out_of_range'
>  what():  bitset::set: __position (which is 1051)1047) >= _Nb (which is 1024)

This message obviously points to an allocation problem. A look in the BitSet.h file shows:

class ANTLR4CPP_PUBLIC BitSet : public std::bitset<1024> {


with a backtrace deep in antlr4::atn::LL1Analyzer::_LOOK()

azr...@googlemail.com

unread,
Apr 5, 2018, 10:57:53 AM4/5/18
to antlr-discussion
Hi,
> terminate called after throwing an instance of 'std::out_of_range'
>  what():  bitset::set: __position (which is 1051)1047) >= _Nb (which is 1024)

This message obviously points to an allocation problem. A look in the BitSet.h file shows:

class ANTLR4CPP_PUBLIC BitSet : public std::bitset<1024> {


thank you for spotting that, I'm not familiar with the antlr internals.
Seems like that limitation is not easily parameterized (i.e. the generator tracking the maximum number of limitations in any given state, and setting the template parameter accordingly)?
In what place would it best be documented?

  azrdev

Mike Lischke

unread,
Apr 5, 2018, 11:40:42 AM4/5/18
to antlr-di...@googlegroups.com

This message obviously points to an allocation problem. A look in the BitSet.h file shows:

class ANTLR4CPP_PUBLIC BitSet : public std::bitset<1024> {


thank you for spotting that, I'm not familiar with the antlr internals.
Seems like that limitation is not easily parameterized (i.e. the generator tracking the maximum number of limitations in any given state, and setting the template parameter accordingly)?
In what place would it best be documented?

Just build the runtime yourself and increase this value (is 4096 too much/enough?), to see if that helps. Once it is confirmed we can create a PR for ANTLR to get that change in.

azr...@googlemail.com

unread,
Apr 7, 2018, 4:51:35 PM4/7/18
to antlr-discussion
 
Just build the runtime yourself and increase this value (is 4096 too much/enough?), to see if that helps.
It does.
 
Once it is confirmed we can create a PR for ANTLR to get that change in.

IMHO just increasing the value is not the best option: It just fixes the issue until somebody comes up with a grammar having more alternatives at some point, yielding again the same inexpressive error. That's why I asked about documenting it -- fixing seems quite some effort, given the usage of class Bitset.

  azrdev

Mike Lischke

unread,
Apr 8, 2018, 5:03:58 AM4/8/18
to azrdev via antlr-discussion
> IMHO just increasing the value is not the best option: It just fixes the issue until somebody comes up with a grammar having more alternatives at some point, yielding again the same inexpressive error. That's why I asked about documenting it -- fixing seems quite some effort, given the usage of class Bitset.


Well, given the fact that you are the first one hitting this limit and the 400% increase if we use that change, likelihood is low that this issue will ever come up again.

And there’s not much effort to change that, just do it once in the Bitset class declaration and you are done. Would be good if you could just do it to see if that solves your problem.

Mike
--
www.soft-gems.net

azr...@googlemail.com

unread,
Apr 9, 2018, 5:47:37 AM4/9/18
to antlr-discussion
 
And there’s not much effort to change that, just do it once in the Bitset class declaration and you are done. Would be good if you could just do it to see if that solves your problem.
 
As I wrote, I did and it does fix the problem.
azrdev
Reply all
Reply to author
Forward
0 new messages