DebugClients/Python/DebugClientBase.py

branch
debugger speed
changeset 5005
684f5ba04f0b
parent 4944
d4709f4818bb
child 5041
f00a4c8bcbbd
equal deleted inserted replaced
5004:556528860c7a 5005:684f5ba04f0b
192 # debugger 192 # debugger
193 193
194 # dictionary of all threads running 194 # dictionary of all threads running
195 self.threads = {} 195 self.threads = {}
196 196
197 # the "current" thread, basically the thread we are at a 197 # the "current" thread, basically the thread we are at a breakpoint
198 # breakpoint for. 198 # for.
199 self.currentThread = self 199 self.currentThread = self
200 200
201 # special objects representing the main scripts thread and frame 201 # special objects representing the main scripts thread and frame
202 self.mainThread = self 202 self.mainThread = self
203 self.mainFrame = None 203 self.mainFrame = None
292 """ 292 """
293 Public method to setup a thread for DebugClient to debug. 293 Public method to setup a thread for DebugClient to debug.
294 294
295 If mainThread is non-zero, then we are attaching to the already 295 If mainThread is non-zero, then we are attaching to the already
296 started mainthread of the app and the rest of the args are ignored. 296 started mainthread of the app and the rest of the args are ignored.
297
298 This is just an empty function and is overridden in the threaded
299 debugger.
300 297
301 @param target the start function of the target thread (i.e. the user 298 @param target the start function of the target thread (i.e. the user
302 code) 299 code)
303 @param args arguments to pass to target 300 @param args arguments to pass to target
304 @param kwargs keyword arguments to pass to target 301 @param kwargs keyword arguments to pass to target
510 sys.path = self.__getSysPath(os.path.dirname(sys.argv[0])) 507 sys.path = self.__getSysPath(os.path.dirname(sys.argv[0]))
511 if wd == '': 508 if wd == '':
512 os.chdir(sys.path[1]) 509 os.chdir(sys.path[1])
513 else: 510 else:
514 os.chdir(wd) 511 os.chdir(wd)
515 tracePython = int(tracePython)
516 self.running = sys.argv[0] 512 self.running = sys.argv[0]
517 self.mainFrame = None 513 self.mainFrame = None
518 self.inRawMode = 0 514 self.inRawMode = 0
519 self.debugging = 1 515 self.debugging = 1
520 516
524 # set the system exception handling function to ensure, that 520 # set the system exception handling function to ensure, that
525 # we report on all unhandled exceptions 521 # we report on all unhandled exceptions
526 sys.excepthook = self.__unhandled_exception 522 sys.excepthook = self.__unhandled_exception
527 self.__interceptSignals() 523 self.__interceptSignals()
528 524
529 # clear all old breakpoints, they'll get set after we 525 # clear all old breakpoints, they'll get set after we have
530 # have started 526 # started
531 self.mainThread.clear_all_breaks() 527 self.mainThread.clear_all_breaks()
532 528
533 self.mainThread.tracePython = tracePython 529 self.mainThread.tracePythonLibs(int(tracePython))
534 530
535 # This will eventually enter a local event loop. 531 # This will eventually enter a local event loop.
536 # Note the use of backquotes to cause a repr of self.running. 532 # Note the use of backquotes to cause a repr of self.running.
537 # The need for this is on Windows os where backslash is the 533 # The need for this is on Windows os where backslash is the
538 # path separator. They will get inadvertantly stripped away 534 # path separator. They will get inadvertantly stripped away
571 # set the system exception handling function to ensure, that 567 # set the system exception handling function to ensure, that
572 # we report on all unhandled exceptions 568 # we report on all unhandled exceptions
573 sys.excepthook = self.__unhandled_exception 569 sys.excepthook = self.__unhandled_exception
574 self.__interceptSignals() 570 self.__interceptSignals()
575 571
576 self.mainThread.tracePython = 0 572 self.mainThread.tracePythonLibs(0)
577 573
578 self.debugMod.__dict__['__file__'] = sys.argv[0] 574 self.debugMod.__dict__['__file__'] = sys.argv[0]
579 sys.modules['__main__'] = self.debugMod 575 sys.modules['__main__'] = self.debugMod
580 res = 0 576 res = 0
581 try: 577 try:
768 return 764 return
769 765
770 if cmd == DebugProtocol.RequestEval: 766 if cmd == DebugProtocol.RequestEval:
771 try: 767 try:
772 value = eval( 768 value = eval(
773 arg, self.currentThread.getCurrentFrame().f_globals, 769 arg,
770 self.currentThread.getCurrentFrame().f_globals,
774 self.currentThread.getFrameLocals(self.framenr)) 771 self.currentThread.getFrameLocals(self.framenr))
775 self.currentThread.storeFrameLocals(self.framenr) 772 self.currentThread.storeFrameLocals(self.framenr)
776 except Exception: 773 except Exception:
777 # Report the exception and the traceback 774 # Report the exception and the traceback
778 try: 775 try:
1335 Private method to return the variables of a frame to the debug server. 1332 Private method to return the variables of a frame to the debug server.
1336 1333
1337 @param frmnr distance of frame reported on. 0 is the current frame 1334 @param frmnr distance of frame reported on. 0 is the current frame
1338 (int) 1335 (int)
1339 @param scope 1 to report global variables, 0 for local variables (int) 1336 @param scope 1 to report global variables, 0 for local variables (int)
1340 @param filter the indices of variable types to be filtered (list of 1337 @param filter the indices of variable types to be filtered
1341 int) 1338 (list of int)
1342 """ 1339 """
1343 if self.currentThread is None: 1340 if self.currentThread is None:
1344 return 1341 return
1345 1342
1346 if scope == 0: 1343 if scope == 0:
1487 oaccess = access 1484 oaccess = access
1488 else: 1485 else:
1489 oaccess = '' 1486 oaccess = ''
1490 try: 1487 try:
1491 exec 'mdict = dict%s.__dict__' % access 1488 exec 'mdict = dict%s.__dict__' % access
1492 ndict.update(mdict) # __IGNORE_WARNING__ 1489 ndict.update(mdict)
1493 exec 'obj = dict%s' % access 1490 exec 'obj = dict%s' % access
1494 if "PyQt4." in str(type(obj)) or \ 1491 if "PyQt4." in str(type(obj)) or \
1495 "PyQt5." in str(type(obj)): 1492 "PyQt5." in str(type(obj)):
1496 qtVariable = True 1493 qtVariable = True
1497 qvar = obj 1494 qvar = obj
1499 .split()[1][1:-1] 1496 .split()[1][1:-1]
1500 except Exception: 1497 except Exception:
1501 pass 1498 pass
1502 try: 1499 try:
1503 exec 'mcdict = dict%s.__class__.__dict__' % access 1500 exec 'mcdict = dict%s.__class__.__dict__' % access
1504 ndict.update(mcdict) # __IGNORE_WARNING__ 1501 ndict.update(mcdict)
1505 if mdict and "sipThis" not in mdict.keys(): # __IGNORE_WARNING__ 1502 if mdict and "sipThis" not in mdict.keys():
1506 del rvar[0:2] 1503 del rvar[0:2]
1507 access = "" 1504 access = ""
1508 except Exception: 1505 except Exception:
1509 pass 1506 pass
1510 try: 1507 try:
1626 self.write('%s%s\n' % ( 1623 self.write('%s%s\n' % (
1627 DebugProtocol.ResponseVariable, unicode(varlist))) 1624 DebugProtocol.ResponseVariable, unicode(varlist)))
1628 1625
1629 def __formatQtVariable(self, value, vtype): 1626 def __formatQtVariable(self, value, vtype):
1630 """ 1627 """
1631 Private method to produce a formated output of a simple Qt4/Qt5 type. 1628 Private method to produce a formatted output of a simple Qt4/Qt5 type.
1632 1629
1633 @param value variable to be formated 1630 @param value variable to be formatted
1634 @param vtype type of the variable to be formatted (string) 1631 @param vtype type of the variable to be formatted (string)
1635 @return A tuple consisting of a list of formatted variables. Each 1632 @return A tuple consisting of a list of formatted variables. Each
1636 variable entry is a tuple of three elements, the variable name, 1633 variable entry is a tuple of three elements, the variable name,
1637 its type and value. 1634 its type and value.
1638 """ 1635 """
1975 self.mainFrame = None 1972 self.mainFrame = None
1976 self.inRawMode = 0 1973 self.inRawMode = 0
1977 self.debugging = 1 1974 self.debugging = 1
1978 1975
1979 self.attachThread(mainThread=1) 1976 self.attachThread(mainThread=1)
1980 self.mainThread.tracePython = tracePython 1977 self.mainThread.tracePythonLibs(tracePython)
1981 1978
1982 # set the system exception handling function to ensure, that 1979 # set the system exception handling function to ensure, that
1983 # we report on all unhandled exceptions 1980 # we report on all unhandled exceptions
1984 sys.excepthook = self.__unhandled_exception 1981 sys.excepthook = self.__unhandled_exception
1985 self.__interceptSignals() 1982 self.__interceptSignals()
2033 self.write("%s%s|%d\n" % ( 2030 self.write("%s%s|%d\n" % (
2034 DebugProtocol.PassiveStartup, self.running, exceptions)) 2031 DebugProtocol.PassiveStartup, self.running, exceptions))
2035 self.__interact() 2032 self.__interact()
2036 2033
2037 self.attachThread(mainThread=1) 2034 self.attachThread(mainThread=1)
2038 self.mainThread.tracePython = tracePython 2035 self.mainThread.tracePythonLibs(tracePython)
2039 2036
2040 # set the system exception handling function to ensure, that 2037 # set the system exception handling function to ensure, that
2041 # we report on all unhandled exceptions 2038 # we report on all unhandled exceptions
2042 sys.excepthook = self.__unhandled_exception 2039 sys.excepthook = self.__unhandled_exception
2043 self.__interceptSignals() 2040 self.__interceptSignals()

eric ide

mercurial