Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Mat1515

New Debugging idea

This topic is 5169 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I just thought of an idea. Im going to make a routine that is only called when i press i button when i press the button it will print the values at that time of mostly every variable in the program in an organized manner. Has anyone ever attempted this? any tips Thanks Where should i start learning about file writing?

Share this post


Link to post
Share on other sites
Advertisement
Uh, not especially useful. For one thing, you''d need to change the code every time you added a variable, or hook into the linker somehow to get all the variables. Also, you wouldn''t be able to dump local variables.

Running the program in a debugger is much, much more useful. You can break it whenever you want, and examine your program''s entire memory space easily.

Not enough people know how to use the debugger effectively. It''s one of the most important programming tools you have available to you; know it inside and out.


"Sneftel is correct, if rather vulgar." --Flarelocke

Share this post


Link to post
Share on other sites
quote:
Original post by Sneftel
Not enough people know how to use the debugger effectively. It''s one of the most important programming tools you have available to you; know it inside and out.
I am for one is one of those people. I am still learning, and it does prove its usefulness. However, I still have no clue how to debug a fullscreen application.

Share this post


Link to post
Share on other sites
alnite, if you''re using MSVC, try looking up "remote debugging" or "multiple-monitor debugging". The first involves using two computers to debug an application. The second involves multiple monitors on the same computer to do debugging.

Share this post


Link to post
Share on other sites
quote:
Original post by SiCrane
alnite, if you''re using MSVC, try looking up "remote debugging" or "multiple-monitor debugging". The first involves using two computers to debug an application. The second involves multiple monitors on the same computer to do debugging.


But what if you''re on single-monitor computer with no network access (except the internet)?

Oxyd

---
- Unreadable code is code written on a piece of paper, but not the one, in which the programmer is using a space in the place you don''t.
- Real programmers aren''t afraid of goto

Share this post


Link to post
Share on other sites
quote:
Original post by Oxyd
quote:
Original post by SiCrane
alnite, if you''re using MSVC, try looking up "remote debugging" or "multiple-monitor debugging". The first involves using two computers to debug an application. The second involves multiple monitors on the same computer to do debugging.


But what if you''re on single-monitor computer with no network access (except the internet)?

Oxyd

---
- Unreadable code is code written on a piece of paper, but not the one, in which the programmer is using a space in the place you don''t.
- Real programmers aren''t afraid of goto

Well, obviously, get online, email Grandma asking her to fire up her 486 and debug your app remotely, unless she''s got something better to do :|

Share this post


Link to post
Share on other sites
Using a keypress to trigger dumping variables is not a great idea - human response is mind-boggling slow compared to the speed at which your app runs. E.g. if your full-screen app is running at 100 fps, then it''s running through your entire game loop, and all the rendering code, 100 times every second. You''ll never hit the key at the moment you want to, and the variables are chaning like mad. At best, all you''ll get is a random, meaningless snapshot of your data. Never mind the headache of collecting all your data so you can display it in the first place - are you going to make all your variables global???

For debugging full-screen apps on a single-monitor, non-networked computer, you still have several much better options:

- implement a logger that creates a text file at the start of your program, and then you can sprinkle throughout your code stuff like this:

#ifdef _DEBUG
Logger("Entering function Move(x, y)\n");
Logger("x = %d, y = %d\n", x, y);
#endif

- another option is to "fake" full-screen: i.e. change the window size to something smaller (e.g. 320x200). Resize your IDE so it''s not full screen, but running in the bottom half of your screen. Compile/link/run (in debug mode by hitting F5). Your app should now be in a smaller window at the top-left of your monitor. Resize your IDE as big as you can make it without overlapping the screen saver window at all. Debug as normal. In your debugger, you have less room to watch variables, etc., but you should be able to manage. See the bottom of my article on screen savers for more info.

- if you''re using MFC, you can use the TRACE macro wherever you want to watch a variable, and it will output to the output window of your IDE, which you can look at after the program ends.


Share this post


Link to post
Share on other sites
1) If possible, it's useful to have a windowed version of your program, as well as fullscreen. That way, 90% of your debugging work can be on the windowed version.

2) Make another program that's 'always on top' of other windows, that catches messages from your fullscreen app, displays loading information, etc. Not nearly as good as a debugger, but nice for some things.

3) One thing I've found EXTREMELY useful is to have a separate logger for each object in your application. This way you can view each objects history in isolation from the rest(or have a way to parse the main log for each object). When you have 50 objects interacting, it can be frustrating to see the messages from 49 objects you don't care about.
For all my major game objects, I inherit from a CGameObject which can log itself.

player1->LOG( "teleporting to station %s", station->name );

Edit: Also, there are a few ways to not have to put
#ifdef _DEBUG
all throughout your code. I usually make my LOG function a macro, and define it as nothing for release. Also, I can silently pass __FUNCTION__ __LINE__ to my logger, however, MSVC++ (very unfortunately) doesn't allow multiple argument macro's so I can't pass that information. Anyway, in VC++ for release, my debug function is an empty inlined function (hopefully gets inlined away to nothing, but I really should test that..)

[edited by - Thrump on March 27, 2004 11:15:28 AM]

Share this post


Link to post
Share on other sites
I've used a simple system to display pretty much any variable I want overlaid on a full-screen game.

Basically it is just a pointer to your variable type, stored in an array with the variable name. So you can do this -


int myvar = 23;

VarList->AddInt(&myvar, "myvar");


Then you can get the value at any point later on to display it in a different part of your code using char * VarList->GetVarString("myvar"); which would return "int myvar: 23". Because it is a pointer to the original variable, it automatically has the latest value to show up-to-date information. It also won't slow down your code at all if you don't display it.

The VarList class I used has a structure that stores the variable name and in my case a union for different types. The name is stored so that I can display the name on screen as well to avoid confusion, plus it means I can add all my main variables and turn them on and off on the display via the console. Custom types can easily be added (vertex, polygon, even large structures like inventory). Local vars can be added by defining them as static.

If you already have the ability to display text on the screen, you can add a basic system like this in less than an hour.

This is only really useful for values that change relatively slowly once per frame, as BriTeg said, like character coordinates, health, etc. I found it perfect for debugging my collision detection code. It won't work from within a .dll though, or I never got it to anyway.

Dan

[edited by - danbrown on March 27, 2004 5:50:00 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!