Пример #1
0
def debug(drv, use_pdb=True):
    # XXX unify some code with rpython.translator.goal.translate
    from rpython.translator.tool.pdbplus import PdbPlusShow
    from rpython.translator.driver import log
    t = drv.translator

    class options:
        huge = 100

    tb = None
    import traceback
    errmsg = ["Error:\n"]
    exc, val, tb = sys.exc_info()

    errmsg.extend([" %s" % line for line in traceback.format_exception(exc, val, [])])
    block = getattr(val, '__annotator_block', None)
    if block:
        class FileLike:
            def write(self, s):
                errmsg.append(" %s" % s)
        errmsg.append("Processing block:\n")
        t.about(block, FileLike())
    log.ERROR(''.join(errmsg))

    log.event("start debugger...")

    if use_pdb:
        pdb_plus_show = PdbPlusShow(t)
        pdb_plus_show.start(tb)
Пример #2
0
def debug(drv, use_pdb=True):
    # XXX unify some code with rpython.translator.goal.translate
    from rpython.translator.tool.pdbplus import PdbPlusShow
    from rpython.translator.driver import log
    t = drv.translator

    class options:
        huge = 100

    tb = None
    import traceback
    errmsg = ["Error:\n"]
    exc, val, tb = sys.exc_info()

    errmsg.extend(
        [" %s" % line for line in traceback.format_exception(exc, val, [])])
    block = getattr(val, '__annotator_block', None)
    if block:

        class FileLike:
            def write(self, s):
                errmsg.append(" %s" % s)

        errmsg.append("Processing block:\n")
        t.about(block, FileLike())
    log.ERROR(''.join(errmsg))

    log.event("start debugger...")

    if use_pdb:
        pdb_plus_show = PdbPlusShow(t)
        pdb_plus_show.start(tb)
Пример #3
0
            return obj._callable(*args)
        except LLException, e:
            raise
        except Exception, e:
            if getattr(e, '_go_through_llinterp_uncaught_', False):
                raise
            if getattr(obj, '_debugexc', False):
                log.ERROR('The llinterpreter got an '
                          'unexpected exception when calling')
                log.ERROR('the external function %r:' % (fptr, ))
                log.ERROR('%s: %s' % (e.__class__.__name__, e))
                if self.llinterpreter.tracer:
                    self.llinterpreter.tracer.flush()
                import sys
                from rpython.translator.tool.pdbplus import PdbPlusShow
                PdbPlusShow(None).post_mortem(sys.exc_info()[2])
            self.make_llexception()

    def find_roots(self, roots):
        #log.findroots(self.curr_block.inputargs)
        vars = []
        for v in self.curr_block.inputargs:
            if isinstance(v, Variable):
                vars.append(v)
        for op in self.curr_block.operations[:self.curr_operation_index]:
            vars.append(op.result)

        for v in vars:
            TYPE = v.concretetype
            if isinstance(TYPE, lltype.Ptr) and TYPE.TO._gckind == 'gc':
                roots.append(_address_of_local_var(self, v))
