diff --git a/engine/src/flutter/common/settings.h b/engine/src/flutter/common/settings.h index 07c70369fd1..812e2167d31 100644 --- a/engine/src/flutter/common/settings.h +++ b/engine/src/flutter/common/settings.h @@ -48,6 +48,10 @@ struct Settings { std::string isolate_snapshot_instr_path; // deprecated MappingCallback isolate_snapshot_instr; + // Returns the Mapping to a kernel buffer which contains sources for dart:* + // libraries. + MappingCallback dart_library_sources_kernel; + std::string application_library_path; std::string application_kernel_asset; std::string application_kernel_list_asset; diff --git a/engine/src/flutter/lib/snapshot/BUILD.gn b/engine/src/flutter/lib/snapshot/BUILD.gn index 42d37626f5e..b12dfe4d6db 100644 --- a/engine/src/flutter/lib/snapshot/BUILD.gn +++ b/engine/src/flutter/lib/snapshot/BUILD.gn @@ -94,6 +94,14 @@ template("bin_to_assembly") { "--target_os", current_os, ] + if (defined(invoker.size_symbol)) { + args += [ + "--size_symbol_name", + invoker.size_symbol, + "--target_arch", + current_cpu, + ] + } if (invoker.executable) { args += [ "--executable" ] } @@ -201,17 +209,29 @@ bin_to_linkable("isolate_snapshot_instructions_linkable") { executable = true } +bin_to_linkable("platform_strong_dill_linkable") { + deps = [ + ":strong_platform", + ] + input = "$root_out_dir/flutter_patched_sdk/platform_strong.dill" + symbol = "kPlatformStrongDill" + size_symbol = "kPlatformStrongDillSize" + executable = false +} + source_set("snapshot") { deps = [ ":isolate_snapshot_data_linkable", ":isolate_snapshot_instructions_linkable", ":vm_snapshot_data_linkable", ":vm_snapshot_instructions_linkable", + ":platform_strong_dill_linkable", ] sources = get_target_outputs(":isolate_snapshot_data_linkable") + get_target_outputs(":isolate_snapshot_instructions_linkable") + get_target_outputs(":vm_snapshot_data_linkable") + - get_target_outputs(":vm_snapshot_instructions_linkable") + get_target_outputs(":vm_snapshot_instructions_linkable") + + get_target_outputs(":platform_strong_dill_linkable") } compile_platform("non_strong_platform") { diff --git a/engine/src/flutter/runtime/dart_vm.cc b/engine/src/flutter/runtime/dart_vm.cc index 382ab05c344..b907db41bd0 100644 --- a/engine/src/flutter/runtime/dart_vm.cc +++ b/engine/src/flutter/runtime/dart_vm.cc @@ -438,6 +438,14 @@ DartVM::DartVM(const Settings& settings, &ServiceStreamCancelCallback); Dart_SetEmbedderInformationCallback(&EmbedderInformationCallback); + + if (settings.dart_library_sources_kernel != nullptr) { + std::unique_ptr dart_library_sources = + settings.dart_library_sources_kernel(); + // Set sources for dart:* libraries for debugging. + Dart_SetDartLibrarySourcesKernel(dart_library_sources->GetMapping(), + dart_library_sources->GetSize()); + } } DartVM::~DartVM() { diff --git a/engine/src/flutter/shell/platform/android/BUILD.gn b/engine/src/flutter/shell/platform/android/BUILD.gn index fa55b71b96f..cb0d8f7225d 100644 --- a/engine/src/flutter/shell/platform/android/BUILD.gn +++ b/engine/src/flutter/shell/platform/android/BUILD.gn @@ -71,6 +71,9 @@ shared_library("flutter_shell_native") { } else { deps += [ "//third_party/dart/runtime:libdart_precompiled_runtime" ] } + if (flutter_runtime_mode == "debug") { + deps += [ "$flutter_root/lib/snapshot" ] + } public_configs = [ "$flutter_root:config" ] diff --git a/engine/src/flutter/shell/platform/android/flutter_main.cc b/engine/src/flutter/shell/platform/android/flutter_main.cc index bfbc4c1ce44..e02eae9faba 100644 --- a/engine/src/flutter/shell/platform/android/flutter_main.cc +++ b/engine/src/flutter/shell/platform/android/flutter_main.cc @@ -25,6 +25,14 @@ namespace shell { +extern "C" { +#if FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG +// Used for debugging dart:* sources. +extern const uint8_t kPlatformStrongDill[]; +extern const intptr_t kPlatformStrongDillSize; +#endif +} + FlutterMain::FlutterMain(blink::Settings settings) : settings_(std::move(settings)) {} @@ -89,6 +97,20 @@ void FlutterMain::Init(JNIEnv* env, settings.task_observer_remove = [](intptr_t key) { fml::MessageLoop::GetCurrent().RemoveTaskObserver(key); }; + +#if FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG + // There are no ownership concerns here as all mappings are owned by the + // embedder and not the engine. + auto make_mapping_callback = [](const uint8_t* mapping, size_t size) { + return [mapping, size]() { + return std::make_unique(mapping, size); + }; + }; + + settings.dart_library_sources_kernel = + make_mapping_callback(kPlatformStrongDill, kPlatformStrongDillSize); +#endif // FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG + // Not thread safe. Will be removed when FlutterMain is refactored to no // longer be a singleton. g_flutter_main.reset(new FlutterMain(std::move(settings))); diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm index 689be749e85..229e620aa61 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm @@ -15,6 +15,14 @@ #include "flutter/shell/platform/darwin/common/command_line.h" #include "flutter/shell/platform/darwin/ios/framework/Headers/FlutterViewController.h" +extern "C" { +#if FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG +// Used for debugging dart:* sources. +extern const uint8_t kPlatformStrongDill[]; +extern const intptr_t kPlatformStrongDillSize; +#endif +} + static const char* kApplicationKernelSnapshotFileName = "kernel_blob.bin"; static blink::Settings DefaultSettingsForProcess(NSBundle* bundle = nil) { @@ -123,6 +131,17 @@ static blink::Settings DefaultSettingsForProcess(NSBundle* bundle = nil) { } } +#if FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG + // There are no ownership concerns here as all mappings are owned by the + // embedder and not the engine. + auto make_mapping_callback = [](const uint8_t* mapping, size_t size) { + return [mapping, size]() { return std::make_unique(mapping, size); }; + }; + + settings.dart_library_sources_kernel = + make_mapping_callback(kPlatformStrongDill, kPlatformStrongDillSize); +#endif // FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG + return settings; } diff --git a/engine/src/flutter/shell/platform/embedder/embedder.cc b/engine/src/flutter/shell/platform/embedder/embedder.cc index 3cce19dc2ce..c9b061d6c93 100644 --- a/engine/src/flutter/shell/platform/embedder/embedder.cc +++ b/engine/src/flutter/shell/platform/embedder/embedder.cc @@ -13,6 +13,14 @@ #define FLUTTER_EXPORT __attribute__((visibility("default"))) #endif // OS_WIN +extern "C" { +#if FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG +// Used for debugging dart:* sources. +extern const uint8_t kPlatformStrongDill[]; +extern const intptr_t kPlatformStrongDillSize; +#endif // FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG +} + #include "flutter/shell/platform/embedder/embedder.h" #include @@ -286,6 +294,11 @@ void PopulateSnapshotMappingCallbacks(const FlutterProjectArgs* args, args->isolate_snapshot_instructions_size); } } + +#if !OS_FUCHSIA && (FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG) + settings.dart_library_sources_kernel = + make_mapping_callback(kPlatformStrongDill, kPlatformStrongDillSize); +#endif // !OS_FUCHSIA && (FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG) } FlutterEngineResult FlutterEngineRun(size_t version,