Click here to Skip to main content
Licence 
First Posted 21 Feb 2005
Views 26,091
Bookmarked 8 times

Hardwired's Debug Class

By | 21 Feb 2005 | Article
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 problems in small applications, but if the things get really complex... then you might consider to use 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:

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

class MyClass
{
    CDebugTrace    Trace;

public:
    MyClass();
    ~MyClass();

    void    SomeMethod(void);

    ...
};
//
// 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:

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

  • 21 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

About the Author

Inocentric

Web Developer

Romania Romania

Member



Organisation (No members)

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.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralOutputDebugString problem Pinmemberresistantgnome1:03 12 Feb '08  
GeneralRelease Mode PinmemberJohn M. Drescher5:13 22 Feb '05  
GeneralRe: Release Mode PinmemberHardwired5:23 22 Feb '05  
GeneralFile not found PinmemberAlexander M.9:22 21 Feb '05  
GeneralRe: File not found PinmemberHardwired2:10 22 Feb '05  
GeneralRe: File not found PinmemberInnowaze19:28 3 Dec '07  

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

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

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 21 Feb 2005
Article Copyright 2005 by Inocentric
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid