I have very rarely needed anything more than printf to debug an application. Failing that, the core file will tell you where it crashed, although not necessarily why. You're unlikely to get more information running gdb for a week, because you're not going to be watching it in the vital few minutes or seconds before it crashes.
My recommendation would be to enable the core file. Then when it crashes, run gdb on the core file and follow the stack frame back to find out exactly what it was doing. You might be able to work it out from there, but if not then add lots of printf's to a log file or the screen, flushing and syncing after any that might be close to the crash-site.
Things you should be looking for:
- Using memory after it has been free'd
- Multi-tasking that needs to be locked but isn't
- A slow memory leak (printf sbrk(0) every few minutes to test. See man sbrk.)
- A memory structure that grows continually
- A coincidence in timing that is ridiculously unlikely. (If it was likely, it wouldn't last a week.)
Ensure that you are checking the return value of
every function call. malloc() sometimes fails and you want to know then, not when the code uses the null pointer half an hour later. Even if you have no idea what to do if an error happens, check every return value and at least printf a log of it.