Пример #4
0
def main():
    sys.setrecursionlimit(2000)  # PyPy can't translate within cpython's 1k limit
    targetspec_dic, translateconfig, config, args = parse_options_and_load_target()
    from rpython.translator import translator
    from rpython.translator import driver
    from rpython.translator.tool.pdbplus import PdbPlusShow

    if translateconfig.view:
        translateconfig.pdb = True

    if translateconfig.profile:
        from cProfile import Profile
        prof = Profile()
        prof.enable()
    else:
        prof = None

    t = translator.TranslationContext(config=config)

    pdb_plus_show = PdbPlusShow(t) # need a translator to support extended commands

    def finish_profiling():
        if prof:
            prof.disable()
            statfilename = 'prof.dump'
            log.info('Dumping profiler stats to: %s' % statfilename)
            prof.dump_stats(statfilename)

    def debug(got_error):
        tb = None
        if got_error:
            import traceback
            stacktrace_errmsg = ["Error:\n"]
            exc, val, tb = sys.exc_info()
            stacktrace_errmsg.extend([" %s" % line for line in traceback.format_tb(tb)])
            summary_errmsg = traceback.format_exception_only(exc, val)
            block = getattr(val, '__annotator_block', None)
            if block:
                class FileLike:
                    def write(self, s):
                        summary_errmsg.append(" %s" % s)
                summary_errmsg.append("Processing block:\n")
                t.about(block, FileLike())
            log.info(''.join(stacktrace_errmsg))
            log.ERROR(''.join(summary_errmsg))
        else:
            log.event('Done.')

        if translateconfig.batch:
            log.event("batch mode, not calling interactive helpers")
            return

        log.event("start debugger...")

        if translateconfig.view:
            try:
                t1 = drv.hint_translator
            except (NameError, AttributeError):
                t1 = t
            from rpython.translator.tool import graphpage
            page = graphpage.TranslatorPage(t1, translateconfig.huge)
            page.display_background()

        pdb_plus_show.start(tb)

    try:
        drv = driver.TranslationDriver.from_targetspec(targetspec_dic, config, args,
                                                       empty_translator=t,
                                                       disable=translateconfig.skipped_goals,
                                                       default_goal='compile')
        log_config(translateconfig, "translate.py configuration")
        if config.translation.jit:
            if (translateconfig.goals != ['annotate'] and
                translateconfig.goals != ['rtype']):
                drv.set_extra_goals(['pyjitpl'])
            # early check:
            from rpython.jit.backend.detect_cpu import getcpuclassname
            getcpuclassname(config.translation.jit_backend)

        log_config(config.translation, "translation configuration")
        pdb_plus_show.expose({'drv': drv, 'prof': prof})

        if config.translation.output:
            drv.exe_name = config.translation.output
        elif drv.exe_name is None and '__name__' in targetspec_dic:
            drv.exe_name = targetspec_dic['__name__'] + '-%(backend)s'

        # Double check to ensure we are not overwriting the current interpreter
        goals = translateconfig.goals
        if not goals or 'compile' in goals:
            try:
                this_exe = py.path.local(sys.executable).new(ext='')
                exe_name = drv.compute_exe_name()
                samefile = this_exe.samefile(exe_name)
                assert not samefile, (
                    'Output file %s is the currently running '
                    'interpreter (please move the executable, and '
                    'possibly its associated libpypy-c, somewhere else '
                    'before you execute it)' % exe_name)
            except EnvironmentError:
                pass

        try:
            drv.proceed(goals)
        finally:
            drv.timer.pprint()
    except SystemExit:
        raise
    except:
        finish_profiling()
        debug(True)
        raise SystemExit(1)
    else:
        finish_profiling()
        if translateconfig.pdb:
            debug(False)
Пример #5
0
def checkmodule(modname,
                translate_startup=True,
                ignore=(),
                c_compile=False,
                extra_func=None,
                rpython_opts=None,
                pypy_opts=None,
                show_pdbplus=False):
    """
    Check that the module 'modname' translates.

    Options:
      translate_startup: TODO, document me

      ignore:       list of module interpleveldefs/appleveldefs to ignore

      c_compile:    determine whether to inokve the C compiler after rtyping

      extra_func:   extra function which will be annotated and called. It takes
                    a single "space" argment

      rpython_opts: dictionariy containing extra configuration options
      pypy_opts:    dictionariy containing extra configuration options

      show_pdbplus: show Pdb+ prompt on error. Useful for pdb commands such as
                    flowg, callg, etc.
    """
    config = get_pypy_config(translating=True)
    if pypy_opts:
        config.set(**pypy_opts)
    space = FakeObjSpace(config)
    seeobj_w = []
    modules = []
    modnames = [modname]
    for modname in modnames:
        mod = __import__('pypy.module.%s.moduledef' % modname, None, None,
                         ['__doc__'])
        # force computation and record what we wrap
        module = mod.Module(space, W_Root())
        module.setup_after_space_initialization()
        module.init(space)
        modules.append(module)
        for name in module.loaders:
            if name in ignore:
                continue
            seeobj_w.append(module._load_lazily(space, name))
        if hasattr(module, 'submodules'):
            for cls in module.submodules.itervalues():
                submod = cls(space, W_Root())
                for name in submod.loaders:
                    seeobj_w.append(submod._load_lazily(space, name))
    #
    def func():
        for mod in modules:
            mod.startup(space)

    if not translate_startup:
        func()  # call it now
        func = None

    opts = {'translation.list_comprehension_operations': True}
    if rpython_opts:
        opts.update(rpython_opts)

    try:
        space.translates(func,
                         seeobj_w=seeobj_w,
                         c_compile=c_compile,
                         extra_func=extra_func,
                         **opts)
    except:
        if not show_pdbplus:
            raise
        print
        exc, val, tb = sys.exc_info()
        traceback.print_exc()
        sys.pdbplus = p = PdbPlusShow(space.t)
        p.start(tb)
    else:
        if show_pdbplus:
            sys.pdbplus = p = PdbPlusShow(space.t)
            p.start(None)
