Log Every 10000th time breakpoint is hit?

Discussion in 'iOS Programming' started by ArtOfWarfare, Feb 15, 2013.

  1. ArtOfWarfare, Feb 15, 2013
    Last edited: Feb 15, 2013

    macrumors 604


    Nov 26, 2007
    I just discovered the "Edit Breakpoint..." options that appear when you right click a breakpoint. It's occurred to me that this allows me to easily insert debug messages without modifying my source files at all.

    I have a loop that I'm expecting will be run approximately 8.1 B times... I don't want it to a log every iteration through the loop, but every 10 Kth iteration through the loop.

    I figured that simply setting the "Ignore x Times Before Stopping" option would do this for me, but that causes it to stop on iteration 10,000, 10,001, 10,002, and so on... not terribly helpful.

    I realize that I could probably utilize the condition field some how, but it's not very easy (I have no iteration counting variable right now... and the whole point here is to avoid modifying code for the sole point of debugging.)

    So... what am I missing? What's the simplest thing I can do here without modifying my code to make it so that it logs every 10Kth iteration only?
  2. macrumors 68030


    Sep 2, 2008
    Here you go. This doesn't break at all. It just logs the value every 5th iteration.

    Attached Files:

  3. ArtOfWarfare, Feb 16, 2013
    Last edited: Feb 16, 2013

    thread starter macrumors 604


    Nov 26, 2007
    I don't have an iteration variable in my code right now (it's a while loop & I'm trying to do this without modifying my code to include a variable just for debugging.)
  4. macrumors 604

    Jul 29, 2003
    Silicon Valley
    Modify your code. This will have less impact on performance than a conditional breakpoint. If your code is checked into source control, then just revert after debugging to get rid of all the temporary debug modifications.
  5. macrumors 68030


    Sep 2, 2008
    OP, you miss the point. Whatever the condition is that you want to have a log use that. Also, you can add a counter that increments each time through the loop.

    The concepts are "conditional breakpoint" and "breakpoint action." You set a condition and it breaks. The action can print or run an applescript or several other possibilities.

    int count = 0;
    while (!done)
    // do whatever
    count++; // set your conditional breakpoint here
  6. thread starter macrumors 604


    Nov 26, 2007
    I'm wondering if maybe it was my goal that was wrong...

    Trying to break less often didn't help me fix my bugs... instead what I had to do was scale back my problem.

    I was trying to read in a list of 90 K words and sort them alphabetically (school assignment - I had to roll my own sorting method,) but I couldn't figure out why some words weren't sorting properly. I ultimately fixed my issue by scaling my list down to just 12 words, following my own procedure on a white board, and then stepping through my code and modifying it to do the same thing as I did on the white board when it strayed.
  7. macrumors 6502a

    Mar 30, 2012
    you can use qsort in Xcode.
  8. macrumors 68000

    Jan 28, 2003
    Less lost in L.A.
    The assignment required writing the sort algorithm.

Share This Page