Debug library

Discussion in 'Additional Libraries' started by agraham, May 17, 2008.

  1. agraham

    agraham Expert Licensed User

    Like me, have you had, on occasion, to scatter your code with debugging code trying to find an obscure bug and then found it difficult to identify all that additional code and clear it out. This library tries to avoid that by providing the ability to insert readily identifiable debug statements in the code and centralise the debugging code in a single event Sub that may just be deleted when the problem is solved. In addition these debug statments are conditional so that debugging code is only invoked when a problem is likely to exist. This makes debugging long loops much easier.

    As the help file says, this library doesn't do more than you could do in B4PPC code. However as it is isolated in a library it does it much more neatly! Let me know if you have any suggestions for improvement.

    EDIT: Version 1.1 posted. See post below.

    EDIT: Version 1.2 posted with the awesome new Watcher object. :) See post #6. This now needs .NET 2.0 so I have left version 1.1 which only needs .NET 1.0/1.1

    EDIT: Version 1.3 posted with a greatly enhanced Watcher that can examine and change properties and invoke methods. See post#7.

    EDIT: Version 1.4 posted with Watcher polished a bit and a new Tracer object. See post #10.

    EDIT: Version 1.5 posted with support for module name prefixes and the awesome new Caller object. :) . See post #11.

    Attached Files:

    Last edited: Oct 15, 2008
  2. specci48

    specci48 Well-Known Member Licensed User

  3. agraham

    agraham Expert Licensed User

    I thought that I would offer some words of explanation to those of you who have looked at the demo program and may be curious why I declared a global array, then assigned it to a Debug property and then unnecessarily assigned the property back to the global array when it always accessible.
    DebugVals(0) = localvar
        Debug.Values = DebugVals() 
    ' can save local variables to pass to DebugEvent
    Sub Debug_DebugEvent
        DebugVals() = Debug.Values 
    ' this can get back saved local variable values
    I had intended to use the new Array keyword to allow saving local variables for analysis without going via a global array but it didn't work! I have asked Erel why and left the property in and documented for the time being. I also anticipated that local arrays may be available some time which will not be visible outside the Sub where thay are declared.
    Debug.Values = Array(lvar1, lvar2) ' can save local variables to pass to DebugEvent
    Sub Debug_DebugEvent
        DebugVals() = Debug.Values 
    ' this can get back saved local variable values
  4. Erel

    Erel Administrator Staff Member Licensed User

    The Array keyword is a "special" keyword. It first checks the left hand side variable and finds it type. This way it knows which type of array it should create (String, Double...).
    In version 6.30 the Array keyword can only be used to initialize already declared arrays.
  5. agraham

    agraham Expert Licensed User

    Thanks for the explanation Erel.

    Version 1.1 now posted with the internal Values array removed as what I intended it for will not work. ID renamed EventID and the example demo tidied up. A new IfTrueTest debug method to test a boolean added. Help file amended.
  6. agraham

    agraham Expert Licensed User

    Presently the debugging of optimised compiled programs is limited to popping up message boxes and maybe writing debug info to temporary controls. I've added a Watcher object to this library that can look inside optimised compiled apps at runtime and display and alter Global variables. It even works on the device. Have a play!

    At present it is limited to normal variables and single dimensioned arrays. I plan to cope with multi-dimensioned arrays and will have a go at typed arrays sometime.
  7. agraham

    agraham Expert Licensed User

    The Watcher in version 1.3, now posted in the first ,post has been hugely enhanced and can now watch and modify multi-dimensioned and typed arrays, it could also deal with typed variables but B4ppc doesn't support them (yet!).

    It can display and alter control properties and invoke control methods, including library controls. Try it on the Debug object in the demo.

    All variables, controls, properties and methods may be selected from combo-boxes so minimising key input on the device. It is thread safe so you can modify GUI elements at runtime if you want.

    Note that it runs on both device and desktop so you can debug an optimised compiled exe on the device.

    An extra breakpoint facility has been added to the Debugger object so that individual breakpoints can be enabled and disabled.
  8. Erel

    Erel Administrator Staff Member Licensed User

    You did an amazing job!
  9. agraham

    agraham Expert Licensed User

    Praise from the master! Thanks Erel :sign0188: I really enjoyed writing that one, and learning along the way :)
  10. agraham

    agraham Expert Licensed User

    Version 1.4 is posted with the Watcher improved by a new layout with larger combo boxes and indicators added for array rank, property readable/writeable and method number of parameters.

    A new Tracer object allows messages to be written to a separate trace window at runtime without having to stop the application by showing message boxes.

    Although needing .NET 2.0 the Debug and Tracer will work in the IDE, legacy and optimised compiled apps. The watcher will only work in an optimised compiled app.
  11. agraham

    agraham Expert Licensed User

    Version 1.5, now posted in the first post, now supports module name prefixes.

    Also, in my efforts to provide debugging facilities for optimised compiled applications, I have added a Caller object to the library. Caller can, at runtime, execute any compiled Sub with three or less parameters and display the return value if any. You can specify the parameter values, copying them from variables if necessary or typing them in directly.

    You could of course create mayhem in your app if you execute Subs arbitrarily so some care will be necessary on occasion!
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice