dart-sdk/pkg/native_stack_traces
Tess Strickland b1b3e34b88 [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>
2024-04-19 08:10:18 +00:00
..
bin [vm] Add non-symbolic stack trace support for deferred loading units. 2024-04-19 08:10:18 +00:00
lib [vm] Add non-symbolic stack trace support for deferred loading units. 2024-04-19 08:10:18 +00:00
test/convert Reland "[native_stack_traces] Remove initial spaces check in stack trace lines." 2022-12-22 11:52:18 +00:00
testcases/convert Reland "[native_stack_traces] Remove initial spaces check in stack trace lines." 2022-12-22 11:52:18 +00:00
.gitignore
analysis_options.yaml pkg:native_stack_trace - enable and fix a few more lints 2021-10-14 07:35:43 +00:00
AUTHORS
CHANGELOG.md [vm] Add non-symbolic stack trace support for deferred loading units. 2024-04-19 08:10:18 +00:00
LICENSE Update LICENSE 2021-04-07 10:28:38 +00:00
OWNERS Also add global owners to CFE/VM packages 2023-11-27 14:35:52 +00:00
pubspec.yaml [vm] Add non-symbolic stack trace support for deferred loading units. 2024-04-19 08:10:18 +00:00
README.md [pkg] prep to publish package:native_stack_traces 2022-05-31 16:39:16 +00:00

pub package package publisher

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.
$ dart 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.
$ dart compile exe -S throws.debug throws.dart

# Run the program, saving the error output to throws.err.
$ ./throws.exe 2>throws.err

# Using the saved debugging information, we can translate the stack trace
# contained in throws.err to its symbolic form.
$ dart pub global run native_stack_traces:decode translate -d throws.debug -i throws.err

Features and bugs

Please file feature requests and bugs at the issue tracker.