Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit fb1c543

Browse files
authored
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.
1 parent dd3656a commit fb1c543

File tree

7 files changed

+90
-1
lines changed

7 files changed

+90
-1
lines changed

common/settings.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ struct Settings {
4848
std::string isolate_snapshot_instr_path; // deprecated
4949
MappingCallback isolate_snapshot_instr;
5050

51+
// Returns the Mapping to a kernel buffer which contains sources for dart:*
52+
// libraries.
53+
MappingCallback dart_library_sources_kernel;
54+
5155
std::string application_library_path;
5256
std::string application_kernel_asset;
5357
std::string application_kernel_list_asset;

lib/snapshot/BUILD.gn

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ template("bin_to_assembly") {
9494
"--target_os",
9595
current_os,
9696
]
97+
if (defined(invoker.size_symbol)) {
98+
args += [
99+
"--size_symbol_name",
100+
invoker.size_symbol,
101+
"--target_arch",
102+
current_cpu,
103+
]
104+
}
97105
if (invoker.executable) {
98106
args += [ "--executable" ]
99107
}
@@ -201,17 +209,29 @@ bin_to_linkable("isolate_snapshot_instructions_linkable") {
201209
executable = true
202210
}
203211

212+
bin_to_linkable("platform_strong_dill_linkable") {
213+
deps = [
214+
":strong_platform",
215+
]
216+
input = "$root_out_dir/flutter_patched_sdk/platform_strong.dill"
217+
symbol = "kPlatformStrongDill"
218+
size_symbol = "kPlatformStrongDillSize"
219+
executable = false
220+
}
221+
204222
source_set("snapshot") {
205223
deps = [
206224
":isolate_snapshot_data_linkable",
207225
":isolate_snapshot_instructions_linkable",
208226
":vm_snapshot_data_linkable",
209227
":vm_snapshot_instructions_linkable",
228+
":platform_strong_dill_linkable",
210229
]
211230
sources = get_target_outputs(":isolate_snapshot_data_linkable") +
212231
get_target_outputs(":isolate_snapshot_instructions_linkable") +
213232
get_target_outputs(":vm_snapshot_data_linkable") +
214-
get_target_outputs(":vm_snapshot_instructions_linkable")
233+
get_target_outputs(":vm_snapshot_instructions_linkable") +
234+
get_target_outputs(":platform_strong_dill_linkable")
215235
}
216236

217237
compile_platform("non_strong_platform") {

runtime/dart_vm.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,14 @@ DartVM::DartVM(const Settings& settings,
438438
&ServiceStreamCancelCallback);
439439

440440
Dart_SetEmbedderInformationCallback(&EmbedderInformationCallback);
441+
442+
if (settings.dart_library_sources_kernel != nullptr) {
443+
std::unique_ptr<fml::Mapping> dart_library_sources =
444+
settings.dart_library_sources_kernel();
445+
// Set sources for dart:* libraries for debugging.
446+
Dart_SetDartLibrarySourcesKernel(dart_library_sources->GetMapping(),
447+
dart_library_sources->GetSize());
448+
}
441449
}
442450

443451
DartVM::~DartVM() {

shell/platform/android/BUILD.gn

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ shared_library("flutter_shell_native") {
7171
} else {
7272
deps += [ "//third_party/dart/runtime:libdart_precompiled_runtime" ]
7373
}
74+
if (flutter_runtime_mode == "debug") {
75+
deps += [ "$flutter_root/lib/snapshot" ]
76+
}
7477

7578
public_configs = [ "$flutter_root:config" ]
7679

shell/platform/android/flutter_main.cc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@
2525

2626
namespace shell {
2727

28+
extern "C" {
29+
#if FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG
30+
// Used for debugging dart:* sources.
31+
extern const uint8_t kPlatformStrongDill[];
32+
extern const intptr_t kPlatformStrongDillSize;
33+
#endif
34+
}
35+
2836
FlutterMain::FlutterMain(blink::Settings settings)
2937
: settings_(std::move(settings)) {}
3038

@@ -89,6 +97,20 @@ void FlutterMain::Init(JNIEnv* env,
8997
settings.task_observer_remove = [](intptr_t key) {
9098
fml::MessageLoop::GetCurrent().RemoveTaskObserver(key);
9199
};
100+
101+
#if FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG
102+
// There are no ownership concerns here as all mappings are owned by the
103+
// embedder and not the engine.
104+
auto make_mapping_callback = [](const uint8_t* mapping, size_t size) {
105+
return [mapping, size]() {
106+
return std::make_unique<fml::NonOwnedMapping>(mapping, size);
107+
};
108+
};
109+
110+
settings.dart_library_sources_kernel =
111+
make_mapping_callback(kPlatformStrongDill, kPlatformStrongDillSize);
112+
#endif // FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG
113+
92114
// Not thread safe. Will be removed when FlutterMain is refactored to no
93115
// longer be a singleton.
94116
g_flutter_main.reset(new FlutterMain(std::move(settings)));

shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@
1515
#include "flutter/shell/platform/darwin/common/command_line.h"
1616
#include "flutter/shell/platform/darwin/ios/framework/Headers/FlutterViewController.h"
1717

18+
extern "C" {
19+
#if FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG
20+
// Used for debugging dart:* sources.
21+
extern const uint8_t kPlatformStrongDill[];
22+
extern const intptr_t kPlatformStrongDillSize;
23+
#endif
24+
}
25+
1826
static const char* kApplicationKernelSnapshotFileName = "kernel_blob.bin";
1927

2028
static blink::Settings DefaultSettingsForProcess(NSBundle* bundle = nil) {
@@ -123,6 +131,17 @@
123131
}
124132
}
125133

134+
#if FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG
135+
// There are no ownership concerns here as all mappings are owned by the
136+
// embedder and not the engine.
137+
auto make_mapping_callback = [](const uint8_t* mapping, size_t size) {
138+
return [mapping, size]() { return std::make_unique<fml::NonOwnedMapping>(mapping, size); };
139+
};
140+
141+
settings.dart_library_sources_kernel =
142+
make_mapping_callback(kPlatformStrongDill, kPlatformStrongDillSize);
143+
#endif // FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG
144+
126145
return settings;
127146
}
128147

shell/platform/embedder/embedder.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@
1313
#define FLUTTER_EXPORT __attribute__((visibility("default")))
1414
#endif // OS_WIN
1515

16+
extern "C" {
17+
#if FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG
18+
// Used for debugging dart:* sources.
19+
extern const uint8_t kPlatformStrongDill[];
20+
extern const intptr_t kPlatformStrongDillSize;
21+
#endif // FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG
22+
}
23+
1624
#include "flutter/shell/platform/embedder/embedder.h"
1725

1826
#include <type_traits>
@@ -286,6 +294,11 @@ void PopulateSnapshotMappingCallbacks(const FlutterProjectArgs* args,
286294
args->isolate_snapshot_instructions_size);
287295
}
288296
}
297+
298+
#if !OS_FUCHSIA && (FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG)
299+
settings.dart_library_sources_kernel =
300+
make_mapping_callback(kPlatformStrongDill, kPlatformStrongDillSize);
301+
#endif // !OS_FUCHSIA && (FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG)
289302
}
290303

291304
FlutterEngineResult FlutterEngineRun(size_t version,

0 commit comments

Comments
 (0)