~ubuntu-branches/ubuntu/jaunty/squid3/jaunty

« back to all changes in this revision

Viewing changes to src/debug.cc

  • Committer: Bazaar Package Importer
  • Author(s): Luigi Gangitano
  • Date: 2008-06-01 05:48:22 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20080601054822-okaglok79te8qmln
Tags: 3.0.STABLE6-2
* debian/control
  - Fixed suggestion on squidlcient package

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * $Id: debug.cc,v 1.106.2.1 2008/02/25 03:01:01 amosjeffries Exp $
 
2
 * $Id: debug.cc,v 1.109 2008/02/26 18:43:30 rousskov Exp $
3
3
 *
4
4
 * DEBUG: section 0     Debug Routines
5
5
 * AUTHOR: Harvest Derived
35
35
#include "squid.h"
36
36
#include "Debug.h"
37
37
#include "SquidTime.h"
38
 
#include <sstream>
39
38
 
40
39
int Debug::Levels[MAX_DEBUG_SECTIONS];
41
40
int Debug::level;
735
734
    return Ctx_Descrs[ctx] ? Ctx_Descrs[ctx] : "<null>";
736
735
}
737
736
 
 
737
int Debug::TheDepth = 0;
 
738
 
738
739
std::ostream &
739
740
Debug::getDebugOut() {
740
 
    assert (CurrentDebug == NULL);
741
 
    CurrentDebug = new std::ostringstream();
742
 
    // set default formatting flags
743
 
    CurrentDebug->setf(std::ios::fixed);
744
 
    CurrentDebug->precision(2);
 
741
    assert(TheDepth >= 0);
 
742
    ++TheDepth;
 
743
    if (TheDepth > 1) {
 
744
        assert(CurrentDebug);
 
745
        *CurrentDebug << std::endl << "reentrant debuging " << TheDepth << "-{";
 
746
    } else {
 
747
        assert(!CurrentDebug);
 
748
        CurrentDebug = new std::ostringstream();
 
749
        // set default formatting flags
 
750
        CurrentDebug->setf(std::ios::fixed);
 
751
        CurrentDebug->precision(2);
 
752
    }
745
753
    return *CurrentDebug;
746
754
}
747
755
 
748
756
void
749
757
Debug::finishDebug() {
750
 
    _db_print("%s\n", CurrentDebug->str().c_str());
751
 
    delete CurrentDebug;
752
 
    CurrentDebug = NULL;
 
758
    assert(TheDepth >= 0);
 
759
    assert(CurrentDebug);
 
760
    if (TheDepth > 1) {
 
761
        *CurrentDebug << "}-" << TheDepth << std::endl;
 
762
    } else {
 
763
        assert(TheDepth == 1);
 
764
        _db_print("%s\n", CurrentDebug->str().c_str());
 
765
        delete CurrentDebug;
 
766
        CurrentDebug = NULL;
 
767
    }
 
768
    --TheDepth;
 
769
}
 
770
 
 
771
// Hack: replaces global ::xassert() to debug debugging assertions
 
772
// Relies on assert macro calling xassert() without a specific scope.
 
773
void
 
774
Debug::xassert(const char *msg, const char *file, int line) {
 
775
        
 
776
    if (CurrentDebug) {
 
777
        *CurrentDebug << "assertion failed: " << file << ":" << line <<
 
778
            ": \"" << msg << "\"";
 
779
    }
 
780
    abort();
753
781
}
754
782
 
755
783
std::ostringstream (*Debug::CurrentDebug)(NULL);