MySQL 9.6.0
Source Code Documentation
mysql::debugging::Object_lifetime_tracker< Self_tp > Class Template Reference

Debug facility to log constructor/assignment/destructor usage for a class. More...

#include <object_lifetime_tracker.h>

Public Member Functions

 Object_lifetime_tracker () noexcept
 Default constructor. More...
 
 Object_lifetime_tracker (std::string_view flavor) noexcept
 Construct using the message "FLAVOR-construct". More...
 
 Object_lifetime_tracker (std::string_view flavor, Tracker_id source) noexcept
 Construct using the message "FLAVOR-construct from SOURCE". More...
 
 Object_lifetime_tracker (const Object_lifetime_tracker &other) noexcept
 Copy-construct using the message "Copy-construct from ID". More...
 
 Object_lifetime_tracker (Object_lifetime_tracker &&other) noexcept
 Copy-construct using the message "Move-construct from ID". More...
 
Object_lifetime_trackeroperator= (const Object_lifetime_tracker &other) noexcept
 Copy-construct using the message "Copy-assign from ID". More...
 
Object_lifetime_trackeroperator= (Object_lifetime_tracker &&other) noexcept
 Move-construct using the message "Move-assign from ID". More...
 
 ~Object_lifetime_tracker () noexcept
 Destruct using the message "Destruct". More...
 
void log (const auto &...args) const
 Write a message to the log. More...
 
void log_for (const auto &id, const auto &...args) const
 Write a message to the log, on behalf of another object having the given ID. More...
 
Tracker_id tracker_id () const
 Return the ID for this object. More...
 
std::string_view type_name () const
 Return the type of this object (not demangled). More...
 

Private Member Functions

void log_construct (std::string_view flavor) const
 Write a message during object construction. More...
 
void log_construct_from (std::string_view flavor, Tracker_id source) const
 Write a message during object construction, including a " from SOURCE" text. More...
 
void log_assign (std::string_view flavor, Tracker_id source) const
 Write a message during object assignment. More...
 
void log_move (Tracker_id id) const
 Write a message on behalf of a moved-from object. More...
 
void do_log (const auto &...args) const
 Low level to log any message. More...
 

Private Attributes

Tracker_id m_id
 

Static Private Attributes

static constexpr bool known_type = !std::same_as<Self_tp, void>
 
static constexpr const char * m_reset = "\033[30m"
 
static constexpr const char * m_red = "\033[31m"
 
static constexpr const char * m_green = "\033[32m"
 
static constexpr const char * m_yellow = "\033[33m"
 
static constexpr const char * m_blue = "\033[34m"
 
static constexpr const char * m_magenta = "\033[35m"
 
static constexpr const char * m_cyan = "\033[36m"
 
static constexpr const char * grey = "\033[37m"
 

Detailed Description

template<class Self_tp = void>
class mysql::debugging::Object_lifetime_tracker< Self_tp >

Debug facility to log constructor/assignment/destructor usage for a class.

To make a class log such life cycle events, make it inherit from this class.

This is only for temporary use in debugging sessions and must never be used in released code (not even debug-only code). It is intended to aid in debugging memory related issues, such as objects used after destruction. It writes a line to stdout for every object life cycle event: to keep the output size manageable it is usually good to minimize the amount of problematic code before using this class.

Template Parameters
Self_tpIf given, log entries for constructor invocations will be annotated with the type name of this class.

Constructor & Destructor Documentation

◆ Object_lifetime_tracker() [1/5]

template<class Self_tp = void>
mysql::debugging::Object_lifetime_tracker< Self_tp >::Object_lifetime_tracker ( )
inlinenoexcept

Default constructor.

◆ Object_lifetime_tracker() [2/5]

template<class Self_tp = void>
mysql::debugging::Object_lifetime_tracker< Self_tp >::Object_lifetime_tracker ( std::string_view  flavor)
inlineexplicitnoexcept

Construct using the message "FLAVOR-construct".

This is usable in custom subclass constructors.

◆ Object_lifetime_tracker() [3/5]

template<class Self_tp = void>
mysql::debugging::Object_lifetime_tracker< Self_tp >::Object_lifetime_tracker ( std::string_view  flavor,
Tracker_id  source 
)
inlineexplicitnoexcept

Construct using the message "FLAVOR-construct from SOURCE".

This is usable in custom subclass constructors.

◆ Object_lifetime_tracker() [4/5]

template<class Self_tp = void>
mysql::debugging::Object_lifetime_tracker< Self_tp >::Object_lifetime_tracker ( const Object_lifetime_tracker< Self_tp > &  other)
inlinenoexcept

Copy-construct using the message "Copy-construct from ID".

This will be called when the subclass is copy-constructed, unless the subclass copy constructor explicitly invokes another constructor in this class.

◆ Object_lifetime_tracker() [5/5]

template<class Self_tp = void>
mysql::debugging::Object_lifetime_tracker< Self_tp >::Object_lifetime_tracker ( Object_lifetime_tracker< Self_tp > &&  other)
inlinenoexcept

Copy-construct using the message "Move-construct from ID".

