ircproxy  The Ultimate Cyborg

debug Namespace Reference


Detailed Description

Debug specific code.


Classes

struct  InvisibleAllocations
 Interface for marking scopes of invisible memory allocations. More...
struct  Indent
 Interface for marking scopes with indented debug output. More...
struct  SecondaryConnection
class  TeeBuf
class  TeeStream

Namespaces

namespace  channels
 Debug Channels (dc) namespace.

Functions

bool is_on_in_rcfile (char const *dc_label)
 Returns the the original state of a debug channel.
void init_thread (void)
 Initialize debugging code from new threads.
void init (void)
 Initialize debugging code from main.
void dump_hex (libcwd::channel_ct const &channel, unsigned char const *buf, size_t size)
 Write a hexadecimal and ascii dump of a buffer to a given debug channel.
char const * state_nt_name (state_nt state)
 Return a string literal representing the name of the state_nt state.
char const * openmode_name (PersistXML::openmode_type openmode)
 Return a string literal representing the name of the PersistXML::openmode_type openmode.
char const * match0_type_name (match0_type mt)
 Return a string literal representing the name of the match0_type mt.
char const * match1_type_name (match1_type mt)
 Return a string literal representing the name of the match1_type mt.
char const * command_name (int command)
 Return a string literal representing the name of the int command.


Function Documentation

bool debug::is_on_in_rcfile ( char const *  dc_label  ) 

Returns the the original state of a debug channel.

For internal use only.

For a given dc_label, which must be the exact name (channel_ct::get_label) of an existing debug channel, this function returns true when the corresponding debug channel was on at the startup of the application, directly after reading the libcwd runtime configuration file (.libcwdrc).

If the label/channel did not exist at the start of the application, it will return false (note that libcwd disallows adding debug channels to modules - so this would probably a bug).

Definition at line 128 of file debug.cc.

Referenced by init_thread().

00129   {
00130     rcfile_dc_states_type::const_iterator iter = rcfile_dc_states.find(std::string(dc_label));
00131     if (iter == rcfile_dc_states.end())
00132     {
00133       Dout(dc::warning, "is_on_in_rcfile(\"" << dc_label << "\"): \"" << dc_label << "\" is an unknown label!");
00134       return false;
00135     }
00136     return iter->second;
00137   }

void debug::init_thread ( void   ) 

Initialize debugging code from new threads.

This function needs to be called at the start of each new thread, because a new thread starts in a completely reset state.

The function turns on all debug channels that were turned on after reading the rcfile at the start of the application. Furthermore it initializes the debug ostream, its mutex and the margin of the default debug object (Dout).

Definition at line 149 of file debug.cc.

References is_on_in_rcfile().

Referenced by init().

00150   {
00151     // Turn on all debug channels that are turned on as per rcfile configuration.
00152     ForAllDebugChannels(
00153         if (!debugChannel.is_on() && is_on_in_rcfile(debugChannel.get_label()))
00154           debugChannel.on();
00155     );
00156 
00157     // Turn on debug output.
00158     Debug( libcw_do.on() );
00159 #if LIBCWD_THREAD_SAFE
00160     Debug( libcw_do.set_ostream(&std::cout, &cout_mutex) );
00161 #else
00162     Debug( libcw_do.set_ostream(&std::cout) );
00163 #endif
00164 
00165     static bool first_thread = true;
00166     if (!first_thread)                  // So far, the application has only one thread.  So don't add a thread id.
00167     {
00168       // Set the thread id in the margin.
00169       char margin[12];
00170       sprintf(margin, "%-10lu ", pthread_self());
00171       Debug( libcw_do.margin().assign(margin, 11) );
00172     }
00173   }

void debug::init ( void   ) 

Initialize debugging code from main.

This function initializes the debug code.

Definition at line 179 of file debug.cc.

References init_thread().

Referenced by Application::main_entered().

