Importance of debug.txt

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
cypher1554R
Chaos Rift Demigod
Chaos Rift Demigod
Posts: 1124
Joined: Sun Jun 22, 2008 5:06 pm

Importance of debug.txt

Post by cypher1554R »

I just want to say that sometimes.. or most of the time, I is dumb as hell.
I spent last 4 days figuring what the heck is wrong with my editor all the sudden working like FDR's legs ( :shock: too soon?).
Well anyway.. Today it just came to my upper part of the body (which looks like a head, except there's not much in it) that I should check my debug.txt file, which I worked so hard on to get every detail in most descriptive way out. In just a few seconds I found the bug. It was a messed up -assign- operator that I wrote for Vec3 class.

There. If you don't use this or some other kind of method, you should start right now. Cause after 5000 lines, you is going to be blind as a bat. And I'm not talking about that creepy animal. I'm talking about the fat stick that is used in baseball game.
User avatar
trufun202
Game Developer
Game Developer
Posts: 1105
Joined: Sun Sep 21, 2008 12:27 am
Location: Dallas, TX
Contact:

Re: Importance of debug.txt

Post by trufun202 »

Speaking of debugging with txt files...

A friend and I were having a friendly argument about one of our apps at work. I was trying to prove him wrong, and if a particular error occured, I logged the error and created a file called "KentSucks.txt"

Well..months had gone by and we forgot about this little "feature"... So, we're in the client's office setting up the application. After hours of pounding our heads against the wall, trying to figure out why it's not working - someone on the client side said, "Hey, what's this KentSucks.txt file do!?"

Problem solved! :mrgreen:
-Chris

YouTube | Twitter | Rad Raygun

“REAL ARTISTS SHIP” - Steve Jobs
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: Importance of debug.txt

Post by dandymcgee »

I always use some sort of debug when I can't get something to work. If I want it there permanently I use a text file, otherwise I use console output or main()'s return value.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
User avatar
Arce
Jealous Self-Righteous Prick
Jealous Self-Righteous Prick
Posts: 2153
Joined: Mon Jul 10, 2006 9:29 pm

Re: Importance of debug.txt

Post by Arce »

I enable debugging via environmental variable. That way I simply change a value before distributing to the team. (my dubug stuff is quite messy, though it's intended for my eyes only. ;P)
<qpHalcy0n> decided to paint the office, now i'm high and my hands hurt
User avatar
aamesxdavid
ES Beta Backer
ES Beta Backer
Posts: 347
Joined: Wed Jan 07, 2009 8:49 pm
Location: Bellevue, WA
Contact:

Re: Importance of debug.txt

Post by aamesxdavid »

So I was about to post a new thread in regards to the mention of it in the Adventures videos, but I figured I'd revive an older thread instead.

Falco mentions that the text file they use logs every file the game is trying to access, etc. I was wondering how exactly that was done, and if a similar thing is possible in Python, which is what I'm currently working with. I can write to text files, but the only thing I know of dealing with an error is the "try" and "except" functions in Python. Assuming that every file load doesn't have a "try" (or the C++ equivalent) and individually write to the text file, how is this file written? I don't mind if you only have the C++ answer, as it's more of the programming theory that I'm looking for I suppose. Thanks!
User avatar
ismetteren
Chaos Rift Junior
Chaos Rift Junior
Posts: 276
Joined: Mon Jul 21, 2008 4:13 pm

Re: Importance of debug.txt

Post by ismetteren »

I dont know how falco handles it, and i dont know how phyton handles files. In C++ a file is represented by a stream (fstream, ifstream of ofstream).

You can create a ifstream(inputStream) object, and then open a file with it(i guees you actully just tells i were to read data from, but i am not sure)

Code: Select all

ifstream stream;
stream.open(file.txt);
now you can do something like:

Code: Select all

//i am not sure if this is correct, but it works atleast very simmilar to this
string txt;
getline(stream, txt);
To write out witch file the code is accessing, you could have made another file stream before this code, and output the file(as a string(the pathname)) that was being opened(file.txt) to it. If you wanted to know if it was successful i guess you could check if stream hat an valid file open, and output if it (not)hat.

I am not sure if that was what you meant. And sorry for my bad english
Image ImageImage Image
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: Importance of debug.txt

Post by MarauderIIC »

aamesxdavid wrote:So I was about to post a new thread in regards to the mention of it in the Adventures videos, but I figured I'd revive an older thread instead.

Falco mentions that the text file they use logs every file the game is trying to access, etc. I was wondering how exactly that was done, and if a similar thing is possible in Python, which is what I'm currently working with. I can write to text files, but the only thing I know of dealing with an error is the "try" and "except" functions in Python. Assuming that every file load doesn't have a "try" (or the C++ equivalent) and individually write to the text file, how is this file written? I don't mind if you only have the C++ answer, as it's more of the programming theory that I'm looking for I suppose. Thanks!
I get what you're saying. We have a Debug class (I think it's a singleton) with a function that works like fprintf() does. Debug is initialized like so:

Code: Select all

void Debug::Initialize() {
    debugFile,open("debug.txt", ios::out); //Clear the existing file or create a new one
    debugFile.close(); //Don't leave it open (we might not actually do this, see end of post)
}
We also have a function that works like printf does in Debug, so then, for instance, our Level::Load is something like

Code: Select all

Debug& debug = Debug::GetInstance();
levelFile.open(filename...);
if (!levelFile) { //there was some sort of error while opening the file
    debug.write("Error loading %s\n", filename);
    return ERROR; //where error is just some constant or error code or something
}
...
if (!(something = new Something)) {
    debug.write("Out of memory!\n");
    return ERROR;
}
Our write() fn would open debugFile for append (ios::app) and then close it after writing to it. This is terribly slow. It would be faster to open the file once and then close it when the program terminates. Which we might actually do, I'm not totally sure anymore :)

We just write to it when something doesn't go our way, in other words, and the Debug class handles the file I/O. We don't do anything with exceptions, which is what try { } except { } says to me, but you would basically do the same thing but in your except block instead of with ifs.

Hopefully I answered your question. If you want to see how to do an ellipsis function (replace like %s with an argument, no definite number of arguments passed to the function), I can help you with that. Also, sorry for the ambiguity, I'm too lazy to open the source :D
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
aamesxdavid
ES Beta Backer
ES Beta Backer
Posts: 347
Joined: Wed Jan 07, 2009 8:49 pm
Location: Bellevue, WA
Contact:

Re: Importance of debug.txt

Post by aamesxdavid »

Wow, that's awesome, thanks guys! I'll be doing some Python tests with this tonight. This is the kind of stuff I need to work on, because I get the syntax and general flow of things, but I wouldn't have thought to make a class to handle it. Well, I'm a step in the right direction now. :)
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: Importance of debug.txt

