2 * Copyright (c) 2014, 2019 ARM Limited
5 * Copyright (c) 2001-2006 The Regents of The University of Michigan
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.
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.
32 #include "base/trace.hh"
40 #include "base/atomicio.hh"
41 #include "base/debug.hh"
42 #include "base/logging.hh"
43 #include "base/output.hh"
44 #include "base/str.hh"
45 #include "debug/FmtFlag.hh"
46 #include "debug/FmtStackTrace.hh"
47 #include "debug/FmtTicksOff.hh"
48 #include "sim/backtrace.hh"
50 const std::string
&name()
52 static const std::string
default_name("global");
60 // This variable holds the output logger for debug information. Other
61 // than setting up/redirecting this logger, do *NOT* reference this
64 Logger
*debug_logger
= NULL
;
69 /* Set a default logger to cerr when no other logger is set */
71 debug_logger
= new OstreamLogger(std::cerr
);
79 return getDebugLogger()->getOstream();
83 setDebugLogger(Logger
*logger
)
86 warn("Trying to set debug logger to NULL\n");
88 debug_logger
= logger
;
94 Debug::Flag::globalEnable();
100 Debug::Flag::globalDisable();
107 Logger::dump(Tick when
, const std::string
&name
,
108 const void *d
, int len
, const std::string
&flag
)
110 if (!name
.empty() && ignore
.match(name
))
113 const char *data
= static_cast<const char *>(d
);
116 for (i
= 0; i
< len
; i
+= 16) {
117 std::ostringstream line
;
119 ccprintf(line
, "%08x ", i
);
123 for (j
= 0; j
< c
; j
++) {
124 ccprintf(line
, "%02x ", data
[i
+ j
] & 0xff);
125 if ((j
& 0xf) == 7 && j
> 0)
133 for (j
= 0; j
< c
; j
++) {
134 int ch
= data
[i
+ j
] & 0x7f;
135 ccprintf(line
, "%c", (char)(isprint(ch
) ? ch
: ' '));
138 ccprintf(line
, "\n");
139 logMessage(when
, name
, flag
, line
.str());
147 OstreamLogger::logMessage(Tick when
, const std::string
&name
,
148 const std::string
&flag
, const std::string
&message
)
150 if (!name
.empty() && ignore
.match(name
))
153 if (!DTRACE(FmtTicksOff
) && (when
!= MaxTick
))
154 ccprintf(stream
, "%7d: ", when
);
156 if (DTRACE(FmtFlag
) && !flag
.empty())
157 stream
<< flag
<< ": ";
160 stream
<< name
<< ": ";
165 if (DTRACE(FmtStackTrace
)) {