Warning, file /kdevelop/kdev-python/debugger/kdevpdb.py was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 # SPDX-FileCopyrightText: 2014 Sven Brauch <svenbrauch@gmail.com>
0002 # SPDX-License-Identifier: GPL-2.0-or-later
0003 
0004 from pdb import *
0005 
0006 import sys
0007 
0008 
0009 class kdevOutputFormatter():
0010     def __init__(self):
0011         from sys import stdout as __stdout
0012         self.__stdout = __stdout
0013     def write(self, data):
0014         self.__stdout.write("__KDEVPYTHON_BEGIN_DEBUGGER_OUTPUT>>>" + str(data) + "<<<__KDEVPYTHON_END___DEBUGGER_OUTPUT")
0015 
0016 class kdevPdb(Pdb):
0017     def __init__(self):
0018         Pdb.__init__(self)
0019         self.stdout = kdevOutputFormatter()
0020         self.prompt = "__KDEVPYTHON_DEBUGGER_PROMPT"
0021         # hack to make the debugger *not* restart the program in any case
0022         self.only_once = False
0023     
0024     def debug_trace(self, *args):
0025         '''Set a tracepoint in the Python debugger that works with Qt'''
0026         try:
0027             from PyQt4.QtCore import pyqtRemoveInputHook
0028             pyqtRemoveInputHook()
0029         except ImportError:
0030             pass
0031         self.set_trace(sys._getframe().f_back)
0032     
0033     def _runscript(self, filename):
0034         import signal
0035         import os
0036         self._user_requested_quit = 1
0037         if self.only_once:
0038             os._exit(0)
0039         self.only_once = True
0040         signal.signal(signal.SIGINT, self.debug_trace)
0041         Pdb._runscript(self, filename)
0042 
0043 if __name__ == '__main__':
0044     import pdb
0045     pdb.Pdb = kdevPdb
0046     pdb.main()