gem5 v24.0.0.0
Loading...
Searching...
No Matches
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
47const std::string &
49{
50 static const std::string default_name("global");
51
52 return default_name;
53}
54
55namespace gem5
56{
57
58namespace 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
67Logger *
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
77std::ostream &
79{
80 return getDebugLogger()->getOstream();
81}
82
83void
85{
86 if (!logger)
87 warn("Trying to set debug logger to NULL\n");
88 else
89 debug_logger = logger;
90}
91
92void
97
98void
103
105
106
107void
108Logger::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
147void
148OstreamLogger::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) {
168 STATIC_ERR("\n");
169 }
170}
171
172} // namespace trace
173} // namespace gem5
#define STATIC_ERR(m)
Statically allocate a string and write it to STDERR.
Definition atomicio.hh:67
const char data[]
ObjectMatch contains a vector of expressions.
Definition match.hh:57
static void globalEnable()
Definition debug.cc:117
static void globalDisable()
Definition debug.cc:125
Debug logging base class.
Definition trace.hh:60
bool isEnabled(const std::string &name) const
Definition trace.hh:67
virtual std::ostream & getOstream()=0
Return an ostream that can be used to send messages to the 'same place' as formatted logMessage messa...
virtual void logMessage(Tick when, const std::string &name, const std::string &flag, const std::string &message)=0
Log formatted message.
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 wrapper for ostreams with the format: <when>: <name>: <message-body>
Definition trace.hh:137
void logMessage(Tick when, const std::string &name, const std::string &flag, const std::string &message) override
Log formatted message.
Definition trace.cc:148
std::ostream & stream
Definition trace.hh:139
#define warn(...)
Definition logging.hh:256
Bitfield< 18, 16 > len
Bitfield< 7 > i
Definition misc_types.hh:67
Bitfield< 29 > c
Definition misc_types.hh:53
Bitfield< 9 > d
Definition misc_types.hh:64
void enable()
Enable/disable debug logging.
Definition trace.cc:93
ObjectMatch ignore
Definition trace.cc:104
void setDebugLogger(Logger *logger)
Delete the current global logger and assign a new one.
Definition trace.cc:84
void disable()
Definition trace.cc:99
Logger * getDebugLogger()
Get the current global debug logger.
Definition trace.cc:68
Logger * debug_logger
Definition trace.cc:65
std::ostream & output()
Get the ostream from the current global logger.
Definition trace.cc:78
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
void print_backtrace()
Print a gem5 post-mortem report.
uint64_t Tick
Tick count type.
Definition types.hh:58
const Tick MaxTick
Definition types.hh:60
void ccprintf(cp::Print &print)
Definition cprintf.hh:130
const std::string & name()
Definition trace.cc:48

Generated on Tue Jun 18 2024 16:24:01 for gem5 by doxygen 1.11.0