Skip to content

Commit

Permalink
Merge branch 'master' of github.com:realgud/realgud-lldb
Browse files Browse the repository at this point in the history
  • Loading branch information
rocky committed May 10, 2019
2 parents c44882b + 4bfd53a commit 4afe1ca
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 140 deletions.
62 changes: 31 additions & 31 deletions lldb/core.el
@@ -1,4 +1,4 @@
;; Copyright (C) 2016 Rocky Bernstein
;; Copyright (C) 2016, 2019 Rocky Bernstein

;; 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
Expand All @@ -13,7 +13,7 @@
;; 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))
(eval-when-compile (require 'cl-lib))

(require 'realgud)

Expand All @@ -24,34 +24,34 @@

;; FIXME: I think the following could be generalized and moved to
;; realgud-... probably via a macro.
(defvar realgud:lldb-minibuffer-history nil
(defvar realgud--lldb-minibuffer-history nil
"minibuffer history list for the command `lldb'.")

(easy-mmode-defmap realgud:lldb-minibuffer-local-map
(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)
(defun realgud--lldb-query-cmdline (&optional opt-debugger)
(realgud-query-cmdline
'realgud:lldb-suggest-invocation
realgud:lldb-minibuffer-local-map
'realgud:lldb-minibuffer-history
'realgud--lldb-suggest-invocation
realgud--lldb-minibuffer-local-map
'realgud--lldb-minibuffer-history
opt-debugger))

(defvar realgud:lldb-file-remap (make-hash-table :test 'equal)
(defvar realgud--lldb-file-remap (make-hash-table :test 'equal)
"How to remap lldb files in when we otherwise can't find in
the filesystem. The hash key is the file string we saw, and the
value is associated filesystem string presumably in the
filesystem")

(defun realgud:lldb-find-file(cmd-marker filename directory)
(defun realgud--lldb-find-file(cmd-marker filename directory)
"A find-file specific for lldb. We will prompt for a mapping and save that in
`realgud:lldb-file-remap' when that works."
`realgud--lldb-file-remap' when that works."
(let ((resolved-filename filename)
(remapped-filename (gethash filename realgud:lldb-file-remap)))
(remapped-filename (gethash filename realgud--lldb-file-remap)))
(cond
((and remapped-filename (stringp remapped-filename)
(file-exists-p remapped-filename)) remapped-filename)
Expand All @@ -60,18 +60,18 @@
(setq resolved-filename
(buffer-file-name
(compilation-find-file (point-marker) filename nil "")))
(puthash filename resolved-filename realgud:lldb-file-remap)))
(puthash filename resolved-filename realgud--lldb-file-remap)))
))

(defun realgud:cmd-lldb-break()
(defun realgud--cmd-lldb-break()
"Set a breakpoint storing mapping between a file and its basename"
(let* ((resolved-filename (realgud-expand-format "%X"))
(cmdbuf (realgud-get-cmdbuf))
(filename (file-name-nondirectory resolved-filename)))

;; Save mapping from basename to long name so that we know what's
;; up in a "Breakpoint set at" message
(puthash filename resolved-filename realgud:lldb-file-remap)
(puthash filename resolved-filename realgud--lldb-file-remap)

;; Run actual command
(realgud:cmd-break)
Expand All @@ -81,13 +81,13 @@
;; FIXME: setting a breakpoint should add a[ file-to-basename mapping
;; so that when this is called it can look up the short name and
;; remap it.
(defun realgud:lldb-loc-fn-callback(text filename lineno source-str
(defun realgud--lldb-loc-fn-callback(text filename lineno source-str
cmd-mark directory column)
(realgud:file-loc-from-line filename lineno
cmd-mark source-str nil nil directory))
;; 'realgud:lldb-find-file directory))
;; 'realgud--lldb-find-file directory))

(defun realgud:lldb-parse-cmd-args (orig-args)
(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.
Expand Down Expand Up @@ -167,9 +167,9 @@ Note that path elements have been expanded via `expand-file-name'.
)))
(list debugger-args nil script-args annotate-p)))))

(defvar realgud:lldb-command-name)
(defvar realgud--lldb-command-name)

(defun realgud:lldb-executable (file-name)
(defun realgud--lldb-executable (file-name)
"Return a priority for whether file-name is likely we can run lldb on"
(let ((output (shell-command-to-string (format "file %s" file-name))))
(cond
Expand All @@ -179,7 +179,7 @@ Note that path elements have been expanded via `expand-file-name'.
('t 5))))


(defun realgud:lldb-suggest-invocation (&optional debugger-name)
(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
Expand All @@ -192,7 +192,7 @@ When all else fails return the empty string."
(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)))
(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
Expand All @@ -203,25 +203,25 @@ When all else fails return the empty string."
(if (equal try-filename (file-name-sans-extension try-filename))
(progn
(setq best-filename try-filename)
(setq priority (1+ (realgud:lldb-executable best-filename))))
(setq priority (1+ (realgud--lldb-executable best-filename))))
;; else
(progn
(setq best-filename try-filename)
(setq priority (realgud:lldb-executable best-filename))
(setq priority (realgud--lldb-executable best-filename))
))
))
(if (< priority 8)
(cond
(realgud:lldb-minibuffer-history
(car realgud:lldb-minibuffer-history))
(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 ()
(defun realgud--lldb-reset ()
"Lldb cleanup - remove debugger's internal buffers (frame,
breakpoints, etc.)."
(interactive)
Expand All @@ -240,9 +240,9 @@ breakpoints, etc.)."
;; lldb-debugger-support-minor-mode-map-when-deactive))


(defun realgud:lldb-customize ()
"Use `customize' to edit the settings of the `realgud:lldb' debugger."
(defun realgud--lldb-customize ()
"Use `customize' to edit the settings of the `realgud--lldb' debugger."
(interactive)
(customize-group 'realgud:lldb))
(customize-group 'realgud--lldb))

(provide-me "realgud:lldb-")
(provide-me "realgud--lldb-")
111 changes: 57 additions & 54 deletions lldb/init.el
Expand Up @@ -19,14 +19,17 @@

(require 'realgud)

(defvar realgud-pat-hash)
(declare-function make-realgud-loc-pat (realgud-loc))

(defvar realgud:lldb-pat-hash (make-hash-table :test 'equal)
(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")

(defvar realgud-pat-hash
nil
"A buffer local hash table which maps a debugger name, .e.g. 'lldb' to its
the debugger specific hash table, e.g. 'realugd-lldd-pat-hash'.")
(declare-function make-realgud-loc-pat (realgud-loc))

(declare-function make-realgud-loc "realgud-loc" (a b c d e f))


Expand All @@ -38,35 +41,35 @@ realgud-loc-pat struct")
;; SolidityParserError.cpp:102
;;
;; Note the minimal-match regexp up to the first colon
(defconst realgud:lldb-file-col-regexp
(defconst realgud--lldb-file-col-regexp
(format "\\(.+?\\):%s\\(?::%s\\)?"
realgud:regexp-captured-num
realgud:regexp-captured-num))

(defconst realgud:lldb-frame-start-regexp
(defconst realgud--lldb-frame-start-regexp
"\\(?:^\\|\n\\)")

;; Some versions of lldb insert "frame" and some don't.
(defconst realgud:lldb-frame-num-regexp
(defconst realgud--lldb-frame-num-regexp
(format "[ ]*\\(?:frame \\)?#%s[:]? "
realgud:regexp-captured-num))

(setf (gethash "loc-callback-fn" realgud:lldb-pat-hash) 'realgud:lldb-loc-fn-callback)
(setf (gethash "loc-callback-fn" realgud--lldb-pat-hash) 'realgud--lldb-loc-fn-callback)

;; realgud-loc-pat that describes a lldb location generally shown
;; before a command prompt.
;; For example:
;; * thread #1: tid = 12866, 0x00000000004004b4 hello`main(argc=1, argv=0x00007fffffffd668) + 4 at hello.c:5, name = 'hello', stop reason = breakpoint 1.1
(setf (gethash "loc" realgud:lldb-pat-hash)
(setf (gethash "loc" realgud--lldb-pat-hash)
(make-realgud-loc-pat
:regexp (format "^\\* thread #%s: .+ at %s, "
realgud:regexp-captured-num realgud:lldb-file-col-regexp)
realgud:regexp-captured-num realgud--lldb-file-col-regexp)
:file-group 2
:line-group 3
:column-group 4))

;; Top frame number
(setf (gethash "top-frame-num" realgud:lldb-pat-hash) 0)
(setf (gethash "top-frame-num" realgud--lldb-pat-hash) 0)

;; realgud-loc-pat that describes a lldb frame generally shown
;; before a command prompt or in frame switching commands
Expand All @@ -75,11 +78,11 @@ realgud-loc-pat struct")
;; #0 main (argc=2, argv=0xbffff564, envp=0xbffff570) at main.c:935
;; instead

(setf (gethash "selected-frame" realgud:lldb-pat-hash)
(setf (gethash "selected-frame" realgud--lldb-pat-hash)
(make-realgud-loc-pat
:regexp (format "^%s.* at %s"
realgud:lldb-frame-num-regexp
realgud:lldb-file-col-regexp
realgud--lldb-frame-num-regexp
realgud--lldb-file-col-regexp
)
:num 1
:file-group 2
Expand All @@ -89,19 +92,19 @@ realgud-loc-pat struct")
;; realgud-loc-pat that describes a lldb prompt
;; For example:
;; (lldb)
(setf (gethash "prompt" realgud:lldb-pat-hash)
(setf (gethash "prompt" realgud--lldb-pat-hash)
(make-realgud-loc-pat
:regexp "^(lldb) "
))

;; realgud-loc-pat that describes a "breakpoint set" line
;; For example:
;; Breakpoint 1: where = hello`main + 4 at hello.c:5, address = 0x00000000004004b4
(setf (gethash "brkpt-set" realgud:lldb-pat-hash)
(setf (gethash "brkpt-set" realgud--lldb-pat-hash)
(make-realgud-loc-pat
:regexp (format "^Breakpoint %s: .* at %s, "
realgud:regexp-captured-num
realgud:lldb-file-col-regexp)
realgud--lldb-file-col-regexp)
:num 1
:file-group 2
:line-group 3
Expand All @@ -116,12 +119,12 @@ realgud-loc-pat struct")
;; #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)
(setf (gethash "debugger-backtrace" realgud--lldb-pat-hash)
(make-realgud-loc-pat
:regexp (concat realgud:lldb-frame-start-regexp
realgud:lldb-frame-num-regexp
:regexp (concat realgud--lldb-frame-start-regexp
realgud--lldb-frame-num-regexp
"\\(?:.\\|\\(?:[\n] \\)\\)+[ ]+at "
realgud:lldb-file-col-regexp
realgud--lldb-file-col-regexp
)
:num 1
:file-group 2
Expand All @@ -134,7 +137,7 @@ realgud-loc-pat struct")
;; For example:
;; 1: name = 'main', locations = 1, resolved = 1, hit count = 1
;; 1.1: where = solc`main + 48 at main.cpp:55:2, address = 0x000000010004a5e0, resolved, hit count = 1
(setf (gethash "debugger-breakpoint" realgud:lldb-pat-hash)
(setf (gethash "debugger-breakpoint" realgud--lldb-pat-hash)
(make-realgud-loc-pat
:regexp (format "^[ \t]*\\([0-9.]\\)+: where = .* at \\(.+\\):%s:%s"
realgud:regexp-captured-num realgud:regexp-captured-num)
Expand All @@ -144,7 +147,7 @@ realgud-loc-pat struct")
:column-group 4)
)

(setf (gethash "font-lock-keywords" realgud:lldb-pat-hash)
(setf (gethash "font-lock-keywords" realgud--lldb-pat-hash)
'(
;; #2 0x080593ac in main (argc=2, argv=0xbffff5a4, envp=0xbffff5b0)
;; at main.c:952
Expand All @@ -159,7 +162,7 @@ realgud-loc-pat struct")
(1 realgud-backtrace-number-face))
))

(setf (gethash "font-lock-breakpoint-keywords" realgud:gdb-pat-hash)
(setf (gethash "font-lock-breakpoint-keywords" realgud--lldb-pat-hash)
'(
;; The breakpoint number, type and disposition
;; 1.1: where =
Expand All @@ -172,37 +175,37 @@ realgud-loc-pat struct")

;; Prefix used in variable names (e.g. short-key-mode-map) for
;; this debugger
(setf (gethash "lldb" realgud:variable-basename-hash) "realgud:lldb")
(setf (gethash "lldb" realgud:variable-basename-hash) "realgud--lldb")

(defvar realgud:lldb-command-hash (make-hash-table :test 'equal)
(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 'process continue'")

(setf (gethash "backtrace" realgud:lldb-command-hash) "bt")
(setf (gethash "break" realgud:lldb-command-hash) "b %X:%l")
(setf (gethash "lldb-break" realgud:lldb-command-hash) "b %X:%l")
(setf (gethash "delete" realgud:lldb-command-hash) "break delete %p")
(setf (gethash "clear" realgud:lldb-command-hash) "break clear %X:%l")
(setf (gethash "continue" realgud:lldb-command-hash) "process continue")
(setf (gethash "delete" realgud:lldb-command-hash) "*not-implemented*") ;; Or rather don't know what the equvalent is
(setf (gethash "delete_all" realgud:lldb-command-hash) "*not-implemented*")
(setf (gethash "disable" realgud:lldb-command-hash) "break disable %p")
(setf (gethash "disable-all" realgud:lldb-command-hash) "break disable")
(setf (gethash "down" realgud:lldb-command-hash) "down %p")
(setf (gethash "enable" realgud:lldb-command-hash) "break enable %p")
(setf (gethash "enable-all" realgud:lldb-command-hash) "break enable")
(setf (gethash "eval" realgud:lldb-command-hash) "print %s")
(setf (gethash "finish" realgud:lldb-command-hash) "thread step-out")
(setf (gethash "frame" realgud:lldb-command-hash) "frame select %p")
(setf (gethash "info-breakpoints" realgud:lldb-command-hash) "break list")
(setf (gethash "quit" realgud:lldb-command-hash) "quit")
(setf (gethash "restart" realgud:lldb-command-hash) "run")
(setf (gethash "step" realgud:lldb-command-hash) "thread step-in --count %p")
(setf (gethash "shell" realgud:lldb-command-hash) "platform shell %s")
(setf (gethash "until" realgud:lldb-command-hash) "thread until %l")
(setf (gethash "up" realgud:lldb-command-hash) "up %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-")
(setf (gethash "backtrace" realgud--lldb-command-hash) "bt")
(setf (gethash "break" realgud--lldb-command-hash) "b %X:%l")
(setf (gethash "lldb-break" realgud--lldb-command-hash) "b %X:%l")
(setf (gethash "delete" realgud--lldb-command-hash) "break delete %p")
(setf (gethash "clear" realgud--lldb-command-hash) "break clear %X:%l")
(setf (gethash "continue" realgud--lldb-command-hash) "process continue")
(setf (gethash "delete" realgud--lldb-command-hash) "*not-implemented*") ;; Or rather don't know what the equvalent is
(setf (gethash "delete_all" realgud--lldb-command-hash) "*not-implemented*")
(setf (gethash "disable" realgud--lldb-command-hash) "break disable %p")
(setf (gethash "disable-all" realgud--lldb-command-hash) "break disable")
(setf (gethash "down" realgud--lldb-command-hash) "down %p")
(setf (gethash "enable" realgud--lldb-command-hash) "break enable %p")
(setf (gethash "enable-all" realgud--lldb-command-hash) "break enable")
(setf (gethash "eval" realgud--lldb-command-hash) "print %s")
(setf (gethash "finish" realgud--lldb-command-hash) "thread step-out")
(setf (gethash "frame" realgud--lldb-command-hash) "frame select %p")
(setf (gethash "info-breakpoints" realgud--lldb-command-hash) "break list")
(setf (gethash "quit" realgud--lldb-command-hash) "quit")
(setf (gethash "restart" realgud--lldb-command-hash) "run")
(setf (gethash "step" realgud--lldb-command-hash) "thread step-in --count %p")
(setf (gethash "shell" realgud--lldb-command-hash) "platform shell %s")
(setf (gethash "until" realgud--lldb-command-hash) "thread until %l")
(setf (gethash "up" realgud--lldb-command-hash) "up %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-")

0 comments on commit 4afe1ca

Please sign in to comment.