From eddac53ff60c579eff28134bde84783fe36d6214 Mon Sep 17 00:00:00 2001 From: Nathan Binkert Date: Fri, 15 Apr 2011 10:44:32 -0700 Subject: trace: reimplement the DTRACE function so it doesn't use a vector At the same time, rename the trace flags to debug flags since they have broader usage than simply tracing. This means that --trace-flags is now --debug-flags and --trace-help is now --debug-help --- src/base/debug.cc | 135 ++++++++++++++++++++++++++++++++++++++++ src/base/debug.hh | 75 ++++++++++++++++++++++ src/base/loader/aout_object.cc | 1 + src/base/loader/ecoff_object.cc | 1 + src/base/loader/elf_object.cc | 1 + src/base/loader/raw_object.cc | 1 + src/base/mysql.cc | 1 + src/base/remote_gdb.cc | 2 + src/base/trace.cc | 63 +------------------ src/base/trace.hh | 20 +++--- src/base/vnc/vncserver.cc | 1 + 11 files changed, 230 insertions(+), 71 deletions(-) (limited to 'src/base') diff --git a/src/base/debug.cc b/src/base/debug.cc index 6f01b3fc0..be301da07 100644 --- a/src/base/debug.cc +++ b/src/base/debug.cc @@ -31,12 +31,24 @@ #include #include +#include #include +#include +#include #include "base/cprintf.hh" +#include "base/debug.hh" +#include "base/misc.hh" + +using namespace std; namespace Debug { +// +// This function will cause the process to signal itself with a +// SIGTRAP which is ignored if not in gdb, but will cause the debugger +// to break if in gdb. +// void breakpoint() { @@ -47,4 +59,127 @@ breakpoint() #endif } +// +// Flags for debugging purposes. Primarily for trace.hh +// +typedef std::map FlagsMap; +int allFlagsVersion = 0; +FlagsMap & +allFlags() +{ + static FlagsMap flags; + return flags; +} + +Flag * +findFlag(const std::string &name) +{ + FlagsMap::iterator i = allFlags().find(name); + if (i == allFlags().end()) + return NULL; + return i->second; +} + +Flag::Flag(const char *name, const char *desc) + : _name(name), _desc(desc) +{ + pair result = + allFlags().insert(make_pair(name, this)); + + if (!result.second) + panic("Flag %s already defined!", name); + + ++allFlagsVersion; +} + +Flag::~Flag() +{ + // should find and remove flag. +} + +void +CompoundFlag::enable() +{ + SimpleFlag::enable(); + for_each(flags.begin(), flags.end(), mem_fun(&Flag::enable)); +} + +void +CompoundFlag::disable() +{ + SimpleFlag::disable(); + for_each(flags.begin(), flags.end(), mem_fun(&Flag::disable)); +} + +struct AllFlags : public Flag +{ + AllFlags() + : Flag("All", "All Flags") + {} + + void + enable() + { + FlagsMap::iterator i = allFlags().begin(); + FlagsMap::iterator end = allFlags().end(); + for (; i != end; ++i) + if (i->second != this) + i->second->enable(); + } + + void + disable() + { + FlagsMap::iterator i = allFlags().begin(); + FlagsMap::iterator end = allFlags().end(); + for (; i != end; ++i) + if (i->second != this) + i->second->enable(); + } +}; + +AllFlags theAllFlags; +Flag *const All = &theAllFlags; + +bool +changeFlag(const char *s, bool value) +{ + Flag *f = findFlag(s); + if (!f) + return false; + + if (value) + f->enable(); + else + f->disable(); + + return true; +} + } // namespace Debug + +// add a set of functions that can easily be invoked from gdb +void +setDebugFlag(const char *string) +{ + Debug::changeFlag(string, true); +} + +void +clearDebugFlag(const char *string) +{ + Debug::changeFlag(string, false); +} + +void +dumpDebugFlags() +{ + using namespace Debug; + FlagsMap::iterator i = allFlags().begin(); + FlagsMap::iterator end = allFlags().end(); + for (; i != end; ++i) { + SimpleFlag *f = dynamic_cast(i->second); + if (f && f->status()) + cprintf("%s\n", f->name()); + } +} diff --git a/src/base/debug.hh b/src/base/debug.hh index ee7402912..ced6b4f48 100644 --- a/src/base/debug.hh +++ b/src/base/debug.hh @@ -1,5 +1,6 @@ /* * Copyright (c) 2003-2005 The Regents of The University of Michigan + * Copyright (c) 2010 The Hewlett-Packard Development Company * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -31,10 +32,84 @@ #ifndef __BASE_DEBUG_HH__ #define __BASE_DEBUG_HH__ +#include +#include + namespace Debug { void breakpoint(); +class Flag +{ + protected: + const char *_name; + const char *_desc; + + public: + Flag(const char *name, const char *desc); + virtual ~Flag(); + + std::string name() const { return _name; } + std::string desc() const { return _desc; } + + virtual void enable() = 0; + virtual void disable() = 0; +}; + +class SimpleFlag : public Flag +{ + protected: + bool _status; + + public: + SimpleFlag(const char *name, const char *desc) + : Flag(name, desc) + { } + + bool status() const { return _status; } + operator bool() const { return _status; } + bool operator!() const { return !_status; } + + void enable() { _status = true; } + void disable() { _status = false; } +}; + +class CompoundFlag : public SimpleFlag +{ + protected: + std::vector flags; + + public: + CompoundFlag(const char *name, const char *desc, + Flag &f00 = *(Flag *)0, Flag &f01 = *(Flag *)0, + Flag &f02 = *(Flag *)0, Flag &f03 = *(Flag *)0, + Flag &f04 = *(Flag *)0, Flag &f05 = *(Flag *)0, + Flag &f06 = *(Flag *)0, Flag &f07 = *(Flag *)0, + Flag &f08 = *(Flag *)0, Flag &f09 = *(Flag *)0, + Flag &f10 = *(Flag *)0, Flag &f11 = *(Flag *)0, + Flag &f12 = *(Flag *)0, Flag &f13 = *(Flag *)0, + Flag &f14 = *(Flag *)0, Flag &f15 = *(Flag *)0, + Flag &f16 = *(Flag *)0, Flag &f17 = *(Flag *)0, + Flag &f18 = *(Flag *)0, Flag &f19 = *(Flag *)0) + : SimpleFlag(name, desc) + { + addFlag(f00); addFlag(f01); addFlag(f02); addFlag(f03); addFlag(f04); + addFlag(f05); addFlag(f06); addFlag(f07); addFlag(f08); addFlag(f09); + addFlag(f10); addFlag(f11); addFlag(f12); addFlag(f13); addFlag(f14); + addFlag(f15); addFlag(f16); addFlag(f17); addFlag(f18); addFlag(f19); + } + + void + addFlag(Flag &f) + { + if (&f != NULL) + flags.push_back(&f); + } + + void enable(); + void disable(); +}; + } // namespace Debug #endif // __BASE_DEBUG_HH__ diff --git a/src/base/loader/aout_object.cc b/src/base/loader/aout_object.cc index 31a6a2868..756f03a9e 100644 --- a/src/base/loader/aout_object.cc +++ b/src/base/loader/aout_object.cc @@ -34,6 +34,7 @@ #include "base/loader/exec_aout.h" #include "base/loader/symtab.hh" #include "base/trace.hh" +#include "debug/Loader.hh" using namespace std; diff --git a/src/base/loader/ecoff_object.cc b/src/base/loader/ecoff_object.cc index 2027a2e1e..263085d16 100644 --- a/src/base/loader/ecoff_object.cc +++ b/src/base/loader/ecoff_object.cc @@ -35,6 +35,7 @@ #include "base/misc.hh" #include "base/trace.hh" #include "base/types.hh" +#include "debug/Loader.hh" // Only alpha will be able to load ecoff files for now. // base/types.hh and ecoff_machdep.h must be before the other .h files diff --git a/src/base/loader/elf_object.cc b/src/base/loader/elf_object.cc index 22316c0d6..6fcbd0ae3 100644 --- a/src/base/loader/elf_object.cc +++ b/src/base/loader/elf_object.cc @@ -37,6 +37,7 @@ #include "base/bitfield.hh" #include "base/misc.hh" #include "base/trace.hh" +#include "debug/Loader.hh" #include "sim/byteswap.hh" #include "gelf.h" diff --git a/src/base/loader/raw_object.cc b/src/base/loader/raw_object.cc index d002d9005..eb1e06d3f 100644 --- a/src/base/loader/raw_object.cc +++ b/src/base/loader/raw_object.cc @@ -31,6 +31,7 @@ #include "base/loader/raw_object.hh" #include "base/loader/symtab.hh" #include "base/trace.hh" +#include "debug/Loader.hh" ObjectFile * RawObject::tryFile(const std::string &fname, int fd, size_t len, uint8_t *data) diff --git a/src/base/mysql.cc b/src/base/mysql.cc index 3216bcf43..a029c13b5 100644 --- a/src/base/mysql.cc +++ b/src/base/mysql.cc @@ -32,6 +32,7 @@ #include "base/mysql.hh" #include "base/trace.hh" +#include "debug/SQL.hh" using namespace std; diff --git a/src/base/remote_gdb.cc b/src/base/remote_gdb.cc index 02ee8e331..01e50824e 100644 --- a/src/base/remote_gdb.cc +++ b/src/base/remote_gdb.cc @@ -136,11 +136,13 @@ #include "config/the_isa.hh" #include "cpu/static_inst.hh" #include "cpu/thread_context.hh" +#include "debug/GDBAll.hh" #include "mem/port.hh" #include "mem/translating_port.hh" #include "sim/system.hh" using namespace std; +using namespace Debug; using namespace TheISA; #ifndef NDEBUG diff --git a/src/base/trace.cc b/src/base/trace.cc index 7783b6d42..1a035d400 100644 --- a/src/base/trace.cc +++ b/src/base/trace.cc @@ -32,9 +32,7 @@ #include #include #include -#include #include -#include #include "base/misc.hh" #include "base/output.hh" @@ -45,8 +43,8 @@ using namespace std; namespace Trace { + const string DefaultName("global"); -FlagVec flags(NumFlags, false); bool enabled = false; // @@ -149,63 +147,4 @@ dump(Tick when, const std::string &name, const void *d, int len) } } -bool -changeFlag(const char *s, bool value) -{ - using namespace Trace; - std::string str(s); - - for (int i = 0; i < numFlagStrings; ++i) { - if (str != flagStrings[i]) - continue; - - if (i < NumFlags) { - flags[i] = value; - } else { - i -= NumFlags; - - const Flags *flagVec = compoundFlags[i]; - for (int j = 0; flagVec[j] != -1; ++j) { - if (flagVec[j] < NumFlags) - flags[flagVec[j]] = value; - } - } - - return true; - } - - // the flag was not found. - return false; -} - -void -dumpStatus() -{ - using namespace Trace; - for (int i = 0; i < numFlagStrings; ++i) { - if (flags[i]) - cprintf("%s\n", flagStrings[i]); - } -} - } // namespace Trace - - -// add a set of functions that can easily be invoked from gdb -void -setTraceFlag(const char *string) -{ - Trace::changeFlag(string, true); -} - -void -clearTraceFlag(const char *string) -{ - Trace::changeFlag(string, false); -} - -void -dumpTraceStatus() -{ - Trace::dumpStatus(); -} diff --git a/src/base/trace.hh b/src/base/trace.hh index a03a34018..dbeffdc8b 100644 --- a/src/base/trace.hh +++ b/src/base/trace.hh @@ -33,23 +33,22 @@ #define __BASE_TRACE_HH__ #include -#include #include "base/cprintf.hh" +#include "base/debug.hh" #include "base/match.hh" -#include "base/traceflags.hh" #include "base/types.hh" #include "sim/core.hh" namespace Trace { +using Debug::SimpleFlag; +using Debug::CompoundFlag; + std::ostream &output(); void setOutput(const std::string &filename); extern bool enabled; -typedef std::vector FlagVec; -extern FlagVec flags; -inline bool IsOn(int t) { return flags[t]; } bool changeFlag(const char *str, bool value); void dumpStatus(); @@ -85,25 +84,28 @@ inline const std::string &name() { return Trace::DefaultName; } #if TRACING_ON -#define DTRACE(x) (Trace::IsOn(Trace::x) && Trace::enabled) +#define DTRACE(x) ((Debug::x) && Trace::enabled) #define DDUMP(x, data, count) do { \ + using namespace Debug; \ if (DTRACE(x)) \ Trace::dump(curTick(), name(), data, count); \ } while (0) #define DPRINTF(x, ...) do { \ + using namespace Debug; \ if (DTRACE(x)) \ Trace::dprintf(curTick(), name(), __VA_ARGS__); \ } while (0) -#define DPRINTFS(x,s, ...) do { \ +#define DPRINTFS(x, s, ...) do { \ + using namespace Debug; \ if (DTRACE(x)) \ - Trace::dprintf(curTick(), s->name(), __VA_ARGS__); \ + Trace::dprintf(curTick(), s->name(), __VA_ARGS__); \ } while (0) - #define DPRINTFR(x, ...) do { \ + using namespace Debug; \ if (DTRACE(x)) \ Trace::dprintf((Tick)-1, std::string(), __VA_ARGS__); \ } while (0) diff --git a/src/base/vnc/vncserver.cc b/src/base/vnc/vncserver.cc index 84e1a20e1..18e581bfe 100644 --- a/src/base/vnc/vncserver.cc +++ b/src/base/vnc/vncserver.cc @@ -55,6 +55,7 @@ #include "base/misc.hh" #include "base/socket.hh" #include "base/trace.hh" +#include "debug/VNC.hh" #include "sim/byteswap.hh" using namespace std; -- cgit v1.2.3