Function to break into the debugger

You must Login before you can answer or comment on any questions.

Does an one know of an undocumented (or documented but I can't find one) function that can be used to cause a break in the debugger?

2 Answers

Accepted Answer

The debugger directive (new in ECMAscript 5) appears to work fine with Titanium Studio:

if (mycondition) {
    debugger;
}

Do you mean add a breakpoint? You can just right click in the left edge of your code editor. A content menu will pop up and one if the choices will be "toggle breakpoint". Click that and you'll see a little blue dot signifying your breakpoint.

— answered 2 years ago by Tony Lukasavage
answer permalink
3 Comments
  • Nah not a breakpoint. This would be a function that when called caused the debug to break execution at that line. It would be very useful for invariant testing in functions and forcing execution to halt on bad conditions. For example

    function checkNotNull(obj)
    {
        if(obj == null)
        {
            Ti.API.debugBreak();
        }
    }
    function checkNonNan(v)
    {
        if(isNaN(v))
        {
            Ti.API.debugBreak();
        }
    }
     
    function doSomethingCool(obj, value)
    {
        // invariants
        checkNotNull(obj);
        checkNonNan(value);
     
        // do cool stuff
    }
    You can obviously do this anyway by creating the check functions and placing breakpoints in them but it is easy to forget to do that and when you get a small collection of them its a pain to set breakpoints on them all. This stuff comes in really handy during development and forcing a halt at the point bad data is detected rather than possibly much further on in execution.

    Martin

    — commented 2 years ago by Martin Slater

  • Ah, conditional debugging. Create a breakpoint like I stated above and then right click on it. Select breakpoint properties. From the resulting dialog click enable condition and this is where you can put your conditional logic for your breakpoint.

    — commented 2 years ago by Tony Lukasavage

  • Nup not conditional breakpoints either :) Something analogous to DebugBreak in Win32 API. The point of this is that it will kick into the debugger without you needing to set a breakpoint at all. This lets you use code like the above (and more complex scenarios) throughout your codebase and be sure if it fails an invariant it will stop in the debugger.

    — commented 2 years ago by Martin Slater

Your Answer

This question has been locked and cannot accept new answers.