gem5 v24.0.0.0
Loading...
Searching...
No Matches
sc_report_handler.cc
Go to the documentation of this file.
1/*
2 * Copyright 2018 Google, Inc.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met: redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer;
8 * redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution;
11 * neither the name of the copyright holders nor the names of its
12 * contributors may be used to endorse or promote products derived from
13 * this software without specific prior written permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#include <fstream>
29#include <map>
30#include <sstream>
31#include <string>
32
33#include "base/cprintf.hh"
40
41namespace sc_core
42{
43
44namespace
45{
46
47std::unique_ptr<std::string> logFileName;
48std::unique_ptr<std::ofstream> logFile;
49
50} // anonymous namespace
51
52void
53sc_report_handler::report(sc_severity severity, const char *msg_type,
54 const char *msg, const char *file, int line)
55{
56 report(severity, msg_type, msg, SC_MEDIUM, file, line);
57}
58
59void
60sc_report_handler::report(sc_severity severity, const char *msg_type,
61 const char *msg, int verbosity, const char *file,
62 int line)
63{
64 if (!msg_type)
65 msg_type = SC_ID_UNKNOWN_ERROR_;
66
67 if (severity == SC_INFO && verbosity > sc_gem5::reportVerbosityLevel)
68 return;
69
72
73 sevInfo.count++;
74 msgInfo.count++;
75 msgInfo.sevCounts[severity]++;
76
77 sc_actions actions = SC_UNSPECIFIED;
78 if (msgInfo.sevActions[severity] != SC_UNSPECIFIED)
79 actions = msgInfo.sevActions[severity];
80 else if (msgInfo.actions != SC_UNSPECIFIED)
81 actions = msgInfo.actions;
82 else if (sevInfo.actions != SC_UNSPECIFIED)
83 actions = sevInfo.actions;
84
85 actions &= ~sc_gem5::reportSuppressedActions;
87
88 msgInfo.checkLimits(severity, actions);
89 sevInfo.checkLimit(actions);
90
92 sc_report report(severity, msg_type, msg, verbosity, file, line,
94 current ? current->name() : nullptr, msgInfo.id);
95
96 if (actions & SC_CACHE_REPORT) {
97 if (current) {
98 current->lastReport(&report);
99 } else {
101 std::unique_ptr<sc_report>(new sc_report(report));
102 }
103 }
104
106
107 for (auto& handler : sc_gem5::getExtraSystemCReportHandlers()) {
108 handler(report, actions);
109 }
110}
111
112void
113sc_report_handler::report(sc_severity severity, int id, const char *msg,
114 const char *file, int line)
115{
116 std::string &msg_type = sc_gem5::reportIdToMsgMap()[id];
117
118 if (sc_gem5::reportWarningsAsErrors && severity == SC_WARNING)
119 severity = SC_ERROR;
120
121 report(severity, msg_type.c_str(), msg, file, line);
122}
123
126{
128 sc_actions previous = info.actions;
129 info.actions = actions;
130 return previous;
131}
132
134sc_report_handler::set_actions(const char *msg_type, sc_actions actions)
135{
136 if (!msg_type)
137 msg_type = SC_ID_UNKNOWN_ERROR_;
138
140 sc_actions previous = info.actions;
141 info.actions = actions;
142 return previous;
143}
144
147 const char *msg_type, sc_severity severity, sc_actions actions)
148{
149 if (!msg_type)
150 msg_type = SC_ID_UNKNOWN_ERROR_;
151
153 sc_actions previous = info.sevActions[severity];
154 info.sevActions[severity] = actions;
155 return previous;
156}
157
158int
160{
162 int previous = info.limit;
163 info.limit = limit;
164 return previous;
165}
166
167int
168sc_report_handler::stop_after(const char *msg_type, int limit)
169{
170 if (!msg_type)
171 msg_type = SC_ID_UNKNOWN_ERROR_;
172
174 int previous = info.limit;
175 info.limit = limit;
176 return previous;
177}
178
179int
181 const char *msg_type, sc_severity severity, int limit)
182{
183 if (!msg_type)
184 msg_type = SC_ID_UNKNOWN_ERROR_;
185
187 int previous = info.sevLimits[severity];
188 info.sevLimits[severity] = limit;
189 return previous;
190}
191
192int
197
198int
199sc_report_handler::get_count(const char *msg_type)
200{
201 if (!msg_type)
202 msg_type = SC_ID_UNKNOWN_ERROR_;
203
204 return sc_gem5::reportMsgInfoMap()[msg_type].count;
205}
206
207int
208sc_report_handler::get_count(const char *msg_type, sc_severity severity)
209{
210 if (!msg_type)
211 msg_type = SC_ID_UNKNOWN_ERROR_;
212
213 return sc_gem5::reportMsgInfoMap()[msg_type].sevCounts[severity];
214}
215
216int
218{
219 int previous = sc_gem5::reportVerbosityLevel;
221 return previous;
222}
223
224int
229
230
238
241{
242 return suppress(SC_UNSPECIFIED);
243}
244
247{
250 return previous;
251}
252
255{
256 return force(SC_UNSPECIFIED);
257}
258
259
262{
265 return previous;
266}
267
273
274
275void
276sc_report_handler::set_handler(sc_report_handler_proc proc)
277{
279}
280
281void
283 const sc_report &report, const sc_actions &actions)
284{
285 if (actions & SC_DISPLAY)
287
288 if ((actions & SC_LOG) && logFile) {
289 gem5::ccprintf(*logFile, "%s: %s\n", report.get_time().to_string(),
290 sc_report_compose_message(report));
291 }
292 if (actions & SC_STOP) {
293 sc_stop_here(report.get_msg_type(), report.get_severity());
294 sc_stop();
295 }
296 if (actions & SC_INTERRUPT)
297 sc_interrupt_here(report.get_msg_type(), report.get_severity());
298 if (actions & SC_ABORT)
299 sc_abort();
300 if (actions & SC_THROW) {
302 if (current)
303 current->isUnwinding(false);
304 throw report;
305 }
306}
307
310{
311 static sc_actions maxAction = SC_ABORT;
312 maxAction = maxAction << 1;
313 return maxAction;
314}
315
316sc_report *
318{
320 if (current)
321 return current->lastReport();
322 return ::sc_gem5::globalReportCache.get();
323}
324
325void
327{
329 if (current) {
330 current->lastReport(nullptr);
331 } else {
333 }
334}
335
336bool
338{
339 if (!new_name) {
340 logFile = nullptr;
341 logFileName = nullptr;
342 return false;
343 } else {
344 if (logFileName)
345 return false;
346 logFileName = std::unique_ptr<std::string>(new std::string(new_name));
347 logFile = std::unique_ptr<std::ofstream>(new std::ofstream(new_name));
348 return true;
349 }
350}
351
352const char *
354{
355 if (!logFileName)
356 return nullptr;
357 else
358 return logFileName->c_str();
359}
360
361void
362sc_interrupt_here(const char *msg_type, sc_severity)
363{
364 // Purposefully empty, for setting breakpoints supposedly.
365}
366
367void
368sc_stop_here(const char *msg_type, sc_severity)
369{
370 // Purposefully empty, for setting breakpoints supposedly.
371}
372
373const std::string
375{
376 std::ostringstream str;
377
378 const char *sevName = sc_gem5::reportSeverityNames[report.get_severity()];
379 int id = report.get_id();
380
381 str << sevName << ": ";
382 if (id >= 0) {
383 gem5::ccprintf(str, "(%c%d) ", sevName[0], id);
384 }
385 str << report.get_msg_type();
386
387 const char *msg = report.get_msg();
388 if (msg && msg[0])
389 str << ": " << msg;
390
391 if (report.get_severity() > SC_INFO) {
392 gem5::ccprintf(str, "\nIn file: %s:%d", report.get_file_name(),
393 report.get_line_number());
394
396 const char *name = report.get_process_name();
397 if (current && sc_is_running() && name) {
398 gem5::ccprintf(str, "\nIn process: %s @ %s", name,
399 report.get_time().to_string());
400 }
401 }
402
403 return str.str();
404}
405
406bool
408{
409 if (logFile) {
410 logFile = nullptr;
411 logFileName = nullptr;
412 return false;
413 }
414 return true;
415}
416
417} // namespace sc_core
const char * name() const
Definition sc_object.cc:44
static sc_report * get_cached_report()
static sc_actions set_actions(sc_severity, sc_actions=SC_UNSPECIFIED)
static int get_count(sc_severity)
static bool set_log_file_name(const char *)
static sc_actions get_new_action_id()
static void default_handler(const sc_report &, const sc_actions &)
static sc_actions get_catch_actions()
static void report(sc_severity, const char *msg_type, const char *msg, const char *file, int line)
static const char * get_log_file_name()
static int stop_after(sc_severity, int limit=-1)
static sc_actions set_catch_actions(sc_actions)
static void set_handler(sc_report_handler_proc)
const char * get_msg_type() const
Definition sc_report.hh:68
const char * get_msg() const
Definition sc_report.hh:69
int get_line_number() const
Definition sc_report.hh:72
const char * get_process_name() const
Definition sc_report.hh:75
int get_id() const
Definition sc_report.hh:87
const sc_time & get_time() const
Definition sc_report.hh:74
sc_severity get_severity() const
Definition sc_report.hh:67
const char * get_file_name() const
Definition sc_report.hh:71
static sc_time from_value(sc_dt::uint64)
Definition sc_time.cc:210
const std::string to_string() const
Definition sc_time.cc:132
bool isUnwinding() const
Definition process.hh:69
void lastReport(::sc_core::sc_report *report)
Definition process.cc:366
Process * current()
Definition scheduler.hh:185
void cprintf(const char *format, const Args &...args)
Definition cprintf.hh:155
void ccprintf(cp::Print &print)
Definition cprintf.hh:130
void sc_stop()
Definition sc_main.cc:103
void sc_abort()
Definition sc_report.cc:178
bool sc_report_close_default_log()
void sc_interrupt_here(const char *msg_type, sc_severity)
bool sc_is_running()
Definition sc_main.cc:141
unsigned sc_actions
const std::string sc_report_compose_message(const sc_report &)
void sc_stop_here(const char *msg_type, sc_severity)
const char SC_ID_UNKNOWN_ERROR_[]
Definition messages.cc:35
int reportVerbosityLevel
Definition report.cc:62
sc_core::sc_report_handler_proc reportHandlerProc
Definition report.cc:68
sc_core::sc_actions reportSuppressedActions
Definition report.cc:64
std::map< std::string, ReportMsgInfo > & reportMsgInfoMap()
Definition report.cc:49
sc_core::sc_actions reportForcedActions
Definition report.cc:65
std::map< int, std::string > & reportIdToMsgMap()
Definition report.cc:56
std::unique_ptr< sc_core::sc_report > globalReportCache
Definition report.cc:96
bool reportWarningsAsErrors
Definition report.cc:98
ReportSevInfo reportSevInfos[sc_core::SC_MAX_SEVERITY]
Definition report.cc:40
const char * reportSeverityNames[]
Definition report.cc:33
Scheduler scheduler
Definition scheduler.cc:494
sc_core::sc_actions reportCatchActions
Definition report.cc:66
const std::list< sc_core::sc_report_handler_proc > & getExtraSystemCReportHandlers()
Definition report.cc:79
sc_core::sc_actions actions
Definition report.hh:64
int sevCounts[sc_core::SC_MAX_SEVERITY]
Definition report.hh:69
int sevLimits[sc_core::SC_MAX_SEVERITY]
Definition report.hh:70
sc_core::sc_actions sevActions[sc_core::SC_MAX_SEVERITY]
Definition report.hh:68
void checkLimits(sc_core::sc_severity severity, sc_core::sc_actions &actions)
Definition report.hh:54
void checkLimit(sc_core::sc_actions &actions)
Definition report.hh:82
sc_core::sc_actions actions
Definition report.hh:88
const std::string & name()
Definition trace.cc:48

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