X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fpbd%2Fdebug.cc;h=419c5bfb379e32ec71fe3bc8511a80834d6db28a;hb=e7a154b9dd8ed43a77424f8624ce61db0fa390d9;hp=98d0fc5091e77265380b36044954db437d40e3ab;hpb=16ce39c2309769789784a1f74e41ce0c49a75282;p=ardour.git diff --git a/libs/pbd/debug.cc b/libs/pbd/debug.cc index 98d0fc5091..419c5bfb37 100644 --- a/libs/pbd/debug.cc +++ b/libs/pbd/debug.cc @@ -24,84 +24,113 @@ #include #include +#include + #include "pbd/debug.h" -#include "i18n.h" +#include "pbd/i18n.h" using namespace std; -static uint64_t _debug_bit = 1; +using PBD::DebugBits; + +static uint64_t _debug_bit = 0; -typedef std::map DebugMap; +typedef std::map DebugMap; namespace PBD { - DebugMap _debug_bit_map; + DebugMap & _debug_bit_map() + { + static DebugMap map; + return map; + } } -uint64_t PBD::DEBUG::Stateful = PBD::new_debug_bit ("stateful"); -uint64_t PBD::DEBUG::Properties = PBD::new_debug_bit ("properties"); -uint64_t PBD::DEBUG::FileManager = PBD::new_debug_bit ("filemanager"); -uint64_t PBD::DEBUG::Pool = PBD::new_debug_bit ("pool"); -uint64_t PBD::DEBUG::EventLoop = PBD::new_debug_bit ("eventloop"); -uint64_t PBD::DEBUG::AbstractUI = PBD::new_debug_bit ("abstractui"); +DebugBits PBD::DEBUG::Stateful = PBD::new_debug_bit ("stateful"); +DebugBits PBD::DEBUG::Properties = PBD::new_debug_bit ("properties"); +DebugBits PBD::DEBUG::FileManager = PBD::new_debug_bit ("filemanager"); +DebugBits PBD::DEBUG::Pool = PBD::new_debug_bit ("pool"); +DebugBits PBD::DEBUG::EventLoop = PBD::new_debug_bit ("eventloop"); +DebugBits PBD::DEBUG::AbstractUI = PBD::new_debug_bit ("abstractui"); +DebugBits PBD::DEBUG::FileUtils = PBD::new_debug_bit ("fileutils"); +DebugBits PBD::DEBUG::Configuration = PBD::new_debug_bit ("configuration"); +DebugBits PBD::DEBUG::UndoHistory = PBD::new_debug_bit ("undohistory"); +DebugBits PBD::DEBUG::Timing = PBD::new_debug_bit ("timing"); +DebugBits PBD::DEBUG::Threads = PBD::new_debug_bit ("threads"); +DebugBits PBD::DEBUG::Locale = PBD::new_debug_bit ("locale"); + +/* These are debug bits that are used by backends. Since these are loaded dynamically, + after command-line parsing, defining them in code that is part of the backend + doesn't make them available for command line parsing. Put them here. + + This is sort of a hack, because it means that the debug bits aren't defined + with the code in which they are relevant. But providing access to debug bits + from dynamically loaded code, for use in command line parsing, is way above the pay grade + of this debug tracing scheme. +*/ +DebugBits PBD::DEBUG::WavesMIDI = PBD::new_debug_bit ("WavesMIDI"); +DebugBits PBD::DEBUG::WavesAudio = PBD::new_debug_bit ("WavesAudio"); -uint64_t PBD::debug_bits = 0x0; +DebugBits PBD::debug_bits; -uint64_t +DebugBits PBD::new_debug_bit (const char* name) { - uint64_t ret; - _debug_bit_map.insert (make_pair (name, _debug_bit)); - ret = _debug_bit; - _debug_bit <<= 1; + DebugBits ret; + DebugMap::iterator i =_debug_bit_map().find (name); + + if (i != _debug_bit_map().end()) { + return i->second; + } + + if (_debug_bit >= debug_bits.size()) { + cerr << "Too many debug bits defined, offender was " << name << endl; + abort (); + /*NOTREACHED*/ + } + + ret.set (_debug_bit++, 1); + _debug_bit_map().insert (make_pair (name, ret)); return ret; } void PBD::debug_print (const char* prefix, string str) { - cerr << prefix << ": " << str; -} - -void -PBD::set_debug_bits (uint64_t bits) -{ - debug_bits = bits; + cout << prefix << ": " << str; } int PBD::parse_debug_options (const char* str) { - char* p; - char* sp; - uint64_t bits = 0; - char* copy = strdup (str); - - p = strtok_r (copy, ",", &sp); - - while (p) { - if (strcasecmp (p, "list") == 0) { + string in_str = str; + typedef boost::tokenizer > tokenizer; + boost::char_separator sep (","); + tokenizer tokens (in_str, sep); + DebugBits bits; + + for (tokenizer::iterator tok_iter = tokens.begin(); tok_iter != tokens.end(); ++tok_iter) { + if (*tok_iter == "list") { list_debug_options (); - free (copy); return 1; } - if (strcasecmp (p, "all") == 0) { - PBD::set_debug_bits (~0ULL); - free (copy); + if (*tok_iter == "all") { + debug_bits.set (); /* sets all bits */ return 0; } - for (map::iterator i = _debug_bit_map.begin(); i != _debug_bit_map.end(); ++i) { - if (strncasecmp (p, i->first, strlen (p)) == 0) { - bits |= i->second; + for (map::iterator i = _debug_bit_map().begin(); i != _debug_bit_map().end(); ++i) { + const char* cstr = (*tok_iter).c_str(); + + if (strncasecmp (cstr, i->first, strlen (cstr)) == 0) { + bits |= i->second; + cout << i->first << " set ... debug bits now set to " << bits << " using " << i->second << endl; } } - - p = strtok_r (0, ",", &sp); } - - free (copy); - PBD::set_debug_bits (bits); + + debug_bits = bits; + return 0; } @@ -109,11 +138,11 @@ void PBD::list_debug_options () { cout << _("The following debug options are available. Separate multiple options with commas.\nNames are case-insensitive and can be abbreviated.") << endl << endl; - cout << '\t' << X_("all") << endl; + cout << '\t' << X_("all") << endl; vector options; - for (map::iterator i = _debug_bit_map.begin(); i != _debug_bit_map.end(); ++i) { + for (map::iterator i = _debug_bit_map().begin(); i != _debug_bit_map().end(); ++i) { options.push_back (i->first); }