Skip to content

Commit b70942a

Browse files
committed
Resolve Linux Warning & Improve Windows Debugging
1 parent 64ac35c commit b70942a

File tree

3 files changed

+46
-9
lines changed

3 files changed

+46
-9
lines changed

src/Utilities/QGCLogging.cc

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,39 @@ QGC_LOGGING_CATEGORY(QGCLoggingLog, "qgc.utilities.qgclogging")
2828

2929
/// CRT Report Hook installed using _CrtSetReportHook. We install this hook when
3030
/// we don't want asserts to pop a dialog on windows.
31-
static int WindowsCrtReportHook(int reportType, char *message, int *returnValue)
31+
static int __cdecl WindowsCrtReportHook(int reportType, char *message, int *returnValue)
3232
{
33-
Q_UNUSED(reportType);
33+
int nRet = FALSE;
3434

35-
std::cerr << message << std::endl; // Output message to stderr
36-
*returnValue = 0; // Don't break into debugger
37-
return true; // We handled this fully ourselves
35+
printf("CRT report hook 1.\n");
36+
printf("CRT report type is \"");
37+
38+
switch (reportType) {
39+
case _CRT_ASSERT:
40+
printf("_CRT_ASSERT");
41+
// nRet = TRUE; // Always stop for this type of report
42+
break;
43+
case _CRT_WARN:
44+
printf("_CRT_WARN");
45+
break;
46+
case _CRT_ERROR:
47+
printf("_CRT_ERROR");
48+
break;
49+
default:
50+
printf("???Unknown???");
51+
break;
52+
}
53+
54+
printf("\".\nCRT report message is:\n\t");
55+
printf("%s", message);
56+
57+
std::cerr << message << std::endl;
58+
59+
if (returnValue) {
60+
*returnValue = 0;
61+
}
62+
63+
return nRet;
3864
}
3965

4066
#endif

src/Utilities/SignalHandler.cc

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ void SignalHandler::_onSigInt()
5050
{
5151
_notifierInt->setEnabled(false);
5252
char b;
53-
(void) ::read(sigIntFd[1], &b, sizeof(b));
53+
if (::read(sigIntFd[1], &b, sizeof(b)) == -1) {
54+
qCWarning(SignalHandlerLog) << "Failed to read from SIGINT socketpair:" << strerror(errno);
55+
}
5456

5557
_sigIntCount++;
5658

@@ -74,7 +76,9 @@ void SignalHandler::_onSigTerm()
7476
{
7577
_notifierTerm->setEnabled(false);
7678
char b;
77-
(void) ::read(sigTermFd[1], &b, sizeof(b));
79+
if (::read(sigTermFd[1], &b, sizeof(b)) == -1) {
80+
qCWarning(SignalHandlerLog) << "Failed to read from SIGTERM socketpair:" << strerror(errno);
81+
}
7882

7983
qCDebug(SignalHandlerLog) << "Caught SIGTERM—shutting down gracefully";
8084
if (qgcApp() && qgcApp()->mainRootWindow()) {
@@ -91,15 +95,19 @@ void SignalHandler::intSignalHandler(int signum)
9195
Q_ASSERT(signum == SIGINT);
9296

9397
char b = 1;
94-
(void) ::write(sigIntFd[0], &b, sizeof(b));
98+
if (::write(sigIntFd[0], &b, sizeof(b)) == -1) {
99+
qCWarning(SignalHandlerLog) << "Failed to write to SIGINT socketpair:" << strerror(errno);
100+
}
95101
}
96102

97103
void SignalHandler::termSignalHandler(int signum)
98104
{
99105
Q_ASSERT(signum == SIGTERM);
100106

101107
char b = 1;
102-
(void) ::write(sigTermFd[0], &b, sizeof(b));
108+
if (::write(sigTermFd[0], &b, sizeof(b)) == -1) {
109+
qCWarning(SignalHandlerLog) << "Failed to write to SIGTERM socketpair:" << strerror(errno);
110+
}
103111
}
104112

105113
int SignalHandler::setupSignalHandlers()

src/main.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ int main(int argc, char *argv[])
153153
// Don't pop up Windows Error Reporting dialog when app crashes.
154154
const DWORD dwMode = SetErrorMode(SEM_NOGPFAULTERRORBOX);
155155
SetErrorMode(dwMode | SEM_NOGPFAULTERRORBOX);
156+
(void) _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG);
157+
(void) _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_DEBUG);
158+
(void) _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_DEBUG);
156159
}
157160
#endif
158161
#endif // Q_OS_WIN

0 commit comments

Comments
 (0)