gem5  v21.1.0.2
trace.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014, 2019 ARM Limited
3  * All rights reserved
4  *
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
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution;
15  * neither the name of the copyright holders nor the names of its
16  * contributors may be used to endorse or promote products derived from
17  * this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
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 
32 #include "base/trace.hh"
33 
34 #include <cctype>
35 #include <fstream>
36 #include <iostream>
37 #include <sstream>
38 
39 #include "base/atomicio.hh"
40 #include "base/logging.hh"
41 #include "base/output.hh"
42 #include "base/str.hh"
43 #include "debug/FmtFlag.hh"
44 #include "debug/FmtStackTrace.hh"
45 #include "debug/FmtTicksOff.hh"
46 #include "sim/backtrace.hh"
47 
48 const std::string &
50 {
51  static const std::string default_name("global");
52 
53  return default_name;
54 }
55 
56 namespace gem5
57 {
58 
59 namespace Trace
60 {
61 
62 // This variable holds the output logger for debug information. Other
63 // than setting up/redirecting this logger, do *NOT* reference this
64 // directly
65 
67 
68 Logger *
70 {
71  /* Set a default logger to cerr when no other logger is set */
72  if (!debug_logger)
73  debug_logger = new OstreamLogger(std::cerr);
74 
75  return debug_logger;
76 }
77 
78 std::ostream &
80 {
81  return getDebugLogger()->getOstream();
82 }
83 
84 void
86 {
87  if (!logger)
88  warn("Trying to set debug logger to NULL\n");
89  else
90  debug_logger = logger;
91 }
92 
93 void
95 {
97 }
98 
99 void
101 {
103 }
104 
106 
107 
108 void
109 Logger::dump(Tick when, const std::string &name,
110  const void *d, int len, const std::string &flag)
111 {
112  if (!name.empty() && ignore.match(name))
113  return;
114 
115  const char *data = static_cast<const char *>(d);
116  int c, i, j;
117 
118  for (i = 0; i < len; i += 16) {
119  std::ostringstream line;
120 
121  ccprintf(line, "%08x ", i);
122  c = len - i;
123  if (c > 16) c = 16;
124 
125  for (j = 0; j < c; j++) {
126  ccprintf(line, "%02x ", data[i + j] & 0xff);
127  if ((j & 0xf) == 7 && j > 0)
128  ccprintf(line, " ");
129  }
130 
131  for (; j < 16; j++)
132  ccprintf(line, " ");
133  ccprintf(line, " ");
134 
135  for (j = 0; j < c; j++) {
136  int ch = data[i + j] & 0x7f;
137  ccprintf(line, "%c", (char)(isprint(ch) ? ch : ' '));
138  }
139 
140  ccprintf(line, "\n");
141  logMessage(when, name, flag, line.str());
142 
143  if (c < 16)
144  break;
145  }
146 }
147 
148 void
149 OstreamLogger::logMessage(Tick when, const std::string &name,
150  const std::string &flag, const std::string &message)
151 {
152  if (!name.empty() && ignore.match(name))
153  return;
154 
155  if (!debug::FmtTicksOff && (when != MaxTick))
156  ccprintf(stream, "%7d: ", when);
157 
158  if (debug::FmtFlag && !flag.empty())
159  stream << flag << ": ";
160 
161  if (!name.empty())
162  stream << name << ": ";
163 
164  stream << message;
165  stream.flush();
166 
167  if (debug::FmtStackTrace) {
168  print_backtrace();
169  STATIC_ERR("\n");
170  }
171 }
172 
173 } // namespace Trace
174 } // namespace gem5
gem5::ObjectMatch
ObjectMatch contains a vector of expressions.
Definition: match.hh:56
gem5::Trace::disable
void disable()
Definition: trace.cc:100
gem5::ArmISA::len
Bitfield< 18, 16 > len
Definition: misc_types.hh:444
warn
#define warn(...)
Definition: logging.hh:245
gem5::debug::Flag::globalDisable
static void globalDisable()
Definition: debug.cc:123
gem5::Trace::Logger::logMessage
virtual void logMessage(Tick when, const std::string &name, const std::string &flag, const std::string &message)=0
Log formatted message.
data
const char data[]
Definition: circlebuf.test.cc:48
atomicio.hh
gem5::ObjectMatch::match
bool match(const std::string &name) const
Definition: match.hh:69
gem5::debug::Flag::globalEnable
static void globalEnable()
Definition: debug.cc:115
gem5::Trace::getDebugLogger
Logger * getDebugLogger()
Get the current global debug logger.
Definition: trace.cc:69
gem5::MaxTick
const Tick MaxTick
Definition: types.hh:60
gem5::Trace::ignore
ObjectMatch ignore
Definition: trace.cc:105
gem5::ArmISA::i
Bitfield< 7 > i
Definition: misc_types.hh:66
output.hh
gem5::ccprintf
void ccprintf(cp::Print &print)
Definition: cprintf.hh:130
str.hh
gem5::Trace::debug_logger
Logger * debug_logger
Definition: trace.cc:66
STATIC_ERR
#define STATIC_ERR(m)
Statically allocate a string and write it to STDERR.
Definition: atomicio.hh:67
gem5::ArmISA::j
Bitfield< 24 > j
Definition: misc_types.hh:57
gem5::ArmISA::d
Bitfield< 9 > d
Definition: misc_types.hh:63
gem5::Tick
uint64_t Tick
Tick count type.
Definition: types.hh:58
gem5::Trace::Logger::getOstream
virtual std::ostream & getOstream()=0
Return an ostream that can be used to send messages to the 'same place' as formatted logMessage messa...
gem5::Trace::Logger
Debug logging base class.
Definition: trace.hh:58
gem5::Trace::OstreamLogger::logMessage
void logMessage(Tick when, const std::string &name, const std::string &flag, const std::string &message) override
Log formatted message.
Definition: trace.cc:149
gem5::Trace::Logger::ignore
ObjectMatch ignore
Name match for objects to ignore.
Definition: trace.hh:62
gem5::Trace::output
std::ostream & output()
Get the ostream from the current global logger.
Definition: trace.cc:79
gem5::ArmISA::c
Bitfield< 29 > c
Definition: misc_types.hh:53
name
const std::string & name()
Definition: trace.cc:49
gem5::Trace::OstreamLogger
Logging wrapper for ostreams with the format: <when>: <name>: <message-body>
Definition: trace.hh:112
logging.hh
gem5::Trace::setDebugLogger
void setDebugLogger(Logger *logger)
Delete the current global logger and assign a new one.
Definition: trace.cc:85
trace.hh
gem5::Trace::enable
void enable()
Enable/disable debug logging.
Definition: trace.cc:94
gem5::Trace::Logger::dump
void dump(Tick when, const std::string &name, const void *d, int len, const std::string &flag)
Dump a block of data of length len.
Definition: trace.cc:109
gem5::Trace::OstreamLogger::stream
std::ostream & stream
Definition: trace.hh:115
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::print_backtrace
void print_backtrace()
Print a gem5 post-mortem report.
Definition: backtrace_glibc.cc:54
backtrace.hh

Generated on Tue Sep 21 2021 12:25:00 for gem5 by doxygen 1.8.17