Skip to content

Commit 39b6886

Browse files
committed
Support communication with the debugged process over UNIX-domain sockets
1 parent b808b02 commit 39b6886

File tree

5 files changed

+91
-22
lines changed

5 files changed

+91
-22
lines changed

doc/Vdebug.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,8 +785,10 @@ retain option settings by adding them to your vimrc.
785785

786786
The default options look like this: >
787787
let g:vdebug_options= {
788+
\ "socket_type": "tcp",
788789
\ "port" : 9000,
789790
\ "server" : 'localhost',
791+
\ "unix_permissions": 0700,
790792
\ "timeout" : 20,
791793
\ "on_close" : 'detach',
792794
\ "break_on_open" : 1,
@@ -810,6 +812,13 @@ if you don't set them.
810812

811813
Here is a list of all the available options.
812814

815+
*VdebugOptions-socket_type*
816+
g:vdebug_options["socket_type"] (default = "tcp")
817+
This sets whether Vdebug waits over a TCP or an Unix-domain
818+
socket. When set to "tcp" the listening address is configured via
819+
the port and server options, when set to "unix" the listening path
820+
is configured via the unix_path option.
821+
813822
*VdebugOptions-port*
814823
g:vdebug_options["port"] (default = 9000)
815824
This sets the port that Vdebug will use to listen for connections. Xdebug
@@ -823,6 +832,16 @@ g:vdebug_options["server"] (default = "localhost")
823832
running on the same machine and also connecting to localhost. If you want
824833
to debug a script on a different machine, look at |VdebugRemote|.
825834

835+
*VdebugOptions-unix_path*
836+
g:vdebug_options["unix_path"] (default = empty)
837+
This sets the path that Vdebug will use to listen for connections
838+
when listening over an Unix-domain socket.
839+
840+
*VdebugOptions-unix_permissions*
841+
g:vdebug_options["unix_permissions"] (default = 0700)
842+
This sets the permissions of the Unix-domain socket that Vdebug
843+
will use to listen for connections.
844+
826845
*VdebugOptions-timeout*
827846
g:vdebug_options["timeout"] (default = 20)
828847
Number of seconds to wait for when listening for a connection. VIM will

plugin/python/vdebug/dbgp.py

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import vdebug.log
44
import base64
55
import time
6+
import os
67

78
""" Response objects for the DBGP module."""
89

@@ -381,20 +382,31 @@ class Connection:
381382
address = None
382383
isconned = 0
383384

384-
def __init__(self, host = '', port = 9000, timeout = 30, input_stream = None):
385+
def __init__(self, endpoint, timeout = 30, input_stream = None):
385386
"""Create a new Connection.
386387
387388
The connection is not established until open() is called.
388389
389-
host -- host name where debugger is running (default '')
390-
port -- port number which debugger is listening on (default 9000)
390+
endpoint -- dictionary containing connection parameters
391+
{
392+
"socket_type": "tcp" (default)/"unix",
393+
# for TCP sockets
394+
"server": "localhost",
395+
"port": 9000,
396+
# for UNIX-domain sockets
397+
"unix_path": "/path/to/socket",
398+
"unix_permissions": 0777,
399+
}
391400
timeout -- time in seconds to wait for a debugger connection before giving up (default 30)
392401
input_stream -- object for checking input stream and user interrupts (default None)
402+
403+
Both "server" and "port" parameters are required for TCP sockets, for UNIX-domain sockets
404+
only "unix_path" is required.
393405
"""
394-
self.port = port
395-
self.host = host
406+
self.endpoint = endpoint
396407
self.timeout = timeout
397408
self.input_stream = input_stream
409+
self.address_type = self.endpoint['socket_type']
398410

399411
def __del__(self):
400412
"""Make sure the connection is closed."""
@@ -404,15 +416,41 @@ def isconnected(self):
404416
"""Whether the connection has been established."""
405417
return self.isconned
406418

419+
def address_description(self):
420+
"""Human-readable local address"""
421+
if self.endpoint['socket_type'] == 'tcp':
422+
return "%s:%s" %(self.endpoint['server'],self.endpoint['port'])
423+
else:
424+
return self.endpoint['unix_path']
425+
426+
def peer_description(self):
427+
"""Human-readable peer address"""
428+
if self.endpoint['socket_type'] == 'tcp':
429+
return "%s:%s" %(self.address[0],self.address[1])
430+
else:
431+
return self.endpoint['unix_path']
432+
407433
def open(self):
408434
"""Listen for a connection from the debugger. Listening for the actual
409435
connection is handled by self.listen()."""
410436
print 'Waiting for a connection (Ctrl-C to cancel, this message will self-destruct in ',self.timeout,' seconds...)'
411-
serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
437+
if self.address_type == 'tcp':
438+
serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
439+
else:
440+
serv = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
412441
try:
413-
serv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
414442
serv.setblocking(0)
415-
serv.bind((self.host, self.port))
443+
if self.endpoint.get('socket_type', 'tcp') == 'tcp':
444+
serv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
445+
serv.bind((self.endpoint['server'], self.endpoint['port']))
446+
else:
447+
path = self.endpoint['unix_path']
448+
if os.path.exists(path):
449+
os.unlink(path)
450+
serv.bind(path)
451+
if self.endpoint.get('unix_permissions'):
452+
os.chmod(path, self.endpoint['unix_permissions']);
453+
416454
serv.listen(5)
417455
(self.sock, self.address) = self.listen(serv, self.timeout)
418456
self.sock.settimeout(None)

plugin/python/vdebug/runner.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ class Runner:
1616
an interface that Vim can use to send commands.
1717
"""
1818

19+
ENDPOINT_ARGS = [
20+
('socket_type', str),
21+
('server', str),
22+
('port', int),
23+
('unix_path', str),
24+
('unix_group', str),
25+
('unix_permissions', int),
26+
]
1927
def __init__(self):
2028
self.api = None
2129
vdebug.opts.Options.set(vim.eval('g:vdebug_options'))
@@ -39,21 +47,23 @@ def open(self):
3947
vdebug.log.Log.set_logger(vdebug.log.FileLogger(\
4048
vdebug.opts.Options.get('debug_file_level'),\
4149
vdebug.opts.Options.get('debug_file')))
50+
endpoint = {}
51+
for arg, pytype in Runner.ENDPOINT_ARGS:
52+
if vdebug.opts.Options.isset(arg):
53+
endpoint[arg] = vdebug.opts.Options.get(arg, pytype)
4254
self.listen(\
43-
vdebug.opts.Options.get('server'),\
44-
vdebug.opts.Options.get('port',int),\
55+
endpoint,\
4556
vdebug.opts.Options.get('timeout',int))
4657

4758
self.ui.open()
4859
self.keymapper.map()
4960
self.ui.set_listener_details(\
50-
vdebug.opts.Options.get('server'),\
51-
vdebug.opts.Options.get('port'),\
61+
self.api.conn.address_description(),\
5262
vdebug.opts.Options.get('ide_key'))
5363

54-
addr = self.api.conn.address
55-
vdebug.log.Log("Found connection from " + str(addr),vdebug.log.Logger.INFO)
56-
self.ui.set_conn_details(addr[0],addr[1])
64+
addr = self.api.conn.peer_description()
65+
vdebug.log.Log("Found connection from " + addr,vdebug.log.Logger.INFO)
66+
self.ui.set_conn_details(addr)
5767

5868
self.set_features()
5969
self.breakpoints.update_lines(self.ui.get_breakpoint_sign_positions())
@@ -253,7 +263,7 @@ def run_to_cursor(self):
253263
self.api.breakpoint_set(bp.get_cmd())
254264
self.run()
255265

256-
def listen(self,server,port,timeout):
266+
def listen(self,endpoint,timeout):
257267
"""Open the vdebug.dbgp API with connection.
258268
259269
Uses existing connection if possible.
@@ -269,8 +279,8 @@ def listen(self,server,port,timeout):
269279
check_ide_key = True
270280
if len(ide_key) == 0:
271281
check_ide_key = False
272-
273-
connection = vdebug.dbgp.Connection(server,port,\
282+
283+
connection = vdebug.dbgp.Connection(endpoint,
274284
timeout,vdebug.util.InputStream())
275285

276286
self.api = vdebug.dbgp.Api(connection)

plugin/python/vdebug/ui/vimui.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,14 @@ def mark_as_stopped(self):
8787
self.statuswin.set_status("stopped")
8888
self.remove_conn_details()
8989

90-
def set_conn_details(self,addr,port):
91-
self.statuswin.insert("Connected to %s:%s" %(addr,port),2,True)
90+
def set_conn_details(self,description):
91+
self.statuswin.insert("Connected to %s" %(description),2,True)
9292

9393
def remove_conn_details(self):
9494
self.statuswin.insert("Not connected",2,True)
9595

96-
def set_listener_details(self,addr,port,idekey):
97-
details = "Listening on %s:%s" %(addr,port)
96+
def set_listener_details(self,description,idekey):
97+
details = "Listening on %s" %(description)
9898
if len(idekey):
9999
details += " (IDE key: %s)" % idekey
100100
self.statuswin.insert(details,1,True)

plugin/vdebug.vim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,11 @@ let g:vdebug_keymap_defaults = {
8383
\}
8484

8585
let g:vdebug_options_defaults = {
86+
\ "socket_type": "tcp",
8687
\ "port" : 9000,
8788
\ "timeout" : 20,
8889
\ "server" : 'localhost',
90+
\ "unix_permissions": 0700,
8991
\ "on_close" : 'detach',
9092
\ "break_on_open" : 1,
9193
\ "ide_key" : '',

0 commit comments

Comments
 (0)