diff --git a/support/hololens/ServoApp/ServoApp.vcxproj b/support/hololens/ServoApp/ServoApp.vcxproj
index 90af50ac707..4d8b9281883 100644
--- a/support/hololens/ServoApp/ServoApp.vcxproj
+++ b/support/hololens/ServoApp/ServoApp.vcxproj
@@ -125,6 +125,7 @@
+
@@ -974,6 +975,7 @@
BrowserPage.xaml
+
diff --git a/support/hololens/ServoApp/ServoApp.vcxproj.filters b/support/hololens/ServoApp/ServoApp.vcxproj.filters
index aca41c20608..bd9b4eec1aa 100644
--- a/support/hololens/ServoApp/ServoApp.vcxproj.filters
+++ b/support/hololens/ServoApp/ServoApp.vcxproj.filters
@@ -25,6 +25,9 @@
Devtools
+
+ ServoControl
+
@@ -48,6 +51,9 @@
ServoControl
+
+ ServoControl
+
diff --git a/support/hololens/ServoApp/ServoControl/Crash.cpp b/support/hololens/ServoApp/ServoControl/Crash.cpp
new file mode 100644
index 00000000000..42809937c7a
--- /dev/null
+++ b/support/hololens/ServoApp/ServoControl/Crash.cpp
@@ -0,0 +1,60 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
+
+#include "pch.h"
+#include "Crash.h"
+#include
+#include
+#include "Servo.h"
+
+namespace winrt::servo {
+
+using namespace Windows::Storage;
+
+void WriteSection(StorageFile const &file, hstring section, hstring content) {
+ hstring title{format(L"\r\n--- %s ---\r\n", section.c_str())};
+ FileIO::AppendTextAsync(file, title).get();
+ FileIO::AppendTextAsync(file, content).get();
+}
+
+void WriteCrashReport(hstring contentBacktrack, hstring contentUrl) {
+ // Making all sync operations sync, as we are crashing.
+ auto storageFolder = ApplicationData::Current().LocalFolder();
+ auto fd = storageFolder
+ .CreateFileAsync(L"crash-report.txt",
+ CreationCollisionOption::ReplaceExisting)
+ .get();
+ FileIO::WriteTextAsync(fd, L"").get();
+
+ // Stdout
+ auto stdout_txt = storageFolder.GetFileAsync(L"stdout.txt").get();
+ auto contentStdout = FileIO::ReadTextAsync(stdout_txt).get();
+
+ // Crash time
+ char cTime[70];
+ auto crash_time = std::chrono::system_clock::now();
+ auto now_c = std::chrono::system_clock::to_time_t(crash_time);
+ std::tm now_tm;
+ localtime_s(&now_tm, &now_c);
+ strftime(cTime, sizeof cTime, "%FT%T%z", &now_tm);
+ auto contentTime = char2hstring(cTime);
+
+ // App + servo version
+ auto pkg = winrt::Windows::ApplicationModel::Package::Current();
+ auto v = pkg.Id().Version();
+ auto servo_version = char2hstring(capi::servo_version());
+ hstring contentVersion{format(L"%i.%i.%i.%i (%s)", v.Major, v.Minor, v.Build,
+ v.Revision, servo_version.c_str())};
+
+ WriteSection(fd, L"CUSTOM MESSAGE",
+ L"Feel free to add details here before reporting");
+ WriteSection(fd, L"CURRENT URL (remove if sensitive)", contentUrl);
+ WriteSection(fd, L"CRASH TIME", contentTime);
+ WriteSection(fd, L"VERSION", contentVersion);
+ WriteSection(fd, L"BACKTRACE", contentBacktrack);
+ WriteSection(fd, L"STDOUT", contentStdout);
+ FileIO::AppendTextAsync(fd, L"\r\n").get();
+}
+
+} // namespace winrt::servo
diff --git a/support/hololens/ServoApp/ServoControl/Crash.h b/support/hololens/ServoApp/ServoControl/Crash.h
new file mode 100644
index 00000000000..573d661e7d8
--- /dev/null
+++ b/support/hololens/ServoApp/ServoControl/Crash.h
@@ -0,0 +1,15 @@
+
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
+
+#pragma once
+
+#include "pch.h"
+#include "strutils.h"
+
+namespace winrt::servo {
+
+void WriteCrashReport(hstring backtrace, hstring url);
+
+} // namespace winrt::servo
diff --git a/support/hololens/ServoApp/ServoControl/Servo.cpp b/support/hololens/ServoApp/ServoControl/Servo.cpp
index 0cc51903f4b..fa6fa5dff12 100644
--- a/support/hololens/ServoApp/ServoControl/Servo.cpp
+++ b/support/hololens/ServoApp/ServoControl/Servo.cpp
@@ -1,5 +1,10 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
+
#include "pch.h"
#include "Servo.h"
+#include "Crash.h"
#include
#include "../DefaultUrl.h"
@@ -27,7 +32,10 @@ void on_url_changed(const char *curl) {
sServo->Delegate().OnServoURLChanged(url);
}
-void wakeup() { sServo->Delegate().WakeUp(); }
+void wakeup() {
+ if (sServo != nullptr)
+ sServo->Delegate().WakeUp();
+}
bool on_allow_navigation(const char *url) {
return sServo->Delegate().OnServoAllowNavigation(char2hstring(url));
@@ -47,28 +55,7 @@ void on_panic(const char *cbacktrace) {
auto backtrace = char2hstring(cbacktrace);
try {
- // Making all sync operations sync, as we are crashing.
- auto storageFolder = ApplicationData::Current().LocalFolder();
- auto stdout_txt = storageFolder.GetFileAsync(L"stdout.txt").get();
- auto crash_txt =
- storageFolder
- .CreateFileAsync(L"crash-report.txt",
- CreationCollisionOption::ReplaceExisting)
- .get();
- auto out = FileIO::ReadTextAsync(stdout_txt).get();
- FileIO::WriteTextAsync(crash_txt, L"--- CUSTOM MESSAGE ---\r\n").get();
- FileIO::AppendTextAsync(crash_txt,
- L"Feel free to add details here before reporting")
- .get();
- FileIO::AppendTextAsync(
- crash_txt, L"\r\n--- CURRENT URL (remove if sensitive) ---\r\n")
- .get();
- FileIO::AppendTextAsync(crash_txt, sServo->CurrentUrl()).get();
- FileIO::AppendTextAsync(crash_txt, L"\r\n--- BACKTRACE ---\r\n").get();
- FileIO::AppendTextAsync(crash_txt, backtrace).get();
- FileIO::AppendTextAsync(crash_txt, L"\r\n--- STDOUT ---\r\n").get();
- FileIO::AppendTextAsync(crash_txt, out).get();
- FileIO::AppendTextAsync(crash_txt, L"\r\n").get();
+ WriteCrashReport(backtrace, sServo->CurrentUrl());
} catch (...) {
log(L"Failed to log panic to crash report");
}