trace.hh revision 8232
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 3756SN/A#include "base/cprintf.hh" 388232Snate@binkert.org#include "base/debug.hh" 391031SN/A#include "base/match.hh" 406214Snate@binkert.org#include "base/types.hh" 414167Sbinkertn@umich.edu#include "sim/core.hh" 422SN/A 432SN/Anamespace Trace { 442SN/A 458232Snate@binkert.orgusing Debug::SimpleFlag; 468232Snate@binkert.orgusing Debug::CompoundFlag; 478232Snate@binkert.org 484046Sbinkertn@umich.edustd::ostream &output(); 494046Sbinkertn@umich.eduvoid setOutput(const std::string &filename); 502SN/A 514046Sbinkertn@umich.eduextern bool enabled; 524046Sbinkertn@umich.edubool changeFlag(const char *str, bool value); 534046Sbinkertn@umich.eduvoid dumpStatus(); 542SN/A 554046Sbinkertn@umich.eduextern ObjectMatch ignore; 564046Sbinkertn@umich.eduextern const std::string DefaultName; 572SN/A 584046Sbinkertn@umich.eduvoid dprintf(Tick when, const std::string &name, const char *format, 594046Sbinkertn@umich.edu CPRINTF_DECLARATION); 604046Sbinkertn@umich.eduvoid dump(Tick when, const std::string &name, const void *data, int len); 612SN/A 627811Ssteve.reinhardt@amd.com} // namespace Trace 634039Sbinkertn@umich.edu 641070SN/A// This silly little class allows us to wrap a string in a functor 651070SN/A// object so that we can give a name() that DPRINTF will like 661070SN/Astruct StringWrap 671070SN/A{ 681070SN/A std::string str; 691070SN/A StringWrap(const std::string &s) : str(s) {} 701070SN/A const std::string &operator()() const { return str; } 711070SN/A}; 721070SN/A 732SN/Ainline const std::string &name() { return Trace::DefaultName; } 742SN/A 752SN/A// 762SN/A// DPRINTF is a debugging trace facility that allows one to 772SN/A// selectively enable tracing statements. To use DPRINTF, there must 782SN/A// be a function or functor called name() that returns a const 792SN/A// std::string & in the current scope. 802SN/A// 812SN/A// If you desire that the automatic printing not occur, use DPRINTFR 822SN/A// (R for raw) 832SN/A// 842SN/A 852SN/A#if TRACING_ON 862SN/A 878232Snate@binkert.org#define DTRACE(x) ((Debug::x) && Trace::enabled) 882SN/A 894041Sbinkertn@umich.edu#define DDUMP(x, data, count) do { \ 908232Snate@binkert.org using namespace Debug; \ 914041Sbinkertn@umich.edu if (DTRACE(x)) \ 927823Ssteve.reinhardt@amd.com Trace::dump(curTick(), name(), data, count); \ 932SN/A} while (0) 942SN/A 954041Sbinkertn@umich.edu#define DPRINTF(x, ...) do { \ 968232Snate@binkert.org using namespace Debug; \ 974041Sbinkertn@umich.edu if (DTRACE(x)) \ 987823Ssteve.reinhardt@amd.com Trace::dprintf(curTick(), name(), __VA_ARGS__); \ 992SN/A} while (0) 1002SN/A 1018232Snate@binkert.org#define DPRINTFS(x, s, ...) do { \ 1028232Snate@binkert.org using namespace Debug; \ 1035806Ssaidi@eecs.umich.edu if (DTRACE(x)) \ 1048232Snate@binkert.org Trace::dprintf(curTick(), s->name(), __VA_ARGS__); \ 1055806Ssaidi@eecs.umich.edu} while (0) 1065806Ssaidi@eecs.umich.edu 1074041Sbinkertn@umich.edu#define DPRINTFR(x, ...) do { \ 1088232Snate@binkert.org using namespace Debug; \ 1094041Sbinkertn@umich.edu if (DTRACE(x)) \ 1104041Sbinkertn@umich.edu Trace::dprintf((Tick)-1, std::string(), __VA_ARGS__); \ 1112SN/A} while (0) 1122SN/A 1134046Sbinkertn@umich.edu#define DDUMPN(data, count) do { \ 1147823Ssteve.reinhardt@amd.com Trace::dump(curTick(), name(), data, count); \ 1154046Sbinkertn@umich.edu} while (0) 1164046Sbinkertn@umich.edu 1174041Sbinkertn@umich.edu#define DPRINTFN(...) do { \ 1187823Ssteve.reinhardt@amd.com Trace::dprintf(curTick(), name(), __VA_ARGS__); \ 1192SN/A} while (0) 1202SN/A 1214041Sbinkertn@umich.edu#define DPRINTFNR(...) do { \ 1224041Sbinkertn@umich.edu Trace::dprintf((Tick)-1, string(), __VA_ARGS__); \ 123507SN/A} while (0) 124507SN/A 1252SN/A#else // !TRACING_ON 1262SN/A 1272SN/A#define DTRACE(x) (false) 1284046Sbinkertn@umich.edu#define DDUMP(x, data, count) do {} while (0) 1294041Sbinkertn@umich.edu#define DPRINTF(x, ...) do {} while (0) 1305806Ssaidi@eecs.umich.edu#define DPRINTFS(x, ...) do {} while (0) 1314041Sbinkertn@umich.edu#define DPRINTFR(...) do {} while (0) 1324046Sbinkertn@umich.edu#define DDUMPN(data, count) do {} while (0) 1334041Sbinkertn@umich.edu#define DPRINTFN(...) do {} while (0) 1344041Sbinkertn@umich.edu#define DPRINTFNR(...) do {} while (0) 1352SN/A 1365543Ssaidi@eecs.umich.edu#endif // TRACING_ON 1372SN/A 1381354SN/A#endif // __BASE_TRACE_HH__ 139