Post by MarauderIIC »

aamesxdavid wrote:So I was about to post a new thread in regards to the mention of it in the Adventures videos, but I figured I'd revive an older thread instead.
Thanks!
aamesxdavid wrote:Wow, that's awesome, thanks guys!
You're welcome =)
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
eatcomics
ES Beta Backer
ES Beta Backer
Posts: 2528
Joined: Sat Mar 08, 2008 7:52 pm
Location: Illinois

Re: Importance of debug.txt

Post by eatcomics »

MarauderIIC wrote:
Gyrovorbis wrote:eatcomics could single handedly destroy the universe
What's that all about... I don't want to destroy it I want to rule it :mrgreen:
But seriously where did that come from???
Image
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: Importance of debug.txt

Post by MarauderIIC »

eatcomics wrote:
MarauderIIC wrote:
Gyrovorbis wrote:eatcomics could single handedly destroy the universe
What's that all about... I don't want to destroy it I want to rule it :mrgreen:
But seriously where did that come from???
Staff forum. Old post talking about horrible typing =)
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Re: Importance of debug.txt

Post by Falco Girgis »

Yeah, Marauder broke it down pretty much exactly as it is.

And currently (until we're ready for release) the debug output is also wrapped back to the Adventure Log (in game text box) so that we can see our debug output during run time without having to exit out. (That's why there's lots of random numbers outputting sometimes during AiGD videos. Debug is also wrapped to Lua, and that's Peter's cout/printf() equivalent).

And welcome! (though I've seen/talked to you already!)
User avatar
eatcomics
ES Beta Backer
ES Beta Backer
Posts: 2528
Joined: Sat Mar 08, 2008 7:52 pm
Location: Illinois

Re: Importance of debug.txt

Post by eatcomics »

MarauderIIC wrote:
eatcomics wrote:
MarauderIIC wrote:
Gyrovorbis wrote:eatcomics could single handedly destroy the universe
What's that all about... I don't want to destroy it I want to rule it :mrgreen:
But seriously where did that come from???
Staff forum. Old post talking about horrible typing =)
Ahhhh....
Gyrovorbis in those days I could have taken over hell if I wanted to :mrgreen: :lol:
Image
Post Reply