gem5  v20.1.0.0
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"
34 #include "systemc/core/process.hh"
39 #include "systemc/utils/report.hh"
40 
41 namespace sc_core
42 {
43 
44 namespace
45 {
46 
47 std::unique_ptr<std::string> logFileName;
48 std::unique_ptr<std::ofstream> logFile;
49 
50 } // anonymous namespace
51 
52 void
53 sc_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 
59 void
60 sc_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 
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 
108 void
109 sc_report_handler::report(sc_severity severity, int id, const char *msg,
110  const char *file, int line)
111 {
112  std::string &msg_type = sc_gem5::reportIdToMsgMap()[id];
113 
114  if (sc_gem5::reportWarningsAsErrors && severity == SC_WARNING)
115  severity = SC_ERROR;
116 
117  report(severity, msg_type.c_str(), msg, file, line);
118 }
119 
122 {
124  sc_actions previous = info.actions;
125  info.actions = actions;
126  return previous;
127 }
128 
130 sc_report_handler::set_actions(const char *msg_type, sc_actions actions)
131 {
132  if (!msg_type)
133  msg_type = SC_ID_UNKNOWN_ERROR_;
134 
136  sc_actions previous = info.actions;
137  info.actions = actions;
138  return previous;
139 }
140 
143  const char *msg_type, sc_severity severity, sc_actions actions)
144 {
145  if (!msg_type)
146  msg_type = SC_ID_UNKNOWN_ERROR_;
147 
149  sc_actions previous = info.sevActions[severity];
150  info.sevActions[severity] = actions;
151  return previous;
152 }
153 
154 int
156 {
158  int previous = info.limit;
159  info.limit = limit;
160  return previous;
161 }
162 
163 int
164 sc_report_handler::stop_after(const char *msg_type, int limit)
165 {
166  if (!msg_type)
167  msg_type = SC_ID_UNKNOWN_ERROR_;
168 
170  int previous = info.limit;
171  info.limit = limit;
172  return previous;
173 }
174 
175 int
177  const char *msg_type, sc_severity severity, int limit)
178 {
179  if (!msg_type)
180  msg_type = SC_ID_UNKNOWN_ERROR_;
181 
183  int previous = info.sevLimits[severity];
184  info.sevLimits[severity] = limit;
185  return previous;
186 }
187 
188 int
190 {
191  return sc_gem5::reportSevInfos[severity].count;
192 }
193 
194 int
195 sc_report_handler::get_count(const char *msg_type)
196 {
197  if (!msg_type)
198  msg_type = SC_ID_UNKNOWN_ERROR_;
199 
200  return sc_gem5::reportMsgInfoMap()[msg_type].count;
201 }
202 
203 int
204 sc_report_handler::get_count(const char *msg_type, sc_severity severity)
205 {
206  if (!msg_type)
207  msg_type = SC_ID_UNKNOWN_ERROR_;
208 
209  return sc_gem5::reportMsgInfoMap()[msg_type].sevCounts[severity];
210 }
211 
212 int
214 {
215  int previous = sc_gem5::reportVerbosityLevel;
217  return previous;
218 }
219 
220 int
222 {
224 }
225 
226 
229 {
232  return previous;
233 }
234 
237 {
238  return suppress(SC_UNSPECIFIED);
239 }
240 
243 {
246  return previous;
247 }
248 
251 {
252  return force(SC_UNSPECIFIED);
253 }
254 
255 
258 {
260  sc_gem5::reportCatchActions = actions;
261  return previous;
262 }
263 
266 {
268 }
269 
270 
271 void
273 {
275 }
276 
277 void
279  const sc_report &report, const sc_actions &actions)
280 {
281  if (actions & SC_DISPLAY)
283 
284  if ((actions & SC_LOG) && logFile) {
285  ccprintf(*logFile, "%s: %s\n", report.get_time().to_string(),
287  }
288  if (actions & SC_STOP) {
289  sc_stop_here(report.get_msg_type(), report.get_severity());
290  sc_stop();
291  }
292  if (actions & SC_INTERRUPT)
293  sc_interrupt_here(report.get_msg_type(), report.get_severity());
294  if (actions & SC_ABORT)
295  sc_abort();
296  if (actions & SC_THROW) {
298  if (current)
299  current->isUnwinding(false);
300  throw report;
301  }
302 }
303 
306 {
307  static sc_actions maxAction = SC_ABORT;
308  maxAction = maxAction << 1;
309  return maxAction;
310 }
311 
312 sc_report *
314 {
316  if (current)
317  return current->lastReport();
319 }
320 
321 void
323 {
325  if (current) {
326  current->lastReport(nullptr);
327  } else {
329  }
330 }
331 
332 bool
334 {
335  if (!new_name) {
336  logFile = nullptr;
337  logFileName = nullptr;
338  return false;
339  } else {
340  if (logFileName)
341  return false;
342  logFileName = std::unique_ptr<std::string>(new std::string(new_name));
343  logFile = std::unique_ptr<std::ofstream>(new std::ofstream(new_name));
344  return true;
345  }
346 }
347 
348 const char *
350 {
351  if (!logFileName)
352  return nullptr;
353  else
354  return logFileName->c_str();
355 }
356 
357 void
358 sc_interrupt_here(const char *msg_type, sc_severity)
359 {
360  // Purposefully empty, for setting breakpoints supposedly.
361 }
362 
363 void
364 sc_stop_here(const char *msg_type, sc_severity)
365 {
366  // Purposefully empty, for setting breakpoints supposedly.
367 }
368 
369 const std::string
371 {
372  std::ostringstream str;
373 
374  const char *sevName = sc_gem5::reportSeverityNames[report.get_severity()];
375  int id = report.get_id();
376 
377  str << sevName << ": ";
378  if (id >= 0) {
379  ccprintf(str, "(%c%d) ", sevName[0], id);
380  }
381  str << report.get_msg_type();
382 
383  const char *msg = report.get_msg();
384  if (msg && msg[0])
385  str << ": " << msg;
386 
387  if (report.get_severity() > SC_INFO) {
388  ccprintf(str, "\nIn file: %s:%d", report.get_file_name(),
389  report.get_line_number());
390 
392  const char *name = report.get_process_name();
393  if (current && sc_is_running() && name) {
394  ccprintf(str, "\nIn process: %s @ %s", name,
395  report.get_time().to_string());
396  }
397  }
398 
399  return str.str();
400 }
401 
402 bool
404 {
405  if (logFile) {
406  logFile = nullptr;
407  logFileName = nullptr;
408  return false;
409  }
410  return true;
411 }
412 
413 } // namespace sc_core
sc_core::SC_INFO
@ SC_INFO
Definition: sc_report.hh:41
sc_core::sc_report_handler::get_count
static int get_count(sc_severity)
Definition: sc_report_handler.cc:189
sc_core::sc_time::from_value
static sc_time from_value(sc_dt::uint64)
Definition: sc_time.cc:210
messages.hh
sc_core::sc_actions
unsigned sc_actions
Definition: sc_report_handler.hh:39
sc_gem5::ReportSevInfo
Definition: report.hh:74
sc_core::SC_WARNING
@ SC_WARNING
Definition: sc_report.hh:42
sc_core::SC_THROW
@ SC_THROW
Definition: sc_report_handler.hh:45
sc_core::sc_severity
sc_severity
Definition: sc_report.hh:39
sc_gem5::reportSeverityNames
const char * reportSeverityNames[]
Definition: report.cc:33
sc_core::sc_report_handler::set_catch_actions
static sc_actions set_catch_actions(sc_actions)
Definition: sc_report_handler.cc:257
sc_core::sc_report_compose_message
const std::string sc_report_compose_message(const sc_report &)
Definition: sc_report_handler.cc:370
sc_core::sc_report_handler::set_actions
static sc_actions set_actions(sc_severity, sc_actions=SC_UNSPECIFIED)
Definition: sc_report_handler.cc:121
sc_core::SC_UNSPECIFIED
@ SC_UNSPECIFIED
Definition: sc_report_handler.hh:43
sc_core
Definition: messages.cc:31
sc_core::sc_report::get_process_name
const char * get_process_name() const
Definition: sc_report.hh:75
report.hh
sc_gem5::reportVerbosityLevel
int reportVerbosityLevel
Definition: report.cc:62
sc_core::sc_report_handler::default_handler
static void default_handler(const sc_report &, const sc_actions &)
Definition: sc_report_handler.cc:278
sc_core::sc_report_close_default_log
bool sc_report_close_default_log()
Definition: sc_report_handler.cc:403
sc_core::sc_report::get_time
const sc_time & get_time() const
Definition: sc_report.hh:74
sc_core::sc_report::get_msg
const char * get_msg() const
Definition: sc_report.hh:69
sc_core::sc_report_handler::force
static sc_actions force()
Definition: sc_report_handler.cc:250
sc_core::sc_report_handler::clear_cached_report
static void clear_cached_report()
Definition: sc_report_handler.cc:322
sc_core::sc_report_handler::suppress
static sc_actions suppress()
Definition: sc_report_handler.cc:236
sc_gem5::ReportMsgInfo::actions
sc_core::sc_actions actions
Definition: report.hh:63
sc_gem5::ReportSevInfo::actions
sc_core::sc_actions actions
Definition: report.hh:87
sc_gem5::ReportSevInfo::count
int count
Definition: report.hh:88
sc_gem5::Process::lastReport
void lastReport(::sc_core::sc_report *report)
Definition: process.cc:366
sc_core::SC_ID_UNKNOWN_ERROR_
const char SC_ID_UNKNOWN_ERROR_[]
Definition: messages.cc:35
sc_core::sc_stop
void sc_stop()
Definition: sc_main.cc:104
sc_core::sc_report_handler::stop_after
static int stop_after(sc_severity, int limit=-1)
Definition: sc_report_handler.cc:155
sc_gem5::reportSevInfos
ReportSevInfo reportSevInfos[sc_core::SC_MAX_SEVERITY]
Definition: report.cc:40
sc_core::sc_report_handler::get_catch_actions
static sc_actions get_catch_actions()
Definition: sc_report_handler.cc:265
sc_gem5::reportHandlerProc
sc_core::sc_report_handler_proc reportHandlerProc
Definition: report.cc:68
cprintf
void cprintf(const char *format, const Args &...args)
Definition: cprintf.hh:152
sc_gem5::ReportSevInfo::checkLimit
void checkLimit(sc_core::sc_actions &actions)
Definition: report.hh:81
sc_gem5::ReportMsgInfo::count
int count
Definition: report.hh:64
sc_main.hh
sc_gem5::ReportMsgInfo::sevLimits
int sevLimits[sc_core::SC_MAX_SEVERITY]
Definition: report.hh:69
sc_gem5::globalReportCache
std::unique_ptr< sc_core::sc_report > globalReportCache
Definition: report.cc:71
sc_core::sc_report_handler::set_verbosity_level
static int set_verbosity_level(int)
Definition: sc_report_handler.cc:213
sc_core::sc_report_handler::report
static void report(sc_severity, const char *msg_type, const char *msg, const char *file, int line)
Definition: sc_report_handler.cc:53
cprintf.hh
sc_gem5::ReportMsgInfo::limit
int limit
Definition: report.hh:65
sc_core::SC_LOG
@ SC_LOG
Definition: sc_report_handler.hh:46
sc_core::sc_report::get_file_name
const char * get_file_name() const
Definition: sc_report.hh:71
sc_gem5::reportMsgInfoMap
std::map< std::string, ReportMsgInfo > & reportMsgInfoMap()
Definition: report.cc:49
sc_core::SC_ABORT
@ SC_ABORT
Definition: sc_report_handler.hh:51
sc_gem5::ReportMsgInfo::sevCounts
int sevCounts[sc_core::SC_MAX_SEVERITY]
Definition: report.hh:68
sc_core::sc_report::get_severity
sc_severity get_severity() const
Definition: sc_report.hh:67
sc_gem5::Process
Definition: process.hh:62
sc_core::SC_DISPLAY
@ SC_DISPLAY
Definition: sc_report_handler.hh:47
sc_core::SC_STOP
@ SC_STOP
Definition: sc_report_handler.hh:50
name
const std::string & name()
Definition: trace.cc:50
sc_gem5::ReportMsgInfo::id
int id
Definition: report.hh:71
sc_core::SC_INTERRUPT
@ SC_INTERRUPT
Definition: sc_report_handler.hh:49
sc_core::sc_report
Definition: sc_report.hh:60
process.hh
sc_gem5::reportWarningsAsErrors
bool reportWarningsAsErrors
Definition: report.cc:73
sc_gem5::ReportMsgInfo::sevActions
sc_core::sc_actions sevActions[sc_core::SC_MAX_SEVERITY]
Definition: report.hh:67
sc_core::sc_stop_here
void sc_stop_here(const char *msg_type, sc_severity)
Definition: sc_report_handler.cc:364
sc_gem5::reportForcedActions
sc_core::sc_actions reportForcedActions
Definition: report.cc:65
sc_core::sc_report::get_id
int get_id() const
Definition: sc_report.hh:87
sc_report_handler.hh
sc_gem5::ReportMsgInfo::checkLimits
void checkLimits(sc_core::sc_severity severity, sc_core::sc_actions &actions)
Definition: report.hh:53
sc_gem5::Scheduler::current
Process * current()
Definition: scheduler.hh:170
sc_core::sc_report_handler_proc
void(* sc_report_handler_proc)(const sc_report &, const sc_actions &)
Definition: sc_report_handler.hh:62
sc_core::SC_MEDIUM
@ SC_MEDIUM
Definition: sc_report.hh:52
sc_core::sc_report_handler::get_new_action_id
static sc_actions get_new_action_id()
Definition: sc_report_handler.cc:305
sc_gem5::reportIdToMsgMap
std::map< int, std::string > & reportIdToMsgMap()
Definition: report.cc:56
sc_core::sc_report_handler::set_handler
static void set_handler(sc_report_handler_proc)
Definition: sc_report_handler.cc:272
sc_core::sc_object::name
const char * name() const
Definition: sc_object.cc:44
sc_core::sc_report_handler::get_verbosity_level
static int get_verbosity_level()
Definition: sc_report_handler.cc:221
sc_core::sc_interrupt_here
void sc_interrupt_here(const char *msg_type, sc_severity)
Definition: sc_report_handler.cc:358
ccprintf
void ccprintf(cp::Print &print)
Definition: cprintf.hh:127
sc_gem5::Process::isUnwinding
bool isUnwinding() const
Definition: process.hh:69
sc_core::sc_report::get_line_number
int get_line_number() const
Definition: sc_report.hh:72
sc_core::sc_abort
void sc_abort()
Definition: sc_report.cc:178
X86ISA::limit
BitfieldType< SegDescriptorLimit > limit
Definition: misc.hh:924
sc_gem5::reportSuppressedActions
sc_core::sc_actions reportSuppressedActions
Definition: report.cc:64
sc_core::sc_report::get_msg_type
const char * get_msg_type() const
Definition: sc_report.hh:68
sc_core::sc_report_handler::get_cached_report
static sc_report * get_cached_report()
Definition: sc_report_handler.cc:313
sc_gem5
Definition: sc_clock.cc:42
sc_gem5::ReportMsgInfo
Definition: report.hh:43
sc_gem5::reportCatchActions
sc_core::sc_actions reportCatchActions
Definition: report.cc:66
sc_gem5::scheduler
Scheduler scheduler
Definition: scheduler.cc:489
sc_core::SC_ERROR
@ SC_ERROR
Definition: sc_report.hh:43
sc_core::sc_report_handler::get_log_file_name
static const char * get_log_file_name()
Definition: sc_report_handler.cc:349
sc_gem5::ReportSevInfo::limit
int limit
Definition: report.hh:89
sc_core::sc_report_handler::set_log_file_name
static bool set_log_file_name(const char *)
Definition: sc_report_handler.cc:333
scheduler.hh
sc_core::SC_CACHE_REPORT
@ SC_CACHE_REPORT
Definition: sc_report_handler.hh:48
ArmISA::id
Bitfield< 33 > id
Definition: miscregs_types.hh:247
sc_core::sc_time::to_string
const std::string to_string() const
Definition: sc_time.cc:132
sc_core::sc_is_running
bool sc_is_running()
Definition: sc_main.cc:142

Generated on Wed Sep 30 2020 14:02:18 for gem5 by doxygen 1.8.17