def _get_slide_value(self, image_addr): if self.debug_images: for debug_image in self.debug_images: if parse_addr( debug_image['image_addr']) == parse_addr(image_addr): return parse_addr(debug_image['image_vmaddr']) return 0
def _convert_frame_to_apple_string(self, frame, next=None, number=0): if frame.get('instruction_addr') is None: return None slide_value = self._get_slide_value(frame.get('image_addr')) instruction_addr = slide_value + \ parse_addr(frame.get('instruction_addr')) image_addr = slide_value + parse_addr(frame.get('image_addr')) offset = '' if frame.get('image_addr') is not None and \ (not self.symbolicated or ( frame.get('function') or NATIVE_UNKNOWN_STRING) == NATIVE_UNKNOWN_STRING): offset = ' + %s' % ( instruction_addr - slide_value - parse_addr(frame.get('symbol_addr')) ) symbol = hex(image_addr) if self.symbolicated: file = '' if frame.get('filename') and frame.get('lineno'): file = ' (%s:%s)' % ( posixpath.basename(frame.get('filename') or NATIVE_UNKNOWN_STRING), frame['lineno'] ) symbol = '%s%s' % (frame.get('function') or NATIVE_UNKNOWN_STRING, file) if next and parse_addr(frame['instruction_addr']) == \ parse_addr(next['instruction_addr']): symbol = '[inlined] ' + symbol return '%s%s%s%s%s' % ( str(number).ljust(4, ' '), (frame.get('package') or NATIVE_UNKNOWN_STRING).rsplit( '/', 1)[-1].ljust(32, ' '), hex(instruction_addr).ljust(20, ' '), symbol, offset )
def _convert_frame_to_apple_string(self, frame, next=None, number=0): if frame.get("instruction_addr") is None: return None slide_value = self._get_slide_value(frame.get("image_addr")) instruction_addr = slide_value + parse_addr(frame.get("instruction_addr")) image_addr = slide_value + parse_addr(frame.get("image_addr")) offset = "" if frame.get("image_addr") is not None and ( not self.symbolicated or (frame.get("function") or NATIVE_UNKNOWN_STRING) == NATIVE_UNKNOWN_STRING ): offset = " + %s" % ( instruction_addr - slide_value - parse_addr(frame.get("symbol_addr")) ) symbol = hex(image_addr) if self.symbolicated: file = "" if frame.get("filename") and frame.get("lineno"): file = " ({}:{})".format( posixpath.basename(frame.get("filename") or NATIVE_UNKNOWN_STRING), frame["lineno"], ) symbol = "{}{}".format(frame.get("function") or NATIVE_UNKNOWN_STRING, file) if next and parse_addr(frame.get("instruction_addr")) == parse_addr( next.get("instruction_addr") ): symbol = "[inlined] " + symbol return "{}{}{}{}{}".format( str(number).ljust(4, " "), image_name(frame.get("package") or NATIVE_UNKNOWN_STRING).ljust(32, " "), hex(instruction_addr).ljust(20, " "), symbol, offset, )
def convert_ios_symbolserver_match(instruction_addr, symbolserver_match): if not symbolserver_match: return [] symbol = symbolserver_match['symbol'] if symbol[:1] == '_': symbol = symbol[1:] # We still use this construct from symbolic for demangling (at least) line_info = LineInfo( sym_addr=parse_addr(symbolserver_match['addr']), instr_addr=parse_addr(instruction_addr), line=None, lang=None, symbol=symbol ) function = line_info.function_name package = symbolserver_match['object_name'] return [{ 'sym_addr': '0x%x' % (line_info.sym_addr,), 'instruction_addr': '0x%x' % (line_info.instr_addr,), 'function': function, 'symbol': symbol if function != symbol else None, 'filename': trim(line_info.rel_path, 256), 'abs_path': trim(line_info.abs_path, 256), 'package': package, }]
def _convert_frame_to_apple_string(self, frame, next=None, number=0): if frame.get('instruction_addr') is None: return None slide_value = self._get_slide_value(frame.get('image_addr')) instruction_addr = slide_value + \ parse_addr(frame.get('instruction_addr')) image_addr = slide_value + parse_addr(frame.get('image_addr')) offset = '' if frame.get('image_addr') is not None and \ (not self.symbolicated or ( frame.get('function') or NATIVE_UNKNOWN_STRING) == NATIVE_UNKNOWN_STRING): offset = ' + %s' % (instruction_addr - slide_value - parse_addr(frame.get('symbol_addr'))) symbol = hex(image_addr) if self.symbolicated: file = '' if frame.get('filename') and frame.get('lineno'): file = ' (%s:%s)' % (posixpath.basename( frame.get('filename') or NATIVE_UNKNOWN_STRING), frame['lineno']) symbol = '%s%s' % (frame.get('function') or NATIVE_UNKNOWN_STRING, file) if next and parse_addr(frame['instruction_addr']) == \ parse_addr(next['instruction_addr']): symbol = '[inlined] ' + symbol return '%s%s%s%s%s' % (str(number).ljust( 4, ' '), (frame.get('package') or NATIVE_UNKNOWN_STRING).rsplit( '/', 1)[-1].ljust(32, ' '), hex(instruction_addr).ljust( 20, ' '), symbol, offset)
def _get_slide_value(self, image_addr): if self.debug_images: for debug_image in self.debug_images: if parse_addr(debug_image.get("image_addr")) == parse_addr( image_addr): return parse_addr(debug_image.get("image_vmaddr", 0)) return 0
def _convert_debug_meta_to_binary_image_row(self, debug_image): slide_value = parse_addr(debug_image['image_vmaddr']) image_addr = parse_addr(debug_image['image_addr']) + slide_value return '%s - %s %s %s <%s> %s' % ( hex(image_addr), hex(image_addr + debug_image['image_size'] - 1), image_name(debug_image['name']), self.context['device']['arch'], debug_image['uuid'].replace('-', '').lower(), debug_image['name'])
def _convert_debug_meta_to_binary_image_row(self, debug_image): slide_value = parse_addr(debug_image['image_vmaddr']) image_addr = parse_addr(debug_image['image_addr']) + slide_value return '%s - %s %s %s <%s> %s' % ( hex(image_addr), hex(image_addr + debug_image['image_size'] - 1), image_name(debug_image['name']), self.context['device']['arch'], debug_image['uuid'].replace('-', '').lower(), debug_image['name'] )
def _convert_debug_meta_to_binary_image_row(self, debug_image): slide_value = parse_addr(debug_image.get("image_vmaddr", 0)) image_addr = parse_addr(debug_image["image_addr"]) + slide_value return "%s - %s %s %s <%s> %s" % ( hex(image_addr), hex(image_addr + debug_image["image_size"] - 1), image_name(debug_image.get("code_file") or NATIVE_UNKNOWN_STRING), get_path(self.context, "device", "arch") or NATIVE_UNKNOWN_STRING, debug_image.get("debug_id").replace("-", "").lower(), debug_image.get("code_file") or NATIVE_UNKNOWN_STRING, )
def _convert_debug_meta_to_binary_image_row(self, debug_image): slide_value = parse_addr(debug_image["image_vmaddr"]) image_addr = parse_addr(debug_image["image_addr"]) + slide_value return "%s - %s %s %s <%s> %s" % ( hex(image_addr), hex(image_addr + debug_image["image_size"] - 1), image_name(debug_image["name"]), self.context["device"]["arch"], (debug_image.get("id") or debug_image.get("uuid")).replace( "-", "").lower(), debug_image["name"], )
def find_best_instruction(self, processable_frame): """Given a frame, stacktrace info and frame index this returns the interpolated instruction address we then use for symbolication later. """ if self.arch is None: return parse_addr(processable_frame['instruction_addr']) crashing_frame = False signal = None ip_reg = None # We only need to provide meta information for frame zero if processable_frame.idx == 0: # The signal is useful information for symbolic in some situations # to disambiugate the first frame. If we can get this information # from the mechanism we want to pass it onwards. signal = self.signal registers = processable_frame.stacktrace_info.stacktrace.get( 'registers') if registers: ip_reg_name = arch_get_ip_reg_name(self.arch) if ip_reg_name: ip_reg = registers.get(ip_reg_name) crashing_frame = True return find_best_instruction(processable_frame['instruction_addr'], arch=self.arch, crashing_frame=crashing_frame, signal=signal, ip_reg=ip_reg)
def find_best_instruction(self, processable_frame): """Given a frame, stacktrace info and frame index this returns the interpolated instruction address we then use for symbolication later. """ if self.arch is None: return parse_addr(processable_frame['instruction_addr']) crashing_frame = False signal = None ip_reg = None # We only need to provide meta information for frame zero if processable_frame.idx == 0: # The signal is useful information for symbolic in some situations # to disambiugate the first frame. If we can get this information # from the mechanism we want to pass it onwards. signal = self.signal registers = processable_frame.stacktrace_info.stacktrace.get('registers') if registers: ip_reg_name = arch_get_ip_reg_name(self.arch) if ip_reg_name: ip_reg = registers.get(ip_reg_name) crashing_frame = True return find_best_instruction( processable_frame['instruction_addr'], arch=self.arch, crashing_frame=crashing_frame, signal=signal, ip_reg=ip_reg )
def sym_mac_app_frame(self, instruction_addr, img, sdk_info=None): object_name = ( "/Users/haza/Library/Developer/Xcode/Archives/2017-06-19/" "CrashProbe 19-06-2017, 08.53.xcarchive/Products/Applications/" "CrashProbe.app/Contents/Frameworks/" "CrashLib.framework/Versions/A/CrashLib") if not (4295098384 <= parse_addr(instruction_addr) < 4295098388): return [{ 'filename': 'Foo.swift', 'abs_path': 'Foo.swift', 'lineno': 82, 'colno': 23, 'package': object_name, 'function': 'other_main', 'symbol_addr': '0x1', "instruction_addr": '0x1', }] return [{ 'filename': 'Foo.swift', 'abs_path': 'Foo.swift', 'lineno': 42, 'colno': 23, 'package': object_name, 'function': 'real_main', 'symbol_addr': '0x1000262a0', "instruction_addr": '0x100026330', }]
def sym_app_frame(self, instruction_addr, img, sdk_info=None): object_name = ( "/var/containers/Bundle/Application/" "B33C37A8-F933-4B6B-9FFA-152282BFDF13/" "SentryTest.app/SentryTest" ) if not (4295098384 <= parse_addr(instruction_addr) < 4295098388): return [{ 'filename': 'Foo.swift', 'abs_path': 'Foo.swift', 'lineno': 82, 'colno': 23, 'package': object_name, 'function': 'other_main', 'symbol_addr': '0x1', "instruction_addr": '0x1', }] return [{ 'filename': 'Foo.swift', 'abs_path': 'Foo.swift', 'lineno': 42, 'colno': 23, 'package': object_name, 'function': 'real_main', 'symbol_addr': '0x1000262a0', "instruction_addr": '0x100026330', }]
def sym_mac_app_frame(self, instruction_addr, img, sdk_info=None): object_name = ( "/Users/haza/Library/Developer/Xcode/Archives/2017-06-19/" "CrashProbe 19-06-2017, 08.53.xcarchive/Products/Applications/" "CrashProbe.app/Contents/Frameworks/" "CrashLib.framework/Versions/A/CrashLib" ) if not (4295098384 <= parse_addr(instruction_addr) < 4295098388): return [{ 'filename': 'Foo.swift', 'abs_path': 'Foo.swift', 'lineno': 82, 'colno': 23, 'package': object_name, 'function': 'other_main', 'symbol_addr': '0x1', "instruction_addr": '0x1', }] return [{ 'filename': 'Foo.swift', 'abs_path': 'Foo.swift', 'lineno': 42, 'colno': 23, 'package': object_name, 'function': 'real_main', 'symbol_addr': '0x1000262a0', "instruction_addr": '0x100026330', }]
def sym_app_frame(self, instruction_addr, img, sdk_info=None): object_name = ("/var/containers/Bundle/Application/" "B33C37A8-F933-4B6B-9FFA-152282BFDF13/" "SentryTest.app/SentryTest") if not (4295098384 <= parse_addr(instruction_addr) < 4295098388): return [{ 'filename': 'Foo.swift', 'abs_path': 'Foo.swift', 'lineno': 82, 'colno': 23, 'package': object_name, 'function': 'other_main', 'symbol_addr': '0x1', "instruction_addr": '0x1', }] return [{ 'filename': 'Foo.swift', 'abs_path': 'Foo.swift', 'lineno': 42, 'colno': 23, 'package': object_name, 'function': 'real_main', 'symbol_addr': '0x1000262a0', "instruction_addr": '0x100026330', }]
def _convert_symbolserver_match(self, instruction_addr, symbolserver_match, obj): """Symbolizes a frame with system symbols only.""" if symbolserver_match is None: return [] symbol = symbolserver_match['symbol'] if symbol[:1] == '_': symbol = symbol[1:] return [ self._process_frame(Symbol( sym_addr=parse_addr(symbolserver_match['addr']), instr_addr=parse_addr(instruction_addr), line=None, symbol=symbol, ), obj, package=symbolserver_match['object_name']) ]
def get_binary_images_apple_string(self): # We don't need binary images on symbolicated crashreport if self.symbolicated or self.debug_images is None: return "" binary_images = map( lambda i: self._convert_debug_meta_to_binary_image_row(debug_image=i), sorted(self.debug_images, key=lambda i: parse_addr(i["image_addr"])), ) return "Binary Images:\n" + "\n".join(binary_images)
def get_binary_images_apple_string(self): # We dont need binary images on symbolicated crashreport if self.symbolicated or self.debug_images is None: return '' binary_images = map( lambda i: self._convert_debug_meta_to_binary_image_row( debug_image=i), sorted(self.debug_images, key=lambda i: parse_addr(i['image_addr'])) ) return 'Binary Images:\n' + '\n'.join(binary_images)
def process_symbolic_image(image): try: symbolic_image = { 'id': normalize_debug_id(image.get('id')), 'image_addr': _addr(image.get('image_addr')), 'image_size': parse_addr(image['image_size']), 'image_vmaddr': _addr(image.get('image_vmaddr') or 0), 'name': image.get('name'), } if image.get('arch') is not None: symbolic_image['arch'] = image.get('arch') return symbolic_image except KeyError as e: raise InterfaceValidationError('Missing value for symbolic image: %s' % e.args[0])
def find_best_instruction(self, processable_frame): """Given a frame, stacktrace info and frame index this returns the interpolated instruction address we then use for symbolication later. """ if self.arch is None: return parse_addr(processable_frame['instruction_addr']) crashing_frame = False signal = None ip_reg = None # We only need to provide meta information for frame zero if processable_frame.idx == 0: # The signal is useful information for symbolic in some situations # to disambiugate the first frame. If we can get this information # from the mechanism we want to pass it onwards. signal = None exc = self.data.get('sentry.interfaces.Exception') if exc is not None: mechanism = exc['values'][0].get('mechanism') if mechanism and 'meta' in mechanism and \ 'signal' in mechanism['meta'] and \ 'number' in mechanism['meta']['signal']: signal = int(mechanism['meta']['signal']['number']) registers = processable_frame.stacktrace_info.stacktrace.get( 'registers') if registers: ip_reg_name = arch_get_ip_reg_name(self.arch) if ip_reg_name: ip_reg = registers.get(ip_reg_name) crashing_frame = True return find_best_instruction( processable_frame['instruction_addr'], arch=self.arch, crashing_frame=crashing_frame, signal=signal, ip_reg=ip_reg )
def _addr(x): if x is None: return None return '0x%x' % parse_addr(x)
def rebase_addr(instr_addr, obj): return parse_addr(instr_addr) - parse_addr(obj.addr)
def _addr(x): return '0x%x' % parse_addr(x)
def _get_slide_value(self, image_addr): if self.debug_images: for debug_image in self.debug_images: if parse_addr(debug_image['image_addr']) == parse_addr(image_addr): return parse_addr(debug_image['image_vmaddr']) return 0