00180   {
00181 #if CWDEBUG_ALLOC && defined(USE_LIBCW)
00182     // Tell the memory leak detector which parts of the code are
00183     // expected to leak so that we won't get an alarm for those.
00184     {
00185       std::vector<std::pair<std::string, std::string> > hide_list;
00186       hide_list.push_back(std::pair<std::string, std::string>("libdl.so.2", "_dlerror_run"));
00187       hide_list.push_back(std::pair<std::string, std::string>("libstdc++.so.6", "__cxa_get_globals"));
00188       // The following is actually necessary because of a bug in glibc
00189       // (see http://sources.redhat.com/bugzilla/show_bug.cgi?id=311).
00190       hide_list.push_back(std::pair<std::string, std::string>("libc.so.6", "dl_open_worker"));
00191       memleak_filter().hide_functions_matching(hide_list);
00192     }
00193     {
00194       std::vector<std::string> hide_list;
00195       // Also because of http://sources.redhat.com/bugzilla/show_bug.cgi?id=311
00196       hide_list.push_back(std::string("ld-linux.so.2"));
00197       memleak_filter().hide_objectfiles_matching(hide_list);
00198     }
00199     memleak_filter().set_flags(libcwd::show_objectfile|libcwd::show_function);
00200 #endif
00201 
00202     // The following call allocated the filebuf's of cin, cout, cerr, wcin, wcout and wcerr.
00203     // Because this causes a memory leak being reported, make them invisible.
00204     Debug(set_invisible_on());
00205 
00206     // You want this, unless you mix streams output with C output.
00207     // Read  http://gcc.gnu.org/onlinedocs/libstdc++/27_io/howto.html#8 for an explanation.
00208     //std::ios::sync_with_stdio(false);
00209 
00210     // Cancel previous call to set_invisible_on.
00211     Debug(set_invisible_off());
00212 
00213     // This will warn you when you are using header files that do not belong to the
00214     // shared libcwd object that you linked with.
00215     Debug( check_configuration() );
00216 
00217     Debug(
00218       libcw_do.on();            // Show which rcfile we are reading!
00219       ForAllDebugChannels(
00220         while (debugChannel.is_on())
00221           debugChannel.off()    // Print as little as possible though.
00222       );
00223       read_rcfile();            // Put 'silent = on' in the rcfile to suppress most of the output here.
00224       libcw_do.off()
00225     );
00226     save_dc_states();
00227 
00228     init_thread();
00229   }

void debug::dump_hex ( libcwd::channel_ct const &  channel,
unsigned char const *  buf,
size_t  size 
)

Write a hexadecimal and ascii dump of a buffer to a given debug channel.

This function can be used to print a binary block of data of size bytes, starting at buf. The output is written to debug channel channel.

Definition at line 236 of file debug.cc.

References DEBUGCHANNELS.

00237   {
00238     for (size_t addr = 0; addr < size; addr += 16)
00239     {
00240       LibcwDoutScopeBegin(DEBUGCHANNELS, libcwd::libcw_do, channel)
00241       LibcwDoutStream << std::hex << std::setfill('0') << std::setw(4) << addr << " |";
00242       int offset;
00243       for (offset = 0; offset < 16 && addr + offset < size; ++offset)
00244         LibcwDoutStream << ' ' << std::hex << std::setfill('0') << std::setw(2) << (int)buf[addr + offset];
00245       for (; offset < 16; ++offset)
00246         LibcwDoutStream << "   ";
00247       LibcwDoutStream << " | ";
00248       for (int offset = 0; offset < 16 && addr + offset < size; ++offset)
00249       {
00250         unsigned char c = buf[addr + offset];
00251         if (!std::isprint(c))
00252           c = '.';
00253         LibcwDoutStream << c;
00254       }
00255       LibcwDoutScopeEnd;
00256     }
00257   }

char const* debug::state_nt_name ( state_nt  state  ) 

Return a string literal representing the name of the state_nt state.

For internal use only.

Definition at line 62 of file debug_ostream_operators.cc.

References authentication_started, CASERETURNSTR, disconnected, login_sent, pong_sent, real_nick_accepted, real_nick_sent, and successful_connect.

Referenced by operator<<().

