gem5  [DEVELOP-FOR-23.0]
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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/str.hh"
42 #include "debug/FmtFlag.hh"
43 #include "debug/FmtStackTrace.hh"
44 #include "debug/FmtTicksOff.hh"
45 #include "sim/backtrace.hh"
46 
47 const std::string &
49 {
50  static const std::string default_name("global");
51 
52  return default_name;
53 }
54 
55 namespace gem5
56 {
57 
58 namespace trace
59 {
60 
61 // This variable holds the output logger for debug information. Other
62 // than setting up/redirecting this logger, do *NOT* reference this
63 // directly
64 
66 
67 Logger *
69 {
70  /* Set a default logger to cerr when no other logger is set */
71  if (!debug_logger)
72  debug_logger = new OstreamLogger(std::cerr);
73 
74  return debug_logger;
75 }
76 
77 std::ostream &
79 {
80  return getDebugLogger()->getOstream();
81 }
82 
83 void
85 {
86  if (!logger)
87  warn("Trying to set debug logger to NULL\n");
88  else
89  debug_logger = logger;
90 }
91 
92 void
94 {
96 }
97 
98 void
100 {
102 }
103 
105 
106 
107 void
108 Logger::dump(Tick when, const std::string &name,
109  const void *d, int len, const std::string &flag)
110 {
111  if (!isEnabled(name))
112  return;
113 
114  const char *data = static_cast<const char *>(d);
115  int c, i, j;
116 
117  for (i = 0; i < len; i += 16) {
118  std::ostringstream line;
119 
120  ccprintf(line, "%08x ", i);
121  c = len - i;
122  if (c > 16) c = 16;
123 
124  for (j = 0; j < c; j++) {
125  ccprintf(line, "%02x ", data[i + j] & 0xff);
126  if ((j & 0xf) == 7 && j > 0)
127  ccprintf(line, " ");
128  }
129 
130  for (; j < 16; j++)
131  ccprintf(line, " ");
132  ccprintf(line, " ");
133 
134  for (j = 0; j < c; j++) {
135  int ch = data[i + j] & 0x7f;
136  ccprintf(line, "%c", (char)(isprint(ch) ? ch : ' '));
137  }
138 
139  ccprintf(line, "\n");
140  logMessage(when, name, flag, line.str());
141 
142  if (c < 16)
143  break;
144  }
145 }
146 
147 void
148 OstreamLogger::logMessage(Tick when, const std::string &name,
149  const std::string &flag, const std::string &message)
150 {
151  if (!isEnabled(name))
152  return;
153 
154  if (!debug::FmtTicksOff && (when != MaxTick))
155  ccprintf(stream, "%7d: ", when);
156 
157  if (debug::FmtFlag && !flag.empty())
158  stream << flag << ": ";
159 
160  if (!name.empty())
161  stream << name << ": ";
162 
163  stream << message;
164  stream.flush();
165 
166  if (debug::FmtStackTrace) {
167  print_backtrace();
168  STATIC_ERR("\n");
169  }
170 }
171 
172 } // namespace trace
173 } // namespace gem5
gem5::ObjectMatch
ObjectMatch contains a vector of expressions.
Definition: match.hh:56
gem5::trace::ignore
ObjectMatch ignore
Definition: trace.cc:104
warn
#define warn(...)
Definition: logging.hh:256
gem5::debug::Flag::globalDisable
static void globalDisable()
Definition: debug.cc:125
data
const char data[]
Definition: circlebuf.test.cc:48
atomicio.hh
gem5::debug::Flag::globalEnable
static void globalEnable()
Definition: debug.cc:117
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.
gem5::MaxTick
const Tick MaxTick
Definition: types.hh:60
gem5::ArmISA::i
Bitfield< 7 > i
Definition: misc_types.hh:67
gem5::ccprintf
void ccprintf(cp::Print &print)
Definition: cprintf.hh:130
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:148
str.hh
gem5::VegaISA::c
Bitfield< 2 > c
Definition: pagetable.hh:63
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:64
gem5::trace::Logger::isEnabled
bool isEnabled(const std::string &name) const
Definition: trace.hh:67
gem5::Tick
uint64_t Tick
Tick count type.
Definition: types.hh:58
len
uint16_t len
Definition: helpers.cc:62
gem5::trace::OstreamLogger
Logging wrapper for ostreams with the format: <when>: <name>: <message-body>
Definition: trace.hh:136
name
const std::string & name()
Definition: trace.cc:48
gem5::trace::getDebugLogger
Logger * getDebugLogger()
Get the current global debug logger.
Definition: trace.cc:68
gem5::trace::output
std::ostream & output()
Get the ostream from the current global logger.
Definition: trace.cc:78
gem5::trace::OstreamLogger::stream
std::ostream & stream
Definition: trace.hh:139
gem5::trace::debug_logger
Logger * debug_logger
Definition: trace.cc:65
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:108
logging.hh
gem5::trace::setDebugLogger
void setDebugLogger(Logger *logger)
Delete the current global logger and assign a new one.
Definition: trace.cc:84
trace.hh
gem5::trace::Logger
Debug logging base class.
Definition: trace.hh:59
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
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::trace::enable
void enable()
Enable/disable debug logging.
Definition: trace.cc:93
gem5::print_backtrace
void print_backtrace()
Print a gem5 post-mortem report.
Definition: backtrace_glibc.cc:54
backtrace.hh
gem5::trace::disable
void disable()
Definition: trace.cc:99

Generated on Sun Jul 30 2023 01:56:51 for gem5 by doxygen 1.8.17