debugging the whole thing

debugging the whole thing

Here is where ideas can be collected for the skirmish AI in development

Moderators: hoijui, Moderators

User avatar
krogothe
AI Developer
Posts: 1050
Joined: 14 Nov 2005, 17:07

debugging the whole thing

Post by krogothe »

Due to KAIs current simplicity it was an easy task tracking and removing all relevant crash bugs, but i have a feeling it would be much easier to have some proper debug information!

before i start writing a complex logger class, it would be better to try it:

do i just compile the spring cvs and KAI in debug mode? how do i get useful info about a crash?


thanks!
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

maybe soemone could tell me how to re-install/redo my debugger without reinstalling VS .Net so it actually works aswell.
User avatar
jcnossen
Former Engine Dev
Posts: 2440
Joined: 05 Jun 2005, 19:13

Post by jcnossen »

You disable "Catch global AI exceptions" in the config app, and build your AI in debug mode (name it AIdebug.dll or something, so you can clearly see you are picking the right one from the list).
You don't need to build spring in debug mode, just the normal executable will suffice (only you will not be able to read code/variable contents from spring functions on the callstack). Spring in debug mode is so slow it really isn't usable for AI dev.

Then just hope it crashes fast enough... it sucks when you have to wait 20 min before it crashes ;)
VS catches the exception, and shows you the exact point of crashing and allows you even to view the contents of variables.

Also, make sure you let it generate the full debug info database when compiling. This should be the default option though, when you select the "Debug" configuration.
User avatar
krogothe
AI Developer
Posts: 1050
Joined: 14 Nov 2005, 17:07

Post by krogothe »

If i was religious, id worship zaph!
ill try that out soon thanks for the tip!
Geryon
Posts: 4
Joined: 05 Jan 2006, 05:14

Post by Geryon »

People that don't have a debugger can get a decent one from MS. These are very important tools that tell you what line caused the crash, the value of all the variables, and what function calls led to the code that crashed (stack traces).

http://www.microsoft.com/whdc/devtools/ ... fault.mspx
http://www.codeproject.com/debug/windbg_part1.asp

I have had pretty good success running it on spring and debugging some ai dlls. Just compile the dlls with debug symbols and tell the debugger to run spring.exe with a startup script that loads the ai (springsp works well for creating the scripts) and point the debugger to the source code. Then all you need to do is click go on the debugger.
User avatar
krogothe
AI Developer
Posts: 1050
Joined: 14 Nov 2005, 17:07

Post by krogothe »

Cool, this might finally let me find out the reason for the most obscure bug ive ever came across in my entire life! its been pretty easy to spot so far since im used to it but its quite stupid IMO:

this crashes:

Code: Select all

if(A && B && C)
  code
and this doesnt! (A, B, and C are IDENTICAL to the ones used above)

Code: Select all

if(A && C)
{
  if(B)
    code
}
its simply a random 10% chance of crash added to every codintion in an if statement (using || seems to crash it even more)...
oh well, thinking again i doubt it will help with that but should cut bugfinding time in half...
SJ
Posts: 618
Joined: 13 Aug 2004, 17:13

Post by SJ »

Well thats pretty obvious. C++ always evaluate if expressions left to right so B will only be executed if A is true or in the later case only if A and C is true...
User avatar
krogothe
AI Developer
Posts: 1050
Joined: 14 Nov 2005, 17:07

Post by krogothe »

why should it crash at startup (and not when that code is run) using the first method and never with the second one though?
A, B and C are not functions but simple statements like "var1 > var2" or "!bool2"
Torrasque
Posts: 1022
Joined: 05 Oct 2004, 23:55

Post by Torrasque »

A, B and C are not functions but simple statements like "var1 > var2" or "!bool2"
Thats really strange, and even more strange if the code in the second exemlple is executed. Are you sure A is not myObject->A etc...?[/quote]
User avatar
Veylon
AI Developer
Posts: 174
Joined: 21 Sep 2005, 19:45

Post by Veylon »

I just log everything and comment out the logs when something is working probably. My logs tend to look like this:

Code: Select all

Creating MetalHandler...
MetalHandler::MetalHandler(00AB19210)
MetalMap::MetalMap(00AB19210)
121 Metal Points found
Mex Radius: 50
High Metal: 1.2
Setting as OTA Map~
~
Creating Building Organizer...
BuildingOrganizer::BuildingOrganizer(00AB19210)
Found 6 Geothermals.
Setting area around to blocked....
And so on and so forth...
There used to be more.
That way you just add more logging when you have a bug and run it again, and comment it out when you kill the bug. It's what I've been doing.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

