Function: gud-lldb-marker-filter

gud-lldb-marker-filter is a byte-compiled function defined in gud.el.gz.

Signature

(gud-lldb-marker-filter STRING)

Documentation

Deduce interesting stuff from process output STRING.

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/gud.el.gz
(defun gud-lldb-marker-filter (string)
  "Deduce interesting stuff from process output STRING."

  ;; Pick information from our own frame info line "!gud LINE:COL:FILE"
  ;; because the file name in the standard LLDB frame-format doesn't have
  ;; a directory.
  (setq string
        (replace-regexp-in-string
         (rx bol "!gud "
             (group (+ digit)) ":"            ; 1: line
             (group (* digit)) ":"            ; 2: column
             (group (+ (not (in "\n\r"))))    ; 3: file
             (* "\r") "\n")
         (lambda (m)
           (let ((line (string-to-number (match-string 1 m)))
                 (col (string-to-number (match-string 2 m)))
                 (file (match-string 3 m)))
             (setq gud-last-frame (if (zerop col)
                                      (cons file line)
                                    (list file line col))))
           ;; Remove the line so that the user won't see it.
           "")
         string t t))

  (when (string-match (rx "Process " (1+ digit) " exited with status")
                      string)
    ;; Process 72874 exited with status = 9 (0x00000009) killed.
    ;; Doesn't seem to be changeable as of LLDB 17.0.2.
    (setq gud-last-last-frame nil)
    (setq gud-overlay-arrow-position nil))

  ;; LLDB sometimes emits certain ECMA-48 sequences even if TERM is "dumb":
  ;; CHA (Character Horizontal Absolute) and ED (Erase in Display),
  ;; seemingly to undo previous output on the same line.
  ;; Filter out these sequences here while carrying out their edits.
  (let ((bol (pos-bol)))
    (when (> (point) bol)
      ;; Move the current line to the string, so that control sequences
      ;; can delete parts of it.
      (setq string (concat (buffer-substring-no-properties bol (point))
                           string))
      (let ((inhibit-read-only t))
        (delete-region bol (point)))))
  (let ((ofs 0))
    (while (string-match (rx (group (* (not (in "\e\n"))))  ; preceding chars
                             "\e["                          ; CSI
                             (? (group (+ digit)))          ; argument
                             (group (in "GJ")))             ; CHA or ED
                         string ofs)
      (let* ((start (match-beginning 1))
             (prefix-end (match-end 1))
             (op (aref string (match-beginning 3)))
             (end (match-end 0))
             (keep-end
              (if (eq op ?G)
                  ;; Move to absolute column (CHA)
                  (min prefix-end
                       (+ start
                          (if (match-beginning 2)
                              (1- (string-to-number (match-string 2 string)))
                            0)))
                ;; Erase in display (ED): no further action.
                prefix-end)))
        ;; Delete the control sequence and possibly part of the preceding chars.
        (setq string (concat (substring string 0 keep-end)
                             (substring string end)))
        (setq ofs start))))
  string)