2013-01-05 04:13:26 -06:00
|
|
|
/*
|
|
|
|
* yosys -- Yosys Open SYnthesis Suite
|
|
|
|
*
|
2021-06-07 17:39:36 -05:00
|
|
|
* Copyright (C) 2012 Claire Xenia Wolf <claire@yosyshq.com>
|
2015-07-02 04:14:30 -05:00
|
|
|
*
|
2013-01-05 04:13:26 -06:00
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
2015-07-02 04:14:30 -05:00
|
|
|
*
|
2013-01-05 04:13:26 -06:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2014-07-30 07:10:15 -05:00
|
|
|
#include "kernel/yosys.h"
|
2014-08-01 12:43:28 -05:00
|
|
|
#include "libs/sha1/sha1.h"
|
2020-08-26 12:29:32 -05:00
|
|
|
#include "backends/rtlil/rtlil_backend.h"
|
2013-01-05 04:13:26 -06:00
|
|
|
|
2014-10-14 19:43:50 -05:00
|
|
|
#if !defined(_WIN32) || defined(__MINGW32__)
|
2014-10-14 18:05:08 -05:00
|
|
|
# include <sys/time.h>
|
2014-10-14 16:07:30 -05:00
|
|
|
#endif
|
|
|
|
|
2018-05-05 06:02:44 -05:00
|
|
|
#if defined(__linux__) || defined(__FreeBSD__)
|
2014-12-29 06:33:33 -06:00
|
|
|
# include <dlfcn.h>
|
|
|
|
#endif
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <vector>
|
|
|
|
#include <list>
|
|
|
|
|
2014-07-31 06:19:47 -05:00
|
|
|
YOSYS_NAMESPACE_BEGIN
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
std::vector<FILE*> log_files;
|
2014-08-23 08:14:58 -05:00
|
|
|
std::vector<std::ostream*> log_streams;
|
2022-11-28 12:03:27 -06:00
|
|
|
std::vector<std::string> log_scratchpads;
|
2016-04-21 16:28:37 -05:00
|
|
|
std::map<std::string, std::set<std::string>> log_hdump;
|
2020-03-13 11:19:54 -05:00
|
|
|
std::vector<YS_REGEX_TYPE> log_warn_regexes, log_nowarn_regexes, log_werror_regexes;
|
2020-05-14 17:52:07 -05:00
|
|
|
dict<std::string, LogExpectedItem> log_expect_log, log_expect_warning, log_expect_error;
|
2020-01-28 10:51:50 -06:00
|
|
|
std::set<std::string> log_warnings, log_experimentals, log_experimentals_ignored;
|
2018-03-04 15:35:59 -06:00
|
|
|
int log_warnings_count = 0;
|
2020-02-22 03:52:46 -06:00
|
|
|
int log_warnings_count_noexpect = 0;
|
2020-02-17 08:36:06 -06:00
|
|
|
bool log_expect_no_warnings = false;
|
2016-04-24 10:12:34 -05:00
|
|
|
bool log_hdump_all = false;
|
2013-01-05 04:13:26 -06:00
|
|
|
FILE *log_errfile = NULL;
|
2014-08-01 12:43:28 -05:00
|
|
|
SHA1 *log_hasher = NULL;
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
bool log_time = false;
|
2015-01-03 15:10:33 -06:00
|
|
|
bool log_error_stderr = false;
|
2013-01-05 04:13:26 -06:00
|
|
|
bool log_cmd_error_throw = false;
|
2014-11-09 04:02:20 -06:00
|
|
|
bool log_quiet_warnings = false;
|
2013-11-17 06:26:31 -06:00
|
|
|
int log_verbose_level;
|
2015-02-19 06:36:54 -06:00
|
|
|
string log_last_error;
|
2017-06-19 21:41:58 -05:00
|
|
|
void (*log_error_atexit)() = NULL;
|
2013-01-05 04:13:26 -06:00
|
|
|
|
2019-04-22 10:25:52 -05:00
|
|
|
int log_make_debug = 0;
|
|
|
|
int log_force_debug = 0;
|
|
|
|
int log_debug_suppressed = 0;
|
|
|
|
|
2015-01-30 15:12:26 -06:00
|
|
|
vector<int> header_count;
|
2019-07-15 10:10:42 -05:00
|
|
|
vector<char*> log_id_cache;
|
2015-06-11 06:39:49 -05:00
|
|
|
vector<shared_str> string_buf;
|
2015-01-30 15:12:26 -06:00
|
|
|
int string_buf_index = -1;
|
2013-01-05 04:13:26 -06:00
|
|
|
|
|
|
|
static struct timeval initial_tv = { 0, 0 };
|
|
|
|
static bool next_print_log = false;
|
2014-08-16 08:34:00 -05:00
|
|
|
static int log_newline_count = 0;
|
2013-01-05 04:13:26 -06:00
|
|
|
|
2019-07-15 10:10:42 -05:00
|
|
|
static void log_id_cache_clear()
|
|
|
|
{
|
|
|
|
for (auto p : log_id_cache)
|
|
|
|
free(p);
|
|
|
|
log_id_cache.clear();
|
|
|
|
}
|
|
|
|
|
2014-10-14 19:43:50 -05:00
|
|
|
#if defined(_WIN32) && !defined(__MINGW32__)
|
2014-10-14 16:07:30 -05:00
|
|
|
// this will get time information and return it in timeval, simulating gettimeofday()
|
|
|
|
int gettimeofday(struct timeval *tv, struct timezone *tz)
|
|
|
|
{
|
|
|
|
LARGE_INTEGER counter;
|
|
|
|
LARGE_INTEGER freq;
|
|
|
|
|
|
|
|
QueryPerformanceFrequency(&freq);
|
|
|
|
QueryPerformanceCounter(&counter);
|
|
|
|
|
|
|
|
counter.QuadPart *= 1000000;
|
|
|
|
counter.QuadPart /= freq.QuadPart;
|
|
|
|
|
2014-10-18 08:20:38 -05:00
|
|
|
tv->tv_sec = long(counter.QuadPart / 1000000);
|
2014-10-14 16:07:30 -05:00
|
|
|
tv->tv_usec = counter.QuadPart % 1000000;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
void logv(const char *format, va_list ap)
|
|
|
|
{
|
2014-08-01 12:43:28 -05:00
|
|
|
while (format[0] == '\n' && format[1] != 0) {
|
|
|
|
log("\n");
|
|
|
|
format++;
|
|
|
|
}
|
|
|
|
|
2019-04-22 10:25:52 -05:00
|
|
|
if (log_make_debug && !ys_debug(1))
|
|
|
|
return;
|
|
|
|
|
2014-08-01 12:43:28 -05:00
|
|
|
std::string str = vstringf(format, ap);
|
|
|
|
|
2014-08-16 08:34:00 -05:00
|
|
|
if (str.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
size_t nnl_pos = str.find_last_not_of('\n');
|
|
|
|
if (nnl_pos == std::string::npos)
|
2014-10-10 09:59:44 -05:00
|
|
|
log_newline_count += GetSize(str);
|
2014-08-16 08:34:00 -05:00
|
|
|
else
|
2014-10-10 09:59:44 -05:00
|
|
|
log_newline_count = GetSize(str) - nnl_pos - 1;
|
2014-08-16 08:34:00 -05:00
|
|
|
|
2014-08-01 12:43:28 -05:00
|
|
|
if (log_hasher)
|
|
|
|
log_hasher->update(str);
|
|
|
|
|
|
|
|
if (log_time)
|
|
|
|
{
|
|
|
|
std::string time_str;
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
if (next_print_log || initial_tv.tv_sec == 0) {
|
|
|
|
next_print_log = false;
|
|
|
|
struct timeval tv;
|
|
|
|
gettimeofday(&tv, NULL);
|
|
|
|
if (initial_tv.tv_sec == 0)
|
|
|
|
initial_tv = tv;
|
|
|
|
if (tv.tv_usec < initial_tv.tv_usec) {
|
|
|
|
tv.tv_sec--;
|
|
|
|
tv.tv_usec += 1000000;
|
|
|
|
}
|
|
|
|
tv.tv_sec -= initial_tv.tv_sec;
|
|
|
|
tv.tv_usec -= initial_tv.tv_usec;
|
2014-08-01 12:43:28 -05:00
|
|
|
time_str += stringf("[%05d.%06d] ", int(tv.tv_sec), int(tv.tv_usec));
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
2014-08-01 12:43:28 -05:00
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
if (format[0] && format[strlen(format)-1] == '\n')
|
|
|
|
next_print_log = true;
|
|
|
|
|
2014-08-01 12:43:28 -05:00
|
|
|
for (auto f : log_files)
|
|
|
|
fputs(time_str.c_str(), f);
|
2014-08-23 08:14:58 -05:00
|
|
|
|
|
|
|
for (auto f : log_streams)
|
|
|
|
*f << time_str;
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
2014-08-01 12:43:28 -05:00
|
|
|
|
|
|
|
for (auto f : log_files)
|
|
|
|
fputs(str.c_str(), f);
|
2014-08-23 08:14:58 -05:00
|
|
|
|
|
|
|
for (auto f : log_streams)
|
|
|
|
*f << str;
|
2016-12-22 16:41:44 -06:00
|
|
|
|
2022-11-28 12:03:27 -06:00
|
|
|
RTLIL::Design *design = yosys_get_design();
|
|
|
|
if (design != nullptr)
|
|
|
|
for (auto &scratchpad : log_scratchpads)
|
|
|
|
design->scratchpad[scratchpad].append(str);
|
|
|
|
|
2016-12-22 16:41:44 -06:00
|
|
|
static std::string linebuffer;
|
|
|
|
static bool log_warn_regex_recusion_guard = false;
|
|
|
|
|
|
|
|
if (!log_warn_regex_recusion_guard)
|
|
|
|
{
|
|
|
|
log_warn_regex_recusion_guard = true;
|
|
|
|
|
2020-02-14 05:21:16 -06:00
|
|
|
if (log_warn_regexes.empty() && log_expect_log.empty())
|
2016-12-22 16:41:44 -06:00
|
|
|
{
|
|
|
|
linebuffer.clear();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
linebuffer += str;
|
|
|
|
|
|
|
|
if (!linebuffer.empty() && linebuffer.back() == '\n') {
|
|
|
|
for (auto &re : log_warn_regexes)
|
2020-03-13 11:19:54 -05:00
|
|
|
if (YS_REGEX_NS::regex_search(linebuffer, re))
|
2016-12-22 16:41:44 -06:00
|
|
|
log_warning("Found log message matching -W regex:\n%s", str.c_str());
|
2020-02-14 05:21:16 -06:00
|
|
|
|
|
|
|
for (auto &item : log_expect_log)
|
2020-05-14 17:52:07 -05:00
|
|
|
if (YS_REGEX_NS::regex_search(linebuffer, item.second.pattern))
|
2020-02-14 05:21:16 -06:00
|
|
|
item.second.current_count++;
|
|
|
|
|
2016-12-22 16:41:44 -06:00
|
|
|
linebuffer.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
log_warn_regex_recusion_guard = false;
|
|
|
|
}
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
|
2016-04-21 16:28:37 -05:00
|
|
|
void logv_header(RTLIL::Design *design, const char *format, va_list ap)
|
2013-01-05 04:13:26 -06:00
|
|
|
{
|
2014-08-02 09:03:18 -05:00
|
|
|
bool pop_errfile = false;
|
|
|
|
|
2014-08-16 08:34:00 -05:00
|
|
|
log_spacer();
|
2013-01-05 04:13:26 -06:00
|
|
|
if (header_count.size() > 0)
|
|
|
|
header_count.back()++;
|
2014-08-02 09:03:18 -05:00
|
|
|
|
|
|
|
if (int(header_count.size()) <= log_verbose_level && log_errfile != NULL) {
|
|
|
|
log_files.push_back(log_errfile);
|
|
|
|
pop_errfile = true;
|
|
|
|
}
|
|
|
|
|
2016-04-21 16:28:37 -05:00
|
|
|
std::string header_id;
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
for (int c : header_count)
|
2016-04-21 16:28:37 -05:00
|
|
|
header_id += stringf("%s%d", header_id.empty() ? "" : ".", c);
|
|
|
|
|
|
|
|
log("%s. ", header_id.c_str());
|
2013-01-05 04:13:26 -06:00
|
|
|
logv(format, ap);
|
|
|
|
log_flush();
|
2013-11-17 06:26:31 -06:00
|
|
|
|
2016-04-24 10:12:34 -05:00
|
|
|
if (log_hdump_all)
|
|
|
|
log_hdump[header_id].insert("yosys_dump_" + header_id + ".il");
|
|
|
|
|
2016-04-21 16:28:37 -05:00
|
|
|
if (log_hdump.count(header_id) && design != nullptr)
|
|
|
|
for (auto &filename : log_hdump.at(header_id)) {
|
|
|
|
log("Dumping current design to '%s'.\n", filename.c_str());
|
2019-03-11 14:12:28 -05:00
|
|
|
if (yosys_xtrace)
|
|
|
|
IdString::xtrace_db_dump();
|
2016-04-21 16:28:37 -05:00
|
|
|
Pass::call(design, {"dump", "-o", filename});
|
2019-03-11 14:12:28 -05:00
|
|
|
if (yosys_xtrace)
|
|
|
|
log("#X# -- end of dump --\n");
|
2016-04-21 16:28:37 -05:00
|
|
|
}
|
|
|
|
|
2014-08-02 09:03:18 -05:00
|
|
|
if (pop_errfile)
|
|
|
|
log_files.pop_back();
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
|
2018-07-19 11:40:20 -05:00
|
|
|
static void logv_warning_with_prefix(const char *prefix,
|
|
|
|
const char *format, va_list ap)
|
2014-11-09 03:44:23 -06:00
|
|
|
{
|
2017-02-12 04:11:00 -06:00
|
|
|
std::string message = vstringf(format, ap);
|
|
|
|
bool suppressed = false;
|
2014-11-09 03:44:23 -06:00
|
|
|
|
2017-02-12 04:11:00 -06:00
|
|
|
for (auto &re : log_nowarn_regexes)
|
2020-03-13 11:19:54 -05:00
|
|
|
if (YS_REGEX_NS::regex_search(message, re))
|
2017-02-12 04:11:00 -06:00
|
|
|
suppressed = true;
|
2014-11-09 03:44:23 -06:00
|
|
|
|
2017-02-12 04:11:00 -06:00
|
|
|
if (suppressed)
|
|
|
|
{
|
2018-07-19 11:40:20 -05:00
|
|
|
log("Suppressed %s%s", prefix, message.c_str());
|
2017-02-12 04:11:00 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-05-22 06:46:38 -05:00
|
|
|
int bak_log_make_debug = log_make_debug;
|
|
|
|
log_make_debug = 0;
|
|
|
|
|
2018-05-04 08:27:28 -05:00
|
|
|
for (auto &re : log_werror_regexes)
|
2020-03-13 11:19:54 -05:00
|
|
|
if (YS_REGEX_NS::regex_search(message, re))
|
2018-05-04 08:27:28 -05:00
|
|
|
log_error("%s", message.c_str());
|
|
|
|
|
2020-02-22 03:52:46 -06:00
|
|
|
bool warning_match = false;
|
2020-02-14 05:21:16 -06:00
|
|
|
for (auto &item : log_expect_warning)
|
2020-05-14 17:52:07 -05:00
|
|
|
if (YS_REGEX_NS::regex_search(message, item.second.pattern)) {
|
2020-02-14 05:21:16 -06:00
|
|
|
item.second.current_count++;
|
2020-02-22 03:52:46 -06:00
|
|
|
warning_match = true;
|
|
|
|
}
|
2020-02-14 05:21:16 -06:00
|
|
|
|
2018-03-04 15:35:59 -06:00
|
|
|
if (log_warnings.count(message))
|
|
|
|
{
|
2018-07-19 11:40:20 -05:00
|
|
|
log("%s%s", prefix, message.c_str());
|
2018-03-04 15:35:59 -06:00
|
|
|
log_flush();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (log_errfile != NULL && !log_quiet_warnings)
|
|
|
|
log_files.push_back(log_errfile);
|
2017-02-12 04:11:00 -06:00
|
|
|
|
2018-07-19 11:40:20 -05:00
|
|
|
log("%s%s", prefix, message.c_str());
|
2018-03-04 15:35:59 -06:00
|
|
|
log_flush();
|
2017-02-12 04:11:00 -06:00
|
|
|
|
2018-03-04 15:35:59 -06:00
|
|
|
if (log_errfile != NULL && !log_quiet_warnings)
|
|
|
|
log_files.pop_back();
|
|
|
|
|
|
|
|
log_warnings.insert(message);
|
|
|
|
}
|
|
|
|
|
2020-02-22 03:52:46 -06:00
|
|
|
if (!warning_match)
|
|
|
|
log_warnings_count_noexpect++;
|
2018-03-04 15:35:59 -06:00
|
|
|
log_warnings_count++;
|
2019-05-22 06:46:38 -05:00
|
|
|
log_make_debug = bak_log_make_debug;
|
2017-02-12 04:11:00 -06:00
|
|
|
}
|
2014-11-09 03:44:23 -06:00
|
|
|
}
|
|
|
|
|
2018-07-19 11:40:20 -05:00
|
|
|
void logv_warning(const char *format, va_list ap)
|
2017-07-27 05:17:04 -05:00
|
|
|
{
|
2018-07-19 11:40:20 -05:00
|
|
|
logv_warning_with_prefix("Warning: ", format, ap);
|
|
|
|
}
|
2018-03-04 15:35:59 -06:00
|
|
|
|
2018-07-19 11:40:20 -05:00
|
|
|
void logv_warning_noprefix(const char *format, va_list ap)
|
|
|
|
{
|
|
|
|
logv_warning_with_prefix("", format, ap);
|
|
|
|
}
|
2017-07-27 05:17:04 -05:00
|
|
|
|
2018-07-19 11:40:20 -05:00
|
|
|
void log_file_warning(const std::string &filename, int lineno,
|
|
|
|
const char *format, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, format);
|
|
|
|
std::string prefix = stringf("%s:%d: Warning: ",
|
2019-06-07 05:41:09 -05:00
|
|
|
filename.c_str(), lineno);
|
2018-07-19 11:40:20 -05:00
|
|
|
logv_warning_with_prefix(prefix.c_str(), format, ap);
|
|
|
|
va_end(ap);
|
2017-07-27 05:17:04 -05:00
|
|
|
}
|
|
|
|
|
2019-05-02 19:10:43 -05:00
|
|
|
void log_file_info(const std::string &filename, int lineno,
|
|
|
|
const char *format, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, format);
|
2019-06-07 05:41:09 -05:00
|
|
|
std::string fmt = stringf("%s:%d: Info: %s",
|
|
|
|
filename.c_str(), lineno, format);
|
|
|
|
logv(fmt.c_str(), ap);
|
2018-07-19 11:40:20 -05:00
|
|
|
va_end(ap);
|
2017-07-27 05:17:04 -05:00
|
|
|
}
|
|
|
|
|
2020-06-18 20:05:59 -05:00
|
|
|
[[noreturn]]
|
2018-07-19 11:40:20 -05:00
|
|
|
static void logv_error_with_prefix(const char *prefix,
|
|
|
|
const char *format, va_list ap)
|
2013-01-05 04:13:26 -06:00
|
|
|
{
|
2015-02-19 06:36:54 -06:00
|
|
|
#ifdef EMSCRIPTEN
|
|
|
|
auto backup_log_files = log_files;
|
|
|
|
#endif
|
2019-05-22 06:46:38 -05:00
|
|
|
int bak_log_make_debug = log_make_debug;
|
|
|
|
log_make_debug = 0;
|
|
|
|
log_suppressed();
|
2015-02-19 06:36:54 -06:00
|
|
|
|
2014-08-02 14:54:30 -05:00
|
|
|
if (log_errfile != NULL)
|
|
|
|
log_files.push_back(log_errfile);
|
|
|
|
|
2015-01-03 15:10:33 -06:00
|
|
|
if (log_error_stderr)
|
|
|
|
for (auto &f : log_files)
|
|
|
|
if (f == stdout)
|
|
|
|
f = stderr;
|
|
|
|
|
2015-02-19 06:36:54 -06:00
|
|
|
log_last_error = vstringf(format, ap);
|
2022-01-03 21:12:22 -06:00
|
|
|
log("%s%s", prefix, log_last_error.c_str());
|
2013-01-05 04:13:26 -06:00
|
|
|
log_flush();
|
2015-02-19 06:36:54 -06:00
|
|
|
|
2019-05-22 06:46:38 -05:00
|
|
|
log_make_debug = bak_log_make_debug;
|
|
|
|
|
2020-02-14 05:21:16 -06:00
|
|
|
for (auto &item : log_expect_error)
|
2020-05-14 17:52:07 -05:00
|
|
|
if (YS_REGEX_NS::regex_search(log_last_error, item.second.pattern))
|
2020-02-14 05:21:16 -06:00
|
|
|
item.second.current_count++;
|
|
|
|
|
2021-08-12 10:36:03 -05:00
|
|
|
log_check_expected();
|
kernel: Trap in `log_error()` when a debugger is attached.
The workflow of debugging fatal pass errors in Yosys is flawed in
three ways:
1. Running Yosys under a debugger is sufficient for the debugger
to catch some fatal errors (segfaults, aborts, STL exceptions)
but not others (`log_error()`, `log_cmd_error()`). This is
neither obvious nor easy to remember.
2. To catch Yosys-specific fatal errors, it is necessary to set
a breakpoint at `logv_error_with_prefix()`, or at least,
`logv_error()`. This is neither obvious nor easy to remember,
and GDB's autocomplete takes many seconds to suggest function
names due to the large amount of symbols in Yosys.
3. If a breakpoint is not set and Yosys encounters with such
a fatal error, the process terminates. When debugging a crash
that takes a long time to reproduce (or a nondeterministic crash)
this can waste a significant amount of time.
To solve this problem, add a macro `YS_DEBUGTRAP` that acts as a hard
breakpoint (if available), and a macro `YS_DEBUGTRAP_IF_DEBUGGING`
that acts as a hard breakpoint only if debugger is present.
Then, use `YS_DEBUGTRAP_IF_DEBUGGING` in `logv_error_with_prefix()`
to obviate the need for a breakpoint on nearly every platform.
Co-Authored-By: Alberto Gonzalez <boqwxp@airmail.cc>
2020-04-24 14:37:47 -05:00
|
|
|
|
2021-02-23 19:39:13 -06:00
|
|
|
if (log_error_atexit)
|
|
|
|
log_error_atexit();
|
|
|
|
|
kernel: Trap in `log_error()` when a debugger is attached.
The workflow of debugging fatal pass errors in Yosys is flawed in
three ways:
1. Running Yosys under a debugger is sufficient for the debugger
to catch some fatal errors (segfaults, aborts, STL exceptions)
but not others (`log_error()`, `log_cmd_error()`). This is
neither obvious nor easy to remember.
2. To catch Yosys-specific fatal errors, it is necessary to set
a breakpoint at `logv_error_with_prefix()`, or at least,
`logv_error()`. This is neither obvious nor easy to remember,
and GDB's autocomplete takes many seconds to suggest function
names due to the large amount of symbols in Yosys.
3. If a breakpoint is not set and Yosys encounters with such
a fatal error, the process terminates. When debugging a crash
that takes a long time to reproduce (or a nondeterministic crash)
this can waste a significant amount of time.
To solve this problem, add a macro `YS_DEBUGTRAP` that acts as a hard
breakpoint (if available), and a macro `YS_DEBUGTRAP_IF_DEBUGGING`
that acts as a hard breakpoint only if debugger is present.
Then, use `YS_DEBUGTRAP_IF_DEBUGGING` in `logv_error_with_prefix()`
to obviate the need for a breakpoint on nearly every platform.
Co-Authored-By: Alberto Gonzalez <boqwxp@airmail.cc>
2020-04-24 14:37:47 -05:00
|
|
|
YS_DEBUGTRAP_IF_DEBUGGING;
|
2022-10-07 08:00:19 -05:00
|
|
|
const char *e = getenv("YOSYS_ABORT_ON_LOG_ERROR");
|
|
|
|
if (e && atoi(e))
|
|
|
|
abort();
|
kernel: Trap in `log_error()` when a debugger is attached.
The workflow of debugging fatal pass errors in Yosys is flawed in
three ways:
1. Running Yosys under a debugger is sufficient for the debugger
to catch some fatal errors (segfaults, aborts, STL exceptions)
but not others (`log_error()`, `log_cmd_error()`). This is
neither obvious nor easy to remember.
2. To catch Yosys-specific fatal errors, it is necessary to set
a breakpoint at `logv_error_with_prefix()`, or at least,
`logv_error()`. This is neither obvious nor easy to remember,
and GDB's autocomplete takes many seconds to suggest function
names due to the large amount of symbols in Yosys.
3. If a breakpoint is not set and Yosys encounters with such
a fatal error, the process terminates. When debugging a crash
that takes a long time to reproduce (or a nondeterministic crash)
this can waste a significant amount of time.
To solve this problem, add a macro `YS_DEBUGTRAP` that acts as a hard
breakpoint (if available), and a macro `YS_DEBUGTRAP_IF_DEBUGGING`
that acts as a hard breakpoint only if debugger is present.
Then, use `YS_DEBUGTRAP_IF_DEBUGGING` in `logv_error_with_prefix()`
to obviate the need for a breakpoint on nearly every platform.
Co-Authored-By: Alberto Gonzalez <boqwxp@airmail.cc>
2020-04-24 14:37:47 -05:00
|
|
|
|
2015-02-19 06:36:54 -06:00
|
|
|
#ifdef EMSCRIPTEN
|
|
|
|
log_files = backup_log_files;
|
|
|
|
throw 0;
|
2016-10-14 11:34:44 -05:00
|
|
|
#elif defined(_MSC_VER)
|
|
|
|
_exit(1);
|
2015-02-19 06:36:54 -06:00
|
|
|
#else
|
2016-08-16 02:36:49 -05:00
|
|
|
_Exit(1);
|
2015-02-19 06:36:54 -06:00
|
|
|
#endif
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
|
2018-07-19 11:40:20 -05:00
|
|
|
void logv_error(const char *format, va_list ap)
|
|
|
|
{
|
|
|
|
logv_error_with_prefix("ERROR: ", format, ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void log_file_error(const string &filename, int lineno,
|
|
|
|
const char *format, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, format);
|
|
|
|
std::string prefix = stringf("%s:%d: ERROR: ",
|
|
|
|
filename.c_str(), lineno);
|
|
|
|
logv_error_with_prefix(prefix.c_str(), format, ap);
|
|
|
|
}
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
void log(const char *format, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, format);
|
|
|
|
logv(format, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
2016-04-21 16:28:37 -05:00
|
|
|
void log_header(RTLIL::Design *design, const char *format, ...)
|
2013-01-05 04:13:26 -06:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, format);
|
2016-04-21 16:28:37 -05:00
|
|
|
logv_header(design, format, ap);
|
2013-01-05 04:13:26 -06:00
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
2014-11-09 03:44:23 -06:00
|
|
|
void log_warning(const char *format, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, format);
|
|
|
|
logv_warning(format, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
2020-01-27 11:27:47 -06:00
|
|
|
void log_experimental(const char *format, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, format);
|
|
|
|
string s = vstringf(format, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
2020-01-28 10:51:50 -06:00
|
|
|
if (log_experimentals_ignored.count(s) == 0 && log_experimentals.count(s) == 0) {
|
2020-01-27 11:27:47 -06:00
|
|
|
log_warning("Feature '%s' is experimental.\n", s.c_str());
|
|
|
|
log_experimentals.insert(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-27 05:17:04 -05:00
|
|
|
void log_warning_noprefix(const char *format, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, format);
|
|
|
|
logv_warning_noprefix(format, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
void log_error(const char *format, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, format);
|
|
|
|
logv_error(format, ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void log_cmd_error(const char *format, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, format);
|
|
|
|
|
|
|
|
if (log_cmd_error_throw) {
|
2015-02-19 06:36:54 -06:00
|
|
|
log_last_error = vstringf(format, ap);
|
|
|
|
log("ERROR: %s", log_last_error.c_str());
|
2013-01-05 04:13:26 -06:00
|
|
|
log_flush();
|
2014-11-07 05:48:15 -06:00
|
|
|
throw log_cmd_error_exception();
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
logv_error(format, ap);
|
|
|
|
}
|
|
|
|
|
2014-08-16 08:34:00 -05:00
|
|
|
void log_spacer()
|
|
|
|
{
|
2016-12-22 19:06:46 -06:00
|
|
|
if (log_newline_count < 2) log("\n");
|
|
|
|
if (log_newline_count < 2) log("\n");
|
2014-08-16 08:34:00 -05:00
|
|
|
}
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
void log_push()
|
|
|
|
{
|
|
|
|
header_count.push_back(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void log_pop()
|
|
|
|
{
|
|
|
|
header_count.pop_back();
|
2019-07-15 10:10:42 -05:00
|
|
|
log_id_cache_clear();
|
2013-01-05 04:13:26 -06:00
|
|
|
string_buf.clear();
|
2015-01-30 15:12:26 -06:00
|
|
|
string_buf_index = -1;
|
2013-01-05 04:13:26 -06:00
|
|
|
log_flush();
|
|
|
|
}
|
|
|
|
|
2018-05-05 06:02:44 -05:00
|
|
|
#if (defined(__linux__) || defined(__FreeBSD__)) && defined(YOSYS_ENABLE_PLUGINS)
|
2014-12-29 06:33:33 -06:00
|
|
|
void log_backtrace(const char *prefix, int levels)
|
|
|
|
{
|
|
|
|
if (levels <= 0) return;
|
|
|
|
|
|
|
|
Dl_info dli;
|
|
|
|
void *p;
|
|
|
|
|
|
|
|
if ((p = __builtin_extract_return_addr(__builtin_return_address(0))) && dladdr(p, &dli)) {
|
|
|
|
log("%sframe #1: %p %s(%p) %s(%p)\n", prefix, p, dli.dli_fname, dli.dli_fbase, dli.dli_sname, dli.dli_saddr);
|
|
|
|
} else {
|
|
|
|
log("%sframe #1: ---\n", prefix);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (levels <= 1) return;
|
|
|
|
|
2018-02-03 08:04:39 -06:00
|
|
|
#ifndef DEBUG
|
|
|
|
log("%sframe #2: [build Yosys with ENABLE_DEBUG for deeper backtraces]\n", prefix);
|
|
|
|
#else
|
2014-12-29 06:33:33 -06:00
|
|
|
if ((p = __builtin_extract_return_addr(__builtin_return_address(1))) && dladdr(p, &dli)) {
|
|
|
|
log("%sframe #2: %p %s(%p) %s(%p)\n", prefix, p, dli.dli_fname, dli.dli_fbase, dli.dli_sname, dli.dli_saddr);
|
|
|
|
} else {
|
|
|
|
log("%sframe #2: ---\n", prefix);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (levels <= 2) return;
|
|
|
|
|
|
|
|
if ((p = __builtin_extract_return_addr(__builtin_return_address(2))) && dladdr(p, &dli)) {
|
|
|
|
log("%sframe #3: %p %s(%p) %s(%p)\n", prefix, p, dli.dli_fname, dli.dli_fbase, dli.dli_sname, dli.dli_saddr);
|
|
|
|
} else {
|
|
|
|
log("%sframe #3: ---\n", prefix);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (levels <= 3) return;
|
|
|
|
|
|
|
|
if ((p = __builtin_extract_return_addr(__builtin_return_address(3))) && dladdr(p, &dli)) {
|
|
|
|
log("%sframe #4: %p %s(%p) %s(%p)\n", prefix, p, dli.dli_fname, dli.dli_fbase, dli.dli_sname, dli.dli_saddr);
|
|
|
|
} else {
|
|
|
|
log("%sframe #4: ---\n", prefix);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (levels <= 4) return;
|
|
|
|
|
|
|
|
if ((p = __builtin_extract_return_addr(__builtin_return_address(4))) && dladdr(p, &dli)) {
|
|
|
|
log("%sframe #5: %p %s(%p) %s(%p)\n", prefix, p, dli.dli_fname, dli.dli_fbase, dli.dli_sname, dli.dli_saddr);
|
|
|
|
} else {
|
|
|
|
log("%sframe #5: ---\n", prefix);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (levels <= 5) return;
|
|
|
|
|
|
|
|
if ((p = __builtin_extract_return_addr(__builtin_return_address(5))) && dladdr(p, &dli)) {
|
|
|
|
log("%sframe #6: %p %s(%p) %s(%p)\n", prefix, p, dli.dli_fname, dli.dli_fbase, dli.dli_sname, dli.dli_saddr);
|
|
|
|
} else {
|
|
|
|
log("%sframe #6: ---\n", prefix);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (levels <= 6) return;
|
|
|
|
|
|
|
|
if ((p = __builtin_extract_return_addr(__builtin_return_address(6))) && dladdr(p, &dli)) {
|
|
|
|
log("%sframe #7: %p %s(%p) %s(%p)\n", prefix, p, dli.dli_fname, dli.dli_fbase, dli.dli_sname, dli.dli_saddr);
|
|
|
|
} else {
|
|
|
|
log("%sframe #7: ---\n", prefix);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (levels <= 7) return;
|
|
|
|
|
|
|
|
if ((p = __builtin_extract_return_addr(__builtin_return_address(7))) && dladdr(p, &dli)) {
|
|
|
|
log("%sframe #8: %p %s(%p) %s(%p)\n", prefix, p, dli.dli_fname, dli.dli_fbase, dli.dli_sname, dli.dli_saddr);
|
|
|
|
} else {
|
|
|
|
log("%sframe #8: ---\n", prefix);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (levels <= 8) return;
|
|
|
|
|
|
|
|
if ((p = __builtin_extract_return_addr(__builtin_return_address(8))) && dladdr(p, &dli)) {
|
|
|
|
log("%sframe #9: %p %s(%p) %s(%p)\n", prefix, p, dli.dli_fname, dli.dli_fbase, dli.dli_sname, dli.dli_saddr);
|
|
|
|
} else {
|
|
|
|
log("%sframe #9: ---\n", prefix);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (levels <= 9) return;
|
2018-02-03 08:04:39 -06:00
|
|
|
#endif
|
2014-12-29 06:33:33 -06:00
|
|
|
}
|
2015-01-06 09:12:43 -06:00
|
|
|
#else
|
|
|
|
void log_backtrace(const char*, int) { }
|
|
|
|
#endif
|
2014-12-29 06:33:33 -06:00
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
void log_reset_stack()
|
|
|
|
{
|
|
|
|
while (header_count.size() > 1)
|
|
|
|
header_count.pop_back();
|
2019-07-15 10:10:42 -05:00
|
|
|
log_id_cache_clear();
|
2013-01-05 04:13:26 -06:00
|
|
|
string_buf.clear();
|
2015-01-30 15:12:26 -06:00
|
|
|
string_buf_index = -1;
|
2013-01-05 04:13:26 -06:00
|
|
|
log_flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
void log_flush()
|
|
|
|
{
|
|
|
|
for (auto f : log_files)
|
|
|
|
fflush(f);
|
2014-08-23 08:14:58 -05:00
|
|
|
|
|
|
|
for (auto f : log_streams)
|
|
|
|
f->flush();
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
|
2015-06-08 07:49:02 -05:00
|
|
|
void log_dump_val_worker(RTLIL::IdString v) {
|
|
|
|
log("%s", log_id(v));
|
|
|
|
}
|
|
|
|
|
2014-07-28 04:08:55 -05:00
|
|
|
void log_dump_val_worker(RTLIL::SigSpec v) {
|
|
|
|
log("%s", log_signal(v));
|
|
|
|
}
|
|
|
|
|
2019-10-02 19:49:07 -05:00
|
|
|
void log_dump_val_worker(RTLIL::State v) {
|
|
|
|
log("%s", log_signal(v));
|
|
|
|
}
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
const char *log_signal(const RTLIL::SigSpec &sig, bool autoint)
|
|
|
|
{
|
2014-08-23 06:54:21 -05:00
|
|
|
std::stringstream buf;
|
2020-08-26 12:29:32 -05:00
|
|
|
RTLIL_BACKEND::dump_sigspec(buf, sig, autoint);
|
2013-01-05 04:13:26 -06:00
|
|
|
|
2015-01-30 15:12:26 -06:00
|
|
|
if (string_buf.size() < 100) {
|
|
|
|
string_buf.push_back(buf.str());
|
|
|
|
return string_buf.back().c_str();
|
|
|
|
} else {
|
|
|
|
if (++string_buf_index == 100)
|
|
|
|
string_buf_index = 0;
|
|
|
|
string_buf[string_buf_index] = buf.str();
|
|
|
|
return string_buf[string_buf_index].c_str();
|
|
|
|
}
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
|
2016-08-09 12:56:10 -05:00
|
|
|
const char *log_const(const RTLIL::Const &value, bool autoint)
|
|
|
|
{
|
|
|
|
if ((value.flags & RTLIL::CONST_FLAG_STRING) == 0)
|
|
|
|
return log_signal(value, autoint);
|
|
|
|
|
|
|
|
std::string str = "\"" + value.decode_string() + "\"";
|
|
|
|
|
|
|
|
if (string_buf.size() < 100) {
|
|
|
|
string_buf.push_back(str);
|
|
|
|
return string_buf.back().c_str();
|
|
|
|
} else {
|
|
|
|
if (++string_buf_index == 100)
|
|
|
|
string_buf_index = 0;
|
|
|
|
string_buf[string_buf_index] = str;
|
|
|
|
return string_buf[string_buf_index].c_str();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-27 09:15:11 -05:00
|
|
|
const char *log_id(const RTLIL::IdString &str)
|
2014-07-19 13:53:29 -05:00
|
|
|
{
|
2019-07-15 10:10:42 -05:00
|
|
|
log_id_cache.push_back(strdup(str.c_str()));
|
|
|
|
const char *p = log_id_cache.back();
|
2015-01-30 15:22:52 -06:00
|
|
|
if (p[0] != '\\')
|
|
|
|
return p;
|
|
|
|
if (p[1] == '$' || p[1] == '\\' || p[1] == 0)
|
|
|
|
return p;
|
|
|
|
if (p[1] >= '0' && p[1] <= '9')
|
|
|
|
return p;
|
|
|
|
return p+1;
|
2014-07-19 13:53:29 -05:00
|
|
|
}
|
2014-07-20 03:35:47 -05:00
|
|
|
|
2016-07-27 08:40:17 -05:00
|
|
|
void log_module(RTLIL::Module *module, std::string indent)
|
|
|
|
{
|
|
|
|
std::stringstream buf;
|
2020-08-26 12:29:32 -05:00
|
|
|
RTLIL_BACKEND::dump_module(buf, indent, module, module->design, false);
|
2016-07-27 08:40:17 -05:00
|
|
|
log("%s", buf.str().c_str());
|
|
|
|
}
|
|
|
|
|
2014-07-20 03:35:47 -05:00
|
|
|
void log_cell(RTLIL::Cell *cell, std::string indent)
|
|
|
|
{
|
2014-08-23 06:54:21 -05:00
|
|
|
std::stringstream buf;
|
2020-08-26 12:29:32 -05:00
|
|
|
RTLIL_BACKEND::dump_cell(buf, indent, cell);
|
2014-08-23 06:54:21 -05:00
|
|
|
log("%s", buf.str().c_str());
|
2014-07-20 03:35:47 -05:00
|
|
|
}
|
|
|
|
|
2017-02-11 04:08:12 -06:00
|
|
|
void log_wire(RTLIL::Wire *wire, std::string indent)
|
|
|
|
{
|
|
|
|
std::stringstream buf;
|
2020-08-26 12:29:32 -05:00
|
|
|
RTLIL_BACKEND::dump_wire(buf, indent, wire);
|
2017-02-11 04:08:12 -06:00
|
|
|
log("%s", buf.str().c_str());
|
|
|
|
}
|
|
|
|
|
2020-02-14 05:21:16 -06:00
|
|
|
void log_check_expected()
|
|
|
|
{
|
2022-01-03 21:12:22 -06:00
|
|
|
// copy out all of the expected logs so that they cannot be re-checked
|
|
|
|
// or match against themselves
|
|
|
|
dict<std::string, LogExpectedItem> expect_log, expect_warning, expect_error;
|
|
|
|
std::swap(expect_warning, log_expect_warning);
|
|
|
|
std::swap(expect_log, log_expect_log);
|
|
|
|
std::swap(expect_error, log_expect_error);
|
|
|
|
|
|
|
|
for (auto &item : expect_warning) {
|
2020-02-22 03:52:46 -06:00
|
|
|
if (item.second.current_count == 0) {
|
2020-02-23 03:56:27 -06:00
|
|
|
log_warn_regexes.clear();
|
2020-05-14 17:52:07 -05:00
|
|
|
log_error("Expected warning pattern '%s' not found !\n", item.first.c_str());
|
2020-02-14 05:21:16 -06:00
|
|
|
}
|
|
|
|
if (item.second.current_count != item.second.expected_count) {
|
2020-02-23 03:56:27 -06:00
|
|
|
log_warn_regexes.clear();
|
kernel: Trap in `log_error()` when a debugger is attached.
The workflow of debugging fatal pass errors in Yosys is flawed in
three ways:
1. Running Yosys under a debugger is sufficient for the debugger
to catch some fatal errors (segfaults, aborts, STL exceptions)
but not others (`log_error()`, `log_cmd_error()`). This is
neither obvious nor easy to remember.
2. To catch Yosys-specific fatal errors, it is necessary to set
a breakpoint at `logv_error_with_prefix()`, or at least,
`logv_error()`. This is neither obvious nor easy to remember,
and GDB's autocomplete takes many seconds to suggest function
names due to the large amount of symbols in Yosys.
3. If a breakpoint is not set and Yosys encounters with such
a fatal error, the process terminates. When debugging a crash
that takes a long time to reproduce (or a nondeterministic crash)
this can waste a significant amount of time.
To solve this problem, add a macro `YS_DEBUGTRAP` that acts as a hard
breakpoint (if available), and a macro `YS_DEBUGTRAP_IF_DEBUGGING`
that acts as a hard breakpoint only if debugger is present.
Then, use `YS_DEBUGTRAP_IF_DEBUGGING` in `logv_error_with_prefix()`
to obviate the need for a breakpoint on nearly every platform.
Co-Authored-By: Alberto Gonzalez <boqwxp@airmail.cc>
2020-04-24 14:37:47 -05:00
|
|
|
log_error("Expected warning pattern '%s' found %d time(s), instead of %d time(s) !\n",
|
2020-05-14 17:52:07 -05:00
|
|
|
item.first.c_str(), item.second.current_count, item.second.expected_count);
|
2020-02-14 05:21:16 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-03 21:12:22 -06:00
|
|
|
for (auto &item : expect_log) {
|
2020-02-14 05:21:16 -06:00
|
|
|
if (item.second.current_count == 0) {
|
2020-02-23 03:56:27 -06:00
|
|
|
log_warn_regexes.clear();
|
2020-05-14 17:52:07 -05:00
|
|
|
log_error("Expected log pattern '%s' not found !\n", item.first.c_str());
|
2020-02-14 05:21:16 -06:00
|
|
|
}
|
|
|
|
if (item.second.current_count != item.second.expected_count) {
|
2020-02-23 03:56:27 -06:00
|
|
|
log_warn_regexes.clear();
|
2020-02-14 05:21:16 -06:00
|
|
|
log_error("Expected log pattern '%s' found %d time(s), instead of %d time(s) !\n",
|
2020-05-14 17:52:07 -05:00
|
|
|
item.first.c_str(), item.second.current_count, item.second.expected_count);
|
2020-02-14 05:21:16 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-03 21:12:22 -06:00
|
|
|
for (auto &item : expect_error)
|
2020-02-14 05:21:16 -06:00
|
|
|
if (item.second.current_count == item.second.expected_count) {
|
2020-02-23 03:56:27 -06:00
|
|
|
log_warn_regexes.clear();
|
2020-05-14 17:52:07 -05:00
|
|
|
log("Expected error pattern '%s' found !!!\n", item.first.c_str());
|
2020-02-14 05:21:16 -06:00
|
|
|
#ifdef EMSCRIPTEN
|
|
|
|
throw 0;
|
|
|
|
#elif defined(_MSC_VER)
|
|
|
|
_exit(0);
|
|
|
|
#else
|
|
|
|
_Exit(0);
|
kernel: Trap in `log_error()` when a debugger is attached.
The workflow of debugging fatal pass errors in Yosys is flawed in
three ways:
1. Running Yosys under a debugger is sufficient for the debugger
to catch some fatal errors (segfaults, aborts, STL exceptions)
but not others (`log_error()`, `log_cmd_error()`). This is
neither obvious nor easy to remember.
2. To catch Yosys-specific fatal errors, it is necessary to set
a breakpoint at `logv_error_with_prefix()`, or at least,
`logv_error()`. This is neither obvious nor easy to remember,
and GDB's autocomplete takes many seconds to suggest function
names due to the large amount of symbols in Yosys.
3. If a breakpoint is not set and Yosys encounters with such
a fatal error, the process terminates. When debugging a crash
that takes a long time to reproduce (or a nondeterministic crash)
this can waste a significant amount of time.
To solve this problem, add a macro `YS_DEBUGTRAP` that acts as a hard
breakpoint (if available), and a macro `YS_DEBUGTRAP_IF_DEBUGGING`
that acts as a hard breakpoint only if debugger is present.
Then, use `YS_DEBUGTRAP_IF_DEBUGGING` in `logv_error_with_prefix()`
to obviate the need for a breakpoint on nearly every platform.
Co-Authored-By: Alberto Gonzalez <boqwxp@airmail.cc>
2020-04-24 14:37:47 -05:00
|
|
|
#endif
|
2020-02-14 05:21:16 -06:00
|
|
|
} else {
|
2020-02-23 03:56:27 -06:00
|
|
|
log_warn_regexes.clear();
|
2020-05-14 17:52:07 -05:00
|
|
|
log_error("Expected error pattern '%s' not found !\n", item.first.c_str());
|
2020-02-14 05:21:16 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-28 04:08:55 -05:00
|
|
|
// ---------------------------------------------------
|
|
|
|
// This is the magic behind the code coverage counters
|
|
|
|
// ---------------------------------------------------
|
2018-05-05 06:02:44 -05:00
|
|
|
#if defined(YOSYS_ENABLE_COVER) && (defined(__linux__) || defined(__FreeBSD__))
|
2014-07-28 04:08:55 -05:00
|
|
|
|
2014-12-26 14:35:22 -06:00
|
|
|
dict<std::string, std::pair<std::string, int>> extra_coverage_data;
|
2014-07-28 04:08:55 -05:00
|
|
|
|
|
|
|
void cover_extra(std::string parent, std::string id, bool increment) {
|
|
|
|
if (extra_coverage_data.count(id) == 0) {
|
|
|
|
for (CoverData *p = __start_yosys_cover_list; p != __stop_yosys_cover_list; p++)
|
|
|
|
if (p->id == parent)
|
|
|
|
extra_coverage_data[id].first = stringf("%s:%d:%s", p->file, p->line, p->func);
|
|
|
|
log_assert(extra_coverage_data.count(id));
|
|
|
|
}
|
|
|
|
if (increment)
|
|
|
|
extra_coverage_data[id].second++;
|
|
|
|
}
|
|
|
|
|
2014-12-26 14:35:22 -06:00
|
|
|
dict<std::string, std::pair<std::string, int>> get_coverage_data()
|
2014-07-28 04:08:55 -05:00
|
|
|
{
|
2014-12-26 14:35:22 -06:00
|
|
|
dict<std::string, std::pair<std::string, int>> coverage_data;
|
2014-07-28 04:08:55 -05:00
|
|
|
|
2014-07-31 06:19:47 -05:00
|
|
|
for (auto &it : pass_register) {
|
2014-07-28 04:08:55 -05:00
|
|
|
std::string key = stringf("passes.%s", it.first.c_str());
|
|
|
|
coverage_data[key].first = stringf("%s:%d:%s", __FILE__, __LINE__, __FUNCTION__);
|
|
|
|
coverage_data[key].second += it.second->call_counter;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto &it : extra_coverage_data) {
|
|
|
|
if (coverage_data.count(it.first))
|
2014-11-09 03:44:23 -06:00
|
|
|
log_warning("found duplicate coverage id \"%s\".\n", it.first.c_str());
|
2014-07-28 04:08:55 -05:00
|
|
|
coverage_data[it.first].first = it.second.first;
|
|
|
|
coverage_data[it.first].second += it.second.second;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (CoverData *p = __start_yosys_cover_list; p != __stop_yosys_cover_list; p++) {
|
|
|
|
if (coverage_data.count(p->id))
|
2014-11-09 03:44:23 -06:00
|
|
|
log_warning("found duplicate coverage id \"%s\".\n", p->id);
|
2014-07-28 04:08:55 -05:00
|
|
|
coverage_data[p->id].first = stringf("%s:%d:%s", p->file, p->line, p->func);
|
|
|
|
coverage_data[p->id].second += p->counter;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto &it : coverage_data)
|
|
|
|
if (!it.second.first.compare(0, strlen(YOSYS_SRC "/"), YOSYS_SRC "/"))
|
|
|
|
it.second.first = it.second.first.substr(strlen(YOSYS_SRC "/"));
|
|
|
|
|
|
|
|
return coverage_data;
|
|
|
|
}
|
|
|
|
|
2014-08-11 08:55:41 -05:00
|
|
|
#endif
|
|
|
|
|
2014-07-31 06:19:47 -05:00
|
|
|
YOSYS_NAMESPACE_END
|