fix test shell with debug
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <QtGlobal> // ✅ 确保 QtMsgType 被正确包含
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <list>
|
||||
@@ -24,7 +24,12 @@ extern bool debugOutputEnabled;
|
||||
void redirectErrorOutput(bool enabled);
|
||||
void redirectWarnOutput(bool enabled);
|
||||
void redirectNormalOutput(bool enabled);
|
||||
void redirectDebugOutput(bool enabled);
|
||||
// ------------------ 重定向函数 ------------------
|
||||
void redirectDebugOutput(bool enable);
|
||||
|
||||
// ------------------ Qt 的消息处理函数 (Qt4) ------------------
|
||||
// Qt4 使用 qInstallMsgHandler(...),签名: void myMsgHandler(QtMsgType, const char*)
|
||||
void myQtMsgHandler(QtMsgType type, const char* msg);
|
||||
|
||||
extern pthread_mutex_t errorListMutex;
|
||||
extern pthread_mutex_t warnListMutex;
|
||||
@@ -37,11 +42,19 @@ void real_echo_msg(const char *format, ...);
|
||||
// **拦截所有 `echo_msgX()`,让它同时存入 `normalList`**
|
||||
#define echo_msgX(format, ...) \
|
||||
do { \
|
||||
real_echo_msg(format, ##__VA_ARGS__); /* 调用原始 `echo_msgX()` */ \
|
||||
char buffer[1024]; \
|
||||
snprintf(buffer, sizeof(buffer), format, ##__VA_ARGS__); \
|
||||
\
|
||||
/* ✅ 先打印到 Shell,确保不会卡死 */ \
|
||||
printf("%s", buffer); \
|
||||
fflush(stdout); /* ✅ 立即刷新,防止标准输出缓存 */ \
|
||||
\
|
||||
/* ✅ 先创建日志副本,避免锁住 `normalList` 过久 */ \
|
||||
std::string logEntry(buffer); \
|
||||
\
|
||||
/* ✅ 仅在 `normalList` 操作时加锁,避免死锁 */ \
|
||||
pthread_mutex_lock(&normalListMutex); \
|
||||
normalList.push_back(buffer); \
|
||||
normalList.push_back(logEntry); \
|
||||
pthread_mutex_unlock(&normalListMutex); \
|
||||
} while (0)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user