|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2009 - 2010 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a debugger stub for remote debugging. |
|
8 """ |
|
9 |
|
10 import os |
|
11 import sys |
|
12 import distutils.sysconfig |
|
13 |
|
14 from eric5config import getConfig |
|
15 |
|
16 debugger = None |
|
17 __scriptname = None |
|
18 |
|
19 modDir = distutils.sysconfig.get_python_lib(True) |
|
20 ericpath = os.getenv('ERICDIR', getConfig('ericDir')) |
|
21 |
|
22 if not ericpath in sys.path: |
|
23 sys.path.insert(-1, ericpath) |
|
24 |
|
25 def initDebugger(kind = "standard"): |
|
26 """ |
|
27 Module function to initialize a debugger for remote debugging. |
|
28 |
|
29 @param kind type of debugger ("standard" or "threads") |
|
30 @return flag indicating success (boolean) |
|
31 """ |
|
32 global debugger |
|
33 res = True |
|
34 try: |
|
35 if kind == "standard": |
|
36 import DebugClient |
|
37 debugger = DebugClient.DebugClient() |
|
38 elif kind == "threads": |
|
39 import DebugClientThreads |
|
40 debugger = DebugClientThreads.DebugClientThreads() |
|
41 else: |
|
42 raise ValueError |
|
43 except ImportError: |
|
44 debugger = None |
|
45 res = False |
|
46 |
|
47 return res |
|
48 |
|
49 def runcall(func, *args): |
|
50 """ |
|
51 Module function mimicing the Pdb interface. |
|
52 |
|
53 @param func function to be called (function object) |
|
54 @param *args arguments being passed to func |
|
55 @return the function result |
|
56 """ |
|
57 global debugger, __scriptname |
|
58 return debugger.run_call(__scriptname, func, *args) |
|
59 |
|
60 def setScriptname(name): |
|
61 """ |
|
62 Module function to set the scriptname to be reported back to the IDE. |
|
63 |
|
64 @param name absolute pathname of the script (string) |
|
65 """ |
|
66 global __scriptname |
|
67 __scriptname = name |
|
68 |
|
69 def startDebugger(enableTrace = True, exceptions = True, |
|
70 tracePython = False, redirect = True): |
|
71 """ |
|
72 Module function used to start the remote debugger. |
|
73 |
|
74 @keyparam enableTrace flag to enable the tracing function (boolean) |
|
75 @keyparam exceptions flag to enable exception reporting of the IDE (boolean) |
|
76 @keyparam tracePython flag to enable tracing into the Python library (boolean) |
|
77 @keyparam redirect flag indicating redirection of stdin, stdout and stderr (boolean) |
|
78 """ |
|
79 global debugger |
|
80 if debugger: |
|
81 debugger.startDebugger(enableTrace = enableTrace, exceptions = exceptions, |
|
82 tracePython = tracePython, redirect = redirect) |