trace.hh revision 4046
12SN/A/* 24039Sbinkertn@umich.edu * Copyright (c) 2001-2006 The Regents of The University of Michigan 32SN/A * All rights reserved. 42SN/A * 52SN/A * Redistribution and use in source and binary forms, with or without 62SN/A * modification, are permitted provided that the following conditions are 72SN/A * met: redistributions of source code must retain the above copyright 82SN/A * notice, this list of conditions and the following disclaimer; 92SN/A * redistributions in binary form must reproduce the above copyright 102SN/A * notice, this list of conditions and the following disclaimer in the 112SN/A * documentation and/or other materials provided with the distribution; 122SN/A * neither the name of the copyright holders nor the names of its 132SN/A * contributors may be used to endorse or promote products derived from 142SN/A * this software without specific prior written permission. 152SN/A * 162SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * Authors: Nathan Binkert 292665Ssaidi@eecs.umich.edu * Steve Reinhardt 302SN/A */ 312SN/A 321354SN/A#ifndef __BASE_TRACE_HH__ 331354SN/A#define __BASE_TRACE_HH__ 342SN/A 354046Sbinkertn@umich.edu#include <string> 362SN/A#include <vector> 372SN/A 3856SN/A#include "base/cprintf.hh" 391031SN/A#include "base/match.hh" 404046Sbinkertn@umich.edu#include "base/traceflags.hh" 4156SN/A#include "sim/host.hh" 421696SN/A#include "sim/root.hh" 432SN/A 442SN/Anamespace Trace { 452SN/A 464046Sbinkertn@umich.edustd::ostream &output(); 474046Sbinkertn@umich.eduvoid setOutput(const std::string &filename); 482SN/A 494046Sbinkertn@umich.eduextern bool enabled; 504046Sbinkertn@umich.edutypedef std::vector<bool> FlagVec; 514046Sbinkertn@umich.eduextern FlagVec flags; 524046Sbinkertn@umich.eduinline bool IsOn(int t) { return flags[t]; } 534046Sbinkertn@umich.edubool changeFlag(const char *str, bool value); 544046Sbinkertn@umich.eduvoid dumpStatus(); 552SN/A 564046Sbinkertn@umich.eduextern ObjectMatch ignore; 574046Sbinkertn@umich.eduextern const std::string DefaultName; 582SN/A 594046Sbinkertn@umich.eduvoid dprintf(Tick when, const std::string &name, const char *format, 604046Sbinkertn@umich.edu CPRINTF_DECLARATION); 614046Sbinkertn@umich.eduvoid dump(Tick when, const std::string &name, const void *data, int len); 622SN/A 634046Sbinkertn@umich.edu/* namespace Trace */ } 644039Sbinkertn@umich.edu 651070SN/A// This silly little class allows us to wrap a string in a functor 661070SN/A// object so that we can give a name() that DPRINTF will like 671070SN/Astruct StringWrap 681070SN/A{ 691070SN/A std::string str; 701070SN/A StringWrap(const std::string &s) : str(s) {} 711070SN/A const std::string &operator()() const { return str; } 721070SN/A}; 731070SN/A 742SN/Ainline const std::string &name() { return Trace::DefaultName; } 752SN/A 762SN/A// 772SN/A// DPRINTF is a debugging trace facility that allows one to 782SN/A// selectively enable tracing statements. To use DPRINTF, there must 792SN/A// be a function or functor called name() that returns a const 802SN/A// std::string & in the current scope. 812SN/A// 822SN/A// If you desire that the automatic printing not occur, use DPRINTFR 832SN/A// (R for raw) 842SN/A// 852SN/A 862SN/A#if TRACING_ON 872SN/A 884042Sbinkertn@umich.edu#define DTRACE(x) (Trace::IsOn(Trace::x) && Trace::enabled) 892SN/A 904041Sbinkertn@umich.edu#define DDUMP(x, data, count) do { \ 914041Sbinkertn@umich.edu if (DTRACE(x)) \ 924046Sbinkertn@umich.edu Trace::dump(curTick, name(), data, count); \ 932SN/A} while (0) 942SN/A 954041Sbinkertn@umich.edu#define DPRINTF(x, ...) do { \ 964041Sbinkertn@umich.edu if (DTRACE(x)) \ 974041Sbinkertn@umich.edu Trace::dprintf(curTick, name(), __VA_ARGS__); \ 982SN/A} while (0) 992SN/A 1004041Sbinkertn@umich.edu#define DPRINTFR(x, ...) do { \ 1014041Sbinkertn@umich.edu if (DTRACE(x)) \ 1024041Sbinkertn@umich.edu Trace::dprintf((Tick)-1, std::string(), __VA_ARGS__); \ 1032SN/A} while (0) 1042SN/A 1054046Sbinkertn@umich.edu#define DDUMPN(data, count) do { \ 1064046Sbinkertn@umich.edu Trace::dump(curTick, name(), data, count); \ 1074046Sbinkertn@umich.edu} while (0) 1084046Sbinkertn@umich.edu 1094041Sbinkertn@umich.edu#define DPRINTFN(...) do { \ 1104041Sbinkertn@umich.edu Trace::dprintf(curTick, name(), __VA_ARGS__); \ 1112SN/A} while (0) 1122SN/A 1134041Sbinkertn@umich.edu#define DPRINTFNR(...) do { \ 1144041Sbinkertn@umich.edu Trace::dprintf((Tick)-1, string(), __VA_ARGS__); \ 115507SN/A} while (0) 116507SN/A 1172SN/A#else // !TRACING_ON 1182SN/A 1192SN/A#define DTRACE(x) (false) 1204046Sbinkertn@umich.edu#define DDUMP(x, data, count) do {} while (0) 1214041Sbinkertn@umich.edu#define DPRINTF(x, ...) do {} while (0) 1224041Sbinkertn@umich.edu#define DPRINTFR(...) do {} while (0) 1234046Sbinkertn@umich.edu#define DDUMPN(data, count) do {} while (0) 1244041Sbinkertn@umich.edu#define DPRINTFN(...) do {} while (0) 1254041Sbinkertn@umich.edu#define DPRINTFNR(...) do {} while (0) 1262SN/A 1272SN/A#endif // TRACING_ON 1282SN/A 1291354SN/A#endif // __BASE_TRACE_HH__ 130