Proyectos de Subversion Iphone Microlearning

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
// Copyright 2019 Google
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//      http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
 
15
#import "Crashlytics/Crashlytics/Operations/Reports/FIRCLSProcessReportOperation.h"
16
 
17
#import "Crashlytics/Crashlytics/Helpers/FIRCLSFile.h"
18
#import "Crashlytics/Crashlytics/Models/FIRCLSInternalReport.h"
19
#import "Crashlytics/Crashlytics/Models/FIRCLSSymbolResolver.h"
20
#import "Crashlytics/Crashlytics/Operations/Symbolication/FIRCLSDemangleOperation.h"
21
#import "Crashlytics/Crashlytics/Operations/Symbolication/FIRCLSSerializeSymbolicatedFramesOperation.h"
22
#import "Crashlytics/Crashlytics/Operations/Symbolication/FIRCLSSymbolicationOperation.h"
23
#import "Crashlytics/Crashlytics/Private/FIRStackFrame_Private.h"
24
 
25
@implementation FIRCLSProcessReportOperation
26
 
27
- (instancetype)initWithReport:(FIRCLSInternalReport *)report
28
                      resolver:(FIRCLSSymbolResolver *)resolver {
29
  self = [super init];
30
  if (!self) {
31
    return nil;
32
  }
33
 
34
  _report = report;
35
  _symbolResolver = resolver;
36
 
37
  return self;
38
}
39
 
40
- (NSString *)binaryImagePath {
41
  return self.report.binaryImagePath;
42
}
43
 
44
- (NSArray *)threadArrayFromFile:(NSString *)path {
45
  NSArray *threads =
46
      FIRCLSFileReadSections([path fileSystemRepresentation], false, ^NSObject *(id obj) {
47
        // use this to select out the one entry that has a "threads" top-level entry
48
        return [obj objectForKey:@"threads"];
49
      });
50
 
51
  if ([threads count] == 0) {
52
    return nil;
53
  }
54
 
55
  // threads is actually an array of arrays
56
  threads = [threads objectAtIndex:0];
57
  if (!threads) {
58
    return nil;
59
  }
60
 
61
  NSMutableArray *threadArray = [NSMutableArray array];
62
 
63
  for (NSDictionary *threadDetails in threads) {
64
    NSMutableArray *frameArray = [NSMutableArray array];
65
 
66
    for (NSNumber *pc in [threadDetails objectForKey:@"stacktrace"]) {
67
      FIRStackFrame *frame = [FIRStackFrame stackFrameWithAddress:[pc unsignedIntegerValue]];
68
 
69
      [frameArray addObject:frame];
70
    }
71
 
72
    [threadArray addObject:frameArray];
73
  }
74
 
75
  return threadArray;
76
}
77
 
78
- (BOOL)symbolicateFile:(NSString *)path withResolver:(FIRCLSSymbolResolver *)resolver {
79
  NSArray *threadArray = [self threadArrayFromFile:path];
80
  if (!threadArray) {
81
    return NO;
82
  }
83
 
84
  FIRCLSSymbolicationOperation *symbolicationOp = [[FIRCLSSymbolicationOperation alloc] init];
85
  [symbolicationOp setThreadArray:threadArray];
86
  [symbolicationOp setSymbolResolver:resolver];
87
 
88
  FIRCLSDemangleOperation *demangleOp = [[FIRCLSDemangleOperation alloc] init];
89
  [demangleOp setThreadArray:threadArray];
90
 
91
  FIRCLSSerializeSymbolicatedFramesOperation *serializeOp =
92
      [[FIRCLSSerializeSymbolicatedFramesOperation alloc] init];
93
  [serializeOp setThreadArray:threadArray];
94
  [serializeOp setOutputPath:[path stringByAppendingPathExtension:@"symbolicated"]];
95
 
96
  [symbolicationOp start];
97
  [demangleOp start];
98
  [serializeOp start];
99
 
100
  return YES;
101
}
102
 
103
- (void)main {
104
  if (![self.symbolResolver loadBinaryImagesFromFile:self.binaryImagePath]) {
105
    return;
106
  }
107
 
108
  [self.report enumerateSymbolicatableFilesInContent:^(NSString *path) {
109
    [self symbolicateFile:path withResolver:self.symbolResolver];
110
  }];
111
}
112
 
113
@end