summaryrefslogtreecommitdiffstats
path: root/src/corelib/global/qlogging_p.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/global/qlogging_p.h')
-rw-r--r--src/corelib/global/qlogging_p.h48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/corelib/global/qlogging_p.h b/src/corelib/global/qlogging_p.h
index 9492f10f1f..bc331c80c0 100644
--- a/src/corelib/global/qlogging_p.h
+++ b/src/corelib/global/qlogging_p.h
@@ -16,6 +16,22 @@
//
#include <QtCore/private/qglobal_p.h>
+#include "qlogging.h"
+#include "qloggingcategory.h"
+
+#if !defined(QT_BOOTSTRAPPED) && QT_CONFIG(regularexpression)
+# if __has_include(<cxxabi.h>) && QT_CONFIG(backtrace)
+# include <optional>
+# include "qvarlengtharray.h"
+# define QLOGGING_USE_EXECINFO_BACKTRACE
+# define QLOGGING_HAVE_BACKTRACE
+# elif QT_CONFIG(cxx23_stacktrace)
+# include <optional>
+# include <stacktrace>
+# define QLOGGING_USE_STD_BACKTRACE
+# define QLOGGING_HAVE_BACKTRACE
+# endif
+#endif // QT_BOOTSTRAPPED
QT_BEGIN_NAMESPACE
@@ -25,6 +41,38 @@ Q_CORE_EXPORT bool shouldLogToStderr();
}
+class QInternalMessageLogContext : public QMessageLogContext
+{
+public:
+ static constexpr int DefaultBacktraceDepth = 32;
+
+#if defined(QLOGGING_USE_EXECINFO_BACKTRACE)
+ using BacktraceStorage = QVarLengthArray<void *, DefaultBacktraceDepth>;
+#elif defined(QLOGGING_USE_STD_BACKTRACE)
+ using BacktraceStorage = std::stacktrace;
+#else
+ using BacktraceStorage = bool; // dummy
+#endif
+
+ std::optional<BacktraceStorage> backtrace;
+
+ Q_ALWAYS_INLINE QInternalMessageLogContext(const QMessageLogContext &logContext)
+ {
+ int backtraceFrames = initFrom(logContext);
+ if (backtraceFrames)
+ populateBacktrace(backtraceFrames);
+ }
+ QInternalMessageLogContext(const QMessageLogContext &logContext,
+ const QLoggingCategory &categoryOverride)
+ : QInternalMessageLogContext(logContext)
+ {
+ category = categoryOverride.categoryName();
+ }
+
+ int initFrom(const QMessageLogContext &logContext);
+ void populateBacktrace(int frameCount);
+};
+
QT_END_NAMESPACE
#endif // QLOGGING_P_H