Skip to content

Commit 9158353

Browse files
mralephCommit Queue
authored and
Commit Queue
committed
[vm] Make it easier to get IL / disassembly out
Make `dart compile exe -v` forward gen_snapshot output in verbose mode. Fix --write_code_comments_as_synthetic_source_to=... flag. There was a change to Dwarf writer API which broke it. Motivated by #50059 TEST=manually Change-Id: I0431925f724a9b24e938bdb9d7ae1019143da83a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/261360 Commit-Queue: Slava Egorov <[email protected]> Reviewed-by: Tess Strickland <[email protected]>
1 parent 7fd4980 commit 9158353

File tree

2 files changed

+31
-23
lines changed

2 files changed

+31
-23
lines changed

pkg/dart2native/lib/generate.dart

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,22 +67,10 @@ Future<void> generateNative({
6767
if (soundNullSafety != null)
6868
'--${soundNullSafety ? '' : 'no-'}sound-null-safety',
6969
]);
70+
await _forwardOutput(kernelResult);
7071
if (kernelResult.exitCode != 0) {
71-
// We pipe both stdout and stderr to stderr because the CFE doesn't print
72-
// errors to stderr. This unfortunately does emit info-only output in
73-
// stderr, though.
74-
stderr.write(kernelResult.stdout);
75-
stderr.write(kernelResult.stderr);
76-
await stderr.flush();
7772
throw 'Generating AOT kernel dill failed!';
7873
}
79-
// Pipe info and warnings from the CFE to stdout since the compilation
80-
// succeeded. Stderr should be empty but we pipe it to stderr for
81-
// completeness.
82-
stdout.write(kernelResult.stdout);
83-
await stdout.flush();
84-
stderr.write(kernelResult.stderr);
85-
await stderr.flush();
8674

8775
if (verbose) {
8876
print('Generating AOT snapshot.');
@@ -93,10 +81,11 @@ Future<void> generateNative({
9381
: path.join(tempDir.path, 'snapshot.aot'));
9482
final snapshotResult = await generateAotSnapshot(genSnapshot, kernelFile,
9583
snapshotFile, debugPath, enableAsserts, extraOptions);
84+
85+
if (verbose || kernelResult.exitCode != 0) {
86+
await _forwardOutput(kernelResult);
87+
}
9688
if (snapshotResult.exitCode != 0) {
97-
stderr.writeln(snapshotResult.stdout);
98-
stderr.writeln(snapshotResult.stderr);
99-
await stderr.flush();
10089
throw 'Generating AOT snapshot failed!';
10190
}
10291

@@ -119,3 +108,22 @@ Future<void> generateNative({
119108
tempDir.deleteSync(recursive: true);
120109
}
121110
}
111+
112+
Future<void> _forwardOutput(ProcessResult result) async {
113+
if (result.stdout.isNotEmpty) {
114+
final bool needsNewLine = !result.stdout.endsWith('\n');
115+
if (result.exitCode == 0) {
116+
stdout.write(result.stdout);
117+
if (needsNewLine) stdout.writeln();
118+
await stdout.flush();
119+
} else {
120+
stderr.write(result.stdout);
121+
if (needsNewLine) stderr.writeln();
122+
}
123+
}
124+
if (result.stderr.isNotEmpty) {
125+
stderr.write(result.stderr);
126+
if (!result.stderr.endsWith('\n')) stderr.writeln();
127+
await stderr.flush();
128+
}
129+
}

runtime/vm/dwarf.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -551,11 +551,11 @@ class LineNumberProgramWriter {
551551
// Associates the given file, line, and column information for the instruction
552552
// at the pc_offset into the instructions payload of the Code object with the
553553
// symbol asm_name. Returns whether any changes were made to the stream.
554-
bool AddRow(intptr_t file,
555-
intptr_t line,
556-
intptr_t column,
557-
const char* asm_name,
558-
intptr_t pc_offset) {
554+
DART_WARN_UNUSED_RESULT bool AddRow(intptr_t file,
555+
intptr_t line,
556+
intptr_t column,
557+
const char* asm_name,
558+
intptr_t pc_offset) {
559559
ASSERT_EQUAL(end_sequence_, false);
560560
bool source_info_changed = false;
561561
// Note that files are 1-indexed.
@@ -675,8 +675,8 @@ void Dwarf::WriteSyntheticLineNumberProgram(LineNumberProgramWriter* writer) {
675675
auto& comments = code.comments();
676676
for (intptr_t i = 0, len = comments.Length(); i < len;) {
677677
intptr_t current_pc_offset = comments.PCOffsetAt(i);
678-
writer->AddRow(comments_file_index, current_line,
679-
DwarfPosition::kNoColumn, asm_name, current_pc_offset);
678+
writer->EmitRow(comments_file_index, current_line,
679+
DwarfPosition::kNoColumn, asm_name, current_pc_offset);
680680
while (i < len && current_pc_offset == comments.PCOffsetAt(i)) {
681681
comments_buffer.AddString(comments.CommentAt(i));
682682
comments_buffer.AddChar('\n');

0 commit comments

Comments
 (0)