Re: [Haskell-cafe] Crash!

Thomas DuBuisson wrote:
So if you have such a specific portion of the code you think is to blame, perhaps you could simple comment that out (return () instead of write the file) and see if it crashes? I understand people avoidance of brute force guess problem-compile-test cycles, but it seems you have good evidence supporting this guess.
Yeah, I can try different optimisation levels and so forth. I'm actually wondering if my code is writing off the end of an array and this "just happens" to hit some data structure used by GTK+? (In which case, minute changes in linkage, etc., would disturb the bug.) Does anybody know of any tools for definitely pinning down stuff like this? Surely C programmers have their code crash several hundred times a day due to bugs like this...
Also, be sure the thunks are evaluated - if the writing of the file is what is forcing the evaluation (and thus triggering the condition) then you need to separate these two cases.
That's the fun part about Haskell, eh? ;-) However, in this instance, there's that much explicit mutation in the I/O monad on unboxed (and therefore strict) arrays that I'm pretty sure that isn't the problem. By the time the save-PNG function is called, the data already exists in the address space managed by GTK+. It has to, or GTK+ wouldn't be able to save it. Unless my *pure* code is somehow generating an access violation - which would surely indicate an actual compiler *bug*... (This seems laughably unlikely.)

On Thu, Oct 23, 2008 at 1:26 PM, Andrew Coppin
Does anybody know of any tools for definitely pinning down stuff like this? Surely C programmers have their code crash several hundred times a day due to bugs like this...
Curiously, the tool I often use with C/C++ to track down things like overrunning past the end of arrays was written by a GHC developer. It's valgrind. If the problem is happening in a foreign C/C++ function, and the executable has debugging information pointing to valid source for those functions, then valgrind might help with Haskell too. Even without source, testing with the 'fail' example earlier in this thread, it at least tells me the problem was trying to read from memory location zero, more information than just "Segmentation Fault".

Andrew Coppin wrote:
I'm actually wondering if my code is writing off the end of an array and this "just happens" to hit some data structure used by GTK+? (In which case, minute changes in linkage, etc., would disturb the bug.)
Yep, that's what it was. (Although not where I was expecting it to be, which kept me guessing for a while...) I thought that all write operations go to the IOUArray, except for the loop that copies it to the Pixbuf. (This loop is constructed such that it cannot go out of bounds, while the ad-hoc writing uses user-supplied coordinates.) I forgot about the second drawing pass, which does write directly to the Pixbuf. *This* appears to be the source of my bug; if you add a range check, the bug goes away. (Oddly, I added the range check back to the IOUArray as well, and even though it's writing the same coordinates, no error is reported. I guess I must have an off-by-one bug as well...!) So there you have it. Premature optimisation => buffer overrun => end of civilisation as we know it. :-/
participants (2)
-
Andrew Coppin
-
Dan Piponi