# Path: symsynd/libdebug.py
# def get_cpu_name(type, subtype):
#     try:
#         return str_from_slice(rustcall(_lib.debug_get_cpu_name, type, subtype))
#     except exceptions.NoSuchArch:
#         pass
# 
# class DebugInfo(object):
# 
#     def __init__(self):
#         raise TypeError('Cannot instanciate debug infos')
# 
#     @staticmethod
#     def _from_ptr(ptr):
#         rv = object.__new__(DebugInfo)
#         rv._ptr = ptr
#         return rv
# 
#     @staticmethod
#     def open_path(path):
#         di = rustcall(_lib.debug_info_open_path, to_bytes(path))
#         return DebugInfo._from_ptr(di)
# 
#     def _get_ptr(self):
#         if self._ptr is None:
#             raise RuntimeError('Debug info closed')
#         return self._ptr
# 
#     def get_compilation_dir(self, cpu_name, path):
#         ptr = self._get_ptr()
# 
#         try:
#             rv = rustcall(_lib.debug_info_get_compilation_dir,
#                           ptr, to_bytes(cpu_name), to_bytes(path))
#             rv = _ffi.string(rv)
#             if isinstance(path, text_type):
#                 rv = rv.decode('utf-8')
#             return rv
#         except exceptions.DwarfLookupError:
#             pass
# 
#     def get_variants(self):
#         ptr = self._get_ptr()
#         count = _ffi.new('int *')
#         arr = rustcall(_lib.debug_info_get_variants, ptr, count)
#         return [Variant(arr[x]) for x in range(count[0])]
# 
#     def get_variant(self, uuid_or_cpu_name):
#         if isinstance(uuid_or_cpu_name, uuid.UUID):
#             id = uuid_or_cpu_name
#             cpu_name = None
#         else:
#             try:
#                 id = uuid.UUID(uuid_or_cpu_name)
#                 cpu_name = None
#             except ValueError:
#                 id = None
#                 cpu_name = uuid_or_cpu_name
#         for variant in self.get_variants():
#             if (id is not None and variant.uuid == id) or \
#                (cpu_name is not None and variant.cpu_name == cpu_name):
#                 return variant
# 
#     def close(self):
#         if self._ptr:
#             _lib.debug_info_free(self._ptr)
#         self._ptr = None
# 
#     def __del__(self):
#         try:
#             self.close()
#         except Exception:
#             pass
# 
# Path: symsynd/exceptions.py
# class DebugInfoError(SymbolicationError):
#     pass
# 
# Path: symsynd/utils.py
# @contextmanager
# def timedsection(key):
#     if not _timeit:
#         yield
#         return
# 
#     try:
#         _local.indent = _local.indent + 1
#     except AttributeError:
#         _local.indent = 0
#     storage = _timers.setdefault(key, [])
#     _indentations[key] = _local.indent
#     now = time.time()
#     try:
#         yield
#     finally:
#         _local.indent -= 1
#         dt = time.time() - now
#         storage.append(dt)
#         del storage[1000:]
# 
#         if _last_print < time.time() - 1:
#             print_timers()
# 
# def parse_addr(x):
#     if x is None:
#         return 0
#     if isinstance(x, int_types):
#         return x
#     if isinstance(x, basestring):
#         if x[:2] == '0x':
#             return int(x[2:], 16)
#         return int(x)
#     raise ValueError('Unsupported address format %r' % (x,))
# 
# Path: symsynd/_compat.py
# PY2 = sys.version_info[0] == 2
# def to_bytes(x):


