Another approach to track down a segmentation fault

This commit is contained in:
Bill Somerville 2020-11-13 19:32:56 +00:00
parent 8cf2fa7752
commit 403528e436
No known key found for this signature in database
GPG Key ID: D864B06D1E81618F
3 changed files with 108 additions and 108 deletions

View File

@ -192,53 +192,53 @@ WSJTXLogging::~WSJTXLogging ()
lg->remove_all_sinks ();
}
// Reroute Qt messages to the system logger
void WSJTXLogging::qt_log_handler (QtMsgType type, QMessageLogContext const& context, QString const& msg)
{
std::cerr << "qt_log_handler: type: " << int(type) << " file: " << context.file << " line: " << context.line << " msg: " << msg.toStdString () << '\n';
// // Reroute Qt messages to the system logger
// void WSJTXLogging::qt_log_handler (QtMsgType type, QMessageLogContext const& context, QString const& msg)
// {
// std::cerr << "qt_log_handler: type: " << int(type) << " file: " << context.file << " line: " << context.line << " msg: " << msg.toStdString () << '\n';
// Convert Qt message types to logger severities
auto severity = trivial::trace;
switch (type)
{
case QtDebugMsg: severity = trivial::debug; break;
case QtInfoMsg: severity = trivial::info; break;
case QtWarningMsg: severity = trivial::warning; break;
case QtCriticalMsg: severity = trivial::error; break;
case QtFatalMsg: severity = trivial::fatal; break;
}
// Map non-default Qt categories to logger channels, Qt logger
// context is mapped to the appropriate logger attributes.
auto log = sys::get ();
std::string file;
std::string function;
if (context.file)
{
file = context.file;
}
if (context.function)
{
function = context.function;
}
if (!context.category || !qstrcmp (context.category, "default"))
{
BOOST_LOG_SEV (log, severity)
// << boost::log::add_value ("Line", context.line)
// << boost::log::add_value ("File", file)
// << boost::log::add_value ("Function", function)
<< msg.toStdString ();
}
else
{
BOOST_LOG_CHANNEL_SEV (log, std::string {context.category}, severity)
// << boost::log::add_value ("Line", context.line)
// << boost::log::add_value ("File", file)
// << boost::log::add_value ("Function", function)
<< msg.toStdString ();
}
if (QtFatalMsg == type)
{
// bail out
throw std::runtime_error {"Fatal Qt Error"};
}
}
// // Convert Qt message types to logger severities
// auto severity = trivial::trace;
// switch (type)
// {
// case QtDebugMsg: severity = trivial::debug; break;
// case QtInfoMsg: severity = trivial::info; break;
// case QtWarningMsg: severity = trivial::warning; break;
// case QtCriticalMsg: severity = trivial::error; break;
// case QtFatalMsg: severity = trivial::fatal; break;
// }
// // Map non-default Qt categories to logger channels, Qt logger
// // context is mapped to the appropriate logger attributes.
// auto log = sys::get ();
// std::string file;
// std::string function;
// if (context.file)
// {
// file = context.file;
// }
// if (context.function)
// {
// function = context.function;
// }
// if (!context.category || !qstrcmp (context.category, "default"))
// {
// BOOST_LOG_SEV (log, severity)
// // << boost::log::add_value ("Line", context.line)
// // << boost::log::add_value ("File", file)
// // << boost::log::add_value ("Function", function)
// << msg.toStdString ();
// }
// else
// {
// BOOST_LOG_CHANNEL_SEV (log, std::string {context.category}, severity)
// // << boost::log::add_value ("Line", context.line)
// // << boost::log::add_value ("File", file)
// // << boost::log::add_value ("Function", function)
// << msg.toStdString ();
// }
// if (QtFatalMsg == type)
// {
// // bail out
// throw std::runtime_error {"Fatal Qt Error"};
// }
// }

View File

