diff options
author | Alexander Golubev <fatzer2@gmail.com> | 2024-03-19 06:03:44 +0300 |
---|---|---|
committer | Alexander Golubev <fatzer2@gmail.com> | 2024-03-29 21:31:02 +0300 |
commit | 9a94c79bd48ed053b9458212ebb9862ef90f7a7e (patch) | |
tree | 52eb3364572fd486738abd02f2f66bab5ea978e6 | |
parent | 676000853b614b9063e38568e94833683bf05ccd (diff) | |
download | tqt3-9a94c79bd48ed053b9458212ebb9862ef90f7a7e.tar.gz tqt3-9a94c79bd48ed053b9458212ebb9862ef90f7a7e.zip |
[DONTMERGE] Add debug tracers for TQFont and TQFontMetrics creation
Signed-off-by: Alexander Golubev <fatzer2@gmail.com>
-rw-r--r-- | src/kernel/qfont.cpp | 79 | ||||
-rw-r--r-- | src/kernel/qfontdata_p.h | 6 |
2 files changed, 84 insertions, 1 deletions
diff --git a/src/kernel/qfont.cpp b/src/kernel/qfont.cpp index 44168a1fa..d9600b7ab 100644 --- a/src/kernel/qfont.cpp +++ b/src/kernel/qfont.cpp @@ -61,15 +61,82 @@ #include "qpainter_p.h" #include "qtextengine_p.h" -// #define TQFONTCACHE_DEBUG +//#define TQFONTCACHE_DEBUG #ifdef TQFONTCACHE_DEBUG # define FC_DEBUG tqDebug #else # define FC_DEBUG if (FALSE) tqDebug #endif +#include <execinfo.h> +template<class T> +class CreationTracerNoop { +public: + void newO(T* ) {} + void delO(T* ) {} +}; +template<class T> +class CreationTracer { + struct TracerData { + char **bt; + int bt_sz; + }; + typedef TQMap<T*, TracerData> MapType; + MapType aliveObj; +public: + + void newO(T* o) { + const size_t buf_sz = 128; + void *buf[buf_sz]; + + int bt_sz = backtrace (buf, buf_sz); + aliveObj.insert(o, TracerData{backtrace_symbols(buf, bt_sz), bt_sz} ); + } + + void delO(T* o) { + auto it =aliveObj.find(o); + if(it!=aliveObj.end()) { + free(it.data().bt); + aliveObj.remove(it); + } + + } + + ~CreationTracer() { + std::string fname = typeid(T).name(); + fname.append("-undestroyed"); + FILE *f = fopen(fname.c_str(), "w"); + if(!f) { + return; + } + for(auto it = aliveObj.begin(), endIt = aliveObj.end(); it!=endIt; ++it) { + for(int i=0; i<it.data().bt_sz; ++i) { + fprintf(f, "%s\n", it.data().bt[i]); + } + fprintf(f, "\n"); + free(it.data().bt); + } + fclose(f); + } +}; + +#define INIT_FIRST __attribute__ ((init_priority (101))) +//#define TQFONT_TRACE +//#define TQFONTMETRIC_TRACE + +#ifdef TQFONT_TRACE +static CreationTracer<TQFont> INIT_FIRST TQFontTracer; +#else +static CreationTracerNoop<TQFont> TQFontTracer; +#endif // TQFONT_TRACE + +#ifdef TQFONT_TRACE +static CreationTracer<TQFontMetrics> INIT_FIRST TQFontMetricsTracer; +#else +static CreationTracerNoop<TQFontMetrics> TQFontMetricsTracer; +#endif // TQFONT_TRACE bool TQFontDef::operator==( const TQFontDef &other ) const { @@ -534,6 +601,7 @@ TQFontEngineData::~TQFontEngineData() */ TQFont::TQFont( TQFontPrivate *data, TQPaintDevice *pd ) { + TQFontTracer.newO(this); d = new TQFontPrivate( *data ); TQ_CHECK_PTR( d ); d->paintdevice = pd; @@ -578,6 +646,7 @@ void TQFont::detach() */ TQFont::TQFont() { + TQFontTracer.newO(this); const TQFont appfont = TQApplication::font(); d = appfont.d; d->ref(); @@ -602,6 +671,7 @@ TQFont::TQFont() */ TQFont::TQFont( const TQString &family, int pointSize, int weight, bool italic ) { + TQFontTracer.newO(this); d = new TQFontPrivate; TQ_CHECK_PTR( d ); @@ -632,6 +702,7 @@ TQFont::TQFont( const TQString &family, int pointSize, int weight, bool italic ) */ TQFont::TQFont( const TQFont &font ) { + TQFontTracer.newO(this); d = font.d; d->ref(); } @@ -641,6 +712,7 @@ TQFont::TQFont( const TQFont &font ) */ TQFont::~TQFont() { + TQFontTracer.delO(this); if ( d->deref() ) delete d; d = 0; @@ -1893,6 +1965,7 @@ TQDataStream &operator>>( TQDataStream &s, TQFont &font ) TQFontMetrics::TQFontMetrics( const TQFont &font ) : d( font.d ), painter( 0 ), fscript( TQFont::NoScript ) { + TQFontMetricsTracer.newO(this); d->ref(); } @@ -1905,6 +1978,7 @@ TQFontMetrics::TQFontMetrics( const TQFont &font ) TQFontMetrics::TQFontMetrics( const TQFont &font, TQFont::Script script ) : d( font.d ), painter( 0 ), fscript( script ) { + TQFontMetricsTracer.newO(this); d->ref(); } @@ -1915,6 +1989,7 @@ TQFontMetrics::TQFontMetrics( const TQFont &font, TQFont::Script script ) TQFontMetrics::TQFontMetrics( const TQPainter *p ) : painter ( (TQPainter *) p ), fscript( TQFont::NoScript ) { + TQFontMetricsTracer.newO(this); #if defined(CHECK_STATE) if ( !painter->isActive() ) tqWarning( "TQFontMetrics: Get font metrics between TQPainter::begin() " @@ -1944,6 +2019,7 @@ TQFontMetrics::TQFontMetrics( const TQPainter *p ) TQFontMetrics::TQFontMetrics( const TQFontMetrics &fm ) : d( fm.d ), painter( 0 ), fscript( fm.fscript ) { + TQFontMetricsTracer.newO(this); d->ref(); } @@ -1953,6 +2029,7 @@ TQFontMetrics::TQFontMetrics( const TQFontMetrics &fm ) */ TQFontMetrics::~TQFontMetrics() { + TQFontMetricsTracer.delO(this); if ( d->deref() ) delete d; } diff --git a/src/kernel/qfontdata_p.h b/src/kernel/qfontdata_p.h index 9c21dfe60..4647fedbb 100644 --- a/src/kernel/qfontdata_p.h +++ b/src/kernel/qfontdata_p.h @@ -121,6 +121,9 @@ public: TQFontEngineData(); ~TQFontEngineData(); + void ref(){TQShared::ref();} + bool deref(){return TQShared::deref();} + uint lineWidth; #if defined(TQ_WS_X11) || defined(TQ_WS_WIN) @@ -147,6 +150,9 @@ public: TQFontPrivate( const TQFontPrivate &other ); ~TQFontPrivate(); + void ref(){TQShared::ref();} + bool deref(){return TQShared::deref();} + void load( TQFont::Script script ); TQFontEngine *engineForScript( TQFont::Script script ) const { if ( script == TQFont::NoScript ) |