Click here to Skip to main content
15,891,316 members
Articles / Programming Languages / C++

Hardwired's Debug Class

Rate me:
Please Sign up or sign in to vote.
1.00/5 (11 votes)
21 Feb 20051 min read 34.8K   8   6
Debugging tool class for both single and multithreaded applications

Introduction

I created this class because I need it to trace some objects in a multithreaded application. Got a lot of problems because of objects used before actual creation and objects referenced after destruction. Of course, you will not have encountered this kind of problem in small applications, but if things get really complex... then you might consider using this from the start.

Using the Code

Using this code is a simple task and you don't have to think about it later. Just set it and forget it. In /RELEASE mode, you will not have any problem, because the CDebugTrace objects will be empty.

First, add debugtrace.h and debugtrace.cpp to your project. After this, add an CDebugTrace object to classes that are important for your project (I advise you to use it for all your classes). Below is a sample usage of this class:

C++
//
// MyClass.h
//
#include "debugtrace.h"

class MyClass
{
    CDebugTrace    Trace;

public:
    MyClass();
    ~MyClass();

    void    SomeMethod(void);

    ...
};
C++
//
// MyClass.cpp
//
#include "myclass.h"

MyClass::MyClass()
:    Trace( "MyClass" )
{
    ...
}

MyClass::~MyClass()
{
    ...
}

void MyClass::SomeMethod()
{
    Trace.Print("entered SomeMethod" );

    ...
}

If you use it like this, you will know when that object was created or destroyed and the life of it.

You can also use CDebugTrace with functions, like this:

C++
void    SomeFunction( void )
{
    CDebugTrace    Trace( "SomeFunction" );

    ...
}

This way, you know when that function executes and how much it took to run.

Points of Interest

This class helps me a lot and a lot of other things can be added. For example, CPU and memory stats would probably help too.

History

  • 21st February, 2005: Version 1.0

Well, I have to begin somewhere. This is my first article.

License

This article has no explicit license attached to it, but may contain usage terms in the article text or the download files themselves. If in doubt, please contact the author via the discussion board below.

A list of licenses authors might use can be found here.


Written By
Web Developer
Romania Romania
Programming C\C++ since 1995. Live to code another day!Smile | :) . Basicly I code anything in C/C++ with API, Platform SDK, Windows DDK, ODBC, OpenGL SDK, DirectX SDK, etc.

For the last six years(starting with 1999) I worked as freelancer.
In 2003 I have co-founded ICode&Ideas SRL, Romania, focusing on security software solutions (Project Manager and Lead Developer of Prisma Firewall).
Starting with 2005 I am the founder and president of Inocentric SRL, Romania.
This is a Organisation (No members)


Comments and Discussions

 
GeneralOutputDebugString problem Pin
resistantgnome12-Feb-08 1:03
resistantgnome12-Feb-08 1:03 
GeneralRelease Mode Pin
John M. Drescher22-Feb-05 5:13
John M. Drescher22-Feb-05 5:13 
GeneralRe: Release Mode Pin
Inocentric22-Feb-05 5:23
Inocentric22-Feb-05 5:23 
Hello,

Ok. If you want to be able to see and log messages all you have to do is to delete the following lines(all of them!) from debugtrace.h and debugtrace.cpp:

#indef _DEBUG
#endif

#ifndef _DEBUG_TOFILE
#endif

Actualy, just delete all #indef and #endif lines from the file.

Sorry, but this was intended to be used only for /DEBUG mode. I will probably update soon a release version too.


Thank you,
Andrei CIUBOTARU [Hardwired]

Lead Developer
ICodeIdeas Romania
hardwired@icode.ro

GeneralFile not found Pin
Alexander M.,21-Feb-05 9:22
Alexander M.,21-Feb-05 9:22 
GeneralRe: File not found Pin
Inocentric22-Feb-05 2:10
Inocentric22-Feb-05 2:10 
GeneralRe: File not found Pin
revram3-Dec-07 19:28
revram3-Dec-07 19:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.