Shop OBEX P1 Docs P2 Docs Learn Events
single stepping through a program... — Parallax Forums

single stepping through a program...

n5hoon5hoo Posts: 4
edited 2007-12-03 04:28 in Robotics
Is there a way to single step through·a Pbasic v2.5 program?
It would be very helpful when debugging.
Thank you

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-12-03 04:28
    You can simulate single stepping by inserting code between each statement. While that may sound like a lot to get rid of, once your code is debugged, it's not so bad if you use conditional compilation, viz:

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    #DEFINE sstep = 0
    
    DO
      #IF sstep #THEN GOSUB halt #ENDIF
      W0 = W0 + 1
      #IF sstep #THEN GOSUB halt #ENDIF
      DEBUG DEC W0, CR
    LOOP
    
    #IF sstep #THEN
    halt:
      DEBUGIN WAIT(" ")
      RETURN
    #ENDIF
    
    
    



    The #IF lines can simply be copied and pasted where needed. By defining sstep to be 0, you can eliminate the debug stuff in you compiled code entirely.

    The halt routine can even be designed to dump all your vairiables and pin states, too, if you want that much info at each step.

    -Phil

    Post Edited (Phil Pilgrim (PhiPi)) : 12/3/2007 4:34:24 AM GMT
Sign In or Register to comment.