c++程序调试加入进出函数跟踪模块

在朗讯的几年总是习惯通过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();

.............

}

 

  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值