As our code gets more and more complex, tracking down those inevitable mysteriously random crashes can be very time consuming. From experience, time spent on these bugs can be dramatically reduced by using tools which check for bad memory conditions. Most of these include features like electric-fence watching of memory bounds, leak-checking, using freed memory, etc.
Over the last week I've investigated close to 10 available memory checkers for Linux. Most did not work very well with our code base, mostly because it is a threaded app.
I did, however, find one library which works well - the latest version of dmalloc. Some hints on it's use:
- dmalloc needs to be linked into the exe - and the library dmallocthcxx is the one to link. This one is compatible with threaded apps and overrides the new/delete operators for c++ code
- for me only the latest version worked, previous versions had issues with it's thread-safe library
- you need to actually download and build from source, not a pre-built package. This is because you need to turn off the check for allocations of size 0 being an error The STL makes calls to new with a size of 0, and this needs to be turned off. It's in settings.h
- once linked in, you can run the game in a debugger and it will stop at any errors
- one feature that this library does not have is the ability to detect reading from unintialized memory.
For tracking hard to reproduce bugs a tool like this can save time. I'll be running it on any new code before I make a commit.
Programmers discuss here anything related to FreeOrion programming. Primarily for the developers to discuss.
1 post • Page 1 of 1