Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit ba8baa4

Browse files
sstricklcommit-bot@chromium.org
authored andcommitted
[pkg/native_stack_traces] Return stub call information when appropriate.
Now when -v/--verbose is used, we will also print call information when those calls appear in stubs that do not correspond to Dart code. The returned information contains the name of the stub (the name of the static symbol in the ELF file generated for the stub) as well as the offset of the frame PC within the stub payload. This change also adds a flag --dump-debug-file-contents that outputs the parsed information from the file passed via -d/--debug. Change-Id: Ic52dd6825f2f3564efa3c2c12b46a8bef23d56bc Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-linux-release-x64-try,vm-kernel-precomp-linux-release-simarm_x64-try,vm-kernel-precomp-mac-release-simarm64-try,vm-kernel-precomp-win-release-x64-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/139280 Commit-Queue: Teagan Strickland <sstrickl@google.com> Reviewed-by: Martin Kustermann <kustermann@google.com>
1 parent dea82cc commit ba8baa4

File tree

9 files changed

+631
-265
lines changed

9 files changed

+631
-265
lines changed

pkg/native_stack_traces/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 0.3.0
4+
5+
- Adds handling of virtual addresses within stub code payloads.
6+
37
## 0.2.2
48

59
- Finds instruction sections by the dynamic symbols the Dart VM creates instead

pkg/native_stack_traces/bin/decode.dart

Lines changed: 51 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,36 @@ import 'package:args/args.dart' show ArgParser, ArgResults;
1010
import 'package:path/path.dart' as path;
1111
import 'package:native_stack_traces/native_stack_traces.dart';
1212

13-
final ArgParser _translateParser = ArgParser(allowTrailingOptions: true)
13+
ArgParser _createBaseDebugParser(ArgParser parser) => parser
1414
..addOption('debug',
1515
abbr: 'd',
1616
help: 'Filename containing debugging information (REQUIRED)',
1717
valueHelp: 'FILE')
18-
..addOption('input',
19-
abbr: 'i', help: 'Filename for processed input', valueHelp: 'FILE')
20-
..addOption('output',
21-
abbr: 'o', help: 'Filename for generated output', valueHelp: 'FILE')
22-
..addFlag('verbose',
23-
abbr: 'v',
24-
negatable: false,
25-
help: 'Translate all frames, not just user or library code frames');
26-
27-
final ArgParser _findParser = ArgParser(allowTrailingOptions: true)
28-
..addOption('debug',
29-
abbr: 'd',
30-
help: 'Filename containing debugging information (REQUIRED)',
31-
valueHelp: 'FILE')
32-
..addMultiOption('location',
33-
abbr: 'l', help: 'PC address to find', valueHelp: 'PC')
3418
..addFlag('verbose',
3519
abbr: 'v',
3620
negatable: false,
3721
help: 'Translate all frames, not just user or library code frames')
38-
..addOption('vm_start',
39-
help: 'Absolute address for start of VM instructions', valueHelp: 'PC')
40-
..addOption('isolate_start',
41-
help: 'Absolute address for start of isolate instructions',
42-
valueHelp: 'PC');
22+
..addFlag('dump_debug_file_contents',
23+
negatable: false,
24+
help: 'Dump all the parsed information from the debugging file');
25+
26+
final ArgParser _translateParser =
27+
_createBaseDebugParser(ArgParser(allowTrailingOptions: true))
28+
..addOption('input',
29+
abbr: 'i', help: 'Filename for processed input', valueHelp: 'FILE')
30+
..addOption('output',
31+
abbr: 'o', help: 'Filename for generated output', valueHelp: 'FILE');
32+
33+
final ArgParser _findParser =
34+
_createBaseDebugParser(ArgParser(allowTrailingOptions: true))
35+
..addMultiOption('location',
36+
abbr: 'l', help: 'PC address to find', valueHelp: 'PC')
37+
..addOption('vm_start',
38+
help: 'Absolute address for start of VM instructions',
39+
valueHelp: 'PC')
40+
..addOption('isolate_start',
41+
help: 'Absolute address for start of isolate instructions',
42+
valueHelp: 'PC');
4343

4444
final ArgParser _helpParser = ArgParser(allowTrailingOptions: true);
4545

@@ -141,14 +141,34 @@ void help(ArgResults options) {
141141
}
142142
}
143143

144+
Dwarf _loadFromFile(String original, Function(String) usageError) {
145+
if (original == null) {
146+
usageError('must provide -d/--debug');
147+
return null;
148+
}
149+
final filename = path.canonicalize(path.normalize(original));
150+
if (!io.File(filename).existsSync()) {
151+
usageError('debug file "$original" does not exist');
152+
return null;
153+
}
154+
final dwarf = Dwarf.fromFile(filename);
155+
if (dwarf == null) {
156+
usageError('file "$original" does not contain debugging information');
157+
}
158+
return dwarf;
159+
}
160+
144161
void find(ArgResults options) {
145162
void usageError(String message) => errorWithUsage(message, command: 'find');
146163
int convertAddress(String s) => int.tryParse(s, radix: 16);
147164

148-
if (options['debug'] == null) {
149-
return usageError('must provide -d/--debug');
165+
final dwarf = _loadFromFile(options['debug'], usageError);
166+
if (dwarf == null) {
167+
return;
168+
}
169+
if (options['dump_debug_file_contents']) {
170+
print(dwarf.dumpFileInfo());
150171
}
151-
final dwarf = Dwarf.fromFile(options['debug']);
152172
final verbose = options['verbose'];
153173

154174
int vm_start;
@@ -215,11 +235,13 @@ Future<void> translate(ArgResults options) async {
215235
void usageError(String message) =>
216236
errorWithUsage(message, command: 'translate');
217237

218-
if (options['debug'] == null) {
219-
return usageError('must provide -d/--debug');
238+
final dwarf = _loadFromFile(options['debug'], usageError);
239+
if (dwarf == null) {
240+
return;
241+
}
242+
if (options['dump_debug_file_contents']) {
243+
print(dwarf.dumpFileInfo());
220244
}
221-
final dwarf =
222-
Dwarf.fromFile(path.canonicalize(path.normalize(options['debug'])));
223245

224246
final verbose = options['verbose'];
225247
final output = options['output'] != null

pkg/native_stack_traces/lib/native_stack_traces.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44

55
export 'src/convert.dart'
66
show collectPCOffsets, DwarfStackTraceDecoder, StackTraceHeader;
7-
export 'src/dwarf.dart' show CallInfo, Dwarf, PCOffset;
7+
export 'src/dwarf.dart'
8+
show CallInfo, DartCallInfo, StubCallInfo, Dwarf, PCOffset;

0 commit comments

Comments
 (0)