コード例 #1
0
ファイル: error.py プロジェクト: xx312022850/pypy
def debug(drv, use_pdb=True):
    # XXX unify some code with pypy.translator.goal.translate
    from pypy.translator.tool.pdbplus import PdbPlusShow
    from pypy.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
ファイル: error.py プロジェクト: Debug-Orz/Sypy
def debug(drv, use_pdb=True):
    # XXX unify some code with pypy.translator.goal.translate
    from pypy.translator.tool.pdbplus import PdbPlusShow
    from pypy.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
ファイル: error.py プロジェクト: TheDunn/flex-pypy
def debug(drv, use_pdb=True):
    # XXX unify some code with pypy.translator.goal.translate
    from pypy.translator.tool.pdbplus import PdbPlusShow
    from pypy.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...")

    def server_setup(port=None):
        if port is not None:
            from pypy.translator.tool.graphserver import run_async_server
            serv_start, serv_show, serv_stop = self.async_server = run_async_server(t, options, port)
            return serv_start, serv_show, serv_stop
        else:
            from pypy.translator.tool.graphserver import run_server_for_inprocess_client
            return run_server_for_inprocess_client(t, options)

    if use_pdb:
        pdb_plus_show = PdbPlusShow(t)
        pdb_plus_show.start(tb, server_setup, graphic=True)
コード例 #4
0
ファイル: translate.py プロジェクト: ieure/pypy
def main():
    targetspec_dic, translateconfig, config, args = parse_options_and_load_target()
    from pypy.translator import translator
    from pypy.translator import driver
    from pypy.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
            errmsg = ["Error:\n"]
            exc, val, tb = sys.exc_info()
            errmsg.extend([" %s" % line for line in traceback.format_exception(exc, val, tb)])
            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))
        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 pypy.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 'jitpolicy' not in targetspec_dic:
                raise Exception('target has no jitpolicy defined.')
            if (translateconfig.goals != ['annotate'] and
                translateconfig.goals != ['rtype']):
                drv.set_extra_goals(['pyjitpl'])
            # early check:
            from pypy.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
        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 (use --output=...)'% exe_name)
        except EnvironmentError:
            pass

        goals = translateconfig.goals
        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
ファイル: translate.py プロジェクト: alkorzt/pypy
def main():
    targetspec_dic, translateconfig, config, args = parse_options_and_load_target()
    from pypy.translator import translator
    from pypy.translator import driver
    from pypy.translator.tool.pdbplus import PdbPlusShow

    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 debug(got_error):
        if prof:
            prof.disable()
            statfilename = "prof.dump"
            log.info("Dumping profiler stats to: %s" % statfilename)
            prof.dump_stats(statfilename)
        tb = None
        if got_error:
            import traceback

            errmsg = ["Error:\n"]
            exc, val, tb = sys.exc_info()
            errmsg.extend([" %s" % line for line in traceback.format_exception(exc, val, tb)])
            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))
        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 pypy.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 "jitpolicy" not in targetspec_dic:
                raise Exception("target has no jitpolicy defined.")
            if translateconfig.goals != ["annotate"] and translateconfig.goals != ["rtype"]:
                drv.set_extra_goals(["pyjitpl"])
        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"

        goals = translateconfig.goals
        try:
            drv.proceed(goals)
        finally:
            drv.timer.pprint()
    except SystemExit:
        raise
    except:
        debug(True)
        raise SystemExit(1)
    else:
        if translateconfig.pdb:
            debug(False)
コード例 #6
0
ファイル: translate.py プロジェクト: purepython/pypy
def main():
    targetspec_dic, translateconfig, config, args = parse_options_and_load_target(
    )
    from pypy.translator import translator
    from pypy.translator import driver
    from pypy.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
            errmsg = ["Error:\n"]
            exc, val, tb = sys.exc_info()
            errmsg.extend([
                " %s" % line
                for line in traceback.format_exception(exc, val, tb)
            ])
            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))
        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 pypy.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 'jitpolicy' not in targetspec_dic:
                raise Exception('target has no jitpolicy defined.')
            if (translateconfig.goals != ['annotate']
                    and translateconfig.goals != ['rtype']):
                drv.set_extra_goals(['pyjitpl'])
            # early check:
            from pypy.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
        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 (use --output=...)' % exe_name)
        except EnvironmentError:
            pass

        goals = translateconfig.goals
        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)
コード例 #7
0
def main():
    targetspec_dic, translateconfig, config, args = parse_options_and_load_target()
    from pypy.translator import translator
    from pypy.translator import driver
    from pypy.translator.tool.pdbplus import PdbPlusShow
    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 debug(got_error):
        if prof:
            prof.disable()
            statfilename = 'prof.dump'
            log.info('Dumping profiler stats to: %s' % statfilename)
            prof.dump_stats(statfilename)
        tb = None
        if got_error:
            import traceback
            errmsg = ["Error:\n"]
            exc, val, tb = sys.exc_info()
            errmsg.extend([" %s" % line for line in traceback.format_exception(exc, val, tb)])
            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))
        else:
            log.event('Done.')

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

        if not translateconfig.text:
            try:
                t1 = drv.hint_translator
            except (NameError, AttributeError):
                t1 = t
            from pypy.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 translateconfig.goal_options.jit:
            if 'portal' not in targetspec_dic:
               raise Exception('target has no portal defined.') 
            drv.set_extra_goals(['timeshift'])
        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'

        goals = translateconfig.goals
        try:
            drv.proceed(goals)
        finally:
            drv.timer.pprint()
    except SystemExit:
        raise
    except:
        debug(True)
        raise SystemExit(1)
    else:
        debug(False)
コード例 #8
0
ファイル: llinterp.py プロジェクト: chyyuu/pygirl
        obj = self.llinterpreter.typer.type_system.deref(fptr)
        try:
            return obj._callable(*args)
        except LLException, e:
            raise
        except Exception, e:
            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 pypy.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 = getattr(v, 'concretetype', None)
            if isinstance(TYPE, lltype.Ptr) and TYPE.TO._gckind == 'gc':
                roots.append(_address_of_local_var(self, v))