0.8.13.10: I don't think we're in lisp-land anymore...
authorNikodemus Siivola <nikodemus@random-state.net>
Thu, 29 Jul 2004 11:29:52 +0000 (11:29 +0000)
committerNikodemus Siivola <nikodemus@random-state.net>
Thu, 29 Jul 2004 11:29:52 +0000 (11:29 +0000)
           * Display foreign function names in backtraces on platforms
              with dladdr. Essentially a port of Helmut Eller's patch
              for CMUCL. Works fine on x86 and Sparc at least.
           * Clean up some spurious sb-alien package prefixes from
              foreign.lisp while at it.

NEWS
package-data-list.lisp-expr
src/code/debug-int.lisp
src/code/foreign.lisp
version.lisp-expr

diff --git a/NEWS b/NEWS
index bd89023..4f52e72 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,7 @@
 changes in sbcl-0.8.14 relative to sbcl-0.8.13:
+  * new feature: on platforms where "dladdr" is available foreign
+    function names now appear in backtraces.  (based on Helmut Eller's
+    work for CMUCL)
   * bug fix: backtraces involving undefined functions or assembly
     routines are more informative.  (thanks to Brian Downing)
   * bug fix: mutually referent alien structures now work correctly.
index f41aa60..44bd7d8 100644 (file)
@@ -1792,6 +1792,7 @@ SB-KERNEL) have been undone, but probably more remain."
                                      "ENABLE-INTERRUPT" "ENUMERATION"
                                      "FD-STREAM-FD" "FD-STREAM-P" 
                                      "FOREIGN-SYMBOL-ADDRESS" "FOREIGN-SYMBOL-ADDRESS-AS-INTEGER"
+                                     "FOREIGN-SYMBOL-IN-ADDRESS"
                                      "GET-PAGE-SIZE" "GET-SYSTEM-INFO"
                                      "IGNORE-INTERRUPT"
                                      "INT-SAP" "INVALIDATE-DESCRIPTOR" "IO-TIMEOUT"
index d58a2c2..352f968 100644 (file)
          (#.lra-save-offset
           (setf (sap-ref-sap pointer (- (* (1+ stack-slot) 4))) value))))))
 
+(defun foreign-function-debug-name (sap)
+  (multiple-value-bind (name file base offset) (foreign-symbol-in-address sap)
+    (if name
+       (format nil "foreign function: ~A [~A: #x~X + #x~X]" name file base offset)
+       (format nil "foreign function: #x~X" (sap-int sap)))))
+
 ;;; This returns a frame for the one existing in time immediately
 ;;; prior to the frame referenced by current-fp. This is current-fp's
 ;;; caller or the next frame down the control stack. If there is no
                           "undefined function"))
                         (:foreign-function
                          (make-bogus-debug-fun
-                          (format nil "foreign function call land:")))
+                          (foreign-function-debug-name (int-sap (get-lisp-obj-address lra)))))
                         ((nil)
                          (make-bogus-debug-fun
                           "bogus stack frame"))
                      (make-bogus-debug-fun
                       "undefined function"))
                     (:foreign-function
-                     (make-bogus-debug-fun
-                      (format nil "foreign function call land: ra=#x~X"
-                                  (sap-int ra))))
+                     (make-bogus-debug-fun (foreign-function-debug-name ra)))
                     ((nil)
                      (make-bogus-debug-fun
                       "bogus stack frame"))
index fc4a3b8..5e1fc57 100644 (file)
     (push (lambda () (setq *handles-from-dlopen* nil))
          *after-save-initializations*)
 
-    (sb-alien:define-alien-routine dlopen system-area-pointer
-      (file sb-alien:c-string) (mode sb-alien:int))
-    (sb-alien:define-alien-routine dlsym system-area-pointer
-      (lib system-area-pointer)
-      (name sb-alien:c-string))
-    (sb-alien:define-alien-routine dlerror sb-alien:c-string)
-
+    (define-alien-routine dlopen system-area-pointer
+      (file c-string) (mode int))
+    
+    (define-alien-routine dlsym system-area-pointer
+      (lib system-area-pointer) (name c-string))
+    
+    (define-alien-routine dlerror c-string)
+    
 ;;; Ensure that we've opened our own binary so we can dynamically resolve 
 ;;; symbols in the C runtime.  
 ;;;
          (unless (zerop possible-result)
            (return possible-result)))))
 
+    (defun foreign-symbol-in-address (sap)
+      (declare (ignore sap)))
+
+    (when (ignore-errors (foreign-symbol-address "dladdr"))
+      (setf (symbol-function 'foreign-symbol-in-address)
+           ;; KLUDGE: This COMPILE trick is to avoid trying to
+           ;; compile a reference to dladdr on platforms without it.
+           (compile nil
+            '(lambda (sap)
+              (let ((addr (sap-int sap)))
+                (with-alien ((info
+                              (struct dl-info
+                                      (filename c-string)
+                                      (base unsigned)
+                                      (symbol c-string)
+                                      (symbol-address unsigned)))
+                             (dladdr
+                              (function unsigned
+                                        unsigned (* (struct dl-info)))
+                              :extern "dladdr"))
+                  (let ((err (alien-funcall dladdr addr (addr info))))
+                    (if (zerop err)
+                        nil
+                        (values (slot info 'symbol)
+                                (slot info 'filename)
+                                addr
+                                (- addr (slot info 'symbol-address)))))))))))
+    
     ))                                 ; PROGN, MACROLET
index e3a00ac..8eebb8e 100644 (file)
@@ -17,4 +17,4 @@
 ;;; checkins which aren't released. (And occasionally for internal
 ;;; versions, especially for internal versions off the main CVS
 ;;; branch, it gets hairier, e.g. "0.pre7.14.flaky4.13".)
-"0.8.13.9"
+"0.8.13.10"