Skip to content

Commit

Permalink
[pkg/native_stack_traces] Make package NNBD compatible.
Browse files Browse the repository at this point in the history
Bug: #43304
Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-nnbd-linux-release-simarm64-try,vm-kernel-precomp-nnbd-linux-release-x64-try
Change-Id: Iaf451047ce74add6520bd514bafae8b0e3c5fa59
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/161704
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
  • Loading branch information
sstrickl authored and commit-bot@chromium.org committed Sep 22, 2020
1 parent df161ac commit 37cfae1
Show file tree
Hide file tree
Showing 15 changed files with 287 additions and 262 deletions.
14 changes: 6 additions & 8 deletions .dart_tool/package_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"constraint, update this by running tools/generate_package_config.dart."
],
"configVersion": 2,
"generated": "2020-08-18T15:38:52.410101",
"generated": "2020-09-22T09:07:43.543180",
"generator": "tools/generate_package_config.dart",
"packages": [
{
Expand Down Expand Up @@ -184,7 +184,7 @@
"name": "dart2js_info",
"rootUri": "../third_party/pkg/dart2js_info",
"packageUri": "lib/",
"languageVersion": "2.0"
"languageVersion": "2.3"
},
{
"name": "dart2js_tools",
Expand All @@ -207,8 +207,7 @@
{
"name": "dart_style",
"rootUri": "../third_party/pkg_tested/dart_style",
"packageUri": "lib/",
"languageVersion": "2.7"
"packageUri": "lib/"
},
{
"name": "dartdev",
Expand Down Expand Up @@ -426,7 +425,7 @@
"name": "native_stack_traces",
"rootUri": "../pkg/native_stack_traces",
"packageUri": "lib/",
"languageVersion": "2.8"
"languageVersion": "2.10"
},
{
"name": "nnbd_migration",
Expand Down Expand Up @@ -484,8 +483,7 @@
{
"name": "pub",
"rootUri": "../third_party/pkg/pub",
"packageUri": "lib/",
"languageVersion": "2.3"
"packageUri": "lib/"
},
{
"name": "pub_semver",
Expand Down Expand Up @@ -752,4 +750,4 @@
"languageVersion": "2.4"
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ const AllowedExperimentalFlags defaultAllowedExperimentalFlags =
"meta": {
ExperimentalFlag.nonNullable,
},
"native_stack_traces": {
ExperimentalFlag.nonNullable,
},
"path": {
ExperimentalFlag.nonNullable,
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/native_stack_traces/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include: package:pedantic/analysis_options.1.8.0.yaml
include: package:pedantic/analysis_options.1.9.2.yaml
22 changes: 12 additions & 10 deletions pkg/native_stack_traces/bin/decode.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ ${_argParser.usage}
Options specific to the find command:
${_findParser.usage}''';

final _usages = <String, String>{
final _usages = <String?, String>{
null: _mainUsage,
'': _mainUsage,
'help': _helpUsage,
Expand All @@ -133,7 +133,7 @@ final _usages = <String, String>{

const int _badUsageExitCode = 1;

void errorWithUsage(String message, {String command}) {
void errorWithUsage(String message, {String? command}) {
print("Error: $message.\n");
print(_usages[command]);
io.exitCode = _badUsageExitCode;
Expand All @@ -156,7 +156,7 @@ void help(ArgResults options) {
}
}

Dwarf _loadFromFile(String original, Function(String) usageError) {
Dwarf? _loadFromFile(String? original, Function(String) usageError) {
if (original == null) {
usageError('must provide -d/--debug');
return null;
Expand All @@ -178,19 +178,19 @@ void find(ArgResults options) {
final bool forceHexadecimal = options['force_hexadecimal'];

void usageError(String message) => errorWithUsage(message, command: 'find');
int parseIntAddress(String s) {
int? tryParseIntAddress(String s) {
if (!forceHexadecimal && !s.startsWith("0x")) {
final decimal = int.tryParse(s);
if (decimal != null) return decimal;
}
return int.tryParse(s.startsWith("0x") ? s.substring(2) : s, radix: 16);
}

PCOffset convertAddress(StackTraceHeader header, String s) {
PCOffset? convertAddress(StackTraceHeader header, String s) {
final parsedOffset = tryParseSymbolOffset(s, forceHexadecimal);
if (parsedOffset != null) return parsedOffset;

final address = parseIntAddress(s);
final address = tryParseIntAddress(s);
if (address != null) return header.offsetOf(address);

return null;
Expand All @@ -209,20 +209,22 @@ void find(ArgResults options) {

int vmStart = dwarf.vmStartAddress;
if (options['vm_start'] != null) {
vmStart = parseIntAddress(options['vm_start']);
if (vmStart == null) {
final address = tryParseIntAddress(options['vm_start']);
if (address == null) {
return usageError('could not parse VM start address '
'${options['vm_start']}');
}
vmStart = address;
}

int isolateStart = dwarf.isolateStartAddress;
if (options['isolate_start'] != null) {
isolateStart = parseIntAddress(options['isolate_start']);
if (isolateStart == null) {
final address = tryParseIntAddress(options['isolate_start']);
if (address == null) {
return usageError('could not parse isolate start address '
'${options['isolate_start']}');
}
isolateStart = address;
}

final header = StackTraceHeader(isolateStart, vmStart);
Expand Down
30 changes: 15 additions & 15 deletions pkg/native_stack_traces/lib/src/convert.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ final _headerEndRE = RegExp(r'isolate_instructions(?:=|: )([\da-f]+),? '
//
// Returns a new [StackTraceHeader] if [line] contains the needed header
// information, otherwise returns `null`.
StackTraceHeader _parseInstructionsLine(String line) {
StackTraceHeader? _parseInstructionsLine(String line) {
final match = _headerEndRE.firstMatch(line);
if (match == null) return null;
final isolateAddr = int.parse(match[1], radix: 16);
final vmAddr = int.parse(match[2], radix: 16);
final isolateAddr = int.parse(match[1]!, radix: 16);
final vmAddr = int.parse(match[2]!, radix: 16);
return StackTraceHeader(isolateAddr, vmAddr);
}

Expand Down Expand Up @@ -81,12 +81,12 @@ final _traceLineRE = RegExp(
/// any hexdecimal digits will be parsed as decimal.
///
/// Returns null if the string is not of the expected format.
PCOffset tryParseSymbolOffset(String s, [bool forceHexadecimal = false]) {
PCOffset? tryParseSymbolOffset(String s, [bool forceHexadecimal = false]) {
final match = _symbolOffsetRE.firstMatch(s);
if (match == null) return null;
final symbolString = match.namedGroup('symbol');
final offsetString = match.namedGroup('offset');
int offset;
final symbolString = match.namedGroup('symbol')!;
final offsetString = match.namedGroup('offset')!;
int? offset;
if (!forceHexadecimal && !offsetString.startsWith("0x")) {
offset = int.tryParse(offsetString);
}
Expand All @@ -108,9 +108,9 @@ PCOffset tryParseSymbolOffset(String s, [bool forceHexadecimal = false]) {
return null;
}

PCOffset _retrievePCOffset(StackTraceHeader header, RegExpMatch match) {
PCOffset? _retrievePCOffset(StackTraceHeader? header, RegExpMatch? match) {
if (match == null) return null;
final restString = match.namedGroup('rest');
final restString = match.namedGroup('rest')!;
// Try checking for symbol information first, since we don't need the header
// information to translate it.
if (restString.isNotEmpty) {
Expand All @@ -120,8 +120,8 @@ PCOffset _retrievePCOffset(StackTraceHeader header, RegExpMatch match) {
// If we're parsing the absolute address, we can only convert it into
// a PCOffset if we saw the instructions line of the stack trace header.
if (header != null) {
final addressString = match.namedGroup('absolute');
final address = int.tryParse(addressString, radix: 16);
final addressString = match.namedGroup('absolute')!;
final address = int.parse(addressString, radix: 16);
return header.offsetOf(address);
}
// If all other cases failed, check for a virtual address. Until this package
Expand All @@ -130,15 +130,15 @@ PCOffset _retrievePCOffset(StackTraceHeader header, RegExpMatch match) {
// debugging information, the other methods should be tried first.
final virtualString = match.namedGroup('virtual');
if (virtualString != null) {
final address = int.tryParse(virtualString, radix: 16);
final address = int.parse(virtualString, radix: 16);
return PCOffset(address, InstructionsSection.none);
}
return null;
}

/// The [PCOffset]s for frames of the non-symbolic stack traces in [lines].
Iterable<PCOffset> collectPCOffsets(Iterable<String> lines) sync* {
StackTraceHeader header;
StackTraceHeader? header;
for (var line in lines) {
final parsedHeader = _parseInstructionsLine(line);
if (parsedHeader != null) {
Expand Down Expand Up @@ -184,7 +184,7 @@ class DwarfStackTraceDecoder extends StreamTransformerBase<String, String> {

Stream<String> bind(Stream<String> stream) async* {
int depth = 0;
StackTraceHeader header;
StackTraceHeader? header;
await for (final line in stream) {
final parsedHeader = _parseInstructionsLine(line);
if (parsedHeader != null) {
Expand All @@ -207,7 +207,7 @@ class DwarfStackTraceDecoder extends StreamTransformerBase<String, String> {
if (callInfo.isEmpty) continue;
// Output the lines for the symbolic frame with the prefix found on the
// original non-symbolic frame line.
final prefix = line.substring(0, lineMatch.start);
final prefix = line.substring(0, lineMatch!.start);
for (final call in callInfo) {
yield prefix + _stackTracePiece(call, depth++);
}
Expand Down
Loading

0 comments on commit 37cfae1

Please sign in to comment.