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

farmerdoug

macrumors 6502a
Original poster
Sep 16, 2008
541
0
I get a "Thread 1: Program received signal: :EXC_BAD_ACCESS" error whenever I run too many conditions in a for loop. I suspect this is a memory problem; I have checked my memory allocation and freeing of memory buffers but of course could have missed something. What is the easy way for a hacker like me to debug this?

Thanks.
 
Let's not go there. The code is somewhat proprietary and beside the point.
I should have just said what are good ways to look for what seem to be errors related to memory.

----------

Does anybody know anything about valgrind or memwatch? Is of them better or easier to use?
 
Let's not go there. The code is somewhat proprietary and beside the point.
I should have just said what are good ways to look for what seem to be errors related to memory.

----------

Does anybody know anything about valgrind or memwatch? Is of them better or easier to use?
Lots of open-source projects use Valgrind to find and fix memory-related problems. I'd imagine that closed-source projects make use of it too. The key to using it is integrating it into your build process, to find these bugs BEFORE they make it to release-level code. As for Memwatch, I've not heard of this tool before.
 
Thanks. I'll probably give it a try. I've used memwatch with makefiles but seem to remember having trouble implementing it.
 
Too many conditions? like..
Code:
void foo(int x) {
    int *y = &x;
    for(y = 0; y < &x && *y == 1; y++) {
        (void) 0;
    }
}

Cause it runs fine (though it slowly) without the second compare.
But in trying to make it speed up, I cause EXEC_BAD_ACCESS... :(

Seriously though, if its repeatable every time, you're probably overflowing an array or something. Set break points earlier and earlier and just step through the code until your crash. You're probably dereferencing something you shouldn't, or overflowing an array due to poor control, or maybe having assignment when it should be comparison (= vs ==)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.