[pypy-svn] r17928 - in pypy/dist/pypy/translator: goal tool

pedronis at codespeak.net pedronis at codespeak.net
Wed Sep 28 02:54:09 CEST 2005


Author: pedronis
Date: Wed Sep 28 02:54:07 2005
New Revision: 17928

Modified:
   pypy/dist/pypy/translator/goal/translate_pypy_new.py
   pypy/dist/pypy/translator/tool/pdbplus.py
Log:
issue132 in-progress

- move some debugger startup logic to pdbplus

- command enable_graphic to activate pygame display even if non-graphic mode was specified originally



Modified: pypy/dist/pypy/translator/goal/translate_pypy_new.py
==============================================================================
--- pypy/dist/pypy/translator/goal/translate_pypy_new.py	(original)
+++ pypy/dist/pypy/translator/goal/translate_pypy_new.py	Wed Sep 28 02:54:07 2005
@@ -157,10 +157,10 @@
     
     def debug(got_error):
         from pypy.translator.tool.pdbplus import PdbPlusShow
-        from pypy.translator.tool.pdbplus import run_debugger_in_thread
         
         pdb_plus_show = PdbPlusShow(t) # need a translator to support extended commands
-        
+
+        tb = None
         if got_error:
             import traceback
             exc, val, tb = sys.exc_info()
@@ -173,34 +173,25 @@
                 print '-'*60
                 t.about(block)
                 print '-'*60
-
-            print >> sys.stderr
-            func, args = pdb_plus_show.post_mortem, (tb,)
+            print
         else:
             print '-'*60
             print 'Done.'
             print
-            func, args = pdb_plus_show.set_trace, ()
-        if not cmd_line_opt.pygame:
-            if cmd_line_opt.batch:
-                print >>sys.stderr, "batch mode, not calling interactive helpers"
-            else:
-                func(*args)
-        else:
-            if cmd_line_opt.batch: 
-                print >>sys.stderr, "batch mode, not calling interactive helpers"
+
+        if cmd_line_opt.batch:
+            print >>sys.stderr, "batch mode, not calling interactive helpers"
+            return
+
+        def server_setup():
+            if serv_start:
+                return serv_start, serv_show, serv_stop, serv_cleanup
             else:
-                if serv_start:
-                    start, show, stop, cleanup = serv_start, serv_show, serv_stop, serv_cleanup
-                else:
-                    from pypy.translator.tool.pygame.server import run_translator_server
-                    start, show, stop, cleanup = run_translator_server(t, entry_point, cmd_line_opt)
-                pdb_plus_show.install_show(show)
-                debugger = run_debugger_in_thread(func, args, stop)
-                debugger.start()
-                start()
-                debugger.join()
-                cleanup()
+                from pypy.translator.tool.pygame.server import run_translator_server
+                return run_translator_server(t, entry_point, cmd_line_opt)
+
+        pdb_plus_show.start(tb, server_setup, graphic=cmd_line_opt.pygame)
+
 
     from optparse import OptionParser
     parser = OptionParser()

Modified: pypy/dist/pypy/translator/tool/pdbplus.py
==============================================================================
--- pypy/dist/pypy/translator/tool/pdbplus.py	(original)
+++ pypy/dist/pypy/translator/tool/pdbplus.py	Wed Sep 28 02:54:07 2005
@@ -1,18 +1,7 @@
 import threading, pdb
 
-def run_debugger_in_thread(fn, args, cleanup=None, cleanup_args=()):
-    def _run_in_thread():
-        try:
-            try:
-                fn(*args)
-                pass # for debugger to land
-            except pdb.bdb.BdbQuit:
-                pass
-        finally:
-            if cleanup is not None:
-                cleanup(*cleanup_args)
-    return threading.Thread(target=_run_in_thread, args=())
-
+class _EnableGraphic:
+    pass
 
 class PdbPlusShow(pdb.Pdb):
 
@@ -346,8 +335,15 @@
         from pypy.translator.tool import graphpage           
         self._show(graphpage.ClassHierarchyPage(self.translator))
 
+    def do_enable_graphic(self, arg):
+        """enable_graphic
+enable pygame graph display even from non-graphic mode"""
+        if self.show:
+            return
+        raise _EnableGraphic
+
     def help_graphs(self):
-        print "graph commands are: showg, flowg, callg, classhier"
+        print "graph commands are: showg, flowg, callg, classhier, enable_graphic"
 
     def help_ann_other(self):
         print "other annotation related commands are: find, findclasses, findfuncs, attrs, attrsann, readpos"
@@ -356,3 +352,40 @@
         print "these prefixes are tried for dotted names in graph commands:"
         print self.TRYPREFIXES
 
+    # start helpers
+    def _run_debugger(self, tb):
+        if tb is None:
+            fn, args = self.set_trace, ()
+        else:
+            fn, args = self.post_mortem, (tb,)
+        try:
+            t = self.translator # define enviroments, xxx more stuff
+            fn(*args)
+            pass # for debugger to land
+        except pdb.bdb.BdbQuit:
+            pass    
+
+    def _run_debugger_in_thread(self, tb, cleanup=None, cleanup_args=()):
+        def _run_in_thread():
+            try:
+                self._run_debugger(tb)
+            finally:
+                if cleanup is not None:
+                    cleanup(*cleanup_args)
+        return threading.Thread(target=_run_in_thread, args=())
+
+    def start(self, tb, server_setup, graphic=False):
+        if not graphic:
+            try:
+                self._run_debugger(tb)
+            except _EnableGraphic:
+                pass
+            else:
+                return
+        start, show, stop, cleanup = server_setup()
+        self.install_show(show)
+        debugger = self._run_debugger_in_thread(tb, stop)
+        debugger.start()
+        start()
+        debugger.join()
+        cleanup()



More information about the Pypy-commit mailing list