-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimgdb
executable file
·200 lines (148 loc) · 2.95 KB
/
vimgdb
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/usr/bin/perl
use warnings;
use strict;
use Socket;
use Carp;
use POSIX qw(tmpnam);
my $SOCK_NAME = 'vimgdb.soc';
my $VIM_EXE = 'gvim --nofork';
my $GEN_LOG = 0;
my $START_VIM = 1;
my $fname = "sureshkumar";
my $lname = "manimuthu";
my $domine = "gmail";
my $suffix = "com";
my $ERROR_FILE = "vimgdb.err";
print "\nvimgdb 1.2 (send your feedbacks to $fname.$lname\@$domine.$suffix)\n\n";
if(@ARGV < 1)
{
if($START_VIM == 0)
{
exec($VIM_EXE, ' -c "runtime misc/vimgdb_tcp.vim" -c \'call Gdb_interf_init()\'');
}
else
{
printf STDERR "Please specify the exe file\n";
}
}
my $gdb_task;
my $msg_task;
print "Setup PIMES\n";
pipe(FROM_VIM, TO_GDB); # setup pipes for communication
pipe(FROM_GDB, TO_VIM);
print "Staring GDB\n";
unless(defined($gdb_task = fork()))
{
die("Unable to fork");
}
if($gdb_task == 0)
{
#print "GDB Task\n";
close FROM_VIM;
close TO_VIM;
open(STDOUT, ">&TO_GDB") || die "Can't redirect stdout";
open(STDERR, ">$ERROR_FILE") || die "Can't redirect stdout";
open(STDIN, "<&FROM_GDB") || die "Can't redirect stdin";
select(TO_GDB); $| = 1; # make unbuffered
select(STDOUT); $| = 1; # make unbuffered
if(system("mipsel-linux-gdb", "-f", "-q", "--args", @ARGV) != 0)
{
print STDERR "GDB Init Error !!!\n";
kill(15, getppid());
}
exit -1;
}
print "Staring Message Task\n";
unless(defined($msg_task = fork()))
{
die("Unable to fork");
}
if($msg_task == 0)
{
close FROM_GDB;
close TO_GDB;
if($GEN_LOG)
{
open(LOGFILE, ">", "vimgdb.log") || die("Unable to open log file");
select(LOGFILE); $| = 1;
}
select(TO_VIM); $| = 1; # make unbuffered
print TO_VIM "set prompt (gdb)\\n\n";
while(<FROM_VIM>)
{
chomp();
if(/^\(gdb\)/ || /^The program is running\. Exit anyway/)
{
last;
}
}
socket(Server, PF_UNIX,SOCK_STREAM, 0) || die "socket: $!";
unlink($SOCK_NAME);
bind(Server, sockaddr_un($SOCK_NAME)) || die "bind: $!";
listen(Server, 1) || die "listen: $!";
while(accept(Client,Server))
{
select(Client); $| = 1;
while(1)
{
my $line = <Client>;
if(!defined($line))
{
exit -1;
}
if($line =~ /^$/)
{
last;
}
chomp($line);
if($GEN_LOG)
{
print LOGFILE "<<", $line, "\n";
}
print TO_VIM $line, "\n";
while(1)
{
my $gdb_line = <FROM_VIM>;
if(!defined($gdb_line))
{
exit -1;
}
chomp($gdb_line);
if($GEN_LOG)
{
print LOGFILE ">> ", $gdb_line, "\n";
}
print Client $gdb_line, "\n";
if($gdb_line =~ /^The program is running\. Exit anyway/)
{
exit -1;
}
if($gdb_line =~ /^\(gdb\)/)
{
last;
}
}
}
close(Client);
}
exit -1;
}
if($START_VIM)
{
print "Staring VIM\n";
system($VIM_EXE . ' -c "runtime misc/vimgdb.vim" -c "call Gdb_interf_init()"');
print TO_VIM "quit\n";
kill(15, $gdb_task, $msg_task);
}
while(wait() != -1)
{
}
if(open(OUT, "<", $ERROR_FILE))
{
while(<OUT>)
{
print;
}
}
unlink ($ERROR_FILE);
unlink ($SOCK_NAME);