mirror of
https://github.com/pragma-/pbot.git
synced 2025-01-10 20:12:35 +01:00
compiler_vm: separate program output and gdb output in watchdog to prevent crossing the streams
This commit is contained in:
parent
91a9c69fa5
commit
0b2b18d93a
@ -13,7 +13,7 @@ use warnings;
|
|||||||
# These are set automatically by the build/commit script
|
# These are set automatically by the build/commit script
|
||||||
use constant {
|
use constant {
|
||||||
BUILD_NAME => "PBot",
|
BUILD_NAME => "PBot",
|
||||||
BUILD_REVISION => 486,
|
BUILD_REVISION => 487,
|
||||||
BUILD_DATE => "2014-02-24",
|
BUILD_DATE => "2014-02-24",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -164,9 +164,10 @@ sub interpret {
|
|||||||
}
|
}
|
||||||
|
|
||||||
print "Executing gdb\n";
|
print "Executing gdb\n";
|
||||||
|
unlink '.output';
|
||||||
my $user_input_quoted = quotemeta $user_input;
|
my $user_input_quoted = quotemeta $user_input;
|
||||||
$user_input_quoted =~ s/\\"/"'\\"'"/g;
|
$user_input_quoted =~ s/\\"/"'\\"'"/g;
|
||||||
($ret, $result) = execute(60, "bash -c \"date -s \@$date; ulimit -t 1; compiler_watchdog.pl $user_input_quoted > .output\"");
|
($ret, $result) = execute(60, "bash -c \"date -s \@$date; ulimit -t 1; compiler_watchdog.pl $user_input_quoted\"");
|
||||||
|
|
||||||
$result = "";
|
$result = "";
|
||||||
|
|
||||||
|
@ -26,6 +26,8 @@ sub execute {
|
|||||||
my ($out, $in);
|
my ($out, $in);
|
||||||
open2($out, $in, "$cmdline 2>&1");
|
open2($out, $in, "$cmdline 2>&1");
|
||||||
|
|
||||||
|
open my $output_file, '>>', '.output' or die "Couldn't open .output: $!";
|
||||||
|
|
||||||
while(my $line = <$out>) {
|
while(my $line = <$out>) {
|
||||||
chomp $line;
|
chomp $line;
|
||||||
print "--- got: [$line]\n" if $debug >= 1;
|
print "--- got: [$line]\n" if $debug >= 1;
|
||||||
@ -44,7 +46,7 @@ sub execute {
|
|||||||
next if $line =~ m/libc_start_main/;
|
next if $line =~ m/libc_start_main/;
|
||||||
|
|
||||||
if($line =~ m/^\d+: (.*? = .*)/) {
|
if($line =~ m/^\d+: (.*? = .*)/) {
|
||||||
print "<$1>\n";
|
print $output_file "<$1>\n";
|
||||||
$got_output = 1;
|
$got_output = 1;
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
@ -82,7 +84,7 @@ sub execute {
|
|||||||
gdb $in, "break $break\n";
|
gdb $in, "break $break\n";
|
||||||
gdb $in, "set width 0\n";
|
gdb $in, "set width 0\n";
|
||||||
gdb $in, "set height 0\n";
|
gdb $in, "set height 0\n";
|
||||||
gdb $in, "run < .input\n";
|
gdb $in, "run < .input > .output\n";
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,7 +92,7 @@ sub execute {
|
|||||||
my $line = <$out>;
|
my $line = <$out>;
|
||||||
print "== got: $line\n" if $debug >= 5;
|
print "== got: $line\n" if $debug >= 5;
|
||||||
if($line =~ m/^\d+\s+return.*?;\s*$/ or $line =~ m/^\d+\s+}\s*$/) {
|
if($line =~ m/^\d+\s+return.*?;\s*$/ or $line =~ m/^\d+\s+}\s*$/) {
|
||||||
if($got_output == 0) {
|
if($got_output == 0 and -s '.output' == 0) {
|
||||||
print "no output, checking locals\n" if $debug >= 5;
|
print "no output, checking locals\n" if $debug >= 5;
|
||||||
gdb $in, "print \"Go.\"\ninfo locals\nprint \"Ok.\"\n";
|
gdb $in, "print \"Go.\"\ninfo locals\nprint \"Ok.\"\n";
|
||||||
|
|
||||||
@ -100,7 +102,7 @@ sub execute {
|
|||||||
|
|
||||||
# fix this
|
# fix this
|
||||||
$peep =~ s/^\d+: (.*?) =/$1 =/;
|
$peep =~ s/^\d+: (.*?) =/$1 =/;
|
||||||
print "<$peep>\n";
|
print $output_file "<$peep>\n";
|
||||||
$got_output = 1;
|
$got_output = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,7 +131,6 @@ sub execute {
|
|||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if($line =~ m/Breakpoint \d+, gdb/) {
|
if($line =~ m/Breakpoint \d+, gdb/) {
|
||||||
gdb $in, "up\n";
|
gdb $in, "up\n";
|
||||||
$line = <$out>;
|
$line = <$out>;
|
||||||
@ -171,7 +172,7 @@ sub execute {
|
|||||||
next if not length $retval;
|
next if not length $retval;
|
||||||
next if $retval =~ m/^\$\d+ = 0/;
|
next if $retval =~ m/^\$\d+ = 0/;
|
||||||
|
|
||||||
print "$retval\n";
|
print $output_file "$retval\n";
|
||||||
$got_output = 1;
|
$got_output = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -192,7 +193,7 @@ sub execute {
|
|||||||
|
|
||||||
$indent++ if $direction eq "leaving";
|
$indent++ if $direction eq "leaving";
|
||||||
|
|
||||||
print "<$direction [$indent]", ' ' x $indent, "$func$return_value>\n";
|
print $output_file "<$direction [$indent]", ' ' x $indent, "$func$return_value>\n";
|
||||||
gdb $in, "cont\n";
|
gdb $in, "cont\n";
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
@ -217,6 +218,10 @@ sub execute {
|
|||||||
$line = "1 gdb(\"ptype $1\");";
|
$line = "1 gdb(\"ptype $1\");";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($line =~ m/^\d+\s+.*\bwhatis\((.*)\)/) {
|
||||||
|
$line = "1 gdb(\"whatis $1\");";
|
||||||
|
}
|
||||||
|
|
||||||
if($line =~ m/^\d+\s+.*\bgdb\("(.*)"\)/) {
|
if($line =~ m/^\d+\s+.*\bgdb\("(.*)"\)/) {
|
||||||
my $command = $1;
|
my $command = $1;
|
||||||
my ($cmd, $args) = split / /, $command, 2;
|
my ($cmd, $args) = split / /, $command, 2;
|
||||||
@ -279,10 +284,10 @@ sub execute {
|
|||||||
if(not $ignore_response) {
|
if(not $ignore_response) {
|
||||||
if($next_line =~ m/=/) {
|
if($next_line =~ m/=/) {
|
||||||
$got_output = 1;
|
$got_output = 1;
|
||||||
print "<$args$next_line>\n";
|
print $output_file "<$args$next_line>\n";
|
||||||
} else {
|
} else {
|
||||||
$got_output = 1;
|
$got_output = 1;
|
||||||
print "<$next_line>\n";
|
print $output_file "<$next_line>\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -307,7 +312,7 @@ sub execute {
|
|||||||
my ($val2) = $new =~ m/New value = (.*)/;
|
my ($val2) = $new =~ m/New value = (.*)/;
|
||||||
|
|
||||||
$got_output = 1;
|
$got_output = 1;
|
||||||
print "<$var = $val2>\n";
|
print $output_file "<$var = $val2>\n";
|
||||||
gdb $in, "cont\n";
|
gdb $in, "cont\n";
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
@ -327,7 +332,7 @@ sub execute {
|
|||||||
$got_output = 1;
|
$got_output = 1;
|
||||||
my $output = "<$var changed: $val1 => $val2>\n";
|
my $output = "<$var changed: $val1 => $val2>\n";
|
||||||
flushall $in, $out;
|
flushall $in, $out;
|
||||||
print $output;
|
print $output_file $output;
|
||||||
gdb $in, "cont\n";
|
gdb $in, "cont\n";
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
@ -340,26 +345,26 @@ sub execute {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if($line =~ m/^Program exited/) {
|
if($line =~ m/^Program exited/) {
|
||||||
print " $local_vars\n" if length $local_vars and not $got_output;
|
print $output_file " $local_vars\n" if length $local_vars and not $got_output;
|
||||||
exit 0;
|
exit 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($line =~ s/\[Inferior .* exited with code (\d+)\]//) {
|
if($line =~ s/\[Inferior .* exited with code (\d+)\]//) {
|
||||||
print "$line\n";
|
print $output_file "$line\n";
|
||||||
print "<Exit $1>\n";
|
print $output_file "<Exit $1>\n";
|
||||||
print " $local_vars\n" if length $local_vars and not $got_output;
|
print $output_file " $local_vars\n" if length $local_vars and not $got_output;
|
||||||
exit 0;
|
exit 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($line =~ s/\[Inferior .* exited normally\]//) {
|
if($line =~ s/\[Inferior .* exited normally\]//) {
|
||||||
print "$line\n" if length $line;
|
print $output_file "$line\n" if length $line;
|
||||||
$got_output = 1 if length $line;
|
$got_output = 1 if length $line;
|
||||||
print " $local_vars\n" if length $local_vars and not $got_output;
|
print $output_file " $local_vars\n" if length $local_vars and not $got_output;
|
||||||
exit 0;
|
exit 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($line =~ m/Program terminated with signal SIGKILL/) {
|
if($line =~ m/Program terminated with signal SIGKILL/) {
|
||||||
print "[Killed]\n";
|
print $output_file "[Killed]\n";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -377,7 +382,7 @@ sub execute {
|
|||||||
$output .= "<$line>\n";
|
$output .= "<$line>\n";
|
||||||
}
|
}
|
||||||
flushall $in, $out;
|
flushall $in, $out;
|
||||||
print $output;
|
print $output_file $output;
|
||||||
gdb $in, "cont\n";
|
gdb $in, "cont\n";
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
@ -389,7 +394,7 @@ sub execute {
|
|||||||
|
|
||||||
$line =~ s/\.$//;
|
$line =~ s/\.$//;
|
||||||
$got_output = 1;
|
$got_output = 1;
|
||||||
print "$line ";
|
print $output_file "$line ";
|
||||||
|
|
||||||
while(my $line = <$out>) {
|
while(my $line = <$out>) {
|
||||||
chomp $line;
|
chomp $line;
|
||||||
@ -440,13 +445,13 @@ sub execute {
|
|||||||
|
|
||||||
$vars = " <local variables: $vars>" if length $vars;
|
$vars = " <local variables: $vars>" if length $vars;
|
||||||
|
|
||||||
print "$result$vars\n";
|
print $output_file "$result$vars\n";
|
||||||
exit 0;
|
exit 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($line =~ s/^\(gdb\)\s*//) {
|
if($line =~ s/^\(gdb\)\s*//) {
|
||||||
$got_output = 1;
|
$got_output = 1;
|
||||||
print "<$line>\n";
|
print $output_file "<$line>\n";
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -457,6 +462,8 @@ sub execute {
|
|||||||
$got_output = 1;
|
$got_output = 1;
|
||||||
print "$line\n";
|
print "$line\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
close $output_file;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub gdb {
|
sub gdb {
|
||||||
|
Loading…
Reference in New Issue
Block a user