Пример #6
0
def main():
    sys.setrecursionlimit(
        2000)  # PyPy can't translate within cpython's 1k limit
    targetspec_dic, translateconfig, config, args = parse_options_and_load_target(
    )
    from rpython.translator import translator
    from rpython.translator import driver
    from rpython.translator.tool.pdbplus import PdbPlusShow

    if translateconfig.view:
        translateconfig.pdb = True

    if translateconfig.profile:
        from cProfile import Profile
        prof = Profile()
        prof.enable()
    else:
        prof = None

    t = translator.TranslationContext(config=config)

    pdb_plus_show = PdbPlusShow(
        t)  # need a translator to support extended commands

    def finish_profiling():
        if prof:
            prof.disable()
            statfilename = 'prof.dump'
            log.info('Dumping profiler stats to: %s' % statfilename)
            prof.dump_stats(statfilename)

    def debug(got_error):
        tb = None
        if got_error:
            import traceback
            stacktrace_errmsg = ["Error:\n"]
            exc, val, tb = sys.exc_info()
            stacktrace_errmsg.extend(
                [" %s" % line for line in traceback.format_tb(tb)])
            summary_errmsg = traceback.format_exception_only(exc, val)
            block = getattr(val, '__annotator_block', None)
            if block:

                class FileLike:
                    def write(self, s):
                        summary_errmsg.append(" %s" % s)

                summary_errmsg.append("Processing block:\n")
                t.about(block, FileLike())
            log.info(''.join(stacktrace_errmsg))
            log.ERROR(''.join(summary_errmsg))
        else:
            log.event('Done.')

        if translateconfig.batch:
            log.event("batch mode, not calling interactive helpers")
            return

        log.event("start debugger...")

        if translateconfig.view:
            try:
                t1 = drv.hint_translator
            except (NameError, AttributeError):
                t1 = t
            from rpython.translator.tool import graphpage
            page = graphpage.TranslatorPage(t1, translateconfig.huge)
            page.display_background()

        pdb_plus_show.start(tb)

    try:
        drv = driver.TranslationDriver.from_targetspec(
            targetspec_dic,
            config,
            args,
            empty_translator=t,
            disable=translateconfig.skipped_goals,
            default_goal='compile')
        log_config(translateconfig, "translate.py configuration")
        if config.translation.jit:
            if (translateconfig.goals != ['annotate']
                    and translateconfig.goals != ['rtype']):
                drv.set_extra_goals(['pyjitpl'])
            # early check:
            from rpython.jit.backend.detect_cpu import getcpuclassname
            getcpuclassname(config.translation.jit_backend)

        log_config(config.translation, "translation configuration")
        pdb_plus_show.expose({'drv': drv, 'prof': prof})

        if config.translation.output:
            drv.exe_name = config.translation.output
        elif drv.exe_name is None and '__name__' in targetspec_dic:
            drv.exe_name = targetspec_dic['__name__'] + '-%(backend)s'

        # Double check to ensure we are not overwriting the current interpreter
        goals = translateconfig.goals
        if not goals or 'compile' in goals:
            try:
                this_exe = py.path.local(sys.executable).new(ext='')
                exe_name = drv.compute_exe_name()
                samefile = this_exe.samefile(exe_name)
                assert not samefile, (
                    'Output file %s is the currently running '
                    'interpreter (please move the executable, and '
                    'possibly its associated libpypy-c, somewhere else '
                    'before you execute it)' % exe_name)
            except EnvironmentError:
                pass

        try:
            drv.proceed(goals)
        finally:
            drv.timer.pprint()
    except SystemExit:
        raise
    except:
        finish_profiling()
        debug(True)
        raise SystemExit(1)
    else:
        finish_profiling()
        if translateconfig.pdb:
            debug(False)