@ -22,7 +22,7 @@ public:
// time, it does not rely on an instance of WSJTXLogging existing,
// so logging occurring before the logging sinks, filters, and
// formatters, etc, are established can take place.
static void qt_log_handler (QtMsgType type, QMessageLogContext const& context, QString const&);
// static void qt_log_handler (QtMsgType type, QMessageLogContext const& context, QString const&);
};
#endif

116
main.cpp
View File

@ -71,34 +71,34 @@ namespace
} seeding;
#endif
// void safe_stream_QVariant (boost::log::record_ostream& os, QVariant const& v)
// {
// switch (static_cast<QMetaType::Type> (v.type ()))
// {
// case QMetaType::QByteArray:
// os << "0x" << v.toByteArray ().toHex (':').toStdString ();
// break;
void safe_stream_QVariant (boost::log::record_ostream& os, QVariant const& v)
{
switch (static_cast<QMetaType::Type> (v.type ()))
{
case QMetaType::QByteArray:
os << "0x" << v.toByteArray ().toHex (':').toStdString ();
break;
// case QMetaType::QBitArray:
// {
// auto const& bits = v.toBitArray ();
// os << "0b";
// for (int i = 0; i < bits.size (); ++ i)
// {
// os << (bits[i] ? '1' : '0');
// }
// }
// break;
case QMetaType::QBitArray:
{
auto const& bits = v.toBitArray ();
os << "0b";
for (int i = 0; i < bits.size (); ++ i)
{
os << (bits[i] ? '1' : '0');
}
}
break;
// default:
// os << v.toString ();
// }
// }
default:
os << v.toString ();
}
}
}
int main(int argc, char *argv[])
{
::qInstallMessageHandler (&WSJTXLogging::qt_log_handler);
// ::qInstallMessageHandler (&WSJTXLogging::qt_log_handler);
init_random_seed ();
// make the Qt type magic happen
@ -325,42 +325,42 @@ int main(int argc, char *argv[])
do
{
// dump settings
// auto sys_lg = sys::get ();
// if (auto rec = sys_lg.open_record
// (
// boost::log::keywords::severity = boost::log::trivial::trace)
// )
// {
// boost::log::record_ostream strm (rec);
// strm << "++++++++++++++++++++++++++++ Settings ++++++++++++++++++++++++++++\n";
// for (auto const& key: multi_settings.settings ()->allKeys ())
// {
// if (!key.contains (QRegularExpression {"^MultiSettings/[^/]*/"}))
// {
// auto const& value = multi_settings.settings ()->value (key);
// if (value.canConvert<QVariantList> ())
// {
// auto const sequence = value.value<QSequentialIterable> ();
// strm << key << ":\n";
// for (auto const& item: sequence)
// {
// strm << "\t";
// safe_stream_QVariant (strm, item);
// strm << '\n';
// }
// }
// else
// {
// strm << key << ": ";
// safe_stream_QVariant (strm, value);
// strm << '\n';
// }
// }
// }
// strm << "---------------------------- Settings ----------------------------\n";
// strm.flush ();
// sys_lg.push_record (boost::move (rec));
// }
auto sys_lg = sys::get ();
if (auto rec = sys_lg.open_record
(
boost::log::keywords::severity = boost::log::trivial::trace)
)
{
boost::log::record_ostream strm (rec);
strm << "++++++++++++++++++++++++++++ Settings ++++++++++++++++++++++++++++\n";
for (auto const& key: multi_settings.settings ()->allKeys ())
{
if (!key.contains (QRegularExpression {"^MultiSettings/[^/]*/"}))
{
auto const& value = multi_settings.settings ()->value (key);
if (value.canConvert<QVariantList> ())
{
auto const sequence = value.value<QSequentialIterable> ();
strm << key << ":\n";
for (auto const& item: sequence)
{
strm << "\t";
safe_stream_QVariant (strm, item);
strm << '\n';
}
}
else
{
strm << key << ": ";
safe_stream_QVariant (strm, value);
strm << '\n';
}
}
}
strm << "---------------------------- Settings ----------------------------\n";
strm.flush ();
sys_lg.push_record (boost::move (rec));
}
// Create and initialize shared memory segment
// Multiple instances: use rig_name as shared memory key