Click here to Skip to main content
Licence 
First Posted 23 Apr 2001
Views 104,395
Bookmarked 42 times

Extended Trace: Trace macros for Win32.

By | 23 Apr 2001 | Article
Trace macros that provide messages with source code link, run-time callstack information, and function prototype information with parameter values.

Sample Image - ExtendedTrace.gif

Overview

Extended Trace is a collection of a lot of useful traces for Win32, such as:

  • TRACE(...) implementation for Win32.
  • Messages with source code links. Just double click on the message in the Output Window, and jump to the source code.
  • Function parameters. Are you wonder what parameters your function was called with? Just call a simple macro, and will trace yor function prototype with the actual parameter values to the Output Window.
  • Call stack information. You can trace the call stack with function prototypes and parameters' values. Just like the Visual Studio Call Stack window, but this is in run-time.

Usage

Add the ExtendedTrace.cpp to your project, and include ExtendedTrace.h to your source file.

Macros

EXTENDEDTRACEINITIALIZE( IniSymbolPath )

Initialize the symbol information. IniSymbolPath is the search path for the symbol files. The built-in path is ".;%_NT_SYMBOL_PATH%;%_NT_ALTERNATE_SYMBOL_PATH%;%SYSTEMROOT%;%SYSTEMROOT%\System32;". IniSymbolPath will be added to the built-in path. IniSymbolPath can be NULL.

EXTENDEDTRACEUNINITIALIZE()

Frees up the symbol information.

SRCLINKTRACECUSTOM( Msg, File, Line)

Write a message(Msg) to the Output Window with a link to File(Line)

SRCLINKTRACE( Msg )

Write a message(Msg) to the Output Window with a link to its source code.

FNPARAMTRACE()

Write the function prototype with parameters to the Output Window. You can call this function anytime in a function.

STACKTRACEMSG( Msg ), STACKTRACE(), THREADSTACKTRACEMSG( hThread, Msg ), THREADSTACKTRACE( hThread )

Dumps the call stack with function prototypes and the parameters' values to the Output Window. The call stack elements dumped with source code links, so you can jump directly to them.

TRACEF(...)

Same as the MFC TRACE(...)

 

Note: If you're using only TRACEF(...) or SRCLINKTRACExxx(...) macros, you don't need EXTENDEDTRACEINITIALIZE(...)/EXTENDEDTRACEUNINITIALIZE.

Example

#include "ExtendedTrace.h"

void g ( LPTSTR )
{
	// Dumps the actual call stack
	STACKTRACE();
}

void f( int, int, int )
{
	// What parameters was this function called with?
	FNPARAMTRACE();
	g( NULL );
}

int main( int, char** )
{
	// Just like the TRACE(...) in MFC
	TRACEF( _T("Application started at %d\n"), clock() );

	// Initializes the symbol files
	EXTENDEDTRACEINITIALIZE( NULL );

	// Trace message with a link to this line in the source code
	SRCLINKTRACE( _T("I'm calling f(...)\n") );

	f( 1, 2, 3);

	// Cleaning up
	EXTENDEDTRACEUNINITIALIZE();

	TRACEF( _T("Application ended at %d\n"), clock() );

	return 0;
}

The output in the Output Window:

Application started at 578
Loaded 'D:\WINNT\system32\dbghelp.dll', no matching symbolic information found.
c:\temp\magictrace\main.cpp(28) : I'm calling f(...)
Function info(thread=0x36C) : void f(int=0x00000001,int=0x00000002,int=0x00000003)
Call stack info(thread=0x36C) : 
     c:\temp\magictrace\main.cpp(12) : void g(char *=0x00000000)
     c:\temp\magictrace\main.cpp(19) : void f(int=0x00000001,int=0x00000002,int=0x00000003)
     c:\temp\magictrace\main.cpp(30) : main(int=0x00000001,TCHAR * *=0x00522C88)
     crtexe.c(338) : mainCRTStartup()
     KERNEL32!0x77E87903 : SetUnhandledExceptionFilter
Application ended at 1171
The thread 0x36C has exited with code 0 (0x0).

Enjoy!

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

Zoltan Csizmadia

Web Developer

United States United States

Member



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
GeneralMissing argument in some error messages PinmemberMenuki2:21 6 Mar '09  
GeneralcallStack.AddrFrame.Offset != 0 Pinmemberxrinlar10:24 13 May '07  
GeneralSometimes, it doesn't work. PinmembermAtrIxdjg21:33 8 Nov '06  
GeneralWorks for me PinmemberTor2k6:11 22 Feb '06  
Generalincorrect symbols PinsussAnonymous7:33 25 Sep '02  
GeneralCan't Get it to work PinmemberAnonymous5:05 5 Apr '02  
GeneralRe: Can't Get it to work PinsussAnonymous3:45 1 Aug '02  
Generalvc7 PinmemberAnonumus9:24 23 Mar '02  
GeneralRe: vc7 PinmemberAnthony_Yio21:01 22 Sep '04  
GeneralRe: vc7 PinmemberScott Langham8:24 17 Dec '04  
GeneralRe: vc7 PinmemberSanDiegoPhil11:36 30 Aug '06  
GeneralSTACKTRACEMSG PinmemberBobby G. Vinyard20:58 8 Mar '02  
GeneralGreat Work PinmemberAnonymous-554873528542318742310:43 28 Dec '01  
GeneralRe: Great Work PinmemberAnonymous2341111111122:16 2 Jan '02  
GeneralWorks only on NT/2000 PinmemberAnonymous5:58 25 Apr '01  
GeneralTRACE, but no more than 512 characters PinmemberAnonymous19:35 24 Apr '01  
GeneralRe: TRACE, but no more than 512 characters Pinmemberlauren20:19 24 Apr '01  
that 512 limit really pisses me off too ... i got to the point of changing the mfc code and recompiling but then wondered if it would break something somewhere deep in the bowels of mfc ... is it as simple as letting the string (they dont use a cstring even) be declared as whatever[1024] and recompiling?
 
---
"every year we invent better idiot proof systems and every year they invent better idiots"
GeneralRe: TRACE, but no more than 512 characters PinmemberMehmet Ozgul6:29 25 Apr '01  
GeneralRe: TRACE, but no more than 512 characters PinmemberZoltan Csizmadia6:58 25 Apr '01  
GeneralRe: TRACE, but no more than 512 characters PinmemberRick York18:05 25 Apr '01  
GeneralRe: TRACE, but no more than 512 characters PinmemberT1000_RUS0:56 31 Jul '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
Web03 | 2.5.120604.1 | Last Updated 24 Apr 2001
Article Copyright 2001 by Zoltan Csizmadia
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid