Subject: bug#14182: updated patch

From: Dima Kogan <[email-masked]>
Date: Thu, 18 Apr 2013 00:48:03 -0700

I used the patch in the original report for a while, and stumbled on
another, related case that emacs doesn't handle. I'm attaching an
updated patch that handles both cases (described in the patch). I've
also broken up the regex for improved readability.

>From 7ead460b535a84692057ddb8d36cec2203d5c3b4 Mon Sep 17 00:00:00 2001
From: Dima Kogan <[email-masked]>
Date: Thu, 11 Apr 2013 03:39:41 -0700
Subject: [PATCH] gud: perldb works with eval-ed subs

When debugging through a subroutine defined in an eval, perldb uses a
slightly different string to communicate the debugger position. This
patch updates the regex matching in gud-perldb-marker-filter to be
able to parse this string.

The "normal" string:
 ^Z^Z/tmp/tst.pl:6:0

The sub-in-eval string that can now be parsed can look like either of
 ^Z^Z(eval 5)[/tmp/tst.pl:6]:3:0
 ^Z^Z(eval 17)[Basic/Core/Core.pm.PL (i.e. PDL::Core.pm):2931]:1:0

Sample perl source that couldn't be stepped through before, and now can be:

 eval 'sub f
 {
   print 34;
 }
 ';

 f();
---
 lisp/progmodes/gud.el |   32 +++++++++++++++++++++++++++++---
 1 file changed, 29 insertions(+), 3 deletions(-)

diff --git a/lisp/progmodes/gud.el b/lisp/progmodes/gud.el
index d339495..15e6d07 100644
--- a/lisp/progmodes/gud.el
+++ b/lisp/progmodes/gud.el
@@ -1487,14 +1487,40 @@ into one that invokes an Emacs-enabled debugging session.
   (let ((output ""))
 
     ;; Process all the complete markers in this chunk.
-    (while (string-match "\032\032\\(\\([a-zA-Z]:\\)?[^:\n]*\\):\\([0-9]*\\):.*\n"
-			 gud-marker-acc)
+    ;;
+    ;; Here I match the string coming out of perldb.
+    ;; The strings can look like any of
+    ;;
+    ;;  "\032\032/tmp/tst.pl:6:0\n"
+    ;;  "\032\032(eval 5)[/tmp/tst.pl:6]:3:0\n"
+    ;;  "\032\032(eval 17)[Basic/Core/Core.pm.PL (i.e. PDL::Core.pm):2931]:1:0\n"
+    ;;
+    ;; From those I want the filename and the line number. I use two
+    ;; regexes. First I look for the eval case. If that doesn't match,
+    ;; I look for the "normal" case
+    (while
+        (or (string-match (concat "\032\032"
+                                  "(eval [0-9]+)"
+                                  "\\["
+                                  "\\(\\(?:[a-zA-Z]:\\)?[^:\n]*\\)" ; path
+                                  "\\(?: (i\.e\. [^)]*)\\)?"        ; optional "(i.e. ...)" line
+                                  ":"
+                                  "\\([0-9]*\\)"                    ; line number
+                                  "\\]"
+                                  ":.*\n")
+                          gud-marker-acc)
+            (string-match (concat "\032\032"
+                                  "\\(\\(?:[a-zA-Z]:\\)?[^:\n]*\\)" ; path
+                                  ":"
+                                  "\\([0-9]*\\)"                    ; line number
+                                  ":.*\n")
+                          gud-marker-acc))
       (setq
 
        ;; Extract the frame position from the marker.
        gud-last-frame
        (cons (match-string 1 gud-marker-acc)
-	     (string-to-number (match-string 3 gud-marker-acc)))
+	     (string-to-number (match-string 2 gud-marker-acc)))
 
        ;; Append any text before the marker to the output we're going
        ;; to return - we don't include the marker in this text.
-- 
1.7.10.4