This will be called when the subclass is move-constructed, unless the subclass move constructor explicitly invokes another constructor in this class.

◆ ~Object_lifetime_tracker()

template<class Self_tp = void>
mysql::debugging::Object_lifetime_tracker< Self_tp >::~Object_lifetime_tracker ( )
inlinenoexcept

Destruct using the message "Destruct".

Member Function Documentation

◆ do_log()

template<class Self_tp = void>
void mysql::debugging::Object_lifetime_tracker< Self_tp >::do_log ( const auto &...  args) const
inlineprivate

Low level to log any message.

◆ log()

template<class Self_tp = void>
void mysql::debugging::Object_lifetime_tracker< Self_tp >::log ( const auto &...  args) const
inline

Write a message to the log.

The parameters will be passed to a std::stringstream using operator<<.

◆ log_assign()

template<class Self_tp = void>
void mysql::debugging::Object_lifetime_tracker< Self_tp >::log_assign ( std::string_view  flavor,
Tracker_id  source 
) const
inlineprivate

Write a message during object assignment.

◆ log_construct()

template<class Self_tp = void>
void mysql::debugging::Object_lifetime_tracker< Self_tp >::log_construct ( std::string_view  flavor) const
inlineprivate

Write a message during object construction.

◆ log_construct_from()

template<class Self_tp = void>
void mysql::debugging::Object_lifetime_tracker< Self_tp >::log_construct_from ( std::string_view  flavor,
Tracker_id  source 
) const
inlineprivate

Write a message during object construction, including a " from SOURCE" text.

◆ log_for()

template<class Self_tp = void>
void mysql::debugging::Object_lifetime_tracker< Self_tp >::log_for ( const auto &  id,
const auto &...  args 
) const
inline

Write a message to the log, on behalf of another object having the given ID.

The parameters will be passed to a std::stringstream using operator<<.

◆ log_move()

template<class Self_tp = void>
void mysql::debugging::Object_lifetime_tracker< Self_tp >::log_move ( Tracker_id  id) const
inlineprivate

Write a message on behalf of a moved-from object.

◆ operator=() [1/2]

template<class Self_tp = void>
Object_lifetime_tracker & mysql::debugging::Object_lifetime_tracker< Self_tp >::operator= ( const Object_lifetime_tracker< Self_tp > &  other)
inlinenoexcept

Copy-construct using the message "Copy-assign from ID".

This will be called when the subclass is copy-assigned to.

◆ operator=() [2/2]

template<class Self_tp = void>
Object_lifetime_tracker & mysql::debugging::Object_lifetime_tracker< Self_tp >::operator= ( Object_lifetime_tracker< Self_tp > &&  other)
inlinenoexcept

Move-construct using the message "Move-assign from ID".

This will be called when the subclass is move-assigned to.

◆ tracker_id()

template<class Self_tp = void>
Tracker_id mysql::debugging::Object_lifetime_tracker< Self_tp >::tracker_id ( ) const
inline

Return the ID for this object.

◆ type_name()

template<class Self_tp = void>
std::string_view mysql::debugging::Object_lifetime_tracker< Self_tp >::type_name ( ) const
inline

Return the type of this object (not demangled).

Member Data Documentation

◆ grey

template<class Self_tp = void>
constexpr const char* mysql::debugging::Object_lifetime_tracker< Self_tp >::grey = "\033[37m"
staticconstexprprivate

◆ known_type

template<class Self_tp = void>
constexpr bool mysql::debugging::Object_lifetime_tracker< Self_tp >::known_type = !std::same_as<Self_tp, void>
staticconstexprprivate

◆ m_blue

template<class Self_tp = void>
constexpr const char* mysql::debugging::Object_lifetime_tracker< Self_tp >::m_blue = "\033[34m"
staticconstexprprivate

◆ m_cyan

template<class Self_tp = void>
constexpr const char* mysql::debugging::Object_lifetime_tracker< Self_tp >::m_cyan = "\033[36m"
staticconstexprprivate

◆ m_green

template<class Self_tp = void>
constexpr const char* mysql::debugging::Object_lifetime_tracker< Self_tp >::m_green = "\033[32m"
staticconstexprprivate

◆ m_id

template<class Self_tp = void>
Tracker_id mysql::debugging::Object_lifetime_tracker< Self_tp >::m_id
private

◆ m_magenta

template<class Self_tp = void>
constexpr const char* mysql::debugging::Object_lifetime_tracker< Self_tp >::m_magenta = "\033[35m"
staticconstexprprivate

◆ m_red

template<class Self_tp = void>
constexpr const char* mysql::debugging::Object_lifetime_tracker< Self_tp >::m_red = "\033[31m"
staticconstexprprivate

◆ m_reset

template<class Self_tp = void>
constexpr const char* mysql::debugging::Object_lifetime_tracker< Self_tp >::m_reset = "\033[30m"
staticconstexprprivate

◆ m_yellow

template<class Self_tp = void>
constexpr const char* mysql::debugging::Object_lifetime_tracker< Self_tp >::m_yellow = "\033[33m"
staticconstexprprivate

The documentation for this class was generated from the following file: