[antlr4] cpp-runtime TokenStreamRewriter getText() crash

50 views
Skip to first unread message

Thomas Burg

unread,
Nov 13, 2016, 8:45:44 AM11/13/16
to antlr-discussion
Hello

I try to use TokenStreamwriter in order to implement a Preprocessor.

However when I call getText() method of the TokenStreamwriter object my program crash:

Reading symbols from demo2/antlr4-demo2...done.
(gdb) r
Starting program: /home/tom/prog/antlr4/Softgem/antlr4-cpp-runtime/demo2/antlr4-demo2

Program received signal SIGSEGV, Segmentation fault.
0x000055555574e2a6 in antlr4::TokenStreamRewriter::reduceToSingleOperationPerIndex (this=0x555555b09a40,
    rewrites
=std::vector of length 103, capacity 103 = {...})
    at
/home/tom/prog/antlr4/Softgem/antlr4-cpp-runtime/runtime/src/TokenStreamRewriter.cpp:417
417          if (iop->index == rop->index) {
(gdb) p rop->index
Cannot access memory at address 0x10
(gdb)



In my code the only operation on the TokenStreamRewrite object is done in an exit Listener function:
vPreprocessor.h:
class vPreprocessor : public  vppBaseListener {
[...]
   
public:
       
TokenStreamRewriter * _rewriter;
        vPreprocessor
(TokenStream *tokens);
       
~vPreprocessor();

         
void enterDefine(vppParser::DefineContext * ctx);
         
void exitDefine(vppParser::DefineContext * );
         
void enterUndef(vppParser::UndefContext * ctx);

};



vPreprocessor.cpp
void vPreprocessor::exitDefine(vppParser::DefineContext * ctx ){
   
    _rewriter
->insertBefore(ctx->getStart(),"//");
}



when this function is call more than one time and I call _rewrite.getText() the program crash.
When input file trig only a single call to this function I do not observe crash and give the expected result.

I build my runtime on Linux ubuntu 16.10 with the source from:
http://www.soft-gems.net/index.php/all-downloads of the 4 November 2016

Where should I report this issue ? I can eventually provide a testcase.

Regards
Thomas

Mike Lischke

unread,
Nov 13, 2016, 9:50:04 AM11/13/16
to antlr-di...@googlegroups.com
Hi Thoms,

Am 13.11.2016 um 14:45 schrieb Thomas Burg <thoma...@gmail.com>:

vPreprocessor.cpp
void vPreprocessor::exitDefine(vppParser::DefineContext * ctx ){
    
    _rewriter
->insertBefore(ctx->getStart(),"//");
}



when this function is call more than one time and I call _rewrite.getText() the program crash.
When input file trig only a single call to this function I do not observe crash and give the expected result.

I build my runtime on Linux ubuntu 16.10 with the source from:
http://www.soft-gems.net/index.php/all-downloads of the 4 November 2016

Where should I report this issue ? I can eventually provide a testcase.

Please file a bug report here: https://github.com/DanMcLaughlin/antlr4/issues and attach your test case.



Thomas Burg

unread,
Nov 13, 2016, 10:49:18 AM11/13/16
to antlr-di...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages