Index: /trunk/source/lisp-kernel/xlbt.c
===================================================================
--- /trunk/source/lisp-kernel/xlbt.c	(revision 14976)
+++ /trunk/source/lisp-kernel/xlbt.c	(revision 14977)
@@ -19,5 +19,103 @@
 #include <signal.h>
 
-
+static LispObj
+function_to_function_vector(LispObj f)
+{
+#ifdef X8664
+  return f - fulltag_function + fulltag_misc;
+#else
+  return f;
+#endif
+}
+
+static Boolean
+functionp(LispObj f)
+{
+#ifdef X8664
+  return fulltag_of(f) == fulltag_function;
+#else
+  return fulltag_of(f) == fulltag_misc &&
+    header_subtag(header_of(f)) == subtag_function;
+#endif
+}
+
+static LispObj
+tra_function(LispObj tra)
+{
+  LispObj f = 0;
+
+#ifdef X8664
+  if (tag_of(tra) == tag_tra) {
+    if ((*((unsigned short *)tra) == RECOVER_FN_FROM_RIP_WORD0) &&
+        (*((unsigned char *)(tra+2)) == RECOVER_FN_FROM_RIP_BYTE2)) {
+      int sdisp = (*(int *) (tra+3));
+      f = RECOVER_FN_FROM_RIP_LENGTH+tra+sdisp;
+    }
+  }
+#else
+  if (fulltag_of(tra) == fulltag_tra) {
+    if (*((unsigned char *)tra) == RECOVER_FN_OPCODE) {
+      natural n = *((natural *)(tra + 1));
+      f = (LispObj)n;
+    }
+  }
+#endif
+  return f;
+}
+
+#if 0
+/* untested */
+static int
+tra_offset(LispObj tra)
+{
+#ifdef X8664
+  if (tag_of(tra) == tag_tra) {
+    if ((*((unsigned short *)tra) == RECOVER_FN_FROM_RIP_WORD0) &&
+        (*((unsigned char *)(tra+2)) == RECOVER_FN_FROM_RIP_BYTE2)) {
+      int sdisp = (*(int *) (tra+3));
+
+      sdisp = - sdisp;
+      sdisp -= RECOVER_FN_FROM_RIP_LENGTH;
+      return sdisp;
+    }
+  }
+#else
+  if (fulltag_of(tra) == fulltag_tra) {
+    if (*((unsigned char *)tra) == RECOVER_FN_OPCODE) {
+      int n = *((int *)(tra + 1));
+      n = n - tra;
+      n = -n;
+      return n;
+    }
+  }
+#endif
+  return 0;
+}
+#endif
+
+natural
+pc_from_xcf(xcf *xcf)
+{
+  if (functionp(xcf->nominal_function)) {
+    LispObj fv = function_to_function_vector(xcf->nominal_function);
+    if (fv == xcf->containing_uvector) {
+      unsigned tag;
+
+#ifdef X8664
+      tag = tag_function;
+#else
+      tag = fulltag_misc;
+#endif
+      return unbox_fixnum(xcf->relative_pc) - tag;
+    } else {
+      LispObj tra = xcf->ra0;
+      LispObj f = tra_function(tra);
+
+      if (f && f == xcf->nominal_function)
+	return 0; /* punt for now */
+    }
+  }
+  return 0;
+}
 
 void
@@ -43,6 +141,13 @@
   }
   if (pc == 0) {
+    natural rpc = pc_from_xcf((xcf *)frame);
+
     fun = ((xcf *)frame)->nominal_function;
-    Dprintf("(#x%08X) #x%08X : %s + ??", frame, pc, print_lisp_object(fun));
+    fprintf(dbgout, "(#x%08X) #x%08X : %s + ", frame, pc,
+	    print_lisp_object(fun));
+    if (rpc)
+      fprintf(dbgout, "%d\n", rpc);
+    else
+      fprintf(dbgout, "??\n", rpc);
     return;
   }
@@ -61,6 +166,13 @@
   }
   if (pc == 0) {
+    natural rpc = pc_from_xcf((xcf *)frame);
+
     fun = ((xcf *)frame)->nominal_function;
-    Dprintf("(#x%016lX) #x%016lX : %s + ??", frame, pc, print_lisp_object(fun));
+    fprintf(dbgout, "(#x%016lX) #x%016lX : %s + ", frame, pc,
+	    print_lisp_object(fun));
+    if (rpc)
+      fprintf(dbgout, "%d\n", rpc);
+    else
+      fprintf(dbgout, "??\n");
     return;
   }
