* bug#25393: FEATURE REQUEST: *Backtrace* -- C source code def highlight + jump to def.
@ 2017-01-08 8:29 Keith David Bershatsky
2018-08-09 0:11 ` Gemini Lasswell
0 siblings, 1 reply; 3+ messages in thread
From: Keith David Bershatsky @ 2017-01-08 8:29 UTC (permalink / raw)
To: 25393
As a feature request, the Emacs team may wish to consider implementing the ability for users to highlight C source code definitions in the *Backtrace* buffer and jump to the function definitions. The highlighting of said functions makes the *Backtrace* buffer prettier, and it's handy to jump to the definitions with buttons. A check should probably be included to see whether the `find-function-C-source-directory' contains C source code files before creating highlighting/buttons for jumping:
Here is the link to the related thread: http://emacs.stackexchange.com/questions/29875/debugging-debugger-mode-how-to-highlight-the-culprit
In my use-case, it wasn't very obvious to me that `/` was the cause of my backtrace error message because it was not highlighted -- this is true even though I am aware that the problem is always near the top of the debugger buffer. It is just not a function I use a lot and it didn't really look like a function because it was just regular text coloration.
(require 'debug)
(defun debugger-make-xrefs (&optional buffer)
"Attach cross-references to function names in the `*Backtrace*' buffer."
(interactive "b")
(with-current-buffer (or buffer (current-buffer))
(save-excursion
(setq buffer (current-buffer))
(let ((inhibit-read-only t)
(old-end (point-min)) (new-end (point-min)))
(if debugger-previous-backtrace
(let (old-start new-start (all-match t))
(goto-char (point-max))
(with-temp-buffer
(insert debugger-previous-backtrace)
(while (and all-match (not (bobp)))
(setq old-end (point))
(forward-line -1)
(setq old-start (point))
(with-current-buffer buffer
(setq new-end (point))
(forward-line -1)
(setq new-start (point)))
(if (not (zerop
(let ((case-fold-search nil))
(compare-buffer-substrings
(current-buffer) old-start old-end
buffer new-start new-end))))
(setq all-match nil))))
(delete-region new-end (point-max))
(goto-char (point-max))
(insert (substring debugger-previous-backtrace
(- old-end (point-min))))
(narrow-to-region (point-min) new-end)))
(goto-char (point-min))
(while (progn
(goto-char (+ (point) 2))
(skip-syntax-forward "^w_")
(not (eobp)))
(let* ((beg (point))
(end (progn (skip-syntax-forward "w_") (point)))
(fn (function-called-at-point)) ;; MODIFICATION
(sym (intern-soft (buffer-substring-no-properties beg end)))
;; MODIFICATION
(file
(if fn
(let* (
(function fn)
(advised (and (symbolp function)
(featurep 'nadvice)
(advice--p (advice--symbol-function function))))
;; If the function is advised, use the symbol that has the
;; real definition, if that symbol is already set up.
(real-function
(or (and advised
(advice--cd*r (advice--symbol-function function)))
function))
;; Get the real definition.
(def (if (symbolp real-function)
(or (symbol-function real-function)
(signal 'void-function (list real-function)))
real-function))
(aliased (or (symbolp def)
;; Advised & aliased function.
(and advised (symbolp real-function)
(not (eq 'autoload (car-safe def))))))
(file-name (find-lisp-object-file-name function (if aliased 'defun
def))))
file-name)
(and sym (symbol-file sym 'defun)))))
(when (or fn file) ;; MODIFICATION
(goto-char beg)
(re-search-forward "\\(\\sw\\|\\s_\\)+")
(help-xref-button 0 'help-function-def sym file)))
(forward-line 1))
(widen))
(setq debugger-previous-backtrace (buffer-string)))))
^ permalink raw reply [flat|nested] 3+ messages in thread
* bug#25393: FEATURE REQUEST: *Backtrace* -- C source code def highlight + jump to def.
2017-01-08 8:29 bug#25393: FEATURE REQUEST: *Backtrace* -- C source code def highlight + jump to def Keith David Bershatsky
@ 2018-08-09 0:11 ` Gemini Lasswell
2018-08-27 18:07 ` Gemini Lasswell
0 siblings, 1 reply; 3+ messages in thread
From: Gemini Lasswell @ 2018-08-09 0:11 UTC (permalink / raw)
To: Keith David Bershatsky; +Cc: 25393, Clément Pit-Claudel
[-- Attachment #1: Type: text/plain, Size: 354 bytes --]
Hi Keith,
The new backtrace mode, in the master branch as of da0054c307, makes
links for built-in functions.
The attached patch improves on current master by making links to C
functions work even when those functions are advised. See
http://lists.gnu.org/archive/html/emacs-devel/2018-08/msg00025.html for
Clément's report of that problem.
[-- Attachment #2: 0001-Fix-links-in-backtraces-to-work-on-advised-built-ins.patch --]
[-- Type: text/plain, Size: 2401 bytes --]
From 7737f48840d3c07b09506eb4b4743646d27cd2aa Mon Sep 17 00:00:00 2001
From: Gemini Lasswell <gazally@runbox.com>
Date: Tue, 7 Aug 2018 19:39:06 -0700
Subject: [PATCH] Fix links in backtraces to work on advised built-ins
(Bug#25393)
* lisp/emacs-lisp/backtrace.el (backtrace--print-func-and-args): Make
links to the original definition of advised functions. Handle the
case when the function slot of the backtrace frame contains the
definition of a built-in function.
---
lisp/emacs-lisp/backtrace.el | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/lisp/emacs-lisp/backtrace.el b/lisp/emacs-lisp/backtrace.el
index f13b43b465..e82d4f5a5a 100644
--- a/lisp/emacs-lisp/backtrace.el
+++ b/lisp/emacs-lisp/backtrace.el
@@ -34,6 +34,7 @@
(eval-when-compile (require 'cl-lib))
(eval-when-compile (require 'pcase))
(eval-when-compile (require 'subr-x)) ; if-let
+(require 'find-func)
(require 'help-mode) ; Define `help-function-def' button type.
(require 'lisp-mode)
@@ -735,11 +736,11 @@ backtrace--print-func-and-args
(evald (backtrace-frame-evald frame))
(fun (backtrace-frame-fun frame))
(args (backtrace-frame-args frame))
- (def (and (symbolp fun) (fboundp fun) (symbol-function fun)))
+ (def (find-function-advised-original fun))
(fun-file (or (symbol-file fun 'defun)
- (and (subrp def)
- (not (eq 'unevalled (cdr (subr-arity def))))
- (find-lisp-object-file-name fun def))))
+ (and (subrp def)
+ (not (eq 'unevalled (cdr (subr-arity def))))
+ (find-lisp-object-file-name fun def))))
(fun-pt (point)))
(cond
((and evald (not debugger-stack-frame-as-list))
@@ -762,7 +763,8 @@ backtrace--print-func-and-args
(insert (backtrace--print-to-string fun-and-args)))
(cl-incf fun-pt)))
(when fun-file
- (make-text-button fun-pt (+ fun-pt (length (symbol-name fun)))
+ (make-text-button fun-pt (+ fun-pt
+ (length (backtrace--print-to-string fun)))
:type 'help-function-def
'help-args (list fun fun-file)))
;; After any frame that uses eval-buffer, insert a comment that
--
2.16.4
[-- Attachment #3: Type: text/plain, Size: 610 bytes --]
Keith David Bershatsky <esq@lawlist.com> writes:
> A check should probably be included to see whether the
> `find-function-C-source-directory' contains C source code files before
> creating highlighting/buttons for jumping:
I chose not to do this. I think it's better to make the buttons
and give an error message when they are pressed if
'find-function-C-source-directory' is misconfigured, because then the
error message lets the user know that there is a configuration problem
so that she or he can try to fix it.
Let me know if you are able to give this a try and how it works for you.
Thanks,
Gemini
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-08-27 18:07 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-01-08 8:29 bug#25393: FEATURE REQUEST: *Backtrace* -- C source code def highlight + jump to def Keith David Bershatsky
2018-08-09 0:11 ` Gemini Lasswell
2018-08-27 18:07 ` Gemini Lasswell
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.