Debugger

Sep 25, 2009 at 11:00am
Hi,
I want to make a debugger for my application.
which also print line number and and file name.
and also accept variable argument list.
We don't need to pass line number and file name at the time of call.
So i have have to make this debugger by #define ?
Exmp --
//MyCpp.c
...
...
...
MyTrace("Hi");
int DD = 10 ;
MyTrace("Hi=%d" , DD);
...
...
...
//End Of File
=========O/P=============
Line 4 File MyCpp.c - Hi
Line 6 File MyCpp.c - Hi=10



Please help me out.
Thanks in advance.
Sep 25, 2009 at 11:25am
See the following preprocessor directives:
__LINE__
__FILE__
__DATE__

I hope it will help you
Sep 25, 2009 at 11:51am
i tried this ...
But its not solving my purpose :(
main problem is how to take variable type argument in #define

#define MyTrace(s) MyFunc(__FILE__,__LINE__,s)
Sep 25, 2009 at 11:56am
1
2
3
4
5
6
7
8
9
10
11
12

#include <iotream>

#define LOG(a)\
std::cout << __LINE__ << '\t' << __FUNCTION__ << '\t' << a << '\n';\


void function(int a)
{
    LOG(a);
    ....//do something
}


But problem in my suggestion, you can pass only one argument
Sep 29, 2009 at 5:22am
Sorry Boss...
I need variable type argument list.
Please help me out.
Sep 29, 2009 at 7:28pm
Last edited on Sep 29, 2009 at 7:29pm
Oct 30, 2009 at 6:24am
Hi Guys,
Finally I found the solution.
anyways thanks for your help.
Andy :)

Solution is given blow -->

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
////////////////////////////////////////////////////////Logger.h//////////////////////////////////////////////////////
#define _ING_DEBUG_MODE_ 1

#ifdef _ING_DEBUG_MODE_
void vLogFileLine(char * pchFile, int inLineNumber);
void vLogMessage(char * pchFormat, ...);
#define LOG_ING(b)	{ vLogFileLine(__FILE__, __LINE__ ); vLogMessage b; }
#else
#define LOG_ING(b)
#endif




////////////////////////////////////////////////////////Logger.c//////////////////////////////////////////////////////
#ifdef _ING_DEBUG_MODE_
void vLogFileLine(char * pchFile, int inLineNumber)
{
	char FileData[100] = {"\0"} ;
	sprintf( FileData ,"File->%s Line->%d Data->" , pchFile , inLineNumber ) ;
	PrintStrGB2312(FileData,FmtHalfWidthHeight);//Print API
}
void vLogMessage(char * pchFormat, ...)
{
	short len = 0 , i = 0;
	char prnBuffer[1000] = { "\0" };
	va_list va;
	va_start(va, pchFormat);
	vsprintf(prnBuffer, pchFormat, va);
	va_end(va);
	len = 1 + (strlen(prnBuffer) / 49) ;
	while(len-- > 0)
		PrintStrGB2312(&prnBuffer[(i++)*48],FmtHalfWidthHeight);//Print API
}
#endif
////////////////////////////////////////////////////////main.c//////////////////////////////////////////////////////
void main()
{
     LOG(("anand rai")); 
     LOG(("length %d" , 1239));
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
Last edited on Oct 30, 2009 at 6:25am
Topic archived. No new replies allowed.