none
Debugger SmallBasic Extension RRS feed

  • General discussion

  • As well as adding lots of TextWindow.WriteLine statements to help debug programs I wrote an extension debugger a while back that may be helpful.

    It works in 2 stages:

    1] Create a modified source file from your SmallBasic code with additional information for the debugging process.

    This is achieved by writing a one line program calling the command LDDebug.Instrument with the path and name of your SmallBasic source, for example:

    LDDebug.Instrument(Program.Directory+"\DebugExample.sb")

    This creates a new SmallBasic file, in this case called 'DebugExample_debug.sb' in the same path as the original, e.g. Program.Directory+"\DebugExample_debug.sb".

    If the original code "DebugExample.sb" was:

    test[1][1] = "A"
    test[1][2] = "B"
    test[2][1] = "C"
    test[2][2] = "D"
    test["Hello"][2][1] = "X"
    
    For i = 1 To 100
      ball[i] = Shapes.AddEllipse(50,50)
    EndFor
    
    While ("True")
      Move()
    EndWhile
    
    Sub Move
      For i = 1 To 100
        Shapes.Move(ball[i],Math.GetRandomNumber(GraphicsWindow.Width)-25,Math.GetRandomNumber(GraphicsWindow.Height)-25)
      EndFor
    EndSub

    Then the modified code "DebugExample_debug.sb" looks like:

    LDDebug.Start()
    LDDebug.Break(1)
    test[1][1] = "A"
    LDDebug.Break(2)
    test[1][2] = "B"
    LDDebug.Break(3)
    test[2][1] = "C"
    LDDebug.Break(4)
    test[2][2] = "D"
    LDDebug.Break(5)
    test["Hello"][2][1] = "X"
    
    LDDebug.Break(7)
    For i = 1 To 100
    LDDebug.Break(8)
      ball[i] = Shapes.AddEllipse(50,50)
    LDDebug.Break(9)
    EndFor
    
    LDDebug.Break(11)
    While ("True")
    LDDebug.Break(12)
      Move()
    LDDebug.Break(13)
    EndWhile
    
    LDDebug.Break(15)
    Sub Move
    LDDebug.Break(16)
      For i = 1 To 100
    LDDebug.Break(17)
        Shapes.Move(ball[i],Math.GetRandomNumber(GraphicsWindow.Width)-25,Math.GetRandomNumber(GraphicsWindow.Height)-25)
    LDDebug.Break(18)
      EndFor
    LDDebug.Break(19)
    EndSub

    2] Load and run this SmallBasic program.

    You can then step though the program, set break points and see the values of your variables and arrays; you can also change values.

    Debug the program to find errors, then modify the original and repeat the process to debug the modified code if required.

    Hit the "?" to get some more help.

    The download for this extension can be found here, just hit the download icon to the right of the LitDev extension.

    Monday, June 4, 2012 11:02 AM
    Moderator

All replies

  • Wow, that's really neat! Nice UI on the breakpoints/ variables console.  i look forward to using this part of your extension.
    Monday, June 4, 2012 1:14 PM
    Answerer
  • Hello,

    I expanded your oneliner with a check if the file exists :

    '' Debug.sb  2012-06-09
    TextWindow.WriteLine("This program makes a debug version of a SB program")
    TextWindow.Write("Give the name of the program (without extension) > ")
    prog=TextWindow.Read()
    FI=Program.Directory+"\"+prog+".sb"
    ff=File.ReadContents(FI)
    ll= Text.GetLength(ff)
    If ll<2 then
      TextWindow.Write("Does this file exist? Length = ")
      TextWindow.WriteLine(ll)
      TextWindow.Pause()
      Program.End()
    EndIf
    TextWindow.WriteLine(FI)
    LDDebug.Instrument(FI)
    TextWindow.Write("The program with debug instructions is called: ")
    TextWindow.WriteLine(prog+"_debug.sb")

    I hope anyone can use this


    Jan [ WhTurner ] The Netherlands

    Saturday, June 9, 2012 1:04 PM
    Answerer
  • Hey,

    your small basic extension download link will not load.

    Monday, August 27, 2012 3:40 AM
  • did you copy the xml and dll into the lib directory? and the other files (samples etc) to some location where you have privileges like your documents folder first ?

    did the extension methods appear in the smallbasic intellisense?

    did the debug example work?

    please supply the code you are using or more details on which stage didn't work.

    Monday, August 27, 2012 9:25 AM
    Moderator
  • Hi litdev,

    the link does not work anymore. The page has moved.

    Could you provide your debugger program in any way to me?

    regards

    Computix-25

    Sunday, January 14, 2018 8:53 PM
  • The LitDev extension that contains this degugger can be found at

    https://gallery.technet.microsoft.com/Small-Basic-LitDev-75827dc5

    However, since this extension method was created I have written a new IDE for SB (called SB-IDE) that includes a more integrated and powerful debugger (I recommend this approach), which can be found at

    https://gallery.technet.microsoft.com/Small-Basic-IDE-10-42648328

    Supporting thread for SB-IDE at

    https://social.msdn.microsoft.com/Forums/en-US/05f9c212-fa4d-4ae2-b4f0-11e8039c49af/new-sbide?forum=smallbasic

    Sunday, January 14, 2018 10:07 PM
    Moderator