Skip to content

Commit

Permalink
Add unknown map to DebugImage
Browse files Browse the repository at this point in the history
  • Loading branch information
denrase committed Jul 9, 2024
1 parent bb7feb6 commit 35bff66
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
26 changes: 25 additions & 1 deletion dart/lib/src/protocol/debug_image.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:meta/meta.dart';

import 'unknown.dart';

/// The list of debug images contains all dynamic libraries loaded into
/// the process and their memory addresses.
/// Instruction addresses in the Stack Trace are mapped into the list of debug
Expand Down Expand Up @@ -51,6 +53,9 @@ class DebugImage {
/// MachO CPU type identifier.
final int? cpuType;

@internal
final Map<String, dynamic>? unknown;

const DebugImage({
required this.type,
this.name,
Expand All @@ -65,6 +70,7 @@ class DebugImage {
this.codeId,
this.cpuType,
this.cpuSubtype,
this.unknown,
});

/// Deserializes a [DebugImage] from JSON [Map].
Expand All @@ -83,12 +89,27 @@ class DebugImage {
codeId: json['code_id'],
cpuType: json['cpu_type'],
cpuSubtype: json['cpu_subtype'],
unknown: unknownFrom(json, {
'type',
'name',
'image_addr',
'image_vmaddr',
'debug_id',
'debug_file',
'image_size',
'uuid',
'code_file',
'arch',
'code_id',
'cpu_type',
'cpu_subtype',
}),
);
}

/// Produces a [Map] that can be serialized to JSON.
Map<String, dynamic> toJson() {
return {
final json = {
'type': type,
if (uuid != null) 'uuid': uuid,
if (debugId != null) 'debug_id': debugId,
Expand All @@ -103,6 +124,8 @@ class DebugImage {
if (cpuType != null) 'cpu_type': cpuType,
if (cpuSubtype != null) 'cpu_subtype': cpuSubtype,
};
json.addAll(unknown ?? {});
return json;
}

DebugImage copyWith({
Expand Down Expand Up @@ -134,5 +157,6 @@ class DebugImage {
codeId: codeId ?? this.codeId,
cpuType: cpuType ?? this.cpuType,
cpuSubtype: cpuSubtype ?? this.cpuSubtype,
unknown: unknown,
);
}
4 changes: 4 additions & 0 deletions dart/test/protocol/debug_image_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import 'package:collection/collection.dart';
import 'package:sentry/sentry.dart';
import 'package:test/test.dart';

import '../mocks.dart';

void main() {
final debugImage = DebugImage(
type: 'type',
Expand All @@ -13,6 +15,7 @@ void main() {
codeFile: 'codeFile',
arch: 'arch',
codeId: 'codeId',
unknown: testUnknown,
);

final debugImageJson = <String, dynamic>{
Expand All @@ -26,6 +29,7 @@ void main() {
'arch': 'arch',
'code_id': 'codeId',
};
debugImageJson.addAll(testUnknown);

group('json', () {
test('toJson', () {
Expand Down

0 comments on commit 35bff66

Please sign in to comment.