1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
#!/usr/bin/env python
#
# Copyright (C) 2009, George Hunt <georgejhunt@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import os
from gettext import gettext as _
#import logging
from pydebug_logging import _logger, log_environment, log_dict
#establish a remote procedure call pipe connection with the PyDebug process
from Rpyc import SocketConnection
try:
c = SocketConnection('localhost')
db = c.modules.pydebug.pydebug_instance
#except AttributeError:
# _logger.error('cannot connect to localhost')
except Exception, e:
_logger.exception('cannot connect to localhost')
print 'Rpyc connection failed'
print(str(e))
assert False
pydebug_path = db.pydebug_path
xmode = db.debug_dict.get('xmode')
_logger.debug('./bin/start_debug.py established connectioon. pydebug path: %s'%pydebug_path)
#these alternative definitions are required for ipython v0.11 and greater
#define interface with the command line ipython instance
#from IPython.core import ipapi
#from IPython.core.macro import Macro
#following definitions work with ipython 0.10
from IPython import ipapi
from IPython.macro import Macro
ip = ipapi.get()
#define macros, one which sets pdb on, the other off
trace_cmd = _('trace')
if not ip.user_ns.has_key(trace_cmd):
cmd = 'run -b 242 -d %s\n'% os.path.join(pydebug_path,'bin','continue_debug.py')
ip.user_ns[trace_cmd] = Macro(cmd)
go_cmd = _('go')
if not ip.user_ns.has_key(go_cmd):
cmd = 'run %s\n'% os.path.join(pydebug_path,'bin','continue_debug.py')
ip.user_ns[go_cmd] = Macro(cmd)
if not ip.user_ns.has_key('pi'):
cmd = 'for k in _margv[0].__dict__.keys(): print "_margv[0]",k,"=",_margv[0].__dict__[k]\n'
ip.user_ns['pi'] = Macro(cmd)
if not ip.user_ns.has_key('ps'):
cmd = 'pi self\n'
ip.user_ns['ps'] = Macro(cmd)
#change the directory to the child_path
child_path = db.child_path
if child_path:
os.chdir(child_path)
else:
os.chdir(db.activity_playpen)
if xmode:
ip.ipmagic('xmode %s'%xmode)
|