FIRStackFrame.m 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // Copyright 2020 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. #import "FIRStackFrame_Private.h"
  15. @interface FIRStackFrame ()
  16. @property(nonatomic, copy, nullable) NSString *symbol;
  17. @property(nonatomic, copy, nullable) NSString *rawSymbol;
  18. @property(nonatomic, copy, nullable) NSString *library;
  19. @property(nonatomic, copy, nullable) NSString *fileName;
  20. @property(nonatomic, assign) uint32_t lineNumber;
  21. @property(nonatomic, assign) uint64_t offset;
  22. @property(nonatomic, assign) uint64_t address;
  23. @property(nonatomic, assign) BOOL isSymbolicated;
  24. @end
  25. @implementation FIRStackFrame
  26. #pragma mark - Public Methods
  27. - (instancetype)initWithSymbol:(NSString *)symbol file:(NSString *)file line:(NSInteger)line {
  28. self = [super init];
  29. if (!self) {
  30. return nil;
  31. }
  32. _symbol = [symbol copy];
  33. _fileName = [file copy];
  34. _lineNumber = (uint32_t)line;
  35. _isSymbolicated = true;
  36. return self;
  37. }
  38. + (instancetype)stackFrameWithSymbol:(NSString *)symbol file:(NSString *)file line:(NSInteger)line {
  39. return [[FIRStackFrame alloc] initWithSymbol:symbol file:file line:line];
  40. }
  41. #pragma mark - Internal Methods
  42. + (instancetype)stackFrame {
  43. return [[self alloc] init];
  44. }
  45. + (instancetype)stackFrameWithAddress:(NSUInteger)address {
  46. FIRStackFrame *frame = [self stackFrame];
  47. [frame setAddress:address];
  48. return frame;
  49. }
  50. + (instancetype)stackFrameWithSymbol:(NSString *)symbol {
  51. FIRStackFrame *frame = [self stackFrame];
  52. frame.symbol = symbol;
  53. frame.rawSymbol = symbol;
  54. return frame;
  55. }
  56. #pragma mark - Overrides
  57. - (NSString *)description {
  58. if (self.isSymbolicated) {
  59. return [NSString
  60. stringWithFormat:@"{%@ - %@:%u}", [self fileName], [self symbol], [self lineNumber]];
  61. }
  62. if (self.fileName) {
  63. return [NSString stringWithFormat:@"{[0x%llx] %@ - %@:%u}", [self address], [self fileName],
  64. [self symbol], [self lineNumber]];
  65. }
  66. return [NSString
  67. stringWithFormat:@"{[0x%llx + %u] %@}", [self address], [self lineNumber], [self symbol]];
  68. }
  69. @end