00063 {
00064   switch(state)
00065   {
00066     // See enum state_nt in ServerConnection.h
00067     CASERETURNSTR(disconnected);
00068     CASERETURNSTR(successful_connect);
00069     CASERETURNSTR(authentication_started);
00070     CASERETURNSTR(pong_sent);
00071     CASERETURNSTR(login_sent);
00072     CASERETURNSTR(real_nick_sent);
00073     CASERETURNSTR(real_nick_accepted);
00074   }
00075   DoutFatal(dc::fatal, "Unhandled state_nt in state_nt_name");
00076 }

char const* debug::openmode_name ( PersistXML::openmode_type  openmode  ) 

Return a string literal representing the name of the PersistXML::openmode_type openmode.

For internal use only.

Definition at line 82 of file debug_ostream_operators.cc.

References CASERETURNSTR, PersistXML::load, PersistXML::not_open, and PersistXML::store.

Referenced by operator<<().

00083 {
00084   switch(openmode)
00085   {
00086     // See enum PersistXML::openmode_type in PersistXML.h
00087     CASERETURNSTR(PersistXML::not_open);
00088     CASERETURNSTR(PersistXML::store);
00089     CASERETURNSTR(PersistXML::load);
00090   }
00091   DoutFatal(dc::fatal, "Unhandled PersistXML::openmode in openmode_name");
00092 }

char const* debug::match0_type_name ( match0_type  mt  ) 

Return a string literal representing the name of the match0_type mt.

For internal use only.

Definition at line 98 of file debug_ostream_operators.cc.

References CASERETURNSTR.

Referenced by operator<<().

00099 {
00100   switch(mt)
00101   {
00102     // See enum match0_type in Matcher.h
00103     CASERETURNSTR(anystring_mt);
00104     CASERETURNSTR(nonemptystring_mt);
00105     CASERETURNSTR(anyserver_mt);
00106     CASERETURNSTR(localserver_mt);
00107     CASERETURNSTR(anynick_mt);
00108     CASERETURNSTR(mynick_mt);
00109     CASERETURNSTR(anychannel_mt);
00110     CASERETURNSTR(anyglobalchannel_mt);
00111     CASERETURNSTR(anylocalchannel_mt);
00112   }
00113   DoutFatal(dc::fatal, "Unhandled match0_type in match0_type_name");
00114 }

char const* debug::match1_type_name ( match1_type  mt  ) 

Return a string literal representing the name of the match1_type mt.

For internal use only.

Definition at line 120 of file debug_ostream_operators.cc.

References CASERETURNSTR.

Referenced by operator<<().

00121 {
00122   switch(mt)
00123   {
00124     // See enum match1_type in Matcher.h
00125     CASERETURNSTR(wildcard_mt);
00126     CASERETURNSTR(regexp_mt);
00127     CASERETURNSTR(exactmatch_mt);
00128   }
00129   DoutFatal(dc::fatal, "Unhandled match1_type in match1_type_name");
00130 }

char const* debug::command_name ( int  command  ) 

Return a string literal representing the name of the int command.

For internal use only.

Definition at line 136 of file debug_ostream_operators.cc.

References CASERETURNSTR.

Referenced by operator<<().

00137 {
00138   using namespace keys;
00139   switch(command)
00140   {
00141     // See irc_commands
00142     CASERETURNSTR(PASS);
00143     CASERETURNSTR(USER);
00144     CASERETURNSTR(NICK);
00145     CASERETURNSTR(PING);
00146     CASERETURNSTR(ERROR);
00147     CASERETURNSTR(QUIT);
00148     CASERETURNSTR(WHO);
00149     CASERETURNSTR(WHOIS);
00150     CASERETURNSTR(WHOWAS);
00151     CASERETURNSTR(PRIVMSG);
00152     CASERETURNSTR(NOTICE);
00153     CASERETURNSTR(CPRIVMSG);
00154     CASERETURNSTR(CNOTICE);
00155     CASERETURNSTR(LINKS);
00156     CASERETURNSTR(JOIN);
00157     CASERETURNSTR(PART);
00158     CASERETURNSTR(KICK);
00159     CASERETURNSTR(MODE);
00160     CASERETURNSTR(NAMES);
00161     CASERETURNSTR(TOPIC);
00162   }
00163   DoutFatal(dc::fatal, "Unhandled command key in command_name");
00164 }


Copyright © 2005-2007 Carlo Wood.  All rights reserved.