.:: Bots United ::.

.:: Bots United ::. (http://forums.bots-united.com/index.php)
-   General Programming (http://forums.bots-united.com/forumdisplay.php?f=25)
-   -   very simple debugging question (MSVC) (http://forums.bots-united.com/showthread.php?t=506)

Pierre-Marie Baty 26-01-2004 04:53

very simple debugging question (MSVC)
 
Okay I know this will soud very dumb to most of you, but I need to know how to break into the debugger when a particuliar variable in the program reaches a certain value.

Let's say I have a boolean flag in my bot structure. I want the DLL to break into the debugger as soon as the bot code decides to set it to TRUE.

I know this is possible, however I'm clueless how.

You have permission to make fun of me.

Lazy 26-01-2004 05:14

Re: very simple debugging question (MSVC)
 
Ok - I just did a small test...

Go into your debug menu and add a new breakpoint.
Go to the data tab.
Add in the variable name. ex ( mystruct.member )
Leave the context blank ( or try adding in a function? )
Click condition
Make sure "has changed" is selected.

When you start in debug mode it should go into the debugger as soon as it has changed. I'm sure there are more options around there to play with.

Hope that helps.

botmeister 26-01-2004 06:22

Re: very simple debugging question (MSVC)
 
Sometimes a debugger is usefull to those who know how and when to use one, and I'm sure that's what PMB is doing in this case.

My advice to anyone who uses a debugger more than once a month is to toss it into the trash can and learn how to program without one. A debugger is like training wheels on a bicycle, and unless you take them off you'll never learn how to ride a bike on only two wheels. A bike without training wheels is way more fun and goes a lot faster. :)

Lazy 26-01-2004 06:25

Re: very simple debugging question (MSVC)
 
Ok, but what if you have all of your null pointer checks, ect in place but it mysteriously crashes every now and then?

I can see your point but it's hard to not see myself using it.
Or, maybe its time I read my debugging c++ book. It might talk about what you've been saying...

Pierre-Marie Baty 26-01-2004 07:05

Re: very simple debugging question (MSVC)
 
thank you ! :)

botmeister 26-01-2004 08:02

Re: very simple debugging question (MSVC)
 
Quote:

Originally Posted by Lazy
Ok, but what if you have all of your null pointer checks, ect in place but it mysteriously crashes every now and then?

That's when you dust off the old debugger you have not needed for at least a month and find out what has gone wrong.

Quote:

I can see your point but it's hard to not see myself using it.
Or, maybe its time I read my debugging c++ book. It might talk about what you've been saying...
A debugger can be a handy tool to have available when needed, I'm not totally mad ... at least I don't think I am :)

Debuggers are such a handy crutch it can be difficult to imagine life without one. If you can go without a debugger for long enough, you will eventually reach the opposite point of view where you can't imagine using a debugger frequently, except in certain types of difficult situations.

It has been my observation that people who make frequent use of a debugger tend to have a frequent occurance of bugs and produce difficult to understand code. The debugger provides the quick fix to these problems, which sustains a level of programming methods that would otherwise be intolerable. If a debugger were no longer available, some of these programming methods would become intolerable, and adjustments would have to be made to compensate, leading to better quality code.

Pierre-Marie Baty 26-01-2004 08:11

Re: very simple debugging question (MSVC)
 
w00t w00t I found my bug !!! :D :D :D

the bots' stuck flag was never set because I was resetting their input buttons BEFORE the sensing part of the AI and not AFTER it (and the stuck check evaluates the past frame's input buttons state...)

thank you debugger! :P

koraX 26-01-2004 08:42

Re: very simple debugging question (MSVC)
 
how can you debug a bot in MSVC ? I'll set Debug build and then what ? What should I specify as executable and how shoud I set up HL for debugging ? thnx

Pierre-Marie Baty 26-01-2004 10:36

Re: very simple debugging question (MSVC)
 
like this

right click on project, choose "settings" and then set up the parameters to something similar to this

http://racc.bots-united.com/msvc-debug-1.png http://racc.bots-united.com/msvc-debug-2.png
http://racc.bots-united.com/msvc-debug-3.png http://racc.bots-united.com/msvc-debug-4.png

Then just put breakpoints and stuff wherever you want, and in order to run HLDS inside a debugger, just hit F5 (or click on the "Go" button in MSVC)
:)

botman 26-01-2004 14:51

Re: very simple debugging question (MSVC)
 
"If you can go without a debugger for long enough, you will eventually reach the opposite point of view where you can't imagine using a debugger frequently, except in certain types of difficult situations."

A debugger is invaluable for verifying that your code is functioning properly. When you are dealing with simple applications ("Hello, world", etc.) a debugger is hardly necessary. When you are dealing with complex data structures (think something like a BSP tree) or complex algorithms (especially things like compression, encryption, or complex pattern matching), debuggers become an invaluable tool that allows you to examine things in individual steps.

It's way to easy to create fencepost errors with loops (having one to few or one too many loops through a block of code) and it's easy to have array index out of range problems when bad pointers will overwrite the wrong stuff in memory (not always causing an access violation which are easy to catch).

A debugger is just a tool. Like a compiler, or an editor is just a tool. You can do without any of these, but it makes life a whole lot harder. If you are constantly using MSVC's Edit-and-Continue feature to fix your code, then you are probably a sloppy programmer. If you use the debugger to verify that your loops are all correct, your pointers are always valid and your code is doing exactly what you designed it to do, then you are simply using a tool to make your code more stable and correct.

botman

koraX 26-01-2004 20:29

Re: very simple debugging question (MSVC)
 
is it possible to debug bot on non-dedicated server ?

Lazy 26-01-2004 20:51

Re: very simple debugging question (MSVC)
 
Yes, it works the same way except you can step through your code without timing out.
With steam its a little different though and I can't remember how exactly to do it.

Pierre-Marie Baty 26-01-2004 21:06

Re: very simple debugging question (MSVC)
 
There is, however, an internal check inside the Counter-Strike client.dll that will make the game simply exit if a debugger is detected in the system. Using the normal Counter-Strike client.dll it is NOT possible to debug your bot inside a listenserver.

What you can do however, is debug a DEDICATED server, then connect to it using the loopback connection :

hl.exe -dev -console +connect 127.0.0.1:27015

this command line will make HL connect to the HLDS server that is running on your OWN machine (this way you will be able to debug your bot while you are playing the game).

koraX 04-09-2004 09:25

Re: very simple debugging question (MSVC)
 
Sorry to revive old thread, but I've found way how to debug without hlds

Quote:

Originally Posted by Pierre-Marie Baty
There is, however, an internal check inside the Counter-Strike client.dll that will make the game simply exit if a debugger is detected in the system. Using the normal Counter-Strike client.dll it is NOT possible to debug your bot inside a listenserver.

So client.dll is causing trouble ? Well ... I deleted it :D . And guess what. Counter-strike ran in debugger, only difference was that I could not join as player, I could only spectate (this is obvious, there is no client dll hehehe). I have CS 1.5. (I set debugger to call c:\sierra\half-life\hl.exe -dev -debug -console -game cstrike +deathmatch 1 +map de_aztec +maxplayers 15 -sw +sv_lan 1)

*edit* well I haven't spawned a bot yet, I wonder if they could spawn if ther is no client.dll, damn.

*edit2* Oh well, they spawn but they don't join :) Damn this client.dll. At least I can debug something.

BTW is cs client 1.6 with steam terminating if it detect debugger too ? Do you have to debug hlds.exe or you can debug hl.exe ?

Whistler 04-09-2004 11:00

Re: very simple debugging question (MSVC)
 
I think Count Floyd has a patched version of CS 1.3 which has that debugger check removed. You can find a version of CS 1.3 and take a look at the RACC install program source code for the patch. PMB has included it.

Also Cs 1.6 doesn't have debugger check code.

koraX 04-09-2004 13:06

Re: very simple debugging question (MSVC)
 
I've found it
Code:

        FILE *fp,*fp2;

      fp = fopen ("client.dll", "rb+"); // opens CLIENT.DLL file readonly
      if (fp != NULL)
      {
        fp2 = fopen ("client.bak", "wb"); // opens backup file for writing
        if (fp2 != NULL)
        {
            int c, count = 0;

            // get the size of the CLIENT.DLL file
            while ((c = fgetc (fp)) != EOF)
              count++;

            //  if it differs from the CS 1.3 original DLL size
/*            if (count != 655360)
            {
              printf ("CLIENT.DLL is not the genuine Counter-Strike 1.3 DLL. Patch cancelled.\n");
              return -1; // don't allow it to be patched
            }
*/
            rewind (fp); // return back to beginning of file
            while ((c = fgetc (fp)) != EOF)
              fputc (c, fp2); // duplicate client.dll to client.bak

            fclose (fp2); // close backup file

            fseek (fp, 191620L, SEEK_SET); // seek at the start of patch offset
            fputc (0x2B, fp); // actually patch client.dll (at offset 191620)
            fclose (fp); // close patched file

            printf ("Counter-Strike's CLIENT.DLL has been successfully patched.\n");
        }
      }
      else
        printf ("CLIENT.DLL not found in ../cstrike/cl_dlls. Patch cancelled.\n");

      return 0; // end of processing

but it does not work in CS 1.5. It crashes. Of course size of client.dll is different than 1.3. If only somebody would know the position of 'patch offset' in cs 1.5 ...

botman 04-09-2004 14:14

Re: very simple debugging question (MSVC)
 
Well, that's an easy problem to solve.

Download CS 1.3, rename it from .dll to .xxx and open it in the MS-DOS debugger. Look at the instruction at address 191620 (0x2EC84 in hex). You can just write down the 5 or 6 bytes at and after that location.

Then copy the CS 1.5 client.dll to "client.xxx" and load it in the MS-DOS debugger. Do a search for those same 5 (or 6) bytes. Do a disassembly at the address(es) displayed and see if they match up with the ones from CS 1.3.

When you find a match, modify the above source code to use the proper offset instead of 191620L.

P.S. If you don't know how to use the MS-DOS debugger, try searching on google.com for "ms-dos debug" or something similar.

botman

Whistler 05-09-2004 06:34

Re: very simple debugging question (MSVC)
 
Quote:

Originally Posted by botman
Well, that's an easy problem to solve.

Download CS 1.3, rename it from .dll to .xxx and open it in the MS-DOS debugger. Look at the instruction at address 191620 (0x2EC84 in hex). You can just write down the 5 or 6 bytes at and after that location.

Then copy the CS 1.5 client.dll to "client.xxx" and load it in the MS-DOS debugger. Do a search for those same 5 (or 6) bytes. Do a disassembly at the address(es) displayed and see if they match up with the ones from CS 1.3.

When you find a match, modify the above source code to use the proper offset instead of 191620L.

P.S. If you don't know how to use the MS-DOS debugger, try searching on google.com for "ms-dos debug" or something similar.

botman

That won't work. If you open the CS 1.5 or 1.6 client.dll you'll find it isn't DLL at all. Valve just encrypted it.

However CS 1.3 client dll does work with CS 1.5 mp.dll (although there are some weird problems with spectating).


All times are GMT +2. The time now is 15:24.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.