Changeset 11053

Show
Ignore:
Timestamp:
01/23/06 14:11:02 (3 years ago)
Author:
rtoy
Message:

Implement tracing of flet/labels functions. This probably needs more
work and could probably be implemented better.

With these changes (trace (labels foo bar)) will trace the labels
function FOO in the function BAR. We only support encapsulate nil,
here. No check is made for this.

code/ntrace.lisp:
o In TRACE-FDEFINITION, recognize a list as a valid function, and

return the list as the value of TRACE-FDEFINITION. This seems
wrong, but I'm not sure if there's a real fdefinition for it, or if
we could create a fake one.

code/debug-int.lisp:
o In FUNCTION-DEBUG-FUNCTION, recognize a list as the name of a

function, and find the corresponding compiled-debug-function and
create and return the new compiled-debug-function.

Location:
trunk/src/code
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/code/debug-int.lisp

    r10648 r10799  
    8484;;; routine that detects them and signals a condition.  For example, 
    8585;;; programmers call A which may fail to return successfully due to a lack of 
    86 ;;; debug information, and there is no B the they could have called to realize 
     86;;; debug information, and there is no B that they could have called to realize 
    8787;;; A would fail.  It is not an error to have called A, but it is an error for 
    8888;;; the program to then ignore the signal generated by A since it cannot 
     
    170170;;; The debug-internals code tries to signal all programmer errors as subtypes 
    171171;;; of debug-error.  There are calls to ERROR signalling simple-errors, but 
    172 ;;; these dummy checks in the code and shouldn't come up. 
     172;;; these dummy checks in the code shouldn't come up. 
    173173;;; 
    174174;;; While under development, this code also signals errors in code branches 
     
    852852(defun cstack-pointer-valid-p (x) 
    853853  (declare (type system:system-area-pointer x)) 
    854   #-:x86 
     854  #-(or :x86 :amd64) 
    855855  (and (system:sap< x (kernel:current-sp)) 
    856856       (system:sap<= #-gengc (alien:alien-sap 
     
    859859                     x) 
    860860       (zerop (logand (system:sap-int x) #b11))) 
    861   #+:x86 ;; stack grows to low address values 
     861  #+(or :x86 :amd64) ;; stack grows to low address values 
    862862  (and (system:sap>= x (kernel:current-sp)) 
    863863       (system:sap> (alien:alien-sap 
     
    866866       (zerop (logand (system:sap-int x) #b11)))) 
    867867 
    868 #+(or gengc x86) 
     868#+(or gengc x86 amd64) 
    869869(alien:def-alien-routine component-ptr-from-pc (system:system-area-pointer) 
    870870  (pc system:system-area-pointer)) 
    871871 
    872 #+(or gengc x86) 
     872#+(or gengc x86 amd64) 
    873873(defun component-from-component-ptr (component-ptr) 
    874874  (declare (type system:system-area-pointer component-ptr)) 
     
    933933   (t 
    934934    ;; Check the two possible frame pointers. 
    935     (let ((lisp-ocfp (sap-ref-sap fp (- (* (1+ vm::ocfp-save-offset) 4)))) 
    936           (lisp-ra (sap-ref-sap fp (- (* (1+ vm::return-pc-save-offset) 4)))) 
     935    (let ((lisp-ocfp (sap-ref-sap fp (- (* (1+ vm::ocfp-save-offset)  
     936                                           vm:word-bytes)))) 
     937          (lisp-ra (sap-ref-sap fp (- (* (1+ vm::return-pc-save-offset) 
     938                                         vm:word-bytes)))) 
    937939          (c-ocfp (sap-ref-sap fp (* 0 vm:word-bytes))) 
    938940          (c-ra (sap-ref-sap fp (* 1 vm:word-bytes)))) 
     
    986988             nil)))))) 
    987989 
    988 ) ; end progn x86 
     990) ; end progn x86 amd64 
    989991 
    990992  
     
    10801082;;; main location. 
    10811083;;; 
    1082 #-x86 
     1084#-(or x86 amd64) 
    10831085(defun get-context-value (frame stack-slot loc) 
    10841086  (declare (type compiled-frame frame) (type unsigned-byte stack-slot) 
     
    10891091        (sub-access-debug-var-slot pointer loc escaped) 
    10901092        (kernel:stack-ref pointer stack-slot)))) 
    1091 #+x86 
     1093#+(or x86 amd64) 
    10921094(defun get-context-value (frame stack-slot loc) 
    10931095  (declare (type compiled-frame frame) (type unsigned-byte stack-slot) 
     
    11011103           (kernel:stack-ref pointer stack-slot)) 
    11021104          (#.vm::lra-save-offset 
    1103            (sap-ref-sap pointer (- (* (1+ stack-slot) 4)))))))) 
    1104  
    1105 ;;; 
    1106 #-x86 
     1105           (sap-ref-sap pointer (- (* (1+ stack-slot) vm:word-bytes)))))))) 
     1106 
     1107;;; 
     1108#-(or x86 amd64) 
    11071109(defun (setf get-context-value) (value frame stack-slot loc) 
    11081110  (declare (type compiled-frame frame) (type unsigned-byte stack-slot) 
     
    11141116        (setf (kernel:stack-ref pointer stack-slot) value)))) 
    11151117 
    1116 #+x86 
     1118#+(or x86 amd64) 
    11171119(defun (setf get-context-value) (value frame stack-slot loc) 
    11181120  (declare (type compiled-frame frame) (type unsigned-byte stack-slot) 
     
    11261128           (setf (kernel:stack-ref pointer stack-slot) value)) 
    11271129          (#.vm::lra-save-offset 
    1128            (setf (sap-ref-sap pointer (- (* (1+ stack-slot) 4))) value)))))) 
     1130           (setf (sap-ref-sap pointer (- (* (1+ stack-slot) vm:word-bytes))) 
     1131                 value)))))) 
    11291132 
    11301133 
     
    11771180 
    11781181 
    1179 #+(or sparc (and x86 linux)) 
     1182#+(or sparc (and (or x86 amd64) linux)) 
    11801183(defun find-foreign-function-name (address) 
    11811184  "Return a string describing the foreign function near ADDRESS" 
     
    12001203                       ))))))) 
    12011204 
    1202 #-(or sparc (and x86 linux)) 
     1205#-(or sparc (and (or x86 amd64) linux)) 
    12031206(defun find-foreign-function-name (ra) 
    12041207  (declare (ignore ra)) 
     
    12491252;;; LRA, and the LRA is the word offset. 
    12501253;;; 
    1251 #-(or gengc x86) 
     1254#-(or gengc x86 amd64) 
    12521255(defun compute-calling-frame (caller lra up-frame) 
    12531256  (declare (type system:system-area-pointer caller)) 
     
    13001303                                 escaped)))))) 
    13011304 
    1302 #+x86 
     1305#+(or x86 amd64) 
    13031306(defun compute-calling-frame (caller ra up-frame) 
    13041307  (declare (type system:system-area-pointer caller ra)) 
     
    15341537;;;     - closure_tramp 
    15351538;;;     - function_end_breakpoint 
    1536 ;;;        arn't ever actually in it, because we copy it into a bogus-lra 
    1537 ;;;        component before every actually using it. 
     1539;;;        aren't ever actually in it, because we copy it into a bogus-lra 
     1540;;;        component before ever actually using it. 
    15381541;;;    or someone jumped someplace strange, in which case we can't do anything. 
    15391542;;; - component w/ :ASSEMBLER-ROUTINE for debug-info: 
     
    17761779                                      (* vm:catch-block-current-cont-slot 
    17771780                                         vm:word-bytes)))) 
    1778         (let* (#-(or gengc x86) 
     1781        (let* (#-(or gengc x86 amd64) 
    17791782               (lra (kernel:stack-ref catch vm:catch-block-entry-pc-slot)) 
    1780                #+(or gengc x86) 
     1783               #+(or gengc x86 amd64) 
    17811784               (ra (system:sap-ref-sap 
    17821785                    catch (* vm:catch-block-entry-pc-slot vm:word-bytes))) 
    1783                #-x86 
     1786               #-(or x86 amd64) 
    17841787               (component 
    17851788                (kernel:stack-ref catch vm:catch-block-current-code-slot)) 
    1786                #+x86 
     1789               #+(or x86 amd64) 
    17871790               (component (component-from-component-ptr  
    17881791                           (component-ptr-from-pc ra))) 
    17891792               (offset 
    1790                 #-(or gengc x86) 
     1793                #-(or gengc x86 amd64) 
    17911794                (* (- (1+ (kernel:get-header-data lra)) 
    17921795                      (kernel:get-header-data component)) 
     
    17971800                      (kernel:get-header-data component)) 
    17981801                   vm:other-pointer-type) 
    1799                 #+x86 
     1802                #+(or x86 amd64) 
    18001803                (- (system:sap-int ra) 
    18011804                   (- (kernel:get-lisp-obj-address component) 
    18021805                      vm:other-pointer-type) 
    18031806                   (* (kernel:get-header-data component) vm:word-bytes)))) 
    1804           (push (cons #-x86 
     1807          (push (cons #-(or x86 amd64) 
    18051808                      (kernel:stack-ref catch vm:catch-block-tag-slot) 
    1806                       #+x86 
     1809                      #+(or x86 amd64) 
    18071810                      (kernel:make-lisp-obj 
    18081811                       (system:sap-ref-32 catch (* vm:catch-block-tag-slot 
     
    37343737;;; 
    37353738;;; The vector elements are in the same format as the compiler's 
    3736 ;;; NODE-SOUCE-PATH; that is, the first element is the form number and the last 
     3739;;; NODE-SOURCE-PATH; that is, the first element is the form number and the last 
    37373740;;; is the top-level-form number. 
    37383741;;; 
     
    39633966        (%make-breakpoint hook-function what kind info)) 
    39643967       (:function-end 
    3965         (unless (eq (c::compiled-debug-function-returns 
    3966                      (compiled-debug-function-compiler-debug-fun what)) 
    3967                     :standard) 
    3968           (error ":FUNCTION-END breakpoints are currently unsupported ~ 
    3969                   for the known return convention.")) 
    3970                    
    3971         (let* ((bpt (%make-breakpoint hook-function what kind info)) 
    3972                (starter (compiled-debug-function-end-starter what))) 
    3973           (unless starter 
    3974             (setf starter (%make-breakpoint #'list what :function-start nil)) 
    3975             (setf (breakpoint-hook-function starter) 
    3976                   (function-end-starter-hook starter what)) 
    3977             (setf (compiled-debug-function-end-starter what) starter)) 
    3978           (setf (breakpoint-start-helper bpt) starter) 
    3979           (push bpt (breakpoint-%info starter)) 
    3980           (setf (breakpoint-cookie-fun bpt) function-end-cookie) 
    3981           bpt)))) 
     3968        (multiple-value-bind (settable known-return) 
     3969            (can-set-function-end-breakpoint-p what) 
     3970          (cond (settable 
     3971                 (let* ((bpt (%make-breakpoint hook-function what kind info)) 
     3972                        (starter (compiled-debug-function-end-starter what))) 
     3973                   (unless starter 
     3974                     (setf starter (%make-breakpoint #'list what :function-start  
     3975                                                     nil)) 
     3976                     (setf (breakpoint-hook-function starter) 
     3977                           (function-end-starter-hook starter what known-return)) 
     3978                     (setf (compiled-debug-function-end-starter what) starter)) 
     3979                   (setf (breakpoint-start-helper bpt) starter) 
     3980                   (push bpt (breakpoint-%info starter)) 
     3981                   (setf (breakpoint-cookie-fun bpt) function-end-cookie) 
     3982                   bpt)) 
     3983                (t 
     3984                 (error ":FUNCTION-END breakpoints are currently unsupported ~ 
     3985                       for the known return convention."))))))) 
    39823986    (interpreted-debug-function 
    39833987     (error ":function-end breakpoints are currently unsupported ~ 
     
    39873991  (typecase what 
    39883992    (compiled-debug-function 
    3989      (eq (c::compiled-debug-function-returns 
    3990           (compiled-debug-function-compiler-debug-fun what)) 
    3991          :standard)))) 
     3993     (let ((returns (c::compiled-debug-function-returns 
     3994                     (compiled-debug-function-compiler-debug-fun what)))) 
     3995       ;; First value says if we can set the function-end-breakpoint. 
     3996       ;; The second value indicates if this is the known return 
     3997       ;; convention. 
     3998       (values (or (eq returns :standard) 
     3999                   (typep returns 'vector)) 
     4000               (not (eq returns :standard))))))) 
    39924001 
    39934002;;; These are unique objects created upon entry into a function by a 
     
    40224031;;; fun-end-bpt. 
    40234032;;; 
    4024 (defun function-end-starter-hook (starter-bpt debug-fun) 
     4033(defun function-end-starter-hook (starter-bpt debug-fun &optional known-return-p) 
    40254034  (declare (type breakpoint starter-bpt) 
    40264035           (type compiled-debug-function debug-fun)) 
     
    40364045                                                 #-gengc vm::lra-save-offset 
    40374046                                                 #+gengc vm::ra-save-offset 
    4038                                                  lra-sc-offset)) 
     4047                                                 lra-sc-offset) 
     4048                              known-return-p) 
    40394049          (setf (get-context-value frame 
    40404050                                   #-gengc vm::lra-save-offset 
     
    40714081        ((not frame) nil) 
    40724082      (when (and (compiled-frame-p frame) 
    4073                  (#-x86 eq #+x86 sys:sap= lra 
     4083                 (#-(or x86 amd64) eq #+(or x86 amd64) sys:sap= lra 
    40744084                     (get-context-value frame 
    40754085                                        #-gengc vm::lra-save-offset 
     
    43964406                                    (breakpoint-data-instruction data)) 
    43974407      ; Under HPUX we can't sigreturn so bp-do-disp-i has to return. 
    4398       #-(or hpux irix x86) 
     4408      #-(or hpux irix x86 amd64) 
    43994409      (error "BREAKPOINT-DO-DISPLACED-INST returned?")))) 
    44004410 
     
    44464456    (remhash component *function-end-cookies*) 
    44474457    (dolist (bpt breakpoints) 
    4448       (funcall (breakpoint-hook-function bpt) 
    4449                frame bpt 
    4450                (get-function-end-breakpoint-values scp) 
    4451                cookie)))) 
    4452  
    4453 (defun get-function-end-breakpoint-values (scp) 
    4454   (let ((ocfp (system:int-sap (vm:sigcontext-register scp 
    4455                                                       #-x86 vm::ocfp-offset 
    4456                                                       #+x86 vm::ebx-offset))) 
     4458      (let ((values (get-function-end-breakpoint-values bpt scp))) 
     4459        (funcall (breakpoint-hook-function bpt) frame bpt values cookie))))) 
     4460 
     4461;;; Return a list of return values at the function end breakpoint 
     4462;;; BREAKPOINT. 
     4463;;; 
     4464(defun get-function-end-breakpoint-values (breakpoint sigcontext) 
     4465  (let* ((what (breakpoint-what breakpoint)) 
     4466         (returns (c::compiled-debug-function-returns 
     4467                   (compiled-debug-function-compiler-debug-fun what)))) 
     4468    (etypecase returns  
     4469      ((member :standard) 
     4470       (function-end-breakpoint-values/standard sigcontext)) 
     4471      (vector 
     4472       (function-end-breakpoint-values/known-return sigcontext returns))))) 
     4473 
     4474;;; Return a list of return values at a breakpoint with standard 
     4475;;; return convention. 
     4476;;;  
     4477(defun function-end-breakpoint-values/standard (scp) 
     4478  (let ((ocfp (sigcontext-ocfp-sap scp)) 
    44574479        (nargs (kernel:make-lisp-obj 
    44584480                (vm:sigcontext-register scp vm::nargs-offset))) 
     
    44644486                 (kernel:make-lisp-obj 
    44654487                  (vm:sigcontext-register scp (pop reg-arg-offsets))) 
    4466               (kernel:stack-ref ocfp arg-num)) 
     4488                (kernel:stack-ref ocfp arg-num)) 
    44674489             results))) 
    44684490    (nreverse results))) 
    44694491 
     4492;;; Return a list of return values at a breakpoint with known-return 
     4493;;; convention. 
     4494;;;  
     4495(defun function-end-breakpoint-values/known-return (sigcontext sc-offsets) 
     4496  (let ((ocfp (sigcontext-ocfp-sap sigcontext))) 
     4497    (loop for offset across sc-offsets 
     4498          collect (sub-access-debug-var-slot ocfp offset sigcontext)))) 
     4499 
     4500;;; Extract the old frame pointer from a sigcontext structure.  The 
     4501;;; result is a SAP. 
     4502;;;  
     4503(defun sigcontext-ocfp-sap (sigcontext) 
     4504  (system:int-sap 
     4505   (vm:sigcontext-register sigcontext 
     4506                           #-(or x86 amd64) vm::ocfp-offset 
     4507                           #+(or x86 amd64) vm::ebx-offset))) 
     4508 
    44704509;;; 
    44714510;;; MAKE-BOGUS-LRA (used for :function-end breakpoints) 
    44724511;;; 
    4473  
    4474 (defconstant bogus-lra-constants #-x86 2 #+x86 3) 
    4475 (defconstant known-return-p-slot (+ vm:code-constants-offset #-x86 1 #+x86 2)) 
     4512;;; (If you change these, look in breakpoint.c too!) 
     4513 
     4514(defconstant bogus-lra-constants #-(or x86 amd64) 2 #+(or x86 amd64) 3) 
     4515(defconstant known-return-p-slot (+ vm:code-constants-offset #-(or x86 amd64) 1 #+(or x86 amd64) 2)) 
    44764516 
    44774517;;; MAKE-BOGUS-LRA -- Interface. 
     
    44954535          (code-object 
    44964536           (system:%primitive 
    4497             #-(and x86 gencgc) c:allocate-code-object 
    4498             #+(and x86 gencgc) c::allocate-dynamic-code-object 
     4537            #-(and (or x86 amd64) gencgc) c:allocate-code-object 
     4538            #+(and (or x86 amd64) gencgc) c::allocate-dynamic-code-object 
    44994539            (1+ bogus-lra-constants) 
    45004540            length)) 
     
    45064546     (setf (kernel:code-header-ref code-object vm:code-trace-table-offset-slot) 
    45074547           length) 
    4508      #-x86 
     4548     #-(or x86 amd64) 
    45094549     (setf (kernel:code-header-ref code-object real-lra-slot) real-lra) 
    4510      #+x86 
     4550     #+(or x86 amd64) 
    45114551     (multiple-value-bind (offset code) 
    45124552         (compute-lra-data-from-pc real-lra) 
     
    45174557     (kernel:system-area-copy src-start 0 dst-start 0 (* length vm:byte-bits)) 
    45184558     (vm:sanctify-for-execution code-object) 
    4519      #+x86 
     4559     #+(or x86 amd64) 
    45204560     (values dst-start code-object (system:sap- trap-loc src-start)) 
    4521      #-x86 
     4561     #-(or x86 amd64) 
    45224562     (let ((new-lra (kernel:make-lisp-obj (+ (system:sap-int dst-start) 
    45234563                                             vm:other-pointer-type)))) 
  • trunk/src/code/ntrace.lisp

    r10785 r11043  
    3535   0.") 
    3636 
    37 (defvar *trace-encapsulate-default* :default 
     37(defvar *trace-encapsulate-default* #-ppc :default #+ppc t 
    3838  "The default value for the :ENCAPSULATE option to trace.") 
    3939