Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix "stack overflow in regexp matcher" in emacs

I'm a big fan of Emacs, and use it a lot, especially while programming and debugging (using gud) (C/C++).

Recently I had to debug a program (rather simple but that compute on a lot of data (Graph Theory)), but I had a rather annoying problem. During the execution step by step of the program, I get the following error:

error in process filter: Stack overflow in regexp matcher

I made some research to find out what it was, and I found out this post: Debugging in emacs (with gud) often results in stack overflow error.

So as I understand it, there is a problem with the regexp matcher and the fact that some things in my program are simply too long? (I do have unusually long function name with a lot of parameters and I also use unusually big container.)

I'd really like to fix this, but I don't know anything about debugging Emacs Lisp, is there anyone to help me ?

Here is the output I get from Emacs internal debbuger : http://pastebin.com/5CKe74e6

I should also point out, that I use a personalized version of Emacs Prelude.

like image 262
SJuhel Avatar asked Jul 03 '15 12:07

SJuhel


1 Answers

The underlying problem is that a regular expression (regexp) contains too many alternatives, and when applied to a (typically long) text it fails to match whatever it tried to match.

In your case it's the regexp:

"\\([[:alnum:]-_]+\\)=\\({\\|\\[\\|\"\"\\|\"\\(?:[^\\\"]\\|\\\\.\\)*\"\\)"

Which is used by the function gdb-jsonify-buffer.

It looks like this regexp tries to match assignments. Basically, it matches a variable to the left of an = and (part of) an expression to the right. One of the things the regexp seems to match is a string, with containing escaped quotes -- this is always a warning sign as Emacs provides far better methods for parsing strings.

The problem can originate from the fact that this regexp is wrong (so that it matches a lot more than your string), that you have a malformed string, or that your program simply contains a really large string.

I would suggest that you file a bug report to the maintainer of that package. Make sure you include the text that caused the error to be triggered.

Alternatively, you could make an attempt at fixing this yourself. I would suggest that you replace the complex regexp with a simpler regexp that find the beginning of a string. You could then use, for example, (forward-sexp) to find the end of the string.

like image 94
Lindydancer Avatar answered Oct 13 '22 20:10

Lindydancer