trace.cc (10292:933dfb9d8279) | trace.cc (10475:5744891a444b) |
---|---|
1/* | 1/* |
2 * Copyright (c) 2014 ARM Limited 3 * All rights reserved 4 * |
|
2 * Copyright (c) 2001-2006 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; 9 * redistributions in binary form must reproduce the above copyright --- 12 unchanged lines hidden (view full) --- 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 * Authors: Nathan Binkert 29 * Steve Reinhardt | 5 * Copyright (c) 2001-2006 The Regents of The University of Michigan 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions are 10 * met: redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer; 12 * redistributions in binary form must reproduce the above copyright --- 12 unchanged lines hidden (view full) --- 25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 * 31 * Authors: Nathan Binkert 32 * Steve Reinhardt |
33 * Andrew Bardsley |
|
30 */ 31 32#include <cctype> 33#include <fstream> 34#include <iostream> | 34 */ 35 36#include <cctype> 37#include <fstream> 38#include <iostream> |
39#include <sstream> |
|
35#include <string> 36 37#include "base/misc.hh" 38#include "base/output.hh" 39#include "base/str.hh" 40#include "base/trace.hh" 41 | 40#include <string> 41 42#include "base/misc.hh" 43#include "base/output.hh" 44#include "base/str.hh" 45#include "base/trace.hh" 46 |
42using namespace std; | 47const std::string &name() 48{ 49 static const std::string default_name("global"); |
43 | 50 |
44namespace Trace { | 51 return default_name; 52} |
45 | 53 |
46const string DefaultName("global"); | 54namespace Trace 55{ 56 |
47bool enabled = false; 48 | 57bool enabled = false; 58 |
49// 50// This variable holds the output stream for debug information. Other 51// than setting up/redirecting this stream, do *NOT* reference this 52// directly; use DebugOut() (see below) to access this stream for 53// output. 54// 55ostream *dprintf_stream = &cerr; 56ostream & | 59// This variable holds the output logger for debug information. Other 60// than setting up/redirecting this logger, do *NOT* reference this 61// directly 62 63Logger *debug_logger = NULL; 64 65Logger * 66getDebugLogger() 67{ 68 /* Set a default logger to cerr when no other logger is set */ 69 if (!debug_logger) 70 debug_logger = new OstreamLogger(std::cerr); 71 72 return debug_logger; 73} 74 75std::ostream & |
57output() 58{ | 76output() 77{ |
59 return *dprintf_stream; | 78 return getDebugLogger()->getOstream(); |
60} 61 62void | 79} 80 81void |
63setOutput(const string &filename) | 82setDebugLogger(Logger *logger) |
64{ | 83{ |
65 dprintf_stream = simout.find(filename); 66 if (!dprintf_stream) 67 dprintf_stream = simout.create(filename); | 84 if (!logger) 85 warn("Trying to set debug logger to NULL\n"); 86 else 87 debug_logger = logger; |
68} 69 70ObjectMatch ignore; 71 | 88} 89 90ObjectMatch ignore; 91 |
72 73bool 74__dprintf_prologue(Tick when, const std::string &name) | 92void 93Logger::dump(Tick when, const std::string &name, const void *d, int len) |
75{ 76 if (!name.empty() && ignore.match(name)) | 94{ 95 if (!name.empty() && ignore.match(name)) |
77 return false; | 96 return; |
78 | 97 |
79 std::ostream &os = *dprintf_stream; 80 81 if (when != MaxTick) 82 ccprintf(os, "%7d: ", when); 83 84 if (!name.empty()) 85 os << name << ": "; 86 87 return true; 88} 89 90void 91dump(Tick when, const std::string &name, const void *d, int len) 92{ | |
93 const char *data = static_cast<const char *>(d); | 98 const char *data = static_cast<const char *>(d); |
94 std::ostream &os = *dprintf_stream; | |
95 int c, i, j; 96 97 for (i = 0; i < len; i += 16) { | 99 int c, i, j; 100 101 for (i = 0; i < len; i += 16) { |
98 if (!__dprintf_prologue(when, name)) 99 return; | 102 std::ostringstream line; |
100 | 103 |
101 ccprintf(os, "%08x ", i); | 104 ccprintf(line, "%08x ", i); |
102 c = len - i; 103 if (c > 16) c = 16; 104 105 for (j = 0; j < c; j++) { | 105 c = len - i; 106 if (c > 16) c = 16; 107 108 for (j = 0; j < c; j++) { |
106 ccprintf(os, "%02x ", data[i + j] & 0xff); | 109 ccprintf(line, "%02x ", data[i + j] & 0xff); |
107 if ((j & 0xf) == 7 && j > 0) | 110 if ((j & 0xf) == 7 && j > 0) |
108 ccprintf(os, " "); | 111 ccprintf(line, " "); |
109 } 110 111 for (; j < 16; j++) | 112 } 113 114 for (; j < 16; j++) |
112 ccprintf(os, " "); 113 ccprintf(os, " "); | 115 ccprintf(line, " "); 116 ccprintf(line, " "); |
114 115 for (j = 0; j < c; j++) { 116 int ch = data[i + j] & 0x7f; | 117 118 for (j = 0; j < c; j++) { 119 int ch = data[i + j] & 0x7f; |
117 ccprintf(os, "%c", (char)(isprint(ch) ? ch : ' ')); | 120 ccprintf(line, "%c", (char)(isprint(ch) ? ch : ' ')); |
118 } 119 | 121 } 122 |
120 ccprintf(os, "\n"); | 123 ccprintf(line, "\n"); 124 logMessage(when, name, line.str()); |
121 122 if (c < 16) 123 break; 124 } 125} 126 | 125 126 if (c < 16) 127 break; 128 } 129} 130 |
131void 132OstreamLogger::logMessage(Tick when, const std::string &name, 133 const std::string &message) 134{ 135 if (!name.empty() && ignore.match(name)) 136 return; 137 138 if (when != MaxTick) 139 ccprintf(stream, "%7d: ", when); 140 141 if (!name.empty()) 142 stream << name << ": "; 143 144 stream << message; 145 stream.flush(); 146} 147 |
|
127} // namespace Trace | 148} // namespace Trace |