Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ArtOfWarfare

macrumors G3
Original poster
Nov 26, 2007
9,553
6,053
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?
 
Last edited:

PhoneyDeveloper

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

Attachments

  • Screen Shot 2013-02-16 at 11.45.41 AM.png
    Screen Shot 2013-02-16 at 11.45.41 AM.png
    65.3 KB · Views: 76
  • Screen Shot 2013-02-16 at 11.46.06 AM.png
    Screen Shot 2013-02-16 at 11.46.06 AM.png
    16.3 KB · Views: 138

ArtOfWarfare

macrumors G3
Original poster
Nov 26, 2007
9,553
6,053
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.)
 
Last edited:

firewood

macrumors G3
Jul 29, 2003
8,107
1,345
Silicon Valley
What's the simplest thing I can do here without modifying my code to make it so that it logs every 10Kth iteration only?

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.
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
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
}
 

ArtOfWarfare

macrumors G3
Original poster
Nov 26, 2007
9,553
6,053
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.
 

xArtx

macrumors 6502a
Mar 30, 2012
764
1
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.

you can use qsort in Xcode.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.