Previously, Code objects of invisible functions were retained in order to omit frames corresponding to such functions from stack traces when stack trace is printed. This change drops Code objects of invisible functions. That also means that frames corresponding to such functions are no longer skipped in binary DWARF stack traces. In order to account for that, DW_AT_artificial attribute is added to generated DWARF debug information to mark invisible functions. Stack trace decoding now looks at this attribute and skips those frames when symbolizing stack trace. Flutter gallery in release-sizeopt mode: Heap size of snapshot objects -4.2% (arm), -4.4% (arm64). A large application in --dwarf_stack_traces mode: Number of discarded Code objects increased from 72.4% to 83.7% (out of all Code objects). Heap size of Code objects -37.4%. Heap size of all snapshot objects -5%. TEST=tests/standalone/dwarf_stack_trace_invisible_functions_test.dart Issue: https://github.com/dart-lang/sdk/issues/44852 Change-Id: Ib804852aba1e083670f1d9b9d66cbaab7dcdcff9 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/196583 Commit-Queue: Alexander Markov <alexmarkov@google.com> Reviewed-by: Tess Strickland <sstrickl@google.com> Reviewed-by: Ryan Macnak <rmacnak@google.com>
native_stack_traces
This package provides libraries and a utility for decoding non-symbolic stack traces generated by an AOT-compiled Dart application.
Converting stack traces
In some modes of AOT compilation, information on mapping execution points to source locations is no longer stored in the Dart image. Instead, this information is translated to separately stored debugging information. This debugging information can then be stripped from the application before shipping.
However, there is a drawback. Stack traces generated by such an application no longer includes file, function, and line number information (i.e., symbolic stack traces). Instead, stack trace frames simply include program counter information. Thus, to find the source information for these frames, we must use the debugging information. This means either keeping the original unstripped application, or saving the debugging information into a separate file.
Given this debugging information, the libraries in this package can turn
non-symbolic stack traces back into symbolic stack traces. In addition, this
package includes a command line tool decode whose output is the same as its
input except that non-symbolic stack traces are translated.
Using decode
Take the following Dart code, which we put in throws.dart. The inlining
pragmas are here just to ensure that bar is inlined into foo and that foo
is not inlined into bar, to illustrate how inlined code is handled in the
translated output.
@pragma('vm:prefer-inline')
bar() => throw null;
@pragma('vm:never-inline')
foo() => bar();
main() => foo();
Now we run the following commands:
# Make sure that we have the native_stack_traces package.
$ pub get native_stack_traces
$ pub global activate native_stack_traces
# We compile the example program, removing the source location information
# from the snapshot and saving the debugging information into throws.debug.
$ dart2native -k aot -S throws.debug -o throws.aotsnapshot throws.dart
# Run the program, saving the error output to throws.err.
$ dartaotruntime throws.aotsnapshot 2>throws.err
# Using the saved debugging information, we can translate the stack trace
# contained in throws.err to its symbolic form.
$ pub global run native_stack_traces:decode translate -d throws.debug -i throws.err
# We can also just pipe the output of running the program directly into
# the utility.
$ dartaotruntime throws.aotsnapshot |& \
pub global run native_stack_traces:decode translate -d throws.debug
Features and bugs
Please file feature requests and bugs at the issue tracker.