From fb1c543dd4f18d19e8aecf5be0e5641f34ae47de Mon Sep 17 00:00:00 2001 From: Ben Konyi Date: Tue, 26 Feb 2019 13:28:04 -0800 Subject: [PATCH] Link dart:* sources into engine for debugger source support (#7908) Link dart:* sources into engine for debugger source support Currently, dart:* libraries appear to have no source in debuggers like Observatory. With this change, these sources will be available in debug mode applications. Sources for dart:* libraries are lazily loaded on a script-by-script basis. Refer to https://dart-review.googlesource.com/c/sdk/+/93375 for the Dart SDK change. --- common/settings.h | 4 ++++ lib/snapshot/BUILD.gn | 22 ++++++++++++++++++- runtime/dart_vm.cc | 8 +++++++ shell/platform/android/BUILD.gn | 3 +++ shell/platform/android/flutter_main.cc | 22 +++++++++++++++++++ .../framework/Source/FlutterDartProject.mm | 19 ++++++++++++++++ shell/platform/embedder/embedder.cc | 13 +++++++++++ 7 files changed, 90 insertions(+), 1 deletion(-) diff --git a/common/settings.h b/common/settings.h index 07c70369f..812e2167d 100644 --- a/common/settings.h +++ b/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/lib/snapshot/BUILD.gn b/lib/snapshot/BUILD.gn index 42d37626f..b12dfe4d6 100644 --- a/lib/snapshot/BUILD.gn +++ b/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/runtime/dart_vm.cc b/runtime/dart_vm.cc index 382ab05c3..b907db41b 100644 --- a/runtime/dart_vm.cc +++ b/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/shell/platform/android/BUILD.gn b/shell/platform/android/BUILD.gn index fa55b71b9..cb0d8f722 100644 --- a/shell/platform/android/BUILD.gn +++ b/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/shell/platform/android/flutter_main.cc b/shell/platform/android/flutter_main.cc index bfbc4c1ce..e02eae9fa 100644 --- a/shell/platform/android/flutter_main.cc +++ b/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/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm b/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm index 689be749e..229e620aa 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm +++ b/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/shell/platform/embedder/embedder.cc b/shell/platform/embedder/embedder.cc index 3cce19dc2..c9b061d6c 100644 --- a/shell/platform/embedder/embedder.cc +++ b/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, -- GitLab