source breakpoints accept user line numbers
authorAndy Wingo <wingo@pobox.com>
Fri, 1 Oct 2010 16:25:44 +0000 (18:25 +0200)
committerAndy Wingo <wingo@pobox.com>
Fri, 1 Oct 2010 16:25:44 +0000 (18:25 +0200)
* module/system/vm/trap-state.scm (add-trap-at-source-location!):
* module/system/vm/traps.scm (trap-at-source-location): Rename "line"
  argument to "user-line", indicating that the line is one-based instead
  of zero-based. Decrement the line before handing off to
  source-closures-or-procedures and source->ip-range.

module/system/vm/trap-state.scm
module/system/vm/traps.scm

index 42033b2..c67ea32 100644 (file)
       idx #t trap
       (format #f "Tracepoint at ~a" proc)))))
 
-(define* (add-trap-at-source-location! file line
+(define* (add-trap-at-source-location! file user-line
                                        #:optional (trap-state (the-trap-state)))
   (let* ((idx (next-index! trap-state))
-         (trap (trap-at-source-location file line
+         (trap (trap-at-source-location file user-line
                                         (handler-for-index trap-state idx))))
     (add-trap-wrapper!
      trap-state
      (make-trap-wrapper
       idx #t trap
-      (format #f "Breakpoint at ~a:~a" file line)))))
+      (format #f "Breakpoint at ~a:~a" file user-line)))))
 
 (define* (add-trap! trap name #:optional (trap-state (the-trap-state)))
   (let* ((idx (next-index! trap-state)))
index e31df85..0e7a540 100644 (file)
 (define (non-negative-integer? x)
   (and (number? x) (integer? x) (exact? x) (not (negative? x))))
 
+(define (positive-integer? x)
+  (and (number? x) (integer? x) (exact? x) (positive? x)))
+
 (define (range? x)
   (and (list? x)
        (and-map (lambda (x)
         (values (source-procedures file line) #f))))
 
 ;; Building on trap-on-instructions-in-procedure, we have
-;; trap-at-source-location.
+;; trap-at-source-location. The parameter `user-line' is one-indexed, as
+;; a user counts lines, instead of zero-indexed, as Guile counts lines.
 ;;
-(define* (trap-at-source-location file line handler
+(define* (trap-at-source-location file user-line handler
                                   #:key current-frame (vm (the-vm)))
   (arg-check file string?)
-  (arg-check line non-negative-integer?)
+  (arg-check user-line positive-integer?)
   (arg-check handler procedure?)
   (let ((traps #f))
     (call-with-values
-        (lambda () (source-closures-or-procedures file line))
+        (lambda () (source-closures-or-procedures file (1- user-line)))
       (lambda (procs closures?)
         (new-enabled-trap
          vm current-frame
            (set! traps
                  (map
                   (lambda (proc)
-                    (let ((range (source->ip-range proc file line)))
+                    (let ((range (source->ip-range proc file (1- user-line))))
                       (trap-at-procedure-ip-in-range proc range handler
                                                      #:current-frame current-frame
                                                      #:vm vm
                                                      #:closure? closures?)))
                   procs))
            (if (null? traps)
-               (error "No procedures found at ~a:~a." file line)))
+               (error "No procedures found at ~a:~a." file user-line)))
          (lambda (frame)
            (for-each (lambda (trap) (trap frame)) traps)
            (set! traps #f)))))))