From: Francesco Chemolli Date: Tue, 3 Mar 2009 13:33:51 +0000 (+0100) Subject: Rolled a basename-alike method to beautify HERE calls for debugs(). X-Git-Tag: SQUID_3_2_0_1~1138^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5b6f3fe5ea085f8c6f93dbfad65532d19e2b18d9;p=thirdparty%2Fsquid.git Rolled a basename-alike method to beautify HERE calls for debugs(). --- diff --git a/src/Debug.h b/src/Debug.h index f9cec79b0b..a668c9023e 100644 --- a/src/Debug.h +++ b/src/Debug.h @@ -34,12 +34,6 @@ #ifndef SQUID_DEBUG_H #define SQUID_DEBUG_H -/* NP: done without pre-requisite config.h */ -/* because we only define with it here. */ -#if HAVE_LIBGEN_H -#include -#endif - #include #undef assert #include @@ -86,6 +80,8 @@ private: extern FILE *debug_log; +SQUIDCEXTERN const char* SkipBuildPrefix(const char* path); + /* Debug stream */ #define debugs(SECTION, LEVEL, CONTENT) \ do { \ @@ -100,7 +96,7 @@ extern FILE *debug_log; * * debugs(1,2, HERE << "some message"); */ -#define HERE basename(__FILE__)<<"("<<__LINE__<<") "<<__FUNCTION__<<": " +#define HERE SkipBuildPrefix(__FILE__)<<"("<<__LINE__<<") "<<__FUNCTION__<<": " /* * MYNAME is for use at debug levels 0 and 1 where HERE is too messy. diff --git a/src/debug.cc b/src/debug.cc index 466e4820d5..ea02e8d4e7 100644 --- a/src/debug.cc +++ b/src/debug.cc @@ -31,6 +31,12 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. * */ + +/* Anyone moving the src/Debug.cc file MUST record its new location here, + * or there will be issues in the debugging statements, possibly fatal! + */ +#define RELATIVE_PATH_TO_DEBUG_CC "src/debug.cc" + #include "config.h" #include "Debug.h" #include "SquidTime.h" @@ -746,3 +752,18 @@ Debug::xassert(const char *msg, const char *file, int line) { } std::ostringstream (*Debug::CurrentDebug)(NULL); + +static const size_t BuildPrefixInit() +{ + //leave immediately if misconfigured. Unfortunately not possible to detect at build + const char *file=__FILE__; + const char *rptdcc=RELATIVE_PATH_TO_DEBUG_CC; + assert(strstr(file,rptdcc)!=NULL); + return strlen(file)-strlen(rptdcc); +} +static const size_t BuildPrefixLength=BuildPrefixInit(); +const char* SkipBuildPrefix(const char* path) +{ + return path+BuildPrefixLength; +} + diff --git a/test-suite/test_tools.cc b/test-suite/test_tools.cc index 02e33fb215..fb5748f14d 100644 --- a/test-suite/test_tools.cc +++ b/test-suite/test_tools.cc @@ -234,3 +234,9 @@ ctx_enter(const char *descr) { void ctx_exit(Ctx ctx) {} + +// for debugs() +const char* SkipBuildPrefix(const char* path) +{ + return path; +}