steps.scm 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. ;;;; (ice-9 debugging steps) -- stepping through code from the debugger
  2. ;;; Copyright (C) 2002, 2004 Free Software Foundation, Inc.
  3. ;;;
  4. ;; This library is free software; you can redistribute it and/or
  5. ;; modify it under the terms of the GNU Lesser General Public
  6. ;; License as published by the Free Software Foundation; either
  7. ;; version 2.1 of the License, or (at your option) any later version.
  8. ;;
  9. ;; This library is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. ;; Lesser General Public License for more details.
  13. ;;
  14. ;; You should have received a copy of the GNU Lesser General Public
  15. ;; License along with this library; if not, write to the Free Software
  16. ;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. (define-module (ice-9 debugging steps)
  18. #:use-module (ice-9 debugging traps)
  19. #:use-module (ice-9 and-let-star)
  20. #:use-module (ice-9 debugger)
  21. #:use-module (ice-9 optargs)
  22. #:export (at-exit
  23. at-entry
  24. at-apply
  25. at-step
  26. at-next))
  27. ;;; at-exit DEPTH BEHAVIOUR
  28. ;;;
  29. ;;; Install a behaviour to run when we exit the current frame.
  30. (define (at-exit depth behaviour)
  31. (install-trap (make <exit-trap>
  32. #:depth depth
  33. #:single-shot #t
  34. #:behaviour behaviour)))
  35. ;;; at-entry BEHAVIOUR [COUNT]
  36. ;;;
  37. ;;; Install a behaviour to run when we get to the COUNT'th next frame
  38. ;;; entry. COUNT defaults to 1.
  39. (define* (at-entry behaviour #:optional (count 1))
  40. (install-trap (make <entry-trap>
  41. #:skip-count (- count 1)
  42. #:single-shot #t
  43. #:behaviour behaviour)))
  44. ;;; at-apply BEHAVIOUR [COUNT]
  45. ;;;
  46. ;;; Install a behaviour to run when we get to the COUNT'th next
  47. ;;; application. COUNT defaults to 1.
  48. (define* (at-apply behaviour #:optional (count 1))
  49. (install-trap (make <apply-trap>
  50. #:skip-count (- count 1)
  51. #:single-shot #t
  52. #:behaviour behaviour)))
  53. ;;; at-step BEHAVIOUR [COUNT [FILENAME [DEPTH]]
  54. ;;;
  55. ;;; Install BEHAVIOUR to run on the COUNT'th next application, frame
  56. ;;; entry or frame exit. COUNT defaults to 1. If FILENAME is
  57. ;;; specified and not #f, only frames that begin in the named file are
  58. ;;; counted.
  59. (define* (at-step behaviour #:optional (count 1) filename (depth 1000))
  60. (install-trap (make <step-trap>
  61. #:file-name filename
  62. #:exit-depth depth
  63. #:skip-count (- count 1)
  64. #:single-shot #t
  65. #:behaviour behaviour)))
  66. ;; (or count (set! count 1))
  67. ;; (letrec ((proc (lambda (trap-context)
  68. ;; ;; Behaviour whenever we enter or exit a frame.
  69. ;; (set! count (- count 1))
  70. ;; (if (= count 0)
  71. ;; (begin
  72. ;; (remove-enter-frame-hook! step)
  73. ;; (remove-apply-frame-hook! step)
  74. ;; (behaviour trap-context)))))
  75. ;; (step (lambda (trap-context)
  76. ;; ;; Behaviour on frame entry: both execute the above
  77. ;; ;; and install it as an exit hook.
  78. ;; (if (or (not filename)
  79. ;; (equal? (frame-file-name (tc:frame trap-context))
  80. ;; filename))
  81. ;; (begin
  82. ;; (proc trap-context)
  83. ;; (at-exit (tc:depth trap-context) proc))))))
  84. ;; (at-exit depth proc)
  85. ;; (add-enter-frame-hook! step)
  86. ;; (add-apply-frame-hook! step)))
  87. ;;; at-next BEHAVIOUR [COUNT]
  88. ;;;
  89. ;;; Install a behaviour to run when we get to the COUNT'th next frame
  90. ;;; entry in the same source file as the current location. COUNT
  91. ;;; defaults to 1. If the current location has no filename, fall back
  92. ;;; silently to `at-entry' behaviour.
  93. ;;; (ice-9 debugging steps) ends here.