]> git.eshelyaron.com Git - emacs.git/commitdiff
Print byte offset of error in backtrace
authorZach Shaftel <zshaftel@gmail.com>
Wed, 29 Apr 2020 17:13:44 +0000 (13:13 -0400)
committerZach Shaftel <zshaftel@gmail.com>
Wed, 29 Apr 2020 17:13:44 +0000 (13:13 -0400)
lisp/emacs-lisp/debug.el
src/bytecode.c
src/eval.c
src/lisp.h

index ed28997292f96d7f9c1ea1445d83eabfe2804f49..db2943b6e73c16ee64764599be6751a63be731bf 100644 (file)
@@ -335,8 +335,10 @@ That buffer should be current already and in debugger-mode."
           nil))
 
   (setq backtrace-view (plist-put backtrace-view :show-flags t)
-        backtrace-insert-header-function (lambda ()
-                                           (debugger--insert-header args))
+        backtrace-insert-header-function
+        (lambda ()
+          (insert (format "Byte-code offset of error: %d\n" (car (last args))))
+          (debugger--insert-header args))
         backtrace-print-function debugger-print-function)
   (backtrace-print)
   ;; Place point on "stack frame 0" (bug#15101).
index 8ef84682035e9b55c0ae9ceb9399022c21260e4b..1c98a516dbb73d6230cc8846fbb4a3dca86a99f1 100644 (file)
@@ -424,13 +424,14 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
         Threading provides a performance boost.  These macros are how
         we allow the code to be compiled both ways.  */
 #ifdef BYTE_CODE_THREADED
+#define UPDATE_OFFSET (backtrace_byte_offset = pc - bytestr_data);
       /* The CASE macro introduces an instruction's body.  It is
         either a label or a case label.  */
 #define CASE(OP) insn_ ## OP
       /* NEXT is invoked at the end of an instruction to go to the
         next instruction.  It is either a computed goto, or a
         plain break.  */
-#define NEXT goto *(targets[op = FETCH])
+#define NEXT UPDATE_OFFSET goto *(targets[op = FETCH])
       /* FIRST is like NEXT, but is only used at the start of the
         interpreter body.  In the switch-based interpreter it is the
         switch, so the threaded definition must include a semicolon.  */
@@ -1448,7 +1449,7 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
        unbind_to (count, Qnil);
       error ("binding stack not balanced (serious byte compiler bug)");
     }
-
+  backtrace_byte_offset = -1;
   Lisp_Object result = TOP;
   SAFE_FREE ();
   return result;
index 4251c3e330422345d26bcbc49ff36f152da39271..82463c41747b1e5e9cfb1598d6730de8ce386700 100644 (file)
@@ -56,6 +56,8 @@ Lisp_Object Vrun_hooks;
 /* FIXME: We should probably get rid of this!  */
 Lisp_Object Vsignaling_function;
 
+int backtrace_byte_offset = -1;
+
 /* These would ordinarily be static, but they need to be visible to GDB.  */
 bool backtrace_p (union specbinding *) EXTERNALLY_VISIBLE;
 Lisp_Object *backtrace_args (union specbinding *) EXTERNALLY_VISIBLE;
@@ -335,7 +337,10 @@ call_debugger (Lisp_Object arg)
         redisplay, which necessarily leads to display problems.  */
   specbind (Qinhibit_eval_during_redisplay, Qt);
 #endif
-
+  if (backtrace_byte_offset >= 0) {
+    arg = CALLN(Fappend, arg, list1(make_fixnum(backtrace_byte_offset)));
+    backtrace_byte_offset = -1;
+  }
   val = apply1 (Vdebugger, arg);
 
   /* Interrupting redisplay and resuming it later is not safe under
@@ -1695,6 +1700,13 @@ signal_or_quit (Lisp_Object error_symbol, Lisp_Object data, bool keyboard_quit)
 
 /* Like xsignal, but takes 0, 1, 2, or 3 args instead of a list.  */
 
+void
+xsignal_with_offset (Lisp_Object error_symbol, Lisp_Object data, int bytecode_offset)
+{
+  backtrace_byte_offset = bytecode_offset;
+  xsignal(error_symbol, data);
+}
+
 void
 xsignal0 (Lisp_Object error_symbol)
 {
index c9b069b56cac4b0580efda92e7128962e4f9bb66..ff60dfa8f0d49f76932b7f6bc3048e9bed274663 100644 (file)
@@ -4089,6 +4089,7 @@ extern Lisp_Object Vautoload_queue;
 extern Lisp_Object Vrun_hooks;
 extern Lisp_Object Vsignaling_function;
 extern Lisp_Object inhibit_lisp_code;
+extern int backtrace_byte_offset;
 
 /* To run a normal hook, use the appropriate function from the list below.
    The calling convention: