1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2002 - 2016 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 eric6config 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 ericpath not in sys.path: |
|
23 sys.path.insert(-1, ericpath) |
|
24 |
|
25 |
|
26 def initDebugger(kind="standard"): |
|
27 """ |
|
28 Module function to initialize a debugger for remote debugging. |
|
29 |
|
30 @param kind type of debugger ("standard" or "threads") |
|
31 @return flag indicating success (boolean) |
|
32 @exception ValueError raised to indicate an invalid debugger kind |
|
33 was requested |
|
34 """ |
|
35 global debugger |
|
36 res = 1 |
|
37 try: |
|
38 if kind == "standard": |
|
39 import DebugClient |
|
40 debugger = DebugClient.DebugClient() |
|
41 elif kind == "threads": |
|
42 import DebugClientThreads |
|
43 debugger = DebugClientThreads.DebugClientThreads() |
|
44 else: |
|
45 raise ValueError |
|
46 except ImportError: |
|
47 debugger = None |
|
48 res = 0 |
|
49 |
|
50 return res |
|
51 |
|
52 |
|
53 def runcall(func, *args): |
|
54 """ |
|
55 Module function mimicing the Pdb interface. |
|
56 |
|
57 @param func function to be called (function object) |
|
58 @param *args arguments being passed to func |
|
59 @return the function result |
|
60 """ |
|
61 global debugger, __scriptname |
|
62 return debugger.run_call(__scriptname, func, *args) |
|
63 |
|
64 |
|
65 def setScriptname(name): |
|
66 """ |
|
67 Module function to set the scriptname to be reported back to the IDE. |
|
68 |
|
69 @param name absolute pathname of the script (string) |
|
70 """ |
|
71 global __scriptname |
|
72 __scriptname = name |
|
73 |
|
74 |
|
75 def startDebugger(enableTrace=True, exceptions=True, |
|
76 tracePython=False, redirect=True): |
|
77 """ |
|
78 Module function used to start the remote debugger. |
|
79 |
|
80 @keyparam enableTrace flag to enable the tracing function (boolean) |
|
81 @keyparam exceptions flag to enable exception reporting of the IDE |
|
82 (boolean) |
|
83 @keyparam tracePython flag to enable tracing into the Python library |
|
84 (boolean) |
|
85 @keyparam redirect flag indicating redirection of stdin, stdout and |
|
86 stderr (boolean) |
|
87 """ |
|
88 global debugger |
|
89 if debugger: |
|
90 debugger.startDebugger(enableTrace=enableTrace, exceptions=exceptions, |
|
91 tracePython=tracePython, redirect=redirect) |
|
92 |
|
93 # |
|
94 # eflag: FileType = Python2 |
|
95 # eflag: noqa = M601, M702 |
|