Using the debugger

Started by cormullion, October 16, 2007, 05:22:18 AM

Previous topic - Next topic

cormullion

I'm just trying to learn to use the debugger.



Here's a function:


(define (t)
(dolist (i (explode "string"))
  (println {i is } i)
  (for (j 0 3)
    (println { j is } j)
    (if (= j 2)
       (trace true))
    ))
)


If i just run this, it does this:


> (t)
i is s
 j is 0
 j is 1
 j is 2
 j is 3
i is t
 j is 0
 j is 1
 j is 2
 j is 3
i is r
 j is 0
 j is 1
 j is 2
 j is 3
i is i
 j is 0
 j is 1
 j is 2
 j is 3
i is n
 j is 0
 j is 1
 j is 2
 j is 3
i is g
 j is 0
 j is 1
 j is 2
 j is 3
nil
 0>


- I was expecting it to stop a bit earlier, when j was 2. Of course, I hadn't started it using (debug ...). Is that required?



But if I go (debug (t)), and then press c (for cont) it runs through without stopping. Again, I was expecting it to stop earlier. Is my understanding of what it does wrong?

Lutz

#1
probably you have hit n/next instead of s/step. Also do this in an interactive termial. When using s/step these are the steps:



> (debug (t))

-----

(define (t )
  #(dolist (i (explode "string"))
   (println "i is " i)
   (for (j 0 3)
    (println " j is " j)
    (if (= j 2)
     (trace true))))#)


[-> 3 ] s|tep n|ext c|ont q|uit > s

-----

(define (t )
  (dolist (i #(explode "string")#)
   (println "i is " i)
   (for (j 0 3)
    (println " j is " j)
    (if (= j 2)
     (trace true)))))


[-> 4 ] s|tep n|ext c|ont q|uit > s

-----

(define (t )
  (dolist (i #(explode "string")#)
   (println "i is " i)
   (for (j 0 3)
    (println " j is " j)
    (if (= j 2)
     (trace true)))))


RESULT: ("s" "t" "r" "i" "n" "g")

[<- 4 ] s|tep n|ext c|ont q|uit > s

-----

(define (t )
  (dolist (i (explode "string"))
   #(println "i is " i)#
   (for (j 0 3)
    (println " j is " j)
    (if (= j 2)
     (trace true)))))


[-> 4 ] s|tep n|ext c|ont q|uit > s
i is s

-----

(define (t )
  (dolist (i (explode "string"))
   #(println "i is " i)#
   (for (j 0 3)
    (println " j is " j)
    (if (= j 2)
     (trace true)))))


RESULT: "s"

[<- 4 ] s|tep n|ext c|ont q|uit > s

-----

(define (t )
  (dolist (i (explode "string"))
   (println "i is " i)
   #(for (j 0 3)
    (println " j is " j)
    (if (= j 2)
     (trace true)))#))


[-> 4 ] s|tep n|ext c|ont q|uit > s

-----

(define (t )
  (dolist (i (explode "string"))
   (println "i is " i)
   (for (j 0 3)
    #(println " j is " j)#
    (if (= j 2)
     (trace true)))))


[-> 5 ] s|tep n|ext c|ont q|uit > s
 j is 0

-----

(define (t )
  (dolist (i (explode "string"))
   (println "i is " i)
   (for (j 0 3)
    #(println " j is " j)#
    (if (= j 2)
     (trace true)))))


RESULT: 0

[<- 5 ] s|tep n|ext c|ont q|uit > s

-----

(define (t )
  (dolist (i (explode "string"))
   (println "i is " i)
   (for (j 0 3)
    (println " j is " j)
    #(if (= j 2)
     (trace true))#)))


[-> 5 ] s|tep n|ext c|ont q|uit > s

-----

(define (t )
  (dolist (i (explode "string"))
   (println "i is " i)
   (for (j 0 3)
    (println " j is " j)
    (if #(= j 2)#
     (trace true)))))


[-> 6 ] s|tep n|ext c|ont q|uit > s

-----

(define (t )
  (dolist (i (explode "string"))
   (println "i is " i)
   (for (j 0 3)
    (println " j is " j)
    (if #(= j 2)#
     (trace true)))))


RESULT: nil

[<- 6 ] s|tep n|ext c|ont q|uit > s

-----

(define (t )
  (dolist (i (explode "string"))
   (println "i is " i)
   (for (j 0 3)
    (println " j is " j)
    #(if (= j 2)
     (trace true))#)))


RESULT: nil

[<- 5 ] s|tep n|ext c|ont q|uit > s

-----

(define (t )
  (dolist (i (explode "string"))
   (println "i is " i)
   (for (j 0 3)
    #(println " j is " j)#
    (if (= j 2)
     (trace true)))))


[-> 5 ] s|tep n|ext c|ont q|uit >


The arrows -> or <- show if you are entering or exiting the code segment marked by hash symbols #



Lutz

cormullion

#2
Hi Lutz!



What I was trying to do was to run for a while normally and then stop at a 'breakpoint'. Reducing it down to this simple example - how do i get it to run at full speed until the moment when trace is set, when j takes a certain value?



Edit: ah, I think I see the issue: the (trace true) drops you into the next function, rather than stopping straight away. Is that a fair assumption?

Lutz

#3
QuoteEdit: ah, I think I see the issue: the (trace true) drops you into the next function, rather than stopping straight away. Is that a fair assumption?


Yes, this is how it is supposed to work, the documentation is misleading.



Lutz