Skip to content

Commit

Permalink
[vm] Refactor vm/dart/use_dwarf_stack_traces_flag tests.
Browse files Browse the repository at this point in the history
Both the regular and deferred versions of this test contain
up to six different test cases:

All platforms:
 * ELF snapshot, using DWARF from the snapshot
 * ELF snapshot, using DWARF from the separate debugging information
For platforms where the test can assemble snapshots:
 * assembled snapshot, using DWARF from the snapshot or
   the separate .dSYM package on MacOS
 * assembled snapshot, using DWARF from the separate debugging
   information
For MacOS only:
 * creating a single-architecture universal binary from the
   separate .dSYM package and extracting DWARF information from it
 * creating a multi-architecture universal binary from the
   separate .dSYM package and extracting DWARF information from it

Originally the tests were written using package:expect, performing
program compilation and execution separately before each test and
lazily reading DWARF information within the test itself. Since tests
using package:expect stop the program immediately on a failure,
a failing expectation keeps other independent test cases from being
checked. However, it's useful to know if the failure is limited to
only a subset of the test cases, since that helps point at which code
is to blame for the test failure(s).

Now the tests are refactored to first set up the tests by performing
all program compilation and execution first, collecting all outputs and
DWARF information as test state. Then the test cases are defined over
the collected test state using package:test instead of package:expect.
This way, as long as there is not a failure in the initial setup, all
of the applicable test cases are run even if one or more of them fail.

-----

In pkg/native_stack_traces, changes the return types of the reader
retrieval methods in the DwarfContainer class and
DwarfSnapshot.fromDwarfContainer to be nullable. If the shared object
does not contain the expected DWARF information, these methods now
return null instead of causing null check exceptions to be thrown.

Issue: #55612

Change-Id: I253965a95894f455e51d021e32dbf2703d8b99cf
Cq-Include-Trybots: luci.dart.try:vm-aot-dwarf-linux-product-x64-try,vm-aot-linux-debug-x64-try,vm-aot-mac-release-arm64-try,vm-aot-mac-product-arm64-try,vm-aot-mac-release-x64-try,vm-aot-win-debug-arm64-try,vm-aot-win-debug-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/375240
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
  • Loading branch information
sstrickl authored and Commit Queue committed Jul 18, 2024
1 parent ad02ce3 commit 953b1a9
Show file tree
Hide file tree
Showing 9 changed files with 759 additions and 608 deletions.
7 changes: 7 additions & 0 deletions pkg/native_stack_traces/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 0.6.0
- Make return type of DwarfContainer reader methods nullable so null
can be returned if there is no relevant DWARF information.
- Allow DwarfSnapshot.fromDwarfContainer to return null if the DwarfContainer
contents is missing expected DWARF information (that is, if any of the
used DwarfContainer reader methods return null).

## 0.5.7

