Advice on bug hunting?

Locked
bludshot
Posts: 65
Joined: Thu Nov 26, 2009 6:14 am

Advice on bug hunting?

Post by bludshot »

My mod has some issue in the code whereby the server hangs and takes 100% cpu. In the server console, all you see is whatever was happening normally prior to that. The hanging doesn't stop after a minute, it continues probably forever.

Do you guys have any advice on how I should go about finding this bug?

Certainly I want to try to replicate the circumstances of triggering the bug, but, so far it appears extremely random.
User avatar
Eraser
Posts: 19174
Joined: Fri Dec 01, 2000 8:00 am

Re: Advice on bug hunting?

Post by Eraser »

I haven't had the situation where I introduced really hard to detect bugs in my mod yet, so I usually have a vague idea what's probably going wrong. If I'm not sure where the offending line of code is, I just comment out portions of code where I suspect the bug is. I then reintroduce portions of code to see what exactly is happening and use a lot of Printf's to dump debugging info to the console. At one point a section of code is reintroduced and the game hangs again, then I can pinpoint exactly which line of code causes the hang or crash.

The problem with hangs or crashes is that (as far as I know) there's no external logging available so it's impossible to look at some log and see what's going wrong. So the first thing I'm trying to do is to prevent the crash from happening and just dump info to the console to see if I can find any irregularities or odd values.

In your case though, if the bug appears to be occurring randomly, this method might not be useful because you don't know if the bug doesn't happen due to the offending code not being executed or because it's just not the right situation for the bug to occur.

Do you see any patterns in when the bug is occuring? Try to filter out as much "junk" as you can. If the bug occurs in a full fledged map for the mod, see if you can create a box map in which you can cause the crash to happen.
^misantropia^
Posts: 4022
Joined: Sat Mar 12, 2005 6:24 pm

Re: Advice on bug hunting?

Post by ^misantropia^ »

Attach a debugger (gdb, msvc) and break when the program hangs.
bludshot
Posts: 65
Joined: Thu Nov 26, 2009 6:14 am

Re: Advice on bug hunting?

Post by bludshot »

Yeah... I tried to figure out how to do that once and failed. But I may need to end up figuring out how to do that.
Locked