It's the corner stone of NTAI development that method
User avatar
jcnossen
Former Engine Dev
Posts: 2440
Joined: 05 Jun 2005, 19:13

Post by jcnossen »

Really all AI devs should learn to use a debugger properly... logs are usually a waste of time when you can run through your code step-by-step and see how all the variables are changing because of it.
Geryon
Posts: 4
Joined: 05 Jan 2006, 05:14

Post by Geryon »

I'll second that. Debuggers are critical. If anyone is having trouble running a debugger let us know so we can help you out.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

When I compile in debug mode and set breakpoints in VS as Zaphod taught me, nothign happens save slowing down. An exception occurs? Same results as a normal build but it's more sluggish in exiting spring, I see no change in VS at all, no extra prompts or messages or anything.

I seem tor emember a debugger error when I first tried it out though It might occur everytime btu I aint compiled in debug mdoe for so long I aint tried. It seemed more todo with a faulty debug setup than a faulty dll.
User avatar
krogothe
AI Developer
Posts: 1050
Joined: 14 Nov 2005, 17:07

Post by krogothe »

lol whats a breakpoint?
where can i learn to debug stuff properly?
User avatar
jcnossen
Former Engine Dev
Posts: 2440
Joined: 05 Jun 2005, 19:13

Post by jcnossen »

In VS, click on the left side of the code (light grey probably), you'll see a red dot, that's the breakpoint. This is where execution pauses when you run your program with the debugger attached to it.

Then setup the project so the debugger starts spring.exe. To do that, go to project properties and the debugging section of it. You need to set the command to spring.exe, and the working directory should also be correct, otherwise spring can't see the files.

Also, select the Debug configuration inside the configuration manager, or directly using the toolbar.

Just play around with it, you'll learn...
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

Ah I just looked through VS .Net and ti said somehtign about debugging nto availabel pelase repair/reinstall so i went into the install thgina dn there was a package missing that ahd stuff like windiff and said soemhtign about debugging too so hopefulyl it's alright now.

hmm I thought there was more to what you said than just setting a breakpoint...
User avatar
krogothe
AI Developer
Posts: 1050
Joined: 14 Nov 2005, 17:07

Post by krogothe »

awesome, it crashes every single time when i compile it in debug mode!
even better is that it never ever gives me a debug button or info!
Running it from the lobby gives a spring error, no debug button...
Running it from spring.exe right after compiling just makes it not respond (wont even start up)

what i get in VS is this:
EDIT: wont fit, basically the same access violation message repeated 100000 times

the little spring debug thingy seems pretty useless:

Code: Select all

- <CallStack>
  <Frame FrameNumber="1" ReturnAddress="0xbf60d60" ModuleName="I:\Program Files\TASpring\aidll\globalai\KAI.dll" FunctionName="UnitTable::Init" FunctionDisplacement="0x280" Filename="i:\documents and settings\admin\my documents\visual studio 2005\taspring\testglobalai\unittable.cpp" LineNumber="229" LineDisplacement="0x24" /> 
  <Frame FrameNumber="2" ReturnAddress="0xbf50397" ModuleName="I:\Program Files\TASpring\aidll\globalai\KAI.dll" FunctionName="CGlobalAI::InitAI" FunctionDisplacement="0x2e7" Filename="i:\documents and settings\admin\my documents\visual studio 2005\taspring\testglobalai\globalai.cpp" LineNumber="51" LineDisplacement="0xa" /> 
  <Frame FrameNumber="3" ReturnAddress="0x482a01" /> 
  <Frame FrameNumber="4" ReturnAddress="0x2f6c6c63" /> 
  <Frame FrameNumber="5" ReturnAddress="0xbf0a0" /> 
  </CallStack>
  </Exception>
it crashes on frame 5 when it shouldnt. what was supposed to help me stomp bugs IS a bug...
Am i doing something terribly wrong here?
Last edited by krogothe on 06 Jan 2006, 22:26, edited 1 time in total.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

nasty

I had similair results running in debug mode. An immediate exception in AI message if ran with exception handling turned on, and a full engine crash if i turn it off. No debugging information was gained whatsoever.
User avatar
krogothe
AI Developer
Posts: 1050
Joined: 14 Nov 2005, 17:07

Post by krogothe »

we are EXACTLY on the same boat, i get just what you said...
Post Reply

Return to “AI”