Skip to content

Commit e5a8bee

Browse files
updated debug macros.
1 parent 83ac5b6 commit e5a8bee

5 files changed

Lines changed: 109 additions & 20 deletions

File tree

src/tdebug.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,6 @@
1414
#include <TLog>
1515
#include <TLogger>
1616

17-
#undef tFatal
18-
#undef tError
19-
#undef tWarn
20-
#undef tInfo
21-
#undef tDebug
22-
#undef tTrace
23-
2417
/*!
2518
\class TDebug
2619
\brief The TDebug class provides a file output stream for debugging information.
@@ -152,10 +145,10 @@ void TDebug::fatal(const char *fmt, ...) const
152145
flushAppLoggers();
153146

154147
if (Tf::appSettings()->value(Tf::ApplicationAbortOnFatal).toBool()) {
155-
#if (defined(Q_OS_UNIX) || defined(Q_CC_MINGW))
148+
#if defined(Q_OS_UNIX)
156149
abort(); // trap; generates core dump
157150
#else
158-
_exit(-1);
151+
std::exit(-1);
159152
#endif
160153
}
161154
}

src/tglobal.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,13 @@ int64_t Tf::getMSecsSinceEpoch()
299299
}
300300

301301

302+
bool getAbortOnFatalFlag()
303+
{
304+
static bool ret = Tf::appSettings()->value(Tf::ApplicationAbortOnFatal).toBool();
305+
return ret;
306+
}
307+
308+
302309
/*!
303310
\def T_EXPORT(VAR)
304311
Exports the current value of a local variable named \a VAR from the

src/tglobal.h

Lines changed: 97 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,6 @@ constexpr auto TF_SRC_REVISION = 3082;
165165
#define T_VARIANT(VAR) (variant(QLatin1String(#VAR)).toString())
166166

167167

168-
#define tFatal TDebug(Tf::FatalLevel).fatal
169-
#define tError TDebug(Tf::ErrorLevel).error
170-
#define tWarn TDebug(Tf::WarnLevel).warn
171-
#define tInfo TDebug(Tf::InfoLevel).info
172-
#define tDebug TDebug(Tf::DebugLevel).debug
173-
#define tTrace TDebug(Tf::TraceLevel).trace
174-
175-
176168
#include "tfexception.h"
177169
#include "tfnamespace.h"
178170
#include "tdeclexport.h"
@@ -181,6 +173,86 @@ constexpr auto TF_SRC_REVISION = 3082;
181173
#include <cstring>
182174
#include <functional>
183175
#include <algorithm>
176+
177+
178+
T_CORE_EXPORT bool getAbortOnFatalFlag();
179+
180+
181+
inline TDebug tFatal()
182+
{
183+
return TDebug(Tf::FatalLevel);
184+
}
185+
186+
inline TDebug tError()
187+
{
188+
return TDebug(Tf::ErrorLevel);
189+
}
190+
191+
inline TDebug tWarn()
192+
{
193+
return TDebug(Tf::WarnLevel);
194+
}
195+
196+
inline TDebug tInfo()
197+
{
198+
return TDebug(Tf::InfoLevel);
199+
}
200+
201+
inline TDebug tDebug()
202+
{
203+
return TDebug(Tf::DebugLevel);
204+
}
205+
206+
inline TDebug tTrace()
207+
{
208+
return TDebug(Tf::TraceLevel);
209+
}
210+
211+
template <typename... Args>
212+
inline void tFatal(const char *fmt, Args&&... args)
213+
{
214+
TDebug(Tf::FatalLevel).fatal(fmt, std::forward<Args>(args)...);
215+
216+
if (getAbortOnFatalFlag()) {
217+
#if defined(Q_OS_UNIX)
218+
abort(); // trap; generates core dump
219+
#else
220+
std::exit(-1);
221+
#endif
222+
}
223+
}
224+
225+
template <typename... Args>
226+
inline void tError(const char *fmt, Args&&... args)
227+
{
228+
TDebug(Tf::FatalLevel).error(fmt, std::forward<Args>(args)...);
229+
}
230+
231+
template <typename... Args>
232+
inline void tWarn(const char *fmt, Args&&... args)
233+
{
234+
TDebug(Tf::FatalLevel).warn(fmt, std::forward<Args>(args)...);
235+
}
236+
237+
template <typename... Args>
238+
inline void tInfo(const char *fmt, Args&&... args)
239+
{
240+
TDebug(Tf::FatalLevel).info(fmt, std::forward<Args>(args)...);
241+
}
242+
243+
template <typename... Args>
244+
inline void tDebug(const char *fmt, Args&&... args)
245+
{
246+
TDebug(Tf::FatalLevel).debug(fmt, std::forward<Args>(args)...);
247+
}
248+
249+
template <typename... Args>
250+
inline void tTrace(const char *fmt, Args&&... args)
251+
{
252+
TDebug(Tf::FatalLevel).trace(fmt, std::forward<Args>(args)...);
253+
}
254+
255+
184256
#ifdef TF_HAVE_STD_FORMAT // std::format
185257
#include <format>
186258

@@ -219,6 +291,7 @@ class TCache;
219291
class QSqlDatabase;
220292

221293
namespace Tf {
294+
222295
T_CORE_EXPORT TWebApplication *app() noexcept;
223296
T_CORE_EXPORT TAppSettings *appSettings() noexcept;
224297
T_CORE_EXPORT const QVariantMap &conf(const QString &configName) noexcept;
@@ -262,6 +335,14 @@ void fatal(const std::format_string<Args...> &fmt, Args&&... args)
262335
{
263336
std::string msg = std::format(fmt, std::forward<Args>(args)...);
264337
Tf::logging(Tf::FatalLevel, QByteArray::fromStdString(msg));
338+
339+
if (getAbortOnFatalFlag()) {
340+
#if defined(Q_OS_UNIX)
341+
abort(); // trap; generates core dump
342+
#else
343+
std::exit(-1);
344+
#endif
345+
}
265346
}
266347

267348
/*!
@@ -375,6 +456,14 @@ void fatal(const std::string &fmt, Args&&... args)
375456
{
376457
auto msg = simple_format(std::string(fmt), std::forward<Args>(args)...);
377458
Tf::logging(Tf::FatalLevel, msg);
459+
460+
if (getAbortOnFatalFlag()) {
461+
#if defined(Q_OS_UNIX)
462+
abort(); // trap; generates core dump
463+
#else
464+
std::exit(-1);
465+
#endif
466+
}
378467
}
379468

380469
template<typename... Args>

tools/tspawn/filewriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ bool FileWriter::write(const QString &data, bool overwrite) const
125125
break;
126126

127127
} else if (c == 'Q' || c == 'q') {
128-
::_exit(1);
128+
std::exit(1);
129129
return false;
130130

131131
} else if (c == 'D' || c == 'd') {

tools/tspawn/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,14 +457,14 @@ int deleteScaffold(const QString &name)
457457
// Removes controllers
458458
rmfiles(ctrls, allRemove, quit, D_CTRLS, "controllers.pro");
459459
if (quit) {
460-
::_exit(1);
460+
std::exit(1);
461461
return 1;
462462
}
463463

464464
// Removes models
465465
rmfiles(models, allRemove, quit, D_MODELS, "models.pro");
466466
if (quit) {
467-
::_exit(1);
467+
std::exit(1);
468468
return 1;
469469
}
470470

0 commit comments

Comments
 (0)