|
11 | 11 | #include "include/dart_embedder_api.h" |
12 | 12 | #include "include/dart_tools_api.h" |
13 | 13 |
|
| 14 | +#if defined(DART_USE_CRASHPAD) |
| 15 | +#include "crashpad/client/crashpad_client.h" |
| 16 | +#include "crashpad/client/crashpad_info.h" |
| 17 | +#endif |
| 18 | + |
14 | 19 | #include "bin/builtin.h" |
15 | 20 | #include "bin/console.h" |
16 | 21 | #include "bin/dartutils.h" |
@@ -947,6 +952,45 @@ Dart_Handle GetVMServiceAssetsArchiveCallback() { |
947 | 952 | static Dart_GetVMServiceAssetsArchive GetVMServiceAssetsArchiveCallback = NULL; |
948 | 953 | #endif // !defined(NO_OBSERVATORY) |
949 | 954 |
|
| 955 | +#if defined(DART_USE_CRASHPAD) |
| 956 | +#if !defined(HOST_OS_WINDOWS) |
| 957 | +#error "Currently we only support Crashpad on Windows" |
| 958 | +#endif |
| 959 | + |
| 960 | +static void ConfigureCrashpadClient(crashpad::CrashpadClient* client) { |
| 961 | + // DART_CRASHPAD_HANDLER and DART_CRASHPAD_CRASHES_DIR are set by the |
| 962 | + // testing framework. |
| 963 | + wchar_t* handler = _wgetenv(L"DART_CRASHPAD_HANDLER"); |
| 964 | + wchar_t* crashes_dir = _wgetenv(L"DART_CRASHPAD_CRASHES_DIR"); |
| 965 | + if (handler == nullptr || crashes_dir == nullptr) { |
| 966 | + return; |
| 967 | + } |
| 968 | + |
| 969 | + // Crashpad uses STL so we use it here too even though in general we |
| 970 | + // avoid it. |
| 971 | + const base::FilePath handler_path{std::wstring(handler)}; |
| 972 | + const base::FilePath crashes_dir_path{std::wstring(crashes_dir)}; |
| 973 | + const std::string url(""); |
| 974 | + std::map<std::string, std::string> annotations; |
| 975 | + char* test_name = getenv("DART_TEST_NAME"); |
| 976 | + if (test_name != nullptr) { |
| 977 | + annotations["dart_test_name"] = test_name; |
| 978 | + } |
| 979 | + |
| 980 | + std::vector<std::string> arguments; |
| 981 | + if (!client->StartHandler(handler_path, crashes_dir_path, crashes_dir_path, |
| 982 | + url, annotations, arguments, |
| 983 | + /*restartable=*/true, |
| 984 | + /*asynchronous_start=*/false)) { |
| 985 | + Log::PrintErr("Failed to start the crash handler!\n"); |
| 986 | + Platform::Exit(kErrorExitCode); |
| 987 | + } |
| 988 | + crashpad::CrashpadInfo::GetCrashpadInfo() |
| 989 | + ->set_gather_indirectly_referenced_memory(crashpad::TriState::kEnabled, |
| 990 | + /*limit=*/500 * MB); |
| 991 | +} |
| 992 | +#endif // DART_USE_CRASHPAD |
| 993 | + |
950 | 994 | void main(int argc, char** argv) { |
951 | 995 | char* script_name; |
952 | 996 | const int EXTRA_VM_ARGUMENTS = 10; |
@@ -1010,6 +1054,11 @@ void main(int argc, char** argv) { |
1010 | 1054 | } |
1011 | 1055 | DartUtils::SetEnvironment(Options::environment()); |
1012 | 1056 |
|
| 1057 | +#if defined(DART_USE_CRASHPAD) |
| 1058 | + crashpad::CrashpadClient crashpad_client; |
| 1059 | + ConfigureCrashpadClient(&crashpad_client); |
| 1060 | +#endif |
| 1061 | + |
1013 | 1062 | Loader::InitOnce(); |
1014 | 1063 |
|
1015 | 1064 | #if defined(DART_LINK_APP_SNAPSHOT) |
|
0 commit comments