c++程序调试加入进出函数跟踪模块
2011-08-16 18:35
423 查看
在朗讯的几年总是习惯通过log找程序问题;写了这个小小的跟踪模块。
还是非常ugly的,以后加入log level.
头文件:traceService.h
/*copyright drbinzhao@hotmail.com edit in 2010 */
#ifndef TRACESERVICE_H
#define TRACESERVICE_H
#include <stdio.h>
#ifdef TRACESERVICE
#define TRACE_SERVICE_ENTRY_EXIT() \
const TraceService TraceService(__LINE__,__func__,__FILE__)
#else
#define TRACE_SERVICE_ENTRY_EXIT()
#endif
class TraceService
{
public:
TraceService( const unsigned int Line, const char * Function_Name, const char * File_name);
~TraceService();
protected:
private:
const char * _m_function_name;
unsigned int _m_line;
const char * _m_file_name;
};
char *GetFileName(const char *path);
#endif // TRACESERVICE_H
traceService.cpp
/*copyright drbinzhao@hotmail.com edit in 2010*/
#include "traceservice.h"
#include <string.h>
TraceService::TraceService(const unsigned int Line, const char * Function_Name,const char * File_name)
{
_m_line=Line;
_m_file_name = GetFileName(File_name);
_m_function_name= Function_Name;
printf("Enter function %-20s (%s, %d)\n",_m_function_name,_m_file_name,_m_line);
}
TraceService::~TraceService()
{
printf("Exit function %-20s (%s, %d)\n",_m_function_name,_m_file_name,_m_line);
}
char *GetFileName(const char *path)
{
char *p;
p=strrchr(path, '/');
if (p)
return p+1;
else
return NULL;
}
用法:
xxx.cpp
#include "traceService.h"
func1()
{
TRACE_SERVICE_ENTRY_EXIT();
..........
}
func2()
{
TRACE_SERVICE_ENTRY_EXIT();
.............
}
还是非常ugly的,以后加入log level.
头文件:traceService.h
/*copyright drbinzhao@hotmail.com edit in 2010 */
#ifndef TRACESERVICE_H
#define TRACESERVICE_H
#include <stdio.h>
#ifdef TRACESERVICE
#define TRACE_SERVICE_ENTRY_EXIT() \
const TraceService TraceService(__LINE__,__func__,__FILE__)
#else
#define TRACE_SERVICE_ENTRY_EXIT()
#endif
class TraceService
{
public:
TraceService( const unsigned int Line, const char * Function_Name, const char * File_name);
~TraceService();
protected:
private:
const char * _m_function_name;
unsigned int _m_line;
const char * _m_file_name;
};
char *GetFileName(const char *path);
#endif // TRACESERVICE_H
traceService.cpp
/*copyright drbinzhao@hotmail.com edit in 2010*/
#include "traceservice.h"
#include <string.h>
TraceService::TraceService(const unsigned int Line, const char * Function_Name,const char * File_name)
{
_m_line=Line;
_m_file_name = GetFileName(File_name);
_m_function_name= Function_Name;
printf("Enter function %-20s (%s, %d)\n",_m_function_name,_m_file_name,_m_line);
}
TraceService::~TraceService()
{
printf("Exit function %-20s (%s, %d)\n",_m_function_name,_m_file_name,_m_line);
}
char *GetFileName(const char *path)
{
char *p;
p=strrchr(path, '/');
if (p)
return p+1;
else
return NULL;
}
用法:
xxx.cpp
#include "traceService.h"
func1()
{
TRACE_SERVICE_ENTRY_EXIT();
..........
}
func2()
{
TRACE_SERVICE_ENTRY_EXIT();
.............
}
相关文章推荐
- 几个关于C/C++程序调试的函数
- C,C++用过的调试方式/函数/小程序
- C,C++用过的调试方式/函数/小程序
- 调试使用了函数模块的程序时需要注意的一个小问题
- 介绍几个关于C/C++程序调试的函数
- 调试使用了函数模块的程序时需要注意的一个小问题
- 介绍几个关于C/C++程序调试的函数
- 介绍几个关于C/C++程序调试的函数
- C/C++程序调试的函数
- Python进阶(一)——安装Python、程序执行、Python模块和IDLE调试
- C++程序编译的时候报错prototype for '类名::函数名'does not match any in class'类名'解决经验。
- c语言写的程序里,调用C++写的库里的函数
- GDB 调试 C++ 程序 core dump
- 在C++ 程序中调用被 C 编译器编译后的函数,为什么要加 extern
- 自己编写小程序开发调试函数
- Python进阶(一)——安装Python、程序执行、Python模块和IDLE调试
- MEX文件调试—MATLAB调用C++程序—混合编程
- Linux C++ 跟踪程序奔溃及函数调用关系
- Linux下如何用GDB调试c++程序
- 使用xml-rpc调试openerp模块中的函数