gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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  * Authors: Gabe Black
28  */
29 
30 #include <fstream>
31 #include <map>
32 #include <sstream>
33 #include <string>
34 
35 #include "base/cprintf.hh"
36 #include "systemc/core/process.hh"
41 #include "systemc/utils/report.hh"
42 
43 namespace sc_core
44 {
45 
46 namespace
47 {
48 
49 std::unique_ptr<std::string> logFileName;
50 std::unique_ptr<std::ofstream> logFile;
51 
52 } // anonymous namespace
53 
54 void
55 sc_report_handler::report(sc_severity severity, const char *msg_type,
56  const char *msg, const char *file, int line)
57 {
58  report(severity, msg_type, msg, SC_MEDIUM, file, line);
59 }
60 
61 void
62 sc_report_handler::report(sc_severity severity, const char *msg_type,
63  const char *msg, int verbosity, const char *file,
64  int line)
65 {
66  if (!msg_type)
67  msg_type = SC_ID_UNKNOWN_ERROR_;
68 
69  if (severity == SC_INFO && verbosity > sc_gem5::reportVerbosityLevel)
70  return;
71 
74 
75  sevInfo.count++;
76  msgInfo.count++;
77  msgInfo.sevCounts[severity]++;
78 
79  sc_actions actions = SC_UNSPECIFIED;
80  if (msgInfo.sevActions[severity] != SC_UNSPECIFIED)
81  actions = msgInfo.sevActions[severity];
82  else if (msgInfo.actions != SC_UNSPECIFIED)
83  actions = msgInfo.actions;
84  else if (sevInfo.actions != SC_UNSPECIFIED)
85  actions = sevInfo.actions;
86 
89 
90  msgInfo.checkLimits(severity, actions);
91  sevInfo.checkLimit(actions);
92 
94  sc_report report(severity, msg_type, msg, verbosity, file, line,
96  current ? current->name() : nullptr, msgInfo.id);
97 
98  if (actions & SC_CACHE_REPORT) {
99  if (current) {
100  current->lastReport(&report);
101  } else {
103  std::unique_ptr<sc_report>(new sc_report(report));
104  }
105  }
106 
108 }
109 
110 void
111 sc_report_handler::report(sc_severity severity, int id, const char *msg,
112  const char *file, int line)
113 {
114  std::string &msg_type = sc_gem5::reportIdToMsgMap()[id];
115 
116  if (sc_gem5::reportWarningsAsErrors && severity == SC_WARNING)
117  severity = SC_ERROR;
118 
119  report(severity, msg_type.c_str(), msg, file, line);
120 }
121 
124 {
126  sc_actions previous = info.actions;
127  info.actions = actions;
128  return previous;
129 }
130 
132 sc_report_handler::set_actions(const char *msg_type, sc_actions actions)
133 {
134  if (!msg_type)
135  msg_type = SC_ID_UNKNOWN_ERROR_;
136 
138  sc_actions previous = info.actions;
139  info.actions = actions;
140  return previous;
141 }
142 
145  const char *msg_type, sc_severity severity, sc_actions actions)
146 {
147  if (!msg_type)
148  msg_type = SC_ID_UNKNOWN_ERROR_;
149 
151  sc_actions previous = info.sevActions[severity];
152  info.sevActions[severity] = actions;
153  return previous;
154 }
155 
156 int
158 {
160  int previous = info.limit;
161  info.limit = limit;
162  return previous;
163 }
164 
165 int
166 sc_report_handler::stop_after(const char *msg_type, int limit)
167 {
168  if (!msg_type)
169  msg_type = SC_ID_UNKNOWN_ERROR_;
170 
172  int previous = info.limit;
173  info.limit = limit;
174  return previous;
175 }
176 
177 int
179  const char *msg_type, sc_severity severity, int limit)
180 {
181  if (!msg_type)
182  msg_type = SC_ID_UNKNOWN_ERROR_;
183 
185  int previous = info.sevLimits[severity];
186  info.sevLimits[severity] = limit;
187  return previous;
188 }
189 
190 int
192 {
193  return sc_gem5::reportSevInfos[severity].count;
194 }
195 
196 int
197 sc_report_handler::get_count(const char *msg_type)
198 {
199  if (!msg_type)
200  msg_type = SC_ID_UNKNOWN_ERROR_;
201 
202  return sc_gem5::reportMsgInfoMap()[msg_type].count;
203 }
204 
205 int
206 sc_report_handler::get_count(const char *msg_type, sc_severity severity)
207 {
208  if (!msg_type)
209  msg_type = SC_ID_UNKNOWN_ERROR_;
210 
211  return sc_gem5::reportMsgInfoMap()[msg_type].sevCounts[severity];
212 }
213 
214 int
216 {
217  int previous = sc_gem5::reportVerbosityLevel;
219  return previous;
220 }
221 
222 int
224 {
226 }
227 
228 
231 {
234  return previous;
235 }
236 
239 {
240  return suppress(SC_UNSPECIFIED);
241 }
242 
245 {
248  return previous;
249 }
250 
253 {
254  return force(SC_UNSPECIFIED);
255 }
256 
257 
260 {
262  sc_gem5::reportCatchActions = actions;
263  return previous;
264 }
265 
268 {
270 }
271 
272 
273 void
275 {
277 }
278 
279 void
281  const sc_report &report, const sc_actions &actions)
282 {
283  if (actions & SC_DISPLAY)
284  cprintf("\n%s\n", sc_report_compose_message(report));
285 
286  if ((actions & SC_LOG) && logFile) {
287  ccprintf(*logFile, "%s: %s\n", report.get_time().to_string(),
288  sc_report_compose_message(report));
289  }
290  if (actions & SC_STOP) {
291  sc_stop_here(report.get_msg_type(), report.get_severity());
292  sc_stop();
293  }
294  if (actions & SC_INTERRUPT)
295  sc_interrupt_here(report.get_msg_type(), report.get_severity());
296  if (actions & SC_ABORT)
297  sc_abort();
298  if (actions & SC_THROW) {
300  if (current)
301  current->isUnwinding(false);
302  throw report;
303  }
304 }
305 
308 {
309  static sc_actions maxAction = SC_ABORT;
310  maxAction = maxAction << 1;
311  return maxAction;
312 }
313 
314 sc_report *
316 {
318  if (current)
319  return current->lastReport();
321 }
322 
323 void
325 {
327  if (current) {
328  current->lastReport(nullptr);
329  } else {
331  }
332 }
333 
334 bool
336 {
337  if (!new_name) {
338  logFile = nullptr;
339  logFileName = nullptr;
340  return false;
341  } else {
342  if (logFileName)
343  return false;
344  logFileName = std::unique_ptr<std::string>(new std::string(new_name));
345  logFile = std::unique_ptr<std::ofstream>(new std::ofstream(new_name));
346  return true;
347  }
348 }
349 
350 const char *
352 {
353  if (!logFileName)
354  return nullptr;
355  else
356  return logFileName->c_str();
357 }
358 
359 void
360 sc_interrupt_here(const char *msg_type, sc_severity)
361 {
362  // Purposefully empty, for setting breakpoints supposedly.
363 }
364 
365 void
366 sc_stop_here(const char *msg_type, sc_severity)
367 {
368  // Purposefully empty, for setting breakpoints supposedly.
369 }
370 
371 const std::string
373 {
374  std::ostringstream str;
375 
376  const char *sevName = sc_gem5::reportSeverityNames[report.get_severity()];
377  int id = report.get_id();
378 
379  str << sevName << ": ";
380  if (id >= 0) {
381  ccprintf(str, "(%c%d) ", sevName[0], id);
382  }
383  str << report.get_msg_type();
384 
385  const char *msg = report.get_msg();
386  if (msg && msg[0])
387  str << ": " << msg;
388 
389  if (report.get_severity() > SC_INFO) {
390  ccprintf(str, "\nIn file: %s:%d", report.get_file_name(),
391  report.get_line_number());
392 
394  const char *name = report.get_process_name();
395  if (current && sc_is_running() && name) {
396  ccprintf(str, "\nIn process: %s @ %s", name,
397  report.get_time().to_string());
398  }
399  }
400 
401  return str.str();
402 }
403 
404 bool
406 {
407  if (logFile) {
408  logFile = nullptr;
409  logFileName = nullptr;
410  return false;
411  }
412  return true;
413 }
414 
415 } // namespace sc_core
unsigned sc_actions
void ccprintf(cp::Print &print)
Definition: cprintf.hh:131
std::map< std::string, ReportMsgInfo > & reportMsgInfoMap()
Definition: report.cc:51
int get_id() const
Definition: sc_report.hh:89
std::unique_ptr< sc_core::sc_report > globalReportCache
Definition: report.cc:73
bool sc_is_running()
Definition: sc_main.cc:144
static sc_actions suppress()
const std::string & name()
Definition: trace.cc:54
sc_core::sc_actions reportSuppressedActions
Definition: report.cc:66
static int stop_after(sc_severity, int limit=-1)
static sc_actions set_catch_actions(sc_actions)
static bool set_log_file_name(const char *)
static int get_count(sc_severity)
const char * get_msg_type() const
Definition: sc_report.hh:70
int reportVerbosityLevel
Definition: report.cc:64
void sc_stop_here(const char *msg_type, sc_severity)
const char * name() const
Definition: sc_object.cc:46
const std::string sc_report_compose_message(const sc_report &)
sc_core::sc_actions sevActions[sc_core::SC_MAX_SEVERITY]
Definition: report.hh:69
sc_severity get_severity() const
Definition: sc_report.hh:69
void lastReport(::sc_core::sc_report *report)
Definition: process.cc:368
static sc_report * get_cached_report()
Bitfield< 33 > id
void sc_interrupt_here(const char *msg_type, sc_severity)
static sc_time from_value(sc_dt::uint64)
Definition: sc_time.cc:212
static const char * get_log_file_name()
std::map< int, std::string > & reportIdToMsgMap()
Definition: report.cc:58
bool sc_report_close_default_log()
sc_core::sc_actions reportCatchActions
Definition: report.cc:68
int get_line_number() const
Definition: sc_report.hh:74
Process * current()
Definition: scheduler.hh:172
sc_core::sc_actions actions
Definition: report.hh:89
const char * get_process_name() const
Definition: sc_report.hh:77
void sc_stop()
Definition: sc_main.cc:106
static void default_handler(const sc_report &, const sc_actions &)
void(* sc_report_handler_proc)(const sc_report &, const sc_actions &)
const char * reportSeverityNames[]
Definition: report.cc:35
Scheduler scheduler
Definition: scheduler.cc:491
bool isUnwinding() const
Definition: process.hh:71
sc_core::sc_report_handler_proc reportHandlerProc
Definition: report.cc:70
static sc_actions get_new_action_id()
static sc_actions set_actions(sc_severity, sc_actions=SC_UNSPECIFIED)
BitfieldType< SegDescriptorLimit > limit
Definition: misc.hh:926
ReportSevInfo reportSevInfos[sc_core::SC_MAX_SEVERITY]
Definition: report.cc:42
sc_core::sc_actions reportForcedActions
Definition: report.cc:67
const char SC_ID_UNKNOWN_ERROR_[]
Definition: messages.cc:37
void checkLimit(sc_core::sc_actions &actions)
Definition: report.hh:83
static void report(sc_severity, const char *msg_type, const char *msg, const char *file, int line)
const std::string to_string() const
Definition: sc_time.cc:134
bool reportWarningsAsErrors
Definition: report.cc:75
int sevCounts[sc_core::SC_MAX_SEVERITY]
Definition: report.hh:70
static void set_handler(sc_report_handler_proc)
void checkLimits(sc_core::sc_severity severity, sc_core::sc_actions &actions)
Definition: report.hh:55
void sc_abort()
Definition: sc_report.cc:180
const char * get_msg() const
Definition: sc_report.hh:71
static sc_actions get_catch_actions()
const sc_time & get_time() const
Definition: sc_report.hh:76
const char * get_file_name() const
Definition: sc_report.hh:73
int sevLimits[sc_core::SC_MAX_SEVERITY]
Definition: report.hh:71
sc_core::sc_actions actions
Definition: report.hh:65
void cprintf(const char *format, const Args &...args)
Definition: cprintf.hh:156

Generated on Fri Feb 28 2020 16:27:06 for gem5 by doxygen 1.8.13