[vm] Add non-symbolic stack trace support for deferred loading units.

Dart VM changes:

Note that the following changes are backwards compatible in the
case that a Dart program has no deferred loading units (i.e., the
Dart program is contained in a single shared object snapshot).

When there are non-root loading units, the non-symbol stack trace
header now includes information about loading units as follows:

loading_unit: N, build_id: S, dso_base: A, instructions: A

where N is an integer, S is a string of hex digits (0-9a-f), and A
is a word-sized address printed as a hex string (without prefix).

In addition, all non-symbolic stack frames for isolate instructions
include a unit field, including those for the root loading unit, e.g.,

   #NN abs <address> unit <id> virt <address> <symbol>+<offset>

If there are no non-root loading units, then the non-symbolic stack
trace is unchanged from its previous format.

Adds a build ID to split deferred loading unit snapshots.
Fixes: https://github.com/dart-lang/sdk/issues/43516

If separate debugging information is requested, the loading unit
manifest includes a 'debugPath' field for each loading unit,
which contains the path to its separate debugging information.

Removes the attempt to store the relocated address of the instructions
section when running from an assembled snapshot in the initialized BSS.

Adds OS::GetAppDSOBase, which takes a pointer to the instructions
section and returns a pointer to its loaded shared object in memory.
For compiled-to-ELF snapshots, it does this using the relocated address
of the instructions in the Image, and for assembled snapshots, it
delegates to NativeSymbolResolver::LookupSharedObject.

-----

Changes to package:native_stack_traces:

PCOffset now has two new fields:

* int? unitId: the unit ID of the loading unit, when available.
* String? buildId: the build ID of the loading unit, when available.

For PCOffsets in the VM section, the unitId and buildId are those of
the root loading unit.

The constructor for the DwarfStackTraceDecoder now takes two
additional optional named arguments:

* Map<int, Dwarf>? dwarfByUnitId: A map associating loading unit IDs
  with the appropriate Dwarf object. May or may not contain an entry
  for the root loading unit.
* Iterable<Dwarf>? unitDwarfs: An iterable container holding Dwarf
  objects. May or may not contain an entry for the root loading unit.

The Dwarf object that is passed to the DwarfStackTraceDecoder as a
positional argument is used for all lookups within the root loading
unit. If the dwarfByUnitId or unitDwarfs arguments contain an entry
for the root loading unit, it should be the same as the positional
argument.

When decoding a non-symbolic stack frame with a non-root loading unit
id, the decoder first looks in the map for the appropriate Dwarf object.
If one is not found, the decoder uses the build ID for the loading unit
to find the appropriate Dwarf object in the iterable container. If an
appropriate Dwarf object cannot be found in either manner, the
non-symbolic stack frame is emitted without change.

The native_stack_traces:decode executable now takes two additional
multi-options for the translate command:

* -u, --unit_debug: Takes a path to the associated DWARF information.
* --unit_id_debug: Takes N=FILE, where N is the loading unit ID and
  FILE is a path to the associated DWARF information.

The arguments to -u are collected into an iterable container to be
passed as the unitDwarfs argument to the DwarfStackTraceDecoder, and
the arguments to --unit-id-debug are collected into a map to be passed
as the dwarfByUnitId argument.

TEST=vm/dart/use_dwarf_stack_traces_flag_deferred

Issue: https://github.com/dart-lang/sdk/issues/53902
Change-Id: I210d4f69e4ae9fd37275a96beb1aac55c5e9d080
Cq-Include-Trybots: luci.dart.try:vm-aot-dwarf-linux-product-x64-try,vm-aot-linux-release-x64-try,vm-aot-linux-debug-x64-try,vm-aot-mac-release-arm64-try,vm-aot-mac-product-arm64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/362380
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
28 files changed
tree: 96e86b06ad0b7638064676505721b67c8e4130d6
  1. .dart_tool/
  2. .github/
  3. benchmarks/
  4. build/
  5. docs/
  6. pkg/
  7. runtime/
  8. samples/
  9. sdk/
  10. tests/
  11. third_party/
  12. tools/
  13. utils/
  14. .clang-format
  15. .gitattributes
  16. .gitconfig
  17. .gitignore
  18. .gn
  19. .mailmap
  20. .style.yapf
  21. AUTHORS
  22. BUILD.gn
  23. CHANGELOG.md
  24. codereview.settings
  25. CONTRIBUTING.md
  26. DEPS
  27. LICENSE
  28. OWNERS
  29. PATENT_GRANT
  30. PRESUBMIT.py
  31. README.dart-sdk
  32. README.md
  33. sdk.code-workspace
  34. sdk_args.gni
  35. sdk_packages.yaml
  36. SECURITY.md
  37. WATCHLISTS
README.md

Dart

An approachable, portable, and productive language for high-quality apps on any platform

Dart is:

  • Approachable: Develop with a strongly typed programming language that is consistent, concise, and offers modern language features like null safety and patterns.

  • Portable: Compile to ARM, x64, or RISC-V machine code for mobile, desktop, and backend. Compile to JavaScript or WebAssembly for the web.

  • Productive: Make changes iteratively: use hot reload to see the result instantly in your running app. Diagnose app issues using DevTools.

Dart's flexible compiler technology lets you run Dart code in different ways, depending on your target platform and goals:

  • Dart Native: For programs targeting devices (mobile, desktop, server, and more), Dart Native includes both a Dart VM with JIT (just-in-time) compilation and an AOT (ahead-of-time) compiler for producing machine code.

  • Dart Web: For programs targeting the web, Dart Web includes both a development time compiler (dartdevc) and a production time compiler (dart2js).

Dart platforms illustration

License & patents

Dart is free and open source.

See LICENSE and PATENT_GRANT.

Using Dart

Visit dart.dev to learn more about the language, tools, and to find codelabs.

Browse pub.dev for more packages and libraries contributed by the community and the Dart team.

Our API reference documentation is published at api.dart.dev, based on the stable release. (We also publish docs from our beta and dev channels, as well as from the primary development branch).

Building Dart

If you want to build Dart yourself, here is a guide to getting the source, preparing your machine to build the SDK, and building.

There are more documents on our wiki.

Contributing to Dart

The easiest way to contribute to Dart is to file issues.

You can also contribute patches, as described in Contributing.

Roadmap

Future plans for Dart are included in the combined Dart and Flutter roadmap on the Flutter wiki.