- Translates non-symbolic stack traces that include information for
Expand Down
16 changes: 11 additions & 5 deletions pkg/native_stack_traces/lib/src/dwarf.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2047,20 +2047,24 @@ class DwarfSnapshot extends Dwarf {
DwarfSnapshot._(this._container, this._abbreviationsTables, this._debugInfo,
this._lineNumberInfo);

static DwarfSnapshot fromDwarfContainer(
static DwarfSnapshot? fromDwarfContainer(
Reader reader, DwarfContainer container) =>
// We use Zone values to pass around the string tables that may be used
// when parsing different sections.
runZoned(() {
final abbrevReader = container.abbreviationsTableReader(reader);
if (abbrevReader == null) return null;
final abbreviationsTables = Map.fromEntries(abbrevReader
.readRepeatedWithOffsets(_AbbreviationsTable.fromReader));

final debugInfo = DebugInfo.fromReader(
container.debugInfoReader(reader), abbreviationsTables);
final debugInfoReader = container.debugInfoReader(reader);
if (debugInfoReader == null) return null;
final debugInfo =
DebugInfo.fromReader(debugInfoReader, abbreviationsTables);

final lineNumberInfo =
LineNumberInfo.fromReader(container.lineNumberInfoReader(reader));
final lineNumberInfoReader = container.lineNumberInfoReader(reader);
if (lineNumberInfoReader == null) return null;
final lineNumberInfo = LineNumberInfo.fromReader(lineNumberInfoReader);

return DwarfSnapshot._(
container, abbreviationsTables, debugInfo, lineNumberInfo);
Expand Down Expand Up @@ -2190,8 +2194,10 @@ class DwarfUniversalBinary extends Dwarf {
final container = binary.containerForCpuType(cpuType)!;
final reader = binary.readerForCpuType(originalReader, cpuType)!;
final dwarf = DwarfSnapshot.fromDwarfContainer(reader, container);
if (dwarf == null) continue;
dwarfs[cpuType] = dwarf;
}
if (dwarfs.isEmpty) return null;
return DwarfUniversalBinary._(binary, dwarfs);
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/native_stack_traces/lib/src/dwarf_container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ abstract class DwarfContainer {
/// not match any expected Dart architecture.
String? get architecture;

Reader debugInfoReader(Reader containerReader);
Reader lineNumberInfoReader(Reader containerReader);
Reader abbreviationsTableReader(Reader containerReader);
Reader? debugInfoReader(Reader containerReader);
Reader? lineNumberInfoReader(Reader containerReader);
Reader? abbreviationsTableReader(Reader containerReader);
DwarfContainerSymbol? staticSymbolAt(int address);

int? get vmStartAddress;
Expand Down
21 changes: 15 additions & 6 deletions pkg/native_stack_traces/lib/src/elf.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1262,16 +1262,25 @@ class Elf extends DwarfContainer {
String? get architecture => _header.architecture;

@override
Reader abbreviationsTableReader(Reader containerReader) =>
namedSections('.debug_abbrev').single.shrink(containerReader);
Reader? abbreviationsTableReader(Reader containerReader) {
final sections = namedSections('.debug_abbrev');
if (sections.length != 1) return null;
return sections.single.shrink(containerReader);
}

@override
Reader lineNumberInfoReader(Reader containerReader) =>
namedSections('.debug_line').single.shrink(containerReader);
Reader? lineNumberInfoReader(Reader containerReader) {
final sections = namedSections('.debug_line');
if (sections.length != 1) return null;
return sections.single.shrink(containerReader);
}

@override
Reader debugInfoReader(Reader containerReader) =>
namedSections('.debug_info').single.shrink(containerReader);
Reader? debugInfoReader(Reader containerReader) {
final sections = namedSections('.debug_info');
if (sections.length != 1) return null;
return sections.single.shrink(containerReader);
}

@override
int? get vmStartAddress => dynamicSymbolFor(constants.vmSymbolName)?.value;
Expand Down
12 changes: 6 additions & 6 deletions pkg/native_stack_traces/lib/src/macho.dart
Original file line number Diff line number Diff line change
Expand Up @@ -506,14 +506,14 @@ class MachO extends DwarfContainer {
String? get architecture => CpuType.fromCode(_header.cputype)?.dartName;

@override
Reader abbreviationsTableReader(Reader containerReader) =>
_dwarfSegment!.sections['__debug_abbrev']!.shrink(containerReader);
Reader? abbreviationsTableReader(Reader containerReader) =>
_dwarfSegment?.sections['__debug_abbrev']?.shrink(containerReader);
@override
Reader lineNumberInfoReader(Reader containerReader) =>
_dwarfSegment!.sections['__debug_line']!.shrink(containerReader);
Reader? lineNumberInfoReader(Reader containerReader) =>
_dwarfSegment?.sections['__debug_line']?.shrink(containerReader);
@override
Reader debugInfoReader(Reader containerReader) =>
_dwarfSegment!.sections['__debug_info']!.shrink(containerReader);
Reader? debugInfoReader(Reader containerReader) =>
_dwarfSegment?.sections['__debug_info']?.shrink(containerReader);

@override
int? get vmStartAddress => _symbolTable[constants.vmSymbolName]?.value;
Expand Down
2 changes: 1 addition & 1 deletion pkg/native_stack_traces/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: native_stack_traces
version: 0.5.7
version: 0.6.0
description: Utilities for working with non-symbolic stack traces.
repository: https://github.com/dart-lang/sdk/tree/main/pkg/native_stack_traces

Expand Down
Loading

0 comments on commit 953b1a9

Please sign in to comment.