<s> try : <EOL> from symsynd . driver import Driver <EOL> from symsynd . report import ReportSymbolizer <EOL> from symsynd . macho . arch import get_cpu_name <EOL> from symsynd . demangle import demangle_symbol <EOL> have_symsynd = True <EOL> except ImportError : <EOL> have_symsynd = False <EOL> from sentry import options <EOL> from sentry . lang . native . dsymcache import dsymcache <EOL> from sentry . utils . safe import trim <EOL> from sentry . models import DSymSymbol <EOL> from sentry . models . dsymfile import MAX_SYM <EOL> def trim_frame ( frame ) : <EOL> frame [ '<STR_LIT>' ] = trim ( frame . get ( '<STR_LIT>' ) , MAX_SYM ) <EOL> frame [ '<STR_LIT:filename>' ] = trim ( frame . get ( '<STR_LIT:filename>' ) , <NUM_LIT> ) <EOL> return frame <EOL> def find_system_symbol ( img , instruction_addr , system_info = None ) : <EOL> """<STR_LIT>""" <EOL> return DSymSymbol . objects . lookup_symbol ( <EOL> instruction_addr = instruction_addr , <EOL> image_addr = img [ '<STR_LIT>' ] , <EOL> uuid = img [ '<STR_LIT>' ] , <EOL> cpu_name = get_cpu_name ( img [ '<STR_LIT>' ] , <EOL> img [ '<STR_LIT>' ] ) , <EOL> object_path = img [ '<STR_LIT:name>' ] , <EOL> system_info = system_info <EOL> ) <EOL> def make_symbolizer ( project , binary_images , threads = None ) : <EOL> """<STR_LIT>""" <EOL> if not have_symsynd : <EOL> raise RuntimeError ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> driver = Driver ( options . get ( '<STR_LIT>' ) or None ) <EOL> if threads is None : <EOL> to_load = [ x [ '<STR_LIT>' ] for x in binary_images ] <EOL> else : <EOL> image_map = { } <EOL> for image in binary_images : <EOL> image_map [ image [ '<STR_LIT>' ] ] = image [ '<STR_LIT>' ] <EOL> to_load = set ( ) <EOL> for thread in threads : <EOL> for frame in thread [ '<STR_LIT>' ] [ '<STR_LIT>' ] : <EOL> img_uuid = image_map . get ( frame [ '<STR_LIT>' ] ) <EOL> if img_uuid is not None : <EOL> to_load . add ( img_uuid ) <EOL> to_load = list ( to_load ) <EOL> dsym_paths , loaded = dsymcache . fetch_dsyms ( project , to_load ) <EOL> return ReportSymbolizer ( driver , dsym_paths , binary_images ) <EOL> class Symbolizer ( object ) : <EOL> def __init__ ( self , project , binary_images , threads = None ) : <EOL> self . symsynd_symbolizer = make_symbolizer ( project , binary_images , <EOL> threads = threads ) <EOL> self . images = dict ( ( img [ '<STR_LIT>' ] , img ) for img in binary_images ) <EOL> def __enter__ ( self ) : <EOL> return self . symsynd_symbolizer . driver . __enter__ ( ) <EOL> def __exit__ ( self , * args ) : <EOL> return self . symsynd_symbolizer . driver . __exit__ ( * args ) <EOL> def symbolize_frame ( self , frame , system_info = None ) : <EOL> new_frame = self . symsynd_symbolizer . symbolize_frame ( frame ) <EOL> if new_frame is not None : <EOL> return trim_frame ( new_frame ) <EOL> img = self . images . get ( frame [ '<STR_LIT>' ] ) <EOL> if img is not None : <EOL> symbol = find_system_symbol ( img , frame [ '<STR_LIT>' ] , <EOL> system_info ) <EOL> if symbol is not None : <EOL> symbol = demangle_symbol ( symbol ) or symbol <EOL> rv = dict ( frame , symbol_name = symbol , filename = None , <EOL> line = <NUM_LIT:0> , column = <NUM_LIT:0> , uuid = img [ '<STR_LIT>' ] ) <EOL> return trim_frame ( rv ) <EOL> def symbolize_backtrace ( self , backtrace , system_info = None ) : <EOL> rv = [ ] <EOL> for frame in backtrace : <EOL> new_frame = self . symbolize_frame ( frame , system_info ) <EOL> rv . append ( new_frame or frame ) <EOL> return rv </s>
