sc_report_handler.cc revision 12997
112852Sgabeblack@google.com/*
212852Sgabeblack@google.com * Copyright 2018 Google, Inc.
312852Sgabeblack@google.com *
412852Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without
512852Sgabeblack@google.com * modification, are permitted provided that the following conditions are
612852Sgabeblack@google.com * met: redistributions of source code must retain the above copyright
712852Sgabeblack@google.com * notice, this list of conditions and the following disclaimer;
812852Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright
912852Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the
1012852Sgabeblack@google.com * documentation and/or other materials provided with the distribution;
1112852Sgabeblack@google.com * neither the name of the copyright holders nor the names of its
1212852Sgabeblack@google.com * contributors may be used to endorse or promote products derived from
1312852Sgabeblack@google.com * this software without specific prior written permission.
1412852Sgabeblack@google.com *
1512852Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1612852Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1712852Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1812852Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1912852Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2012852Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2112852Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2212852Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2312852Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2412852Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2512852Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2612852Sgabeblack@google.com *
2712852Sgabeblack@google.com * Authors: Gabe Black
2812852Sgabeblack@google.com */
2912852Sgabeblack@google.com
3012997Sgabeblack@google.com#include <fstream>
3112997Sgabeblack@google.com#include <map>
3212997Sgabeblack@google.com#include <sstream>
3312997Sgabeblack@google.com#include <string>
3412997Sgabeblack@google.com
3512852Sgabeblack@google.com#include "base/logging.hh"
3612997Sgabeblack@google.com#include "systemc/core/process.hh"
3712997Sgabeblack@google.com#include "systemc/core/scheduler.hh"
3812997Sgabeblack@google.com#include "systemc/ext/core/sc_main.hh"
3912852Sgabeblack@google.com#include "systemc/ext/utils/sc_report_handler.hh"
4012852Sgabeblack@google.com
4112852Sgabeblack@google.comnamespace sc_core
4212852Sgabeblack@google.com{
4312852Sgabeblack@google.com
4412997Sgabeblack@google.comnamespace
4512997Sgabeblack@google.com{
4612997Sgabeblack@google.com
4712997Sgabeblack@google.comstd::unique_ptr<std::string> logFileName;
4812997Sgabeblack@google.comstd::unique_ptr<std::ofstream> logFile;
4912997Sgabeblack@google.com
5012997Sgabeblack@google.comstruct ReportCatInfo
5112997Sgabeblack@google.com{
5212997Sgabeblack@google.com    explicit ReportCatInfo(sc_actions actions) :
5312997Sgabeblack@google.com        actions(actions), count(0), limit(-1)
5412997Sgabeblack@google.com    {}
5512997Sgabeblack@google.com    ReportCatInfo() : ReportCatInfo(SC_UNSPECIFIED) {}
5612997Sgabeblack@google.com
5712997Sgabeblack@google.com    bool
5812997Sgabeblack@google.com    checkLimit(sc_actions &actions)
5912997Sgabeblack@google.com    {
6012997Sgabeblack@google.com        if (limit == 0 || count < limit)
6112997Sgabeblack@google.com            return false;
6212997Sgabeblack@google.com        if (limit != -1)
6312997Sgabeblack@google.com            actions |= SC_STOP;
6412997Sgabeblack@google.com        return true;
6512997Sgabeblack@google.com    }
6612997Sgabeblack@google.com
6712997Sgabeblack@google.com    sc_actions actions;
6812997Sgabeblack@google.com    int count;
6912997Sgabeblack@google.com    int limit;
7012997Sgabeblack@google.com};
7112997Sgabeblack@google.com
7212997Sgabeblack@google.comconst char *severityNames[] = {
7312997Sgabeblack@google.com    [SC_INFO] = "Info",
7412997Sgabeblack@google.com    [SC_WARNING] = "Warning",
7512997Sgabeblack@google.com    [SC_ERROR] = "Error",
7612997Sgabeblack@google.com    [SC_FATAL] = "Fatal"
7712997Sgabeblack@google.com};
7812997Sgabeblack@google.com
7912997Sgabeblack@google.comReportCatInfo catForSeverity[SC_MAX_SEVERITY] =
8012997Sgabeblack@google.com{
8112997Sgabeblack@google.com    [SC_INFO] = ReportCatInfo(SC_DEFAULT_INFO_ACTIONS),
8212997Sgabeblack@google.com    [SC_WARNING] = ReportCatInfo(SC_DEFAULT_WARNING_ACTIONS),
8312997Sgabeblack@google.com    [SC_ERROR] = ReportCatInfo(SC_DEFAULT_ERROR_ACTIONS),
8412997Sgabeblack@google.com    [SC_FATAL] = ReportCatInfo(SC_DEFAULT_FATAL_ACTIONS)
8512997Sgabeblack@google.com};
8612997Sgabeblack@google.com
8712997Sgabeblack@google.comstd::map<std::string, ReportCatInfo> catForMsgType;
8812997Sgabeblack@google.comstd::map<std::pair<std::string, sc_severity>, ReportCatInfo>
8912997Sgabeblack@google.com    catForSeverityAndMsgType;
9012997Sgabeblack@google.com
9112997Sgabeblack@google.comint verbosityLevel = SC_MEDIUM;
9212997Sgabeblack@google.com
9312997Sgabeblack@google.comsc_actions suppressedActions = SC_UNSPECIFIED;
9412997Sgabeblack@google.comsc_actions forcedActions = SC_UNSPECIFIED;
9512997Sgabeblack@google.comsc_actions catchActions = SC_UNSPECIFIED;
9612997Sgabeblack@google.com
9712997Sgabeblack@google.comsc_report_handler_proc reportHandlerProc = &sc_report_handler::default_handler;
9812997Sgabeblack@google.com
9912997Sgabeblack@google.comsc_actions maxAction = SC_ABORT;
10012997Sgabeblack@google.com
10112997Sgabeblack@google.comstd::unique_ptr<sc_report> globalReportCache;
10212997Sgabeblack@google.com
10312997Sgabeblack@google.com} // anonymous namespace
10412997Sgabeblack@google.com
10512852Sgabeblack@google.comvoid
10612997Sgabeblack@google.comsc_report_handler::report(sc_severity severity, const char *msg_type,
10712997Sgabeblack@google.com                          const char *msg, const char *file, int line)
10812852Sgabeblack@google.com{
10912997Sgabeblack@google.com    report(severity, msg_type, msg, SC_MEDIUM, file, line);
11012852Sgabeblack@google.com}
11112852Sgabeblack@google.com
11212852Sgabeblack@google.comvoid
11312997Sgabeblack@google.comsc_report_handler::report(sc_severity severity, const char *msg_type,
11412997Sgabeblack@google.com                          const char *msg, int verbosity, const char *file,
11512997Sgabeblack@google.com                          int line)
11612852Sgabeblack@google.com{
11712997Sgabeblack@google.com    if (severity == SC_INFO && verbosity > verbosityLevel)
11812997Sgabeblack@google.com        return;
11912997Sgabeblack@google.com
12012997Sgabeblack@google.com    ReportCatInfo &sevInfo = catForSeverity[severity];
12112997Sgabeblack@google.com    ReportCatInfo &msgInfo = catForMsgType[msg_type];
12212997Sgabeblack@google.com    ReportCatInfo &sevMsgInfo = catForSeverityAndMsgType[
12312997Sgabeblack@google.com        std::make_pair(std::string(msg_type), severity)];
12412997Sgabeblack@google.com
12512997Sgabeblack@google.com    sevInfo.count++;
12612997Sgabeblack@google.com    msgInfo.count++;
12712997Sgabeblack@google.com    sevMsgInfo.count++;
12812997Sgabeblack@google.com
12912997Sgabeblack@google.com    sc_actions actions = SC_UNSPECIFIED;
13012997Sgabeblack@google.com    if (sevMsgInfo.actions != SC_UNSPECIFIED)
13112997Sgabeblack@google.com        actions = sevMsgInfo.actions;
13212997Sgabeblack@google.com    else if (msgInfo.actions != SC_UNSPECIFIED)
13312997Sgabeblack@google.com        actions = msgInfo.actions;
13412997Sgabeblack@google.com    else if (sevInfo.actions != SC_UNSPECIFIED)
13512997Sgabeblack@google.com        actions = sevInfo.actions;
13612997Sgabeblack@google.com
13712997Sgabeblack@google.com    actions &= ~suppressedActions;
13812997Sgabeblack@google.com    actions |= forcedActions;
13912997Sgabeblack@google.com
14012997Sgabeblack@google.com    if (sevMsgInfo.checkLimit(actions) && msgInfo.checkLimit(actions))
14112997Sgabeblack@google.com        sevInfo.checkLimit(actions);
14212997Sgabeblack@google.com
14312997Sgabeblack@google.com    ::sc_gem5::Process *current = ::sc_gem5::scheduler.current();
14412997Sgabeblack@google.com    sc_report report(severity, msg_type, msg, verbosity, file, line,
14512997Sgabeblack@google.com            sc_time::from_value(::sc_gem5::scheduler.getCurTick()),
14612997Sgabeblack@google.com            current ? current->name() : nullptr, -1);
14712997Sgabeblack@google.com
14812997Sgabeblack@google.com    if (actions & SC_CACHE_REPORT) {
14912997Sgabeblack@google.com        if (current) {
15012997Sgabeblack@google.com            current->lastReport(&report);
15112997Sgabeblack@google.com        } else {
15212997Sgabeblack@google.com            globalReportCache =
15312997Sgabeblack@google.com                std::unique_ptr<sc_report>(new sc_report(report));
15412997Sgabeblack@google.com        }
15512997Sgabeblack@google.com    }
15612997Sgabeblack@google.com
15712997Sgabeblack@google.com    reportHandlerProc(report, actions);
15812852Sgabeblack@google.com}
15912852Sgabeblack@google.com
16012902Sgabeblack@google.comvoid
16112902Sgabeblack@google.comsc_report_handler::report(sc_severity, int id, const char *msg,
16212902Sgabeblack@google.com                          const char *file, int line)
16312902Sgabeblack@google.com{
16412997Sgabeblack@google.com    warn("%s:%d %s\n", file, line, msg);
16512902Sgabeblack@google.com    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
16612902Sgabeblack@google.com}
16712902Sgabeblack@google.com
16812852Sgabeblack@google.comsc_actions
16912997Sgabeblack@google.comsc_report_handler::set_actions(sc_severity severity, sc_actions actions)
17012852Sgabeblack@google.com{
17112997Sgabeblack@google.com    ReportCatInfo &info = catForSeverity[severity];
17212997Sgabeblack@google.com    sc_actions previous = info.actions;
17312997Sgabeblack@google.com    info.actions = actions;
17412997Sgabeblack@google.com    return previous;
17512852Sgabeblack@google.com}
17612852Sgabeblack@google.com
17712852Sgabeblack@google.comsc_actions
17812997Sgabeblack@google.comsc_report_handler::set_actions(const char *msg_type, sc_actions actions)
17912852Sgabeblack@google.com{
18012997Sgabeblack@google.com    ReportCatInfo &info = catForMsgType[msg_type];
18112997Sgabeblack@google.com    sc_actions previous = info.actions;
18212997Sgabeblack@google.com    info.actions = actions;
18312997Sgabeblack@google.com    return previous;
18412852Sgabeblack@google.com}
18512852Sgabeblack@google.com
18612852Sgabeblack@google.comsc_actions
18712997Sgabeblack@google.comsc_report_handler::set_actions(
18812997Sgabeblack@google.com        const char *msg_type, sc_severity severity, sc_actions actions)
18912852Sgabeblack@google.com{
19012997Sgabeblack@google.com    ReportCatInfo &info = catForSeverityAndMsgType[
19112997Sgabeblack@google.com        std::make_pair(std::string(msg_type), severity)];
19212997Sgabeblack@google.com    sc_actions previous = info.actions;
19312997Sgabeblack@google.com    info.actions = actions;
19412997Sgabeblack@google.com    return previous;
19512852Sgabeblack@google.com}
19612852Sgabeblack@google.com
19712852Sgabeblack@google.comint
19812997Sgabeblack@google.comsc_report_handler::stop_after(sc_severity severity, int limit)
19912852Sgabeblack@google.com{
20012997Sgabeblack@google.com    ReportCatInfo &info = catForSeverity[severity];
20112997Sgabeblack@google.com    int previous = info.limit;
20212997Sgabeblack@google.com    info.limit = limit;
20312997Sgabeblack@google.com    return previous;
20412852Sgabeblack@google.com}
20512852Sgabeblack@google.com
20612852Sgabeblack@google.comint
20712852Sgabeblack@google.comsc_report_handler::stop_after(const char *msg_type, int limit)
20812852Sgabeblack@google.com{
20912997Sgabeblack@google.com    ReportCatInfo &info = catForMsgType[msg_type];
21012997Sgabeblack@google.com    int previous = info.limit;
21112997Sgabeblack@google.com    info.limit = limit;
21212997Sgabeblack@google.com    return previous;
21312852Sgabeblack@google.com}
21412852Sgabeblack@google.com
21512852Sgabeblack@google.comint
21612997Sgabeblack@google.comsc_report_handler::stop_after(
21712997Sgabeblack@google.com        const char *msg_type, sc_severity severity, int limit)
21812852Sgabeblack@google.com{
21912997Sgabeblack@google.com    ReportCatInfo &info = catForSeverityAndMsgType[
22012997Sgabeblack@google.com        std::make_pair(std::string(msg_type), severity)];
22112997Sgabeblack@google.com    int previous = info.limit;
22212997Sgabeblack@google.com    info.limit = limit;
22312997Sgabeblack@google.com    return previous;
22412852Sgabeblack@google.com}
22512852Sgabeblack@google.com
22612852Sgabeblack@google.comint
22712997Sgabeblack@google.comsc_report_handler::get_count(sc_severity severity)
22812852Sgabeblack@google.com{
22912997Sgabeblack@google.com    return catForSeverity[severity].count;
23012852Sgabeblack@google.com}
23112852Sgabeblack@google.com
23212852Sgabeblack@google.comint
23312852Sgabeblack@google.comsc_report_handler::get_count(const char *msg_type)
23412852Sgabeblack@google.com{
23512997Sgabeblack@google.com    return catForMsgType[msg_type].count;
23612852Sgabeblack@google.com}
23712852Sgabeblack@google.com
23812852Sgabeblack@google.comint
23912997Sgabeblack@google.comsc_report_handler::get_count(const char *msg_type, sc_severity severity)
24012852Sgabeblack@google.com{
24112997Sgabeblack@google.com    return catForSeverityAndMsgType[
24212997Sgabeblack@google.com        std::make_pair(std::string(msg_type), severity)].count;
24312852Sgabeblack@google.com}
24412852Sgabeblack@google.com
24512852Sgabeblack@google.comint
24612997Sgabeblack@google.comsc_report_handler::set_verbosity_level(int vl)
24712852Sgabeblack@google.com{
24812997Sgabeblack@google.com    int previous = verbosityLevel;
24912997Sgabeblack@google.com    verbosityLevel = vl;
25012997Sgabeblack@google.com    return previous;
25112852Sgabeblack@google.com}
25212852Sgabeblack@google.com
25312852Sgabeblack@google.comint
25412852Sgabeblack@google.comsc_report_handler::get_verbosity_level()
25512852Sgabeblack@google.com{
25612997Sgabeblack@google.com    return verbosityLevel;
25712852Sgabeblack@google.com}
25812852Sgabeblack@google.com
25912852Sgabeblack@google.com
26012852Sgabeblack@google.comsc_actions
26112997Sgabeblack@google.comsc_report_handler::suppress(sc_actions actions)
26212852Sgabeblack@google.com{
26312997Sgabeblack@google.com    sc_actions previous = suppressedActions;
26412997Sgabeblack@google.com    suppressedActions = actions;
26512997Sgabeblack@google.com    return previous;
26612852Sgabeblack@google.com}
26712852Sgabeblack@google.com
26812852Sgabeblack@google.comsc_actions
26912852Sgabeblack@google.comsc_report_handler::suppress()
27012852Sgabeblack@google.com{
27112997Sgabeblack@google.com    return suppress(SC_UNSPECIFIED);
27212852Sgabeblack@google.com}
27312852Sgabeblack@google.com
27412852Sgabeblack@google.comsc_actions
27512997Sgabeblack@google.comsc_report_handler::force(sc_actions actions)
27612852Sgabeblack@google.com{
27712997Sgabeblack@google.com    sc_actions previous = forcedActions;
27812997Sgabeblack@google.com    forcedActions = actions;
27912997Sgabeblack@google.com    return previous;
28012852Sgabeblack@google.com}
28112852Sgabeblack@google.com
28212852Sgabeblack@google.comsc_actions
28312852Sgabeblack@google.comsc_report_handler::force()
28412852Sgabeblack@google.com{
28512997Sgabeblack@google.com    return force(SC_UNSPECIFIED);
28612852Sgabeblack@google.com}
28712852Sgabeblack@google.com
28812852Sgabeblack@google.com
28912911Sgabeblack@google.comsc_actions
29012997Sgabeblack@google.comsc_report_handler::set_catch_actions(sc_actions actions)
29112911Sgabeblack@google.com{
29212997Sgabeblack@google.com    sc_actions previous = catchActions;
29312997Sgabeblack@google.com    catchActions = actions;
29412997Sgabeblack@google.com    return previous;
29512911Sgabeblack@google.com}
29612911Sgabeblack@google.com
29712911Sgabeblack@google.comsc_actions
29812911Sgabeblack@google.comsc_report_handler::get_catch_actions()
29912911Sgabeblack@google.com{
30012997Sgabeblack@google.com    return catchActions;
30112911Sgabeblack@google.com}
30212911Sgabeblack@google.com
30312911Sgabeblack@google.com
30412852Sgabeblack@google.comvoid
30512997Sgabeblack@google.comsc_report_handler::set_handler(sc_report_handler_proc proc)
30612852Sgabeblack@google.com{
30712997Sgabeblack@google.com    reportHandlerProc = proc;
30812852Sgabeblack@google.com}
30912852Sgabeblack@google.com
31012852Sgabeblack@google.comvoid
31112997Sgabeblack@google.comsc_report_handler::default_handler(
31212997Sgabeblack@google.com        const sc_report &report, const sc_actions &actions)
31312852Sgabeblack@google.com{
31412997Sgabeblack@google.com    if (actions & SC_DISPLAY)
31512997Sgabeblack@google.com        cprintf("\n%s\n", sc_report_compose_message(report));
31612997Sgabeblack@google.com
31712997Sgabeblack@google.com    if ((actions & SC_LOG) && logFile) {
31812997Sgabeblack@google.com        ccprintf(*logFile, "%s: %s\n", report.get_time().to_string(),
31912997Sgabeblack@google.com                 sc_report_compose_message(report));
32012997Sgabeblack@google.com    }
32112997Sgabeblack@google.com    if (actions & SC_STOP) {
32212997Sgabeblack@google.com        sc_stop_here(report.get_msg_type(), report.get_severity());
32312997Sgabeblack@google.com        sc_stop();
32412997Sgabeblack@google.com    }
32512997Sgabeblack@google.com    if (actions & SC_INTERRUPT)
32612997Sgabeblack@google.com        sc_interrupt_here(report.get_msg_type(), report.get_severity());
32712997Sgabeblack@google.com    if (actions & SC_ABORT)
32812997Sgabeblack@google.com        sc_abort();
32912997Sgabeblack@google.com    if (actions & SC_THROW) {
33012997Sgabeblack@google.com        ::sc_gem5::Process *current = ::sc_gem5::scheduler.current();
33112997Sgabeblack@google.com        if (current)
33212997Sgabeblack@google.com            current->isUnwinding(false);
33312997Sgabeblack@google.com        throw report;
33412997Sgabeblack@google.com    }
33512852Sgabeblack@google.com}
33612852Sgabeblack@google.com
33712852Sgabeblack@google.comsc_actions
33812852Sgabeblack@google.comsc_report_handler::get_new_action_id()
33912852Sgabeblack@google.com{
34012997Sgabeblack@google.com    maxAction = maxAction << 1;
34112997Sgabeblack@google.com    return maxAction;
34212852Sgabeblack@google.com}
34312852Sgabeblack@google.com
34412852Sgabeblack@google.comsc_report *
34512852Sgabeblack@google.comsc_report_handler::get_cached_report()
34612852Sgabeblack@google.com{
34712997Sgabeblack@google.com    ::sc_gem5::Process *current = ::sc_gem5::scheduler.current();
34812997Sgabeblack@google.com    if (current)
34912997Sgabeblack@google.com        return current->lastReport();
35012997Sgabeblack@google.com    return globalReportCache.get();
35112852Sgabeblack@google.com}
35212852Sgabeblack@google.com
35312852Sgabeblack@google.comvoid
35412852Sgabeblack@google.comsc_report_handler::clear_cached_report()
35512852Sgabeblack@google.com{
35612997Sgabeblack@google.com    ::sc_gem5::Process *current = ::sc_gem5::scheduler.current();
35712997Sgabeblack@google.com    if (current) {
35812997Sgabeblack@google.com        current->lastReport(nullptr);
35912997Sgabeblack@google.com    } else {
36012997Sgabeblack@google.com        globalReportCache = nullptr;
36112997Sgabeblack@google.com    }
36212852Sgabeblack@google.com}
36312852Sgabeblack@google.com
36412852Sgabeblack@google.combool
36512997Sgabeblack@google.comsc_report_handler::set_log_file_name(const char *new_name)
36612852Sgabeblack@google.com{
36712997Sgabeblack@google.com    if (!new_name) {
36812997Sgabeblack@google.com        logFile = nullptr;
36912997Sgabeblack@google.com        logFileName = nullptr;
37012997Sgabeblack@google.com        return false;
37112997Sgabeblack@google.com    } else {
37212997Sgabeblack@google.com        if (logFileName)
37312997Sgabeblack@google.com            return false;
37412997Sgabeblack@google.com        logFileName = std::unique_ptr<std::string>(new std::string(new_name));
37512997Sgabeblack@google.com        logFile = std::unique_ptr<std::ofstream>(new std::ofstream(new_name));
37612997Sgabeblack@google.com        return true;
37712997Sgabeblack@google.com    }
37812852Sgabeblack@google.com}
37912852Sgabeblack@google.com
38012852Sgabeblack@google.comconst char *
38112852Sgabeblack@google.comsc_report_handler::get_log_file_name()
38212852Sgabeblack@google.com{
38312997Sgabeblack@google.com    if (!logFileName)
38412997Sgabeblack@google.com        return nullptr;
38512997Sgabeblack@google.com    else
38612997Sgabeblack@google.com        return logFileName->c_str();
38712852Sgabeblack@google.com}
38812852Sgabeblack@google.com
38912852Sgabeblack@google.comvoid
39012852Sgabeblack@google.comsc_interrupt_here(const char *msg_type, sc_severity)
39112852Sgabeblack@google.com{
39212997Sgabeblack@google.com    // Purposefully empty, for setting breakpoints supposedly.
39312852Sgabeblack@google.com}
39412852Sgabeblack@google.com
39512852Sgabeblack@google.comvoid
39612852Sgabeblack@google.comsc_stop_here(const char *msg_type, sc_severity)
39712852Sgabeblack@google.com{
39812997Sgabeblack@google.com    // Purposefully empty, for setting breakpoints supposedly.
39912852Sgabeblack@google.com}
40012852Sgabeblack@google.com
40112921Sgabeblack@google.comconst std::string
40212997Sgabeblack@google.comsc_report_compose_message(const sc_report &report)
40312921Sgabeblack@google.com{
40412997Sgabeblack@google.com    std::ostringstream str;
40512997Sgabeblack@google.com
40612997Sgabeblack@google.com    const char *sevName = severityNames[report.get_severity()];
40712997Sgabeblack@google.com    int id = report.get_id();
40812997Sgabeblack@google.com
40912997Sgabeblack@google.com    str << sevName << ": ";
41012997Sgabeblack@google.com    if (id >= 0) {
41112997Sgabeblack@google.com        ccprintf(str, "(%c%d) ", sevName[0], id);
41212997Sgabeblack@google.com    }
41312997Sgabeblack@google.com    str << report.get_msg_type();
41412997Sgabeblack@google.com
41512997Sgabeblack@google.com    const char *msg = report.get_msg();
41612997Sgabeblack@google.com    if (msg[0])
41712997Sgabeblack@google.com        str << ": " << msg;
41812997Sgabeblack@google.com
41912997Sgabeblack@google.com    if (report.get_severity() > SC_INFO) {
42012997Sgabeblack@google.com        ccprintf(str, "\nIn file: %s:%d", report.get_file_name(),
42112997Sgabeblack@google.com                 report.get_line_number());
42212997Sgabeblack@google.com
42312997Sgabeblack@google.com        ::sc_gem5::Process *current = ::sc_gem5::scheduler.current();
42412997Sgabeblack@google.com        const char *name = report.get_process_name();
42512997Sgabeblack@google.com        if (current && sc_is_running() && name) {
42612997Sgabeblack@google.com            ccprintf(str, "\nIn process: %s @ %s", name,
42712997Sgabeblack@google.com                    report.get_time().to_string());
42812997Sgabeblack@google.com        }
42912997Sgabeblack@google.com    }
43012997Sgabeblack@google.com
43112997Sgabeblack@google.com    return str.str();
43212921Sgabeblack@google.com}
43312921Sgabeblack@google.com
43412921Sgabeblack@google.combool
43512921Sgabeblack@google.comsc_report_close_default_log()
43612921Sgabeblack@google.com{
43712997Sgabeblack@google.com    if (logFile) {
43812997Sgabeblack@google.com        logFile = nullptr;
43912997Sgabeblack@google.com        logFileName = nullptr;
44012997Sgabeblack@google.com        return false;
44112997Sgabeblack@google.com    }
44212997Sgabeblack@google.com    return true;
44312921Sgabeblack@google.com}
44412921Sgabeblack@google.com
44512852Sgabeblack@google.com} // namespace sc_core
446