how to track down out-of-bounds error?

Derek Elkins
Wed, 28 May 2003 10:35:00 -0400

On Wed, 28 May 2003 09:36:31 -0400
David Roundy <> wrote:

> In some code which uses UArrays, I'm getting the following error:
> Fail: Ix{Int}.index: Index (3723) out of range ((0,3722))
> Presumably this means I'm trying to access one beyond the end of an
> array. The problem is trying to figure out where I'm doing this. 
> Unfortunately, I have only been able to see this error on a rather
> large test repository, where it takes seven minutes for the test to
> show up.
> Any suggestions how I might most easily track this bug down?
> -- 
> David Roundy

1) (If you are using GHC) compile for
profiling and use the -xc runtime option.  This causes GHC to dump a
"stack" dump when an exception is thrown.

2) See the various debuggers that are out there.  I haven't used Hat
(is a pain to compile on Win2k with 64MB) but it seems like your best
bet. Buddha may work but it would require you to mark a lot of code
trusted likely to avoid running out of memory or taking all day.

3) Classic debugging: throw traces (or use HOOD, HOOD is Debug.Trace on
massive steroids) in suspected parts of your code and see what looks
wrong.  I think HOOD has some kind of support for exceptions so it may
dump out some very helpful information.

4) Classic debugging part two: chop out code, make tests, you certainly
know the drill.