summaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authorisanae <14251494+isanae@users.noreply.github.com>2019-07-01 08:42:58 -0400
committerisanae <14251494+isanae@users.noreply.github.com>2019-07-01 08:42:58 -0400
commitdfe8093c1ad16e1611c12e88d52d1ac38371d3f6 (patch)
tree3952f970ef9a4315ab143553c94f16a220b72faf /src/main.cpp
parent5a74b02442302fb484b1db68cf0ce1736af4911c (diff)
added --crashdump to generate dumps of a running MO process
added dump_running_process.bat to start another instance of MO with that flag
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp45
1 files changed, 43 insertions, 2 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 518d31a0..f74a9cf4 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -485,8 +485,6 @@ int runApplication(MOApplication &application, SingleInstance &instance,
for (const auto& m : env.loadedModules()) {
qDebug().nospace().noquote() << " . " << m.toString();
}
-
- return 0;
}
QString dataPath = application.property("dataPath").toString();
@@ -682,9 +680,52 @@ int runApplication(MOApplication &application, SingleInstance &instance,
}
}
+int doCoreDump(env::CoreDumpTypes type)
+{
+ // open a console
+ AllocConsole();
+
+ // redirect stdin, stdout and stderr to it
+ FILE* in=nullptr;
+ FILE* out=nullptr;
+ FILE* err=nullptr;
+ freopen_s(&in, "CONIN$", "r", stdin);
+ freopen_s(&out, "CONOUT$", "w", stdout);
+ freopen_s(&err, "CONOUT$", "w", stderr);
+
+ // dump
+ const auto b = env::coredumpOther(type);
+ if (!b) {
+ std::wcerr << L"\n>>>> a minidump file was not written\n\n";
+ }
+
+ std::wcerr << L"Press enter to continue...";
+ std::wcin.get();
+
+ // close redirected handles
+ std::fclose(err);
+ std::fclose(out);
+ std::fclose(in);
+
+ // close console
+ FreeConsole();
+
+ return (b ? 0 : 1);
+}
int main(int argc, char *argv[])
{
+ // handle --crashdump first
+ for (int i=1; i<argc; ++i) {
+ if (std::strcmp(argv[i], "--crashdump") == 0) {
+ return doCoreDump(env::CoreDumpTypes::Mini);
+ } else if (std::strcmp(argv[i], "--crashdump-data") == 0) {
+ return doCoreDump(env::CoreDumpTypes::Data);
+ } else if (std::strcmp(argv[i], "--crashdump-full") == 0) {
+ return doCoreDump(env::CoreDumpTypes::Full);
+ }
+ }
+
//Make sure the configured temp folder exists
QDir tempDir = QDir::temp();
if (!tempDir.exists())