emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/realgud-lldb 8faf094 01/56: 1st cut at an external lldb


From: Rocky Bernstein
Subject: [elpa] externals/realgud-lldb 8faf094 01/56: 1st cut at an external lldb plugin for realgud.
Date: Thu, 23 May 2019 02:11:35 -0400 (EDT)

branch: externals/realgud-lldb
commit 8faf094fc19f394bc84ed33a5d00b4ab5ae90938
Author: rocky <address@hidden>
Commit: rocky <address@hidden>

    1st cut at an external lldb plugin for realgud.
---
 .gitignore               |  22 +++++
 INSTALL                  |   1 +
 Makefile.am              |  47 ++++++++++
 README.md                |   1 +
 autogen.sh               |   7 ++
 common.mk                |  10 +++
 compute-lispdir.sh       |  46 ++++++++++
 configure.ac             |  54 ++++++++++++
 lldb/Makefile.am         |   1 +
 lldb/core.el             | 217 +++++++++++++++++++++++++++++++++++++++++++++++
 lldb/init.el             | 118 ++++++++++++++++++++++++++
 lldb/lldb.el             |  93 ++++++++++++++++++++
 lldb/track-mode.el       |  70 +++++++++++++++
 test/Makefile.am         |  69 +++++++++++++++
 test/lldb/bar.sh         |   2 +
 test/lldb/baz            |   0
 test/lldb/baz.c          |   0
 test/lldb/foo            |   0
 test/lldb/foo.c          |   0
 test/lldb/test2/bar.sh   |   2 +
 test/lldb/test2/baz.c    |   0
 test/regexp-helper.el    |  50 +++++++++++
 test/test-lldb.el        |  64 ++++++++++++++
 test/test-regexp-lldb.el | 108 +++++++++++++++++++++++
 24 files changed, 982 insertions(+)

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..ebc253a
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,22 @@
+*.elc
+*~
+/*-pkg.el
+/*.tar.gz
+/.python-version
+/README
+/aclocal.m4
+/autom4te.cache
+/config.log
+/config.status
+/configure
+/configure.lineno
+/elpa
+/install-sh
+/missing
+/test/npm-debug.log
+/tmp
+Makefile
+Makefile.in
+elc-stamp
+elc-temp
+script
diff --git a/INSTALL b/INSTALL
new file mode 100644
index 0000000..d94829e
--- /dev/null
+++ b/INSTALL
@@ -0,0 +1 @@
+bash ./autogen.sh
diff --git a/Makefile.am b/Makefile.am
new file mode 100644
index 0000000..4134762
--- /dev/null
+++ b/Makefile.am
@@ -0,0 +1,47 @@
+# Note: This makefile include remake-style target comments.
+# These comments before the targets start with #:
+# remake --tasks to shows the targets and the comments
+
+SUBDIRS = lldb test
+
+GIT2CL ?= git2cl
+RUBY   ?= ruby
+
+lispdir = @lispdir@
+
+include common.mk
+
+PHONY=check clean dist distclean test check-short check-terse install-short
+
+EXTRA_DIST+=common.mk README.md THANKS
+
+if MAINTAINER_MODE
+
+#: Remove change log: ChangeLog
+rmChangeLog:
+       rm ChangeLog || true
+
+#: Create a ChangeLog file from git logs
+ChangeLog: rmChangeLog
+       git log --pretty --numstat --summary | $(GIT2CL) > $@
+
+ACLOCAL_AMFLAGS=-I .
+
+endif
+
+#: Run all tests
+test: check
+
+#: Run all tests without bloated output
+check-short:
+       $(MAKE) check 2>&1  | $(RUBY) test/make-check-filter.rb
+
+#: Run all tests without and show just the failure lines
+check-terse:
+       $(MAKE) check 2>&1  | $(RUBY) tes/make-check-filter.rb | grep failure
+
+#: Run "make install"
+install-short:
+       $(MAKE) install 2>&1  | $(RUBY) test/make-check-filter.rb
+
+.PHONY: test check check-short rmChangeLog
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..94e1804
--- /dev/null
+++ b/README.md
@@ -0,0 +1 @@
+Module to add lldb support to realgud
diff --git a/autogen.sh b/autogen.sh
new file mode 100755
index 0000000..4ec4b71
--- /dev/null
+++ b/autogen.sh
@@ -0,0 +1,7 @@
+#!/bin/sh
+ln -fs README.md README
+autoreconf -vfi && \
+autoconf && {
+  echo "Running configure with --enable-maintainer-mode $@"
+  ./configure --enable-maintainer-mode $@
+}
diff --git a/common.mk b/common.mk
new file mode 100644
index 0000000..c8fc92a
--- /dev/null
+++ b/common.mk
@@ -0,0 +1,10 @@
+lisp_files := $(wildcard *.el)
+lisp_LISP = $(lisp_files)
+EXTRA_DIST = $(lisp_files)
+MOSTLYCLEANFILES = *.elc
+
+short:
+       $(MAKE) 2>&1 >/dev/null | ruby $(top_srcdir)/make-check-filter.rb
+
+%.short:
+       $(MAKE) $(@:.short=) 2>&1 >/dev/null
diff --git a/compute-lispdir.sh b/compute-lispdir.sh
new file mode 100755
index 0000000..220befd
--- /dev/null
+++ b/compute-lispdir.sh
@@ -0,0 +1,46 @@
+#!/bin/bash
+# Figures out a reasonable --prefix
+typeset -i rc=0
+typeset -i DEBUG=${DEBUG:-0}
+EMACS_PROG=${EMACS_PROG:-emacs}
+list=$($EMACS_PROG --batch --no-splash --no-site-file --eval '(message 
(substring (format "%s" load-path) 1 -1))' 2>&1)
+rc=$?
+if (( rc != 0 )) ; then
+    echo  >&2 "Something went wrong running $EMACS_PROG"
+    exit $rc
+$cmd
+fi
+for dir in $list ; do
+    if [[ -d $dir ]] ; then
+       case $dir in
+           */emacs/site-lisp)
+               ((DEBUG)) && echo "site lisp: $dir"
+               echo "$dir"
+               exit 0
+               ;;
+       esac
+    fi
+done
+for dir in $list ; do
+    if [[ -d $dir ]] ; then
+       case $dir in
+           */emacs/2[34]\.[0-9]/site-lisp)
+               ((DEBUG)) && echo "versioned site lisp: $dir"
+               echo "$dir"
+               exit 0
+               ;;
+       esac
+    fi
+done
+for dir in $list ; do
+    if [[ -d $dir ]] ; then
+       case $dir in
+           */emacs/2[34]\.[0-9]/site-lisp)
+               ((DEBUG)) && echo "versioned site lisp: $dir"
+               echo "$dir"
+               exit 0
+               ;;
+       esac
+    fi
+done
+exit 0
diff --git a/configure.ac b/configure.ac
new file mode 100644
index 0000000..f70128f
--- /dev/null
+++ b/configure.ac
@@ -0,0 +1,54 @@
+dnl FIXME: pick up from realgud.el
+AC_INIT(realgud-lldb, 1.0,)
+AC_CONFIG_SRCDIR(lldb/lldb.el)
+AM_INIT_AUTOMAKE([foreign])
+AM_MAINTAINER_MODE
+
+AC_PATH_PROG([EMACS], [emacs], [emacs])
+AC_ARG_WITH(emacs, AC_HELP_STRING([--with-emacs],
+                  [location of emacs program]), EMACS=$withval)
+
+AC_MSG_NOTICE("Checking emacs version")
+$EMACS -batch -q --no-site-file -eval \
+  '(if (<= emacs-major-version 23)
+       (progn
+         (error "You need GNU Emacs 24 or better.")
+         (kill-emacs 1)
+       )
+   )'
+if test $? -ne 0 ; then
+    AC_MSG_ERROR([Can't continue until above error is corrected.])
+fi
+
+##################################################################
+# See if --with-lispdir was set. If not, set it to a reasonable default
+# based on where bash thinks bashdb is supposed to be installed.
+##################################################################
+
+AM_MISSING_PROG(GIT2CL, git2cl, $missing_dir)
+
+# Check whether --with-lispdir was given.
+if test "${with_lispdir+set}" = set; then :
+else
+  my_lispdir=$(EMACS_PROG=$EMACS $SH_PROG $(dirname $0)/compute-lispdir.sh)
+  if test "${my_lispdir+set}" = set; then :
+    with_lispdir=$my_lispdir
+    echo "'compute-lispdir.sh' lispdir install directory override: 
'$with_lispdir'"
+  fi
+fi
+
+##
+## Find out where to install the debugger emacs lisp files
+##
+AM_PATH_LISPDIR
+lispdir_realgud=$lispdir/realgud
+AC_SUBST([lispdir])
+AC_SUBST([lispdir_realgud])
+
+AM_CONDITIONAL(INSTALL_EMACS_LISP, test "x$lispdir_realgud" != "x")
+
+AC_CONFIG_FILES([Makefile \
+                lldb/Makefile \
+                test/Makefile \
+                ])
+AC_OUTPUT
diff --git a/lldb/Makefile.am b/lldb/Makefile.am
new file mode 100644
index 0000000..23f8a8f
--- /dev/null
+++ b/lldb/Makefile.am
@@ -0,0 +1 @@
+include ../common.mk
diff --git a/lldb/core.el b/lldb/core.el
new file mode 100644
index 0000000..c5e14fa
--- /dev/null
+++ b/lldb/core.el
@@ -0,0 +1,217 @@
+;; Copyright (C) 2015 Free Software Foundation, Inc
+
+;; Author: Rocky Bernstein <address@hidden>
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+(eval-when-compile (require 'cl))
+
+(require 'load-relative)
+(require 'realgud-track)
+(require 'realgud-core)
+(require 'realgud-lang)
+
+(declare-function realgud:expand-file-name-if-exists 'realgud-core)
+(declare-function realgud-lang-mode? 'realgud-lang)
+(declare-function realgud-parse-command-arg 'realgud-core)
+(declare-function realgud-query-cmdline 'realgud-core)
+
+;; FIXME: I think the following could be generalized and moved to
+;; realgud-... probably via a macro.
+(defvar realgud:lldb-minibuffer-history nil
+  "minibuffer history list for the command `lldb'.")
+
+(easy-mmode-defmap realgud:lldb-minibuffer-local-map
+  '(("\C-i" . comint-dynamic-complete-filename))
+  "Keymap for minibuffer prompting of gud startup command."
+  :inherit minibuffer-local-map)
+
+;; FIXME: I think this code and the keymaps and history
+;; variable chould be generalized, perhaps via a macro.
+(defun realgud:lldb-query-cmdline (&optional opt-debugger)
+  (realgud-query-cmdline
+   'realgud:lldb-suggest-invocation
+   realgud:lldb-minibuffer-local-map
+   'realgud:lldb-minibuffer-history
+   opt-debugger))
+
+(defun realgud:lldb-parse-cmd-args (orig-args)
+  "Parse command line ARGS for the annotate level and name of script to debug.
+
+ORIG_ARGS should contain a tokenized list of the command line to run.
+
+We return the a list containing
+* the name of the debugger given (e.g. lldb) and its arguments - a list of 
strings
+* nil (a placehoder in other routines of this ilk for a debugger
+* the script name and its arguments - list of strings
+* whether the annotate or emacs option was given ('-A', '--annotate' or 
'--emacs) - a boolean
+
+For example for the following input
+  (map 'list 'symbol-name
+   '(lldb --tty /dev/pts/1 -cd ~ --emacs ./gcd.py a b))
+
+we might return:
+   ((\"lldb\" \"--tty\" \"/dev/pts/1\" \"-cd\" \"home/rocky\' \"--emacs\") nil 
\"(/tmp/gcd.py a b\") 't\")
+
+Note that path elements have been expanded via `expand-file-name'.
+"
+
+  ;; Parse the following kind of pattern:
+  ;;  lldb lldb-options script-name script-options
+  (let (
+       (args orig-args)
+       (pair)          ;; temp return from
+
+       ;; One dash is added automatically to the below, so
+       ;; h is really -h and -host is really --host.
+       (lldb-two-args '("x" "-command" "b" "-exec"
+                       "cd" "-pid"  "-core" "-directory"
+                       "-annotate"
+                       "se" "-symbols" "-tty"))
+       ;; lldb doesn't optionsl 2-arg options.
+       (lldb-opt-two-args '())
+
+       ;; Things returned
+       (script-name nil)
+       (debugger-name nil)
+       (debugger-args '())
+       (script-args '())
+       (annotate-p nil))
+
+    (if (not (and args))
+       ;; Got nothing: return '(nil nil nil nil)
+       (list debugger-args nil script-args annotate-p)
+      ;; else
+      (progn
+
+       ;; Remove "lldb" from "lldb --lldb-options script
+       ;; --script-options"
+       (setq debugger-name (file-name-sans-extension
+                            (file-name-nondirectory (car args))))
+       (unless (string-match "^lldb.*" debugger-name)
+         (message
+          "Expecting debugger name `%s' to be `lldb'"
+          debugger-name))
+       (setq debugger-args (list (pop args)))
+
+       ;; Skip to the first non-option argument.
+       (while (and args (not script-name))
+         (let ((arg (car args)))
+           (cond
+            ;; Annotation or emacs option with level number.
+            ((or (member arg '("--annotate" "-A"))
+                 (equal arg "--emacs"))
+             (setq annotate-p t)
+             (nconc debugger-args (list (pop args) (pop args))))
+            ;; Combined annotation and level option.
+            ((string-match "^--annotate=[0-9]" arg)
+             (nconc debugger-args (list (pop args) (pop args)) )
+             (setq annotate-p t))
+            ;; path-argument ooptions
+            ((member arg '("-cd" ))
+             (setq arg (pop args))
+             (nconc debugger-args
+                    (list arg (realgud:expand-file-name-if-exists
+                               (pop args)))))
+            ;; Options with arguments.
+            ((string-match "^-" arg)
+             (setq pair (realgud-parse-command-arg
+                         args lldb-two-args lldb-opt-two-args))
+             (nconc debugger-args (car pair))
+             (setq args (cadr pair)))
+            ;; Anything else must be the script to debug.
+            (t (setq script-name arg)
+               (setq script-args args))
+            )))
+       (list debugger-args nil script-args annotate-p)))))
+
+(defvar realgud:lldb-command-name)
+
+(defun realgud:lldb-executable (file-name)
+"Return a priority for wehther file-name is likely we can run lldb on"
+  (let ((output (shell-command-to-string (format "file %s" file-name))))
+    (cond
+     ((string-match "ASCII" output) 2)
+     ((string-match "ELF" output) 7)
+     ((string-match "executable" output) 6)
+     ('t 5))))
+
+
+(defun realgud:lldb-suggest-invocation (&optional debugger-name)
+  "Suggest a lldb command invocation. Here is the priority we use:
+* an executable file with the name of the current buffer stripped of its 
extension
+* any executable file in the current directory with no extension
+* the last invocation in lldb:minibuffer-history
+* any executable in the current directory
+When all else fails return the empty string."
+  (let* ((file-list (directory-files default-directory))
+        (priority 2)
+        (best-filename nil)
+        (try-filename (file-name-base (or (buffer-file-name) "lldb"))))
+    (when (member try-filename (directory-files default-directory))
+       (setq best-filename try-filename)
+       (setq priority (+ (realgud:lldb-executable try-filename) 2)))
+
+    ;; FIXME: I think a better test would be to look for
+    ;; c-mode in the buffer that have a corresponding executable
+    (while (and (setq try-filename (car-safe file-list)) (< priority 8))
+      (setq file-list (cdr file-list))
+      (if (and (file-executable-p try-filename)
+              (not (file-directory-p try-filename)))
+         (if (equal try-filename (file-name-sans-extension try-filename))
+             (progn
+               (setq best-filename try-filename)
+               (setq priority (1+ (realgud:lldb-executable best-filename))))
+           ;; else
+           (progn
+             (setq best-filename try-filename)
+             (setq priority (realgud:lldb-executable best-filename))
+             ))
+       ))
+    (if (< priority 8)
+       (cond
+        (realgud:lldb-minibuffer-history
+         (car realgud:lldb-minibuffer-history))
+        ((equal priority 7)
+         (concat "lldb " best-filename))
+        (t "lldb "))
+      ;; else
+      (concat "lldb " best-filename))
+    ))
+
+(defun realgud:lldb-reset ()
+  "Lldb cleanup - remove debugger's internal buffers (frame,
+breakpoints, etc.)."
+  (interactive)
+  ;; (lldb-breakpoint-remove-all-icons)
+  (dolist (buffer (buffer-list))
+    (when (string-match "\\*lldb-[a-z]+\\*" (buffer-name buffer))
+      (let ((w (get-buffer-window buffer)))
+        (when w
+          (delete-window w)))
+      (kill-buffer buffer))))
+
+;; (defun lldb-reset-keymaps()
+;;   "This unbinds the special debugger keys of the source buffers."
+;;   (interactive)
+;;   (setcdr (assq 'lldb-debugger-support-minor-mode minor-mode-map-alist)
+;;       lldb-debugger-support-minor-mode-map-when-deactive))
+
+
+(defun realgud:lldb-customize ()
+  "Use `customize' to edit the settings of the `realgud:lldb' debugger."
+  (interactive)
+  (customize-group 'realgud:lldb))
+
+(provide-me "realgud:lldb-")
diff --git a/lldb/init.el b/lldb/init.el
new file mode 100644
index 0000000..01d6bd9
--- /dev/null
+++ b/lldb/init.el
@@ -0,0 +1,118 @@
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; lldb debugger
+
+(eval-when-compile (require 'cl))
+
+(require 'load-relative)
+(require 'realgud-regexp)
+(require 'realgud-loc)
+
+(defvar realgud-pat-hash)
+(declare-function make-realgud-loc-pat (realgud-loc))
+
+(defvar realgud:lldb-pat-hash (make-hash-table :test 'equal)
+  "hash key is the what kind of pattern we want to match:
+backtrace, prompt, etc.  the values of a hash entry is a
+realgud-loc-pat struct")
+
+(declare-function make-realgud-loc "realgud-loc" (a b c d e f))
+
+(defconst realgud:lldb-frame-file-regexp
+  (format "\\(.+\\):%s" realgud:regexp-captured-num))
+
+;; regular expression that describes a lldb location generally shown
+;; before a command prompt. NOTE: we assume annotate 1!
+(setf (gethash "loc" realgud:lldb-pat-hash)
+      (make-realgud-loc-pat
+       :regexp (format "^%s:%s:beg:0x\\([0-9a-f]+\\)"
+                      realgud:lldb-frame-file-regexp 
realgud:regexp-captured-num)
+       :file-group 1
+       :line-group 2
+       :char-offset-group 3))
+
+(setf (gethash "prompt" realgud:lldb-pat-hash)
+      (make-realgud-loc-pat
+       :regexp   "^(lldb) "
+       ))
+
+;;  regular expression that describes a "breakpoint set" line
+(setf (gethash "brkpt-set" realgud:lldb-pat-hash)
+      (make-realgud-loc-pat
+       :regexp (format "^Breakpoint %s at 0x\\([0-9a-f]*\\): file \\(.+\\), 
line %s.\n"
+                      realgud:regexp-captured-num realgud:regexp-captured-num)
+       :num 1
+       :file-group 3
+       :line-group 4))
+
+(defconst realgud:lldb-frame-start-regexp
+  "\\(?:^\\|\n\\)")
+
+(defconst realgud:lldb-frame-num-regexp
+  (format "#%s " realgud:regexp-captured-num))
+
+;; Regular expression that describes a lldb "backtrace" command line.
+;; For example:
+;; #0  main (argc=2, argv=0xbffff564, envp=0xbffff570) at main.c:935
+;; #1  0xb7e9f4a5 in *__GI___strdup (s=0xbffff760 "/tmp/remake/remake") at 
strdup.c:42
+;; #2  0x080593ac in main (argc=2, argv=0xbffff5a4, envp=0xbffff5b0)
+;;    at main.c:952
+;; #46 0xb7f51b87 in vm_call_cfunc (th=0x804d188, reg_cfp=0xb7ba9e88, num=0,
+;;    recv=157798080, blockptr=0x0, me=0x80d12a0) at vm_insnhelper.c:410
+
+(setf (gethash "debugger-backtrace" realgud:lldb-pat-hash)
+      (make-realgud-loc-pat
+       :regexp         (concat realgud:lldb-frame-start-regexp
+                       realgud:lldb-frame-num-regexp
+                       "\\(?:.\\|\\(?:[\n] \\)\\)+[ ]+at "
+                       realgud:lldb-frame-file-regexp
+                       )
+       :num 1
+       :file-group 2
+       :line-group 3)
+      )
+
+(setf (gethash "font-lock-keywords" realgud:lldb-pat-hash)
+      '(
+       ;; #2  0x080593ac in main (argc=2, argv=0xbffff5a4, envp=0xbffff5b0)
+       ;;    at main.c:952
+       ("[ \n]+at \\(.*\\):\\([0-9]+\\)"
+        (1 realgud-file-name-face)
+        (2 realgud-line-number-face))
+
+       ;; The frame number and first type name, if present.
+       ;; E.g. =>#0  Makefile.in at /tmp/Makefile:216
+       ;;      ---^
+       ( "#\\(?:^\\|\n\\)\\([0-9]+\\)  "
+        (1 realgud-backtrace-number-face))
+       ))
+
+(setf (gethash "lldb" realgud-pat-hash) realgud:lldb-pat-hash)
+
+(defvar realgud:lldb-command-hash (make-hash-table :test 'equal)
+  "Hash key is command name like 'continue' and the value is
+  the lldb command to use, like 'continue'")
+
+(setf (gethash "break"    realgud:lldb-command-hash) "break %l")
+(setf (gethash "clear"    realgud:lldb-command-hash) "clear %l")
+(setf (gethash "continue" realgud:lldb-command-hash) "continue")
+(setf (gethash "eval"     realgud:lldb-command-hash) "print %s")
+(setf (gethash "quit"     realgud:lldb-command-hash) "quit")
+(setf (gethash "run"      realgud:lldb-command-hash) "run")
+(setf (gethash "step"     realgud:lldb-command-hash) "step %p")
+(setf (gethash "lldb" realgud-command-hash) realgud:lldb-command-hash)
+
+(setf (gethash "lldb" realgud-pat-hash) realgud:lldb-pat-hash)
+
+(provide-me "realgud:lldb-")
diff --git a/lldb/lldb.el b/lldb/lldb.el
new file mode 100644
index 0000000..9bf3b2a
--- /dev/null
+++ b/lldb/lldb.el
@@ -0,0 +1,93 @@
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+;;  `realgud:lldb' Main interface to lldb via Emacs
+(require 'cl)
+(require 'list-utils)
+(require 'load-relative)
+(require-relative-list '("../../common/helper" "../../common/utils")
+                      "realgud-")
+(require-relative-list '("core" "track-mode") "realgud:lldb-")
+
+;; This is needed, or at least the docstring part of it is needed to
+;; get the customization menu to work in Emacs 24.
+(defgroup realgud:lldb nil
+  "The realgud interface to lldb"
+  :group 'realgud
+  :version "24.1")
+
+;; -------------------------------------------------------------------
+;; User definable variables
+;;
+
+(defcustom realgud:lldb-command-name
+  ;;"lldb
+  "gdb"
+  "File name for executing the and command options.
+This should be an executable on your path, or an absolute file name."
+  :type 'string
+  :group 'realgud:lldb)
+
+(declare-function realgud:lldb-track-mode     'realgud:lldb-track-mode)
+(declare-function realgud-command            'realgud:lldb-core)
+(declare-function realgud:lldb-parse-cmd-args 'realgud:lldb-core)
+(declare-function realgud:lldb-query-cmdline  'realgud:lldb-core)
+(declare-function realgud:run-process        'realgud-core)
+(declare-function realgud:flatten            'realgud-utils)
+
+;; -------------------------------------------------------------------
+;; The end.
+;;
+
+;;;###autoload
+(defun realgud:lldb (&optional opt-cmd-line no-reset)
+  "Invoke the lldb debugger and start the Emacs user interface.
+
+OPT-CMD-LINE is treated like a shell string; arguments are
+tokenized by `split-string-and-unquote'.
+
+Normally, command buffers are reused when the same debugger is
+reinvoked inside a command buffer with a similar command. If we
+discover that the buffer has prior command-buffer information and
+NO-RESET is nil, then that information which may point into other
+buffers and source buffers which may contain marks and fringe or
+marginal icons is reset. See `loc-changes-clear-buffer' to clear
+fringe and marginal icons.
+"
+
+  (interactive)
+  (let* ((cmd-str (or opt-cmd-line (realgud:lldb-query-cmdline "lldb")))
+        (cmd-args (split-string-and-unquote cmd-str))
+        (parsed-args (realgud:lldb-parse-cmd-args cmd-args))
+        (script-args (caddr parsed-args))
+        (script-name (car script-args))
+        (parsed-cmd-args
+         (cl-remove-if 'nil (realgud:flatten parsed-args)))
+        (cmd-buf (realgud:run-process realgud:lldb-command-name
+                                      script-name parsed-cmd-args
+                                      'realgud:lldb-minibuffer-history
+                                      nil))
+        )
+    (if cmd-buf
+       (with-current-buffer cmd-buf
+         (realgud-command "set annotate 1" nil nil nil)
+         )
+      )
+    )
+  )
+
+(provide-me "realgud-")
+
+;; Local Variables:
+;; byte-compile-warnings: (not cl-functions)
+;; End:
diff --git a/lldb/track-mode.el b/lldb/track-mode.el
new file mode 100644
index 0000000..5e2f72d
--- /dev/null
+++ b/lldb/track-mode.el
@@ -0,0 +1,70 @@
+;;; track-mode.el ---
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+;; lldb tracking a comint or eshell buffer.
+
+(eval-when-compile (require 'cl))
+(require 'load-relative)
+(require-relative-list '(
+                        "../../common/cmds"
+                        "../../common/menu"
+                        "../../common/track"
+                        "../../common/track-mode"
+                        )
+                      "realgud-")
+(require-relative-list '("core" "init") "realgud:lldb-")
+
+(realgud-track-mode-vars "realgud:lldb")
+
+(declare-function realgud-track-mode 'realgud-track-mode)
+(declare-function realgud:track-mode-hook 'realgud-track-mode)
+(declare-function realgud-track-mode-setup 'realgud-track-mode)
+(declare-function realgud:track-set-debugger 'realgud-track-mode)
+
+(define-key realgud:lldb-track-mode-map
+  (kbd "C-c !b") 'realgud:goto-debugger-backtrace-line)
+
+(defun realgud:lldb-track-mode-hook()
+  (use-local-map realgud:lldb-track-mode-map)
+  (realgud-track-mode-setup 't)
+  (message "realgud:lldb track-mode-hook called")
+)
+
+(define-minor-mode realgud:lldb-track-mode
+  "Minor mode for tracking lldb inside a process shell via realgud.
+
+If called interactively with no prefix argument, the mode is toggled. A prefix 
argument, captured as ARG, enables the mode if the argument is positive, and 
disables it otherwise.
+
+Key bindings:
+\\{realgud:lldb-track-mode-map}
+"
+  :init-value nil
+  ;; :lighter " lldb"   ;; mode-line indicator from realgud-track is 
sufficient.
+  ;; The minor mode bindings.
+  :global nil
+  :group 'realgud:lldb
+  :keymap realgud:lldb-track-mode-map
+  (if realgud:lldb-track-mode
+      (progn
+       (realgud:track-set-debugger "lldb")
+        (realgud:lldb-track-mode-hook)
+        (realgud:track-mode-enable))
+    (progn
+      (setq realgud-track-mode nil)
+      ))
+)
+
+(provide-me "realgud:lldb-")
+;;; track-mode.el ends here
diff --git a/test/Makefile.am b/test/Makefile.am
new file mode 100644
index 0000000..c0e7ede
--- /dev/null
+++ b/test/Makefile.am
@@ -0,0 +1,69 @@
+include $(top_srcdir)/common.mk
+
+PHONY=check test all check-elget test-elget help
+EXTRA_DIST += gcd.py gcd.rb gdb
+
+#: overall help on running the make targets
+help:
+       @echo "The main function of this Makefile is to facilitate running 
tests."
+       @echo
+       @echo "To run all of the tests, use targets \"test\", \"check\" or 
\"check-short\"."
+       @echo "For example:"
+       @echo
+       @echo "    make check"
+       @echo "or:"
+       @echo "    make check-short"
+       @echo
+       @echo "The -short target uses a filter written in Ruby to remove 
extreanous output."
+       @echo
+       @echo "To run a specific test like test-srcbuf.el, change \".el\" to"
+       @echo "\".run\". For example:"
+       @echo
+       @echo "    make test-srcbuf.run"
+       @echo
+       @echo "Tests can also be run via the Emacs el-get package and this 
loads dependent emacs "
+       @echo "package, like load-relative. To do this, use targets, 
\"check-elget\","
+       @echo "\"test-elget\", or \"check-short-elget\"."
+       @echo
+       @echo  "To run a specific test like test-srcbuf.el via el-get change 
\".el\""
+       @echo "to \".elrun\" For example:"
+       @echo
+       @echo "    make test-srcbuf.elrun"
+
+
+#: same thing as "check"
+test: check
+
+#: same thing as "check-elget"
+test-elget: check-elget
+
+test_files := $(wildcard test-*.el)
+
+CHECK_FILES = $(notdir $(test_files:.el=.run))
+EL_GET_CHECK_FILES = $(notdir $(test_files:.el=.elrun))
+
+#: Run all tests
+check: $(CHECK_FILES)
+
+#: Run all tests via el-get
+check-elget: $(EL_GET_CHECK_FILES)
+
+#: Run all tests with minimum verbosity
+check-short:
+       $(MAKE) check 2>&1  | ruby ../make-check-filter.rb
+
+#: Run all tests with minimum verbosity via el-get
+check-short-elget:
+       $(MAKE) check-elget 2>&1  | ruby ../make-check-filter.rb
+
+test-%.run:
+       (cd $(top_srcdir)/test && $(EMACS) --batch --no-site-file --no-splash 
--load $(@:.run=.el))
+
+#: Run tests using el-get to specify external Lisp dependencies
+test-%.elrun:
+       (cd $(top_srcdir)/test && $(EMACS) --batch --no-site-file --no-splash 
--load ../el-get-install.el --load $(@:.elrun=.el))
+
+# Whatever it is you want to do, it should be forwarded to the
+# to top-level directories
+# %:
+#      $(MAKE) -C .. $@
diff --git a/test/lldb/bar.sh b/test/lldb/bar.sh
new file mode 100755
index 0000000..6c961d1
--- /dev/null
+++ b/test/lldb/bar.sh
@@ -0,0 +1,2 @@
+#!/bin/sh
+echo This Should get selected 3rd
diff --git a/test/lldb/baz b/test/lldb/baz
new file mode 100755
index 0000000..e69de29
diff --git a/test/lldb/baz.c b/test/lldb/baz.c
new file mode 100644
index 0000000..e69de29
diff --git a/test/lldb/foo b/test/lldb/foo
new file mode 100755
index 0000000..e69de29
diff --git a/test/lldb/foo.c b/test/lldb/foo.c
new file mode 100644
index 0000000..e69de29
diff --git a/test/lldb/test2/bar.sh b/test/lldb/test2/bar.sh
new file mode 100755
index 0000000..6c961d1
--- /dev/null
+++ b/test/lldb/test2/bar.sh
@@ -0,0 +1,2 @@
+#!/bin/sh
+echo This Should get selected 3rd
diff --git a/test/lldb/test2/baz.c b/test/lldb/test2/baz.c
new file mode 100644
index 0000000..e69de29
diff --git a/test/regexp-helper.el b/test/regexp-helper.el
new file mode 100644
index 0000000..6c67de3
--- /dev/null
+++ b/test/regexp-helper.el
@@ -0,0 +1,50 @@
+(require 'test-simple)
+(require 'realgud-buffer-command)
+
+(eval-when-compile
+  (defvar helper-bps)
+  (defvar helper-loc)
+  (defvar helper-tb)
+  (defvar prompt-pat)
+)
+
+(declare-function realgud-loc-pat-regexp 'realgud-backtrace-mode)
+(declare-function realgud-cmdbuf-info-loc-regexp 'realgud-buffer-command)
+(declare-function test-simple-start 'test-simple)
+
+
+(defun setup-regexp-vars(pat-hash)
+  (setq helper-bps    (gethash "brkpt-set" pat-hash))
+  (setq helper-loc    (gethash "loc"       pat-hash))
+  (setq helper-tb     (gethash "lang-backtrace" pat-hash))
+)
+
+(defun loc-match(text var)
+  "Match TEXT against regexp field VAR"
+  (string-match (realgud-loc-pat-regexp var) text)
+)
+
+(defun bp-loc-match(text)
+  (string-match (realgud-loc-pat-regexp helper-bps) text)
+)
+
+(defun tb-loc-match(text)
+  (string-match (realgud-loc-pat-regexp helper-tb) text)
+)
+
+(defun cmdbuf-loc-match(text dbgr)
+  "Match TEXT against cmdbuf-info-loc field VAR"
+  (string-match (realgud-cmdbuf-info-loc-regexp dbgr) text)
+  )
+
+(defun prompt-match(prompt-str &optional num-str fmt-str)
+  (unless fmt-str (setq fmt-str "debugger prompt %s"))
+  (assert-equal 0 (string-match (realgud-loc-pat-regexp prompt-pat)
+                               prompt-str)
+               (format fmt-str prompt-str))
+  (cond (num-str
+        (assert-equal num-str (substring prompt-str
+                                      (match-beginning 1) (match-end 1))))
+       ('t 't))
+  )
+(provide 'realgud-regexp-helper)
diff --git a/test/test-lldb.el b/test/test-lldb.el
new file mode 100644
index 0000000..72e72fa
--- /dev/null
+++ b/test/test-lldb.el
@@ -0,0 +1,64 @@
+(require 'test-simple)
+(require 'load-relative)
+(load-file "../lldb/core.el")
+(load-file "./regexp-helper.el")
+
+(eval-when-compile
+  (defvar realgud:lldb-minibuffer-history)
+  (defvar test:realgud-lldb-executable-save)
+  (defvar test:realgud-minibuffer-history-save)
+)
+
+(declare-function realgud:lldb-suggest-invocation 'realgud:bashdb)
+(declare-function __FILE__              'require-relative)
+
+(test-simple-start)
+
+;; Save value realgud:run-process and change it to something we want
+(setq test:realgud-lldb-executable-save (symbol-function 
'realgud:lldb-executable))
+(setq test:realgud-minibuffer-history-save realgud:lldb-minibuffer-history)
+
+(defun realgud:lldb-executable (filename)
+  "Mock function for testing"
+  (cond ((equal filename "bar.sh") 7)
+       ((equal filename "foo") 8)
+       ((equal filename "baz") 8)
+       (t 3)))
+
+(defun lldb-test()
+  (note "realgud:lldb-suggest-invocation")
+  (setq realgud:lldb-minibuffer-history nil)
+  (let ((my-directory (file-name-directory (__FILE__))))
+    (save-excursion
+      (note "Test preference to buffer editing")
+      (setq default-directory
+           (concat my-directory "lldb"))
+      (find-file-literally "foo.c")
+      (assert-equal "lldb foo" (realgud:lldb-suggest-invocation)
+                   "Should find file sans extension - foo")
+      (find-file-literally "baz.c")
+      (assert-equal "lldb baz" (realgud:lldb-suggest-invocation)
+                   "Should find file sans extension - baz")
+      )
+    (save-excursion
+      (note "Pick up non-sans executable")
+      (setq default-directory
+           (concat my-directory  "lldb/test2"))
+      ;; (assert-equal "lldb bar.sh" (realgud:lldb-suggest-invocation))
+      (setq realgud:lldb-minibuffer-history '("lldb testing"))
+      (setq default-directory
+           (concat my-directory  "lldb/test2"))
+      (assert-equal "lldb testing" (realgud:lldb-suggest-invocation)
+                   "After setting minibuffer history - takes precidence")
+      )
+    (setq default-directory my-directory)
+    )
+  )
+(lldb-test)
+(end-tests)
+
+;; Restore the old values.
+;; You might have to run the below if you run this interactively.
+(fset 'realgud:lldb-executable test:realgud-lldb-executable-save)
+(setq realgud:lldb-minibuffer-history test:realgud-minibuffer-history-save)
+(setq default-directory (file-name-directory (__FILE__)))
diff --git a/test/test-regexp-lldb.el b/test/test-regexp-lldb.el
new file mode 100644
index 0000000..7f55c2d
--- /dev/null
+++ b/test/test-regexp-lldb.el
@@ -0,0 +1,108 @@
+(require 'test-simple)
+(require 'load-relative)
+(require 'realgud-buffer-command)
+(load-file "../lldb/init.el")
+(load-file "./regexp-helper.el")
+
+(declare-function __FILE__              'load-relative)
+
+(test-simple-start)
+
+(eval-when-compile
+  (defvar dbg-name)   (defvar realgud-pat-hash)   (defvar realgud-bt-hash)
+  (defvar loc-pat)    (defvar prompt-pat)         (defvar s1)
+  (defvar file-group) (defvar line-group)         (defvar pos)
+  (defvar test-dbgr)  (defvar test-text)
+)
+
+; Some setup usually done in setting up the buffer.
+; We customize this for this debugger.
+; FIXME: encapsulate this.
+(setq dbg-name "gdb")
+
+(setq loc-pat (gethash "loc" (gethash dbg-name realgud-pat-hash)))
+(setq test-dbgr (make-realgud-cmdbuf-info
+                 :debugger-name dbg-name
+                 :loc-regexp (realgud-loc-pat-regexp loc-pat)
+                 :file-group (realgud-loc-pat-file-group loc-pat)
+                 :line-group (realgud-loc-pat-line-group loc-pat)))
+
+;; FIXME: we get a void variable somewhere in here when running
+;;        even though we define it in lexical-let. Dunno why.
+;;        setq however will workaround this.
+(setq test-text "/home/rocky/c/ctest.c:80:2000:beg:0x8048748>")
+(note "traceback location matching")
+
+(assert-t (numberp (cmdbuf-loc-match test-text test-dbgr)) "basic location")
+(assert-equal "/home/rocky/c/ctest.c"
+             (match-string (realgud-cmdbuf-info-file-group test-dbgr)
+                           test-text) "extract file name")
+(assert-equal "80"
+             (match-string (realgud-cmdbuf-info-line-group test-dbgr)
+                           test-text) "extract line number")
+(note "debugger-backtrace")
+(setq realgud-bt-pat  (gethash "debugger-backtrace"
+                           realgud:gdb-pat-hash))
+(setq s1
+      "#0  main (argc=2, argv=0xbffff564, envp=0xbffff570) at main.c:935
+#1  0xb7e9f4a5 in *__GI___strdup (s=0xbffff760 \"/tmp/remake/remake\") at 
strdup.c:42
+#2  0x080593ac in main (argc=2, argv=0xbffff5a4, envp=0xbffff5b0)
+    at main.c:952
+#46 0xb7f51b87 in vm_call_cfunc (th=0x804d188, reg_cfp=0xb7ba9e88, num=0,
+    recv=157798080, blockptr=0x0, me=0x80d12a0) at vm_insnhelper.c:410
+")
+(setq realgud-bt-re (realgud-loc-pat-regexp realgud-bt-pat))
+(setq file-group (realgud-loc-pat-file-group realgud-bt-pat))
+(setq line-group (realgud-loc-pat-line-group realgud-bt-pat))
+(assert-equal 0 (string-match realgud-bt-re s1))
+(assert-equal "main.c"
+             (substring s1
+                        (match-beginning file-group)
+                        (match-end file-group)))
+(assert-equal "935"
+             (substring s1
+                        (match-beginning line-group)
+                        (match-end line-group)))
+
+(setq pos (match-end 0))
+(assert-equal 65 pos)
+(assert-equal 65 (string-match realgud-bt-re s1 pos))
+(assert-equal "strdup.c"
+             (substring s1
+                        (match-beginning file-group)
+                        (match-end file-group)))
+(assert-equal "42"
+             (substring s1
+                        (match-beginning line-group)
+                        (match-end line-group)))
+
+(setq pos (match-end 0))
+(assert-equal 149 pos)
+(assert-equal 149 (string-match realgud-bt-re s1 pos))
+(assert-equal "main.c"
+             (substring s1
+                        (match-beginning file-group)
+                        (match-end file-group)))
+(assert-equal "952"
+             (substring s1
+                        (match-beginning line-group)
+                        (match-end line-group)))
+
+(setq pos (match-end 0))
+(assert-equal 233 pos)
+(assert-equal 233 (string-match realgud-bt-re s1 pos))
+(assert-equal "vm_insnhelper.c"
+             (substring s1
+                        (match-beginning file-group)
+                        (match-end file-group)))
+(assert-equal "410"
+             (substring s1
+                        (match-beginning line-group)
+                        (match-end line-group)))
+
+(note "prompt")
+(set (make-local-variable 'prompt-pat)
+     (gethash "prompt" realgud:gdb-pat-hash))
+(prompt-match "(gdb) ")
+
+(end-tests)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]