trace.hh revision 10259
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 7510259SAndrew.Bardsley@arm.com// Interface for things with names. (cf. SimObject but without other 7610259SAndrew.Bardsley@arm.com// functionality). This is useful when using DPRINTF 7710259SAndrew.Bardsley@arm.comclass Named 7810259SAndrew.Bardsley@arm.com{ 7910259SAndrew.Bardsley@arm.com protected: 8010259SAndrew.Bardsley@arm.com const std::string _name; 8110259SAndrew.Bardsley@arm.com 8210259SAndrew.Bardsley@arm.com public: 8310259SAndrew.Bardsley@arm.com Named(const std::string &name_) : _name(name_) { } 8410259SAndrew.Bardsley@arm.com 8510259SAndrew.Bardsley@arm.com public: 8610259SAndrew.Bardsley@arm.com const std::string &name() const { return _name; } 8710259SAndrew.Bardsley@arm.com}; 8810259SAndrew.Bardsley@arm.com 892SN/A// 902SN/A// DPRINTF is a debugging trace facility that allows one to 912SN/A// selectively enable tracing statements. To use DPRINTF, there must 922SN/A// be a function or functor called name() that returns a const 932SN/A// std::string & in the current scope. 942SN/A// 952SN/A// If you desire that the automatic printing not occur, use DPRINTFR 962SN/A// (R for raw) 972SN/A// 982SN/A 992SN/A#if TRACING_ON 1002SN/A 1018232Snate@binkert.org#define DTRACE(x) ((Debug::x) && Trace::enabled) 1022SN/A 1034041Sbinkertn@umich.edu#define DDUMP(x, data, count) do { \ 1048232Snate@binkert.org using namespace Debug; \ 1054041Sbinkertn@umich.edu if (DTRACE(x)) \ 1067823Ssteve.reinhardt@amd.com Trace::dump(curTick(), name(), data, count); \ 1072SN/A} while (0) 1082SN/A 1094041Sbinkertn@umich.edu#define DPRINTF(x, ...) do { \ 1108232Snate@binkert.org using namespace Debug; \ 1114041Sbinkertn@umich.edu if (DTRACE(x)) \ 1127823Ssteve.reinhardt@amd.com Trace::dprintf(curTick(), name(), __VA_ARGS__); \ 1132SN/A} while (0) 1142SN/A 1158232Snate@binkert.org#define DPRINTFS(x, s, ...) do { \ 1168232Snate@binkert.org using namespace Debug; \ 1175806Ssaidi@eecs.umich.edu if (DTRACE(x)) \ 1188232Snate@binkert.org Trace::dprintf(curTick(), s->name(), __VA_ARGS__); \ 1195806Ssaidi@eecs.umich.edu} while (0) 1205806Ssaidi@eecs.umich.edu 1214041Sbinkertn@umich.edu#define DPRINTFR(x, ...) do { \ 1228232Snate@binkert.org using namespace Debug; \ 1234041Sbinkertn@umich.edu if (DTRACE(x)) \ 1244041Sbinkertn@umich.edu Trace::dprintf((Tick)-1, std::string(), __VA_ARGS__); \ 1252SN/A} while (0) 1262SN/A 1274046Sbinkertn@umich.edu#define DDUMPN(data, count) do { \ 1287823Ssteve.reinhardt@amd.com Trace::dump(curTick(), name(), data, count); \ 1294046Sbinkertn@umich.edu} while (0) 1304046Sbinkertn@umich.edu 1314041Sbinkertn@umich.edu#define DPRINTFN(...) do { \ 1327823Ssteve.reinhardt@amd.com Trace::dprintf(curTick(), name(), __VA_ARGS__); \ 1332SN/A} while (0) 1342SN/A 1354041Sbinkertn@umich.edu#define DPRINTFNR(...) do { \ 1364041Sbinkertn@umich.edu Trace::dprintf((Tick)-1, string(), __VA_ARGS__); \ 137507SN/A} while (0) 138507SN/A 1392SN/A#else // !TRACING_ON 1402SN/A 1412SN/A#define DTRACE(x) (false) 1424046Sbinkertn@umich.edu#define DDUMP(x, data, count) do {} while (0) 1434041Sbinkertn@umich.edu#define DPRINTF(x, ...) do {} while (0) 1445806Ssaidi@eecs.umich.edu#define DPRINTFS(x, ...) do {} while (0) 1454041Sbinkertn@umich.edu#define DPRINTFR(...) do {} while (0) 1464046Sbinkertn@umich.edu#define DDUMPN(data, count) do {} while (0) 1474041Sbinkertn@umich.edu#define DPRINTFN(...) do {} while (0) 1484041Sbinkertn@umich.edu#define DPRINTFNR(...) do {} while (0) 1492SN/A 1505543Ssaidi@eecs.umich.edu#endif // TRACING_ON 1512SN/A 1521354SN/A#endif // __BASE_TRACE_HH__ 153