import os
import bisect
from symsynd.libdebug import get_cpu_name, DebugInfo
from symsynd.exceptions import DebugInfoError
from symsynd.utils import timedsection, parse_addr
from symsynd._compat import string_types, itervalues
    """
    images_to_load = set()

    with timedsection('iterimages0'):
        for image in binary_images:
            if get_image_cpu_name(image) is not None:
                images_to_load.add(image['uuid'].lower())

    images = {}

    # Step one: load images that are named by their UUID
    with timedsection('loadimages-fast'):
        for uuid in list(images_to_load):
            for dsym_path in dsym_paths:
                fn = os.path.join(dsym_path, uuid)
                if os.path.isfile(fn):
                    images[uuid] = fn
                    images_to_load.discard(uuid)
                    break

    # Otherwise fall back to loading images from the dsym bundle.  Because
    # this loading strategy is pretty slow we do't actually want to use it
    # unless we have a path that looks like a bundle.  As a result we
    # find all the paths which are bundles and then only process those.
    if images_to_load:
        slow_paths = []
        for dsym_path in dsym_paths:
            if os.path.isdir(os.path.join(dsym_path, 'Contents')):
                slow_paths.append(dsym_path)


# Path: symsynd/libdebug.py
# def get_cpu_name(type, subtype):
#     try:
#         return str_from_slice(rustcall(_lib.debug_get_cpu_name, type, subtype))
#     except exceptions.NoSuchArch:
#         pass
# 
# class DebugInfo(object):
# 
#     def __init__(self):
#         raise TypeError('Cannot instanciate debug infos')
# 
#     @staticmethod
#     def _from_ptr(ptr):
#         rv = object.__new__(DebugInfo)
#         rv._ptr = ptr
#         return rv
# 
#     @staticmethod
#     def open_path(path):
#         di = rustcall(_lib.debug_info_open_path, to_bytes(path))
#         return DebugInfo._from_ptr(di)
# 
#     def _get_ptr(self):
#         if self._ptr is None:
#             raise RuntimeError('Debug info closed')
#         return self._ptr
# 
#     def get_compilation_dir(self, cpu_name, path):
#         ptr = self._get_ptr()
# 
#         try:
#             rv = rustcall(_lib.debug_info_get_compilation_dir,
#                           ptr, to_bytes(cpu_name), to_bytes(path))
#             rv = _ffi.string(rv)
#             if isinstance(path, text_type):
#                 rv = rv.decode('utf-8')
#             return rv
#         except exceptions.DwarfLookupError:
#             pass
# 
#     def get_variants(self):
#         ptr = self._get_ptr()
#         count = _ffi.new('int *')
#         arr = rustcall(_lib.debug_info_get_variants, ptr, count)
#         return [Variant(arr[x]) for x in range(count[0])]
# 
#     def get_variant(self, uuid_or_cpu_name):
#         if isinstance(uuid_or_cpu_name, uuid.UUID):
#             id = uuid_or_cpu_name
#             cpu_name = None
#         else:
#             try:
#                 id = uuid.UUID(uuid_or_cpu_name)
#                 cpu_name = None
#             except ValueError:
#                 id = None
#                 cpu_name = uuid_or_cpu_name
#         for variant in self.get_variants():
#             if (id is not None and variant.uuid == id) or \
#                (cpu_name is not None and variant.cpu_name == cpu_name):
#                 return variant
# 
#     def close(self):
#         if self._ptr:
#             _lib.debug_info_free(self._ptr)
#         self._ptr = None
# 
#     def __del__(self):
#         try:
#             self.close()
#         except Exception:
#             pass
# 
# Path: symsynd/exceptions.py
# class DebugInfoError(SymbolicationError):
#     pass
# 
# Path: symsynd/utils.py
# @contextmanager
# def timedsection(key):
#     if not _timeit:
#         yield
#         return
# 
#     try:
#         _local.indent = _local.indent + 1
#     except AttributeError:
#         _local.indent = 0
#     storage = _timers.setdefault(key, [])
#     _indentations[key] = _local.indent
#     now = time.time()
#     try:
#         yield
#     finally:
#         _local.indent -= 1
#         dt = time.time() - now
#         storage.append(dt)
#         del storage[1000:]
# 
#         if _last_print < time.time() - 1:
#             print_timers()
# 
# def parse_addr(x):
#     if x is None:
#         return 0
#     if isinstance(x, int_types):
#         return x
#     if isinstance(x, basestring):
#         if x[:2] == '0x':
#             return int(x[2:], 16)
#         return int(x)
#     raise ValueError('Unsupported address format %r' % (x,))
# 
# Path: symsynd/_compat.py
# PY2 = sys.version_info[0] == 2
# def to_bytes(x):


# Path: symsynd/images.py
import os
import bisect
from symsynd.libdebug import get_cpu_name, DebugInfo
from symsynd.exceptions import DebugInfoError
from symsynd.utils import timedsection, parse_addr
from symsynd._compat import string_types, itervalues

    """
    images_to_load = set()

    with timedsection('iterimages0'):
        for image in binary_images:
            if get_image_cpu_name(image) is not None:
                images_to_load.add(image['uuid'].lower())

    images = {}

    # Step one: load images that are named by their UUID
    with timedsection('loadimages-fast'):
        for uuid in list(images_to_load):
            for dsym_path in dsym_paths:
                fn = os.path.join(dsym_path, uuid)
                if os.path.isfile(fn):
                    images[uuid] = fn
                    images_to_load.discard(uuid)
                    break

    # Otherwise fall back to loading images from the dsym bundle.  Because
    # this loading strategy is pretty slow we do't actually want to use it
    # unless we have a path that looks like a bundle.  As a result we
    # find all the paths which are bundles and then only process those.
    if images_to_load:
        slow_paths = []
        for dsym_path in dsym_paths:
            if os.path.isdir(os.path.join(dsym_path, 'Contents')):
                slow_paths.append(dsym_path)


        with timedsection('loadimages-slow'):