From 2c5fc8d03420855301993bee6d8afa28d64503d6 Mon Sep 17 00:00:00 2001 From: Andy Wingo Date: Fri, 1 Oct 2010 18:25:44 +0200 Subject: [PATCH] source breakpoints accept user line numbers * 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 | 6 +++--- module/system/vm/traps.scm | 16 ++++++++++------ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/module/system/vm/trap-state.scm b/module/system/vm/trap-state.scm index 42033b230..c67ea322e 100644 --- a/module/system/vm/trap-state.scm +++ b/module/system/vm/trap-state.scm @@ -209,16 +209,16 @@ 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))) diff --git a/module/system/vm/traps.scm b/module/system/vm/traps.scm index e31df855e..0e7a540ec 100644 --- a/module/system/vm/traps.scm +++ b/module/system/vm/traps.scm @@ -249,6 +249,9 @@ (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) @@ -345,16 +348,17 @@ (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 @@ -362,14 +366,14 @@ (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))))))) -- 2.20.1