Skip to content

Commit f196f80

Browse files
committed
+code
1 parent be14bd9 commit f196f80

File tree

5 files changed

+171
-0
lines changed

5 files changed

+171
-0
lines changed

WinProcessListHelper.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import paramiko
2+
import os
3+
import sys
4+
import ConfigParser
5+
6+
sys.path.append(os.path.dirname(sys.argv[0]))
7+
import config_place
8+
9+
config = ConfigParser.ConfigParser()
10+
config.read(config_place.configFilePath)
11+
12+
class SSHCmd:
13+
def __init__(self, hostName, userName, password):
14+
self.hostName = hostName
15+
self.userName = userName
16+
self.password = password
17+
18+
def run(self, cmd):
19+
ssh = paramiko.SSHClient()
20+
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
21+
ssh.connect(self.hostName, username=self.userName, password=self.password)
22+
self.chan = ssh._transport.open_session(timeout=5)
23+
self.chan.exec_command(cmd)
24+
25+
retData = []
26+
while True:
27+
data = self.chan.recv(1024)
28+
if not data:
29+
break
30+
retData.append(data.strip())
31+
return retData
32+
33+
34+
if __name__ == "__main__":
35+
outData = ""
36+
# winProcListCmd = "WinProcessListHelper.exe.bak"
37+
# for arg in sys.argv:
38+
# winProcListCmd += " " + arg
39+
# output = os.popen(winProcListCmd)
40+
# for line in output:
41+
# outData += line
42+
43+
sshcmd = SSHCmd(config.get("server", "host"),
44+
config.get("server", "user"),
45+
config.get("server", "password"))
46+
data = sshcmd.run("for pid in `ps xu | grep -v PID | awk '{print $2}'`; do echo $pid ` ls -l /proc/$pid/exe | awk -F'->' '{print $2}'` ; done")
47+
for line in data:
48+
sp = line.split()
49+
if len(sp) != 2:
50+
continue
51+
pid, cmdLine = sp
52+
sp1 = cmdLine.split("/")
53+
exe = sp1[len(sp1)-1]
54+
outData += "%s\n%s\n%s\n" % (pid, exe, cmdLine)
55+
56+
sys.stdout.write(outData)
57+

config.ini

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
[server]
3+
host=192.168.200.129
4+
user=hyj
5+
password=123456
6+
gdb=/usr/bin/gdb
7+
8+
[mapping]
9+
;localEnv 1--Mingw 2--Cygwin
10+
localEnv=1
11+
localMapPath=C:/Users/dell-pc/ClionProjects/Stest/
12+
serverMapPath=/home/hyj/ClionProjects/Stest/
13+
;if localEnv==2
14+
cygwinMapPath=/cygdrive/c/Users/dell-pc/ClionProjects/Stest/

config_place.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
configFilePath=""

gdb.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import os
2+
import thread
3+
import paramiko
4+
import sys
5+
import ConfigParser
6+
7+
sys.path.append(os.path.dirname(sys.argv[0]))
8+
import config_place
9+
10+
config = ConfigParser.ConfigParser()
11+
config.read(config_place.configFilePath)
12+
13+
localMapPath = config.get("mapping", "localMapPath")
14+
localMapPathCygwin = config.get("mapping", "cygwinMapPath")
15+
serverMapPath = config.get("mapping", "serverMapPath")
16+
localEnv = config.get("mapping", "localEnv")
17+
localEnv = int(localEnv)
18+
19+
class SSHCmd:
20+
def __init__(self, hostName, userName, password):
21+
self.hostName = hostName
22+
self.userName = userName
23+
self.password = password
24+
25+
def run(self, cmd):
26+
ssh = paramiko.SSHClient()
27+
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
28+
ssh.connect(self.hostName, username=self.userName, password=self.password)
29+
chan = ssh._transport.open_session()
30+
chan.exec_command(cmd)
31+
32+
def doStdin(chan):
33+
while True:
34+
buff = ''
35+
sendBuff = ''
36+
while True:
37+
d = sys.stdin.read(1)
38+
if not d:
39+
break
40+
buff += d
41+
sendBuff += d
42+
sys.stderr.write(d)
43+
if d == '\n':
44+
if buff.find("-break-insert -f") == 0 \
45+
or buff.find("-file-exec-and-symbols") == 0 \
46+
or buff.find("-environment-cd") == 0:
47+
sendBuff = sendBuff.replace(localMapPath, serverMapPath)
48+
sendBuff = sendBuff.replace(localMapPathCygwin, serverMapPath)
49+
break
50+
sys.stderr.write(sendBuff)
51+
sys.stderr.flush()
52+
chan.send(sendBuff)
53+
54+
def doChan(sock):
55+
while True:
56+
data = sock.recv(2560)
57+
if not data:
58+
sys.stderr.write('\r\nchan *** EOF ***\r\n\r\n')
59+
sys.stderr.flush()
60+
break
61+
if data.find(serverMapPath) > 0:
62+
if localEnv == 1:
63+
data = data.replace(serverMapPath, localMapPath)
64+
if localEnv == 2:
65+
data = data.replace(serverMapPath, localMapPathCygwin)
66+
sys.stderr.write(data)
67+
sys.stderr.flush()
68+
sys.stdout.write(data)
69+
sys.stdout.flush()
70+
71+
thread.start_new_thread(doStdin, (chan,))
72+
doChan(chan)
73+
thread.exit_thread()
74+
75+
if __name__ == "__main__":
76+
sshcmd = SSHCmd(config.get("server", "host"),
77+
config.get("server", "user"),
78+
config.get("server", "password"))
79+
argStr = ""
80+
for s in sys.argv[1:]:
81+
argStr += " " + s
82+
sys.stderr.write("py:args=" + argStr + "\n")
83+
sshcmd.run(config.get("server", "gdb") + argStr)

setup.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import os
2+
import sys
3+
from PyInstaller import __main__ as PyInstallerMain
4+
5+
if __name__ == "__main__":
6+
configPath=os.path.join(os.path.dirname(sys.argv[0]), "config.ini")
7+
configPlacePyFile = os.path.join(os.path.dirname(sys.argv[0]), "config_place.py")
8+
f = open(configPlacePyFile, "w")
9+
f.write("configFilePath=\"" + configPath + "\"")
10+
f.close()
11+
12+
sys.argv = [sys.argv[0], "--onefile", "gdb.py"]
13+
PyInstallerMain.run()
14+
15+
sys.argv[2] = "WinProcessListHelper.py"
16+
PyInstallerMain.run()

0 commit comments

Comments
 (0)