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

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

I recently had to debug a program (quite simple, but it can be calculated from a lot of data (diagram theory)), but I had a rather unpleasant problem. At runtime, step by step, I get the following error:

error in process filter: Qaru in regexp matcher 

I did some research to find out what it was, and I recognized this message: Debugging in emacs (with gud) often leads to an error .

So, as far as I understand, the regexp regex problem and the fact that some things in my program are too long? (I have an unusually long function name with many parameters, and I also use an unusually large container.)

I would love to fix this, but I don’t know anything about debugging Emacs Lisp, is there anyone who could help me?

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

I should also indicate that I am using a personalized version of Emacs Prelude.

+6
source share
2 answers

The main problem is that the regexp contains too many alternatives, and when applied to (usually long) text, it doesn't match what it tried to match.

In your case, this is a regular expression:

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

Used by gdb-jsonify-buffer function.

This regex seems to be trying to match destinations. Basically, it maps the variable to the left of the = symbol and (part of) the expression to the right. One of the things that seems to match the regular expression is a string containing escaped quotes is always a warning sign, since Emacs provides much better methods for parsing strings.

The problem may arise because this regular expression is incorrect (so that it matches much more than your string), that your string is incorrect, or that your program simply contains a very large string.

I would suggest that you send an error report to the originator of this package. Make sure you include the text that caused the error.

Alternatively, you can try to fix this yourself. I would suggest that you replace the complex regular expression with a simpler regular expression that will find the beginning of the line. Then you can use, for example, (forward-sexp) to find the end of the line.

+4
source

I also had this problem, so I used the Lindydancer suggestion to convert a regular expression to a string literal for use (forward-sexp), and it works fine for me.

I posted the patch:

http://lists.gnu.org/archive/html/bug-gnu-emacs/2017-12/msg00968.html

so hopefully at some point it will be merged. In the meantime, you can use this for gdb-jsonify-buffer:

 (defun gdb-jsonify-buffer (&optional fix-key fix-list) "Prepare GDB/MI output in current buffer for parsing with `json-read'. Field names are wrapped in double quotes and equal signs are replaced with semicolons. If FIX-KEY is non-nil, strip all \"FIX-KEY=\" occurrences from partial output. This is used to get rid of useless keys in lists in MI messages, eg: [key=.., key=..]. -stack-list-frames and -break-info are examples of MI commands which issue such responses. If FIX-LIST is non-nil, \"FIX-LIST={..}\" is replaced with \"FIX-LIST=[..]\" prior to parsing. This is used to fix broken -break-info output when it contains breakpoint script field incompatible with GDB/MI output syntax. If `default-directory' is remote, full file names are adapted accordingly." (save-excursion (let ((remote (file-remote-p default-directory))) (when remote (goto-char (point-min)) (while (re-search-forward "[\\[,]fullname=\"\\(.+\\)\"" nil t) (replace-match (concat remote "\\1") nil nil nil 1)))) (goto-char (point-min)) (when fix-key (save-excursion (while (re-search-forward (concat "[\\[,]\\(" fix-key "=\\)") nil t) (replace-match "" nil nil nil 1)))) (when fix-list (save-excursion ;; Find positions of braces which enclose broken list (while (re-search-forward (concat fix-list "={\"") nil t) (let ((p1 (goto-char (- (point) 2))) (p2 (progn (forward-sexp) (1- (point))))) ;; Replace braces with brackets (save-excursion (goto-char p1) (delete-char 1) (insert "[") (goto-char p2) (delete-char 1) (insert "]")))))) (goto-char (point-min)) (insert "{") (let ((re (concat "\\([[:alnum:]-_]+\\)="))) (while (re-search-forward re nil t) (replace-match "\"\\1\":" nil nil) (if (eq (char-after) ?\") (forward-sexp) (forward-char)))) (goto-char (point-max)) (insert "}"))) 
+2
source

All Articles