mirror of
https://github.com/pragma-/pbot.git
synced 2024-11-26 22:09:26 +01:00
Do not print values of uninitialized/unassigned objects
This commit is contained in:
parent
b15267c587
commit
593fe59263
@ -16,17 +16,53 @@ my $closing = "\n\n";
|
|||||||
my $watching = 0;
|
my $watching = 0;
|
||||||
my $got_output = 0;
|
my $got_output = 0;
|
||||||
my $local_vars = "";
|
my $local_vars = "";
|
||||||
|
my $locals_start;
|
||||||
|
my $locals_end;
|
||||||
my $last_statement;
|
my $last_statement;
|
||||||
|
my ($main_start, $main_end);
|
||||||
sub flushall;
|
sub flushall;
|
||||||
sub gdb;
|
sub gdb;
|
||||||
|
|
||||||
|
my ($out, $in);
|
||||||
|
|
||||||
|
sub getlocals {
|
||||||
|
print "getting locals\n" if $debug >= 5;
|
||||||
|
gdb $in, "print \"Go.\"\ninfo locals\nprint \"Ok.\"\n";
|
||||||
|
|
||||||
|
while(my $peep = <$out>) {
|
||||||
|
chomp $peep;
|
||||||
|
print "got peep: [$peep]\n" if $debug >= 5;
|
||||||
|
last if $peep =~ m/\(gdb\) \$\d+ = "Go."/;
|
||||||
|
|
||||||
|
# fix this
|
||||||
|
$peep =~ s/^\d+: (.*?) =/$1 =/;
|
||||||
|
print "$opening$peep$closing";
|
||||||
|
$got_output = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
my $result = {};
|
||||||
|
|
||||||
|
while(my $line = <$out>) {
|
||||||
|
chomp $line;
|
||||||
|
print "got: [$line]\n" if $debug >= 5;
|
||||||
|
last if $line =~ m/\(gdb\) \$\d+ = "Ok."/;
|
||||||
|
if($line =~ m/([^=]+)=\s+(.*)/) {
|
||||||
|
my $var = $1;
|
||||||
|
my $value = $2;
|
||||||
|
$var =~ s/^\(gdb\)\s+//;
|
||||||
|
$var =~ s/\s+$//;
|
||||||
|
$result->{$var} = $value;
|
||||||
|
print " got local: $var = $value\n" if $debug >= 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
sub execute {
|
sub execute {
|
||||||
my ($cmdline) = @_;
|
my ($cmdline) = @_;
|
||||||
my ($ret, $result);
|
my ($ret, $result);
|
||||||
|
|
||||||
my ($out, $in);
|
|
||||||
open2($out, $in, "$cmdline 2>&1");
|
open2($out, $in, "$cmdline 2>&1");
|
||||||
|
|
||||||
while(my $line = <$out>) {
|
while(my $line = <$out>) {
|
||||||
@ -61,22 +97,23 @@ sub execute {
|
|||||||
|
|
||||||
gdb $in, "list main,9001\n";
|
gdb $in, "list main,9001\n";
|
||||||
gdb $in, "\nprint \"Ok.\"\n";
|
gdb $in, "\nprint \"Ok.\"\n";
|
||||||
my $break = 0;
|
my ($bracket, $main_ended) = (0);
|
||||||
my $bracket = 0;
|
|
||||||
my $main_ended = 0;
|
|
||||||
while(my $line = <$out>) {
|
while(my $line = <$out>) {
|
||||||
chomp $line;
|
chomp $line;
|
||||||
print "list got: [$line]\n" if $debug >= 4;
|
print "list got: [$line]\n" if $debug >= 4;
|
||||||
my ($line_number) = $line =~ m/^(\d+)/g;
|
my ($line_number) = $line =~ m/^(?:\(gdb\)\s+)?(\d+)/g;
|
||||||
while($line =~ m/(.)/g) {
|
while($line =~ m/(.)/g) {
|
||||||
my $char = $1;
|
my $char = $1;
|
||||||
if($char eq '{') {
|
if($char eq '{' and not $main_ended) {
|
||||||
|
if ($bracket == 0) {
|
||||||
|
$main_start = $line_number;
|
||||||
|
}
|
||||||
$bracket++;
|
$bracket++;
|
||||||
} elsif($char eq '}') {
|
} elsif($char eq '}') {
|
||||||
$bracket--;
|
$bracket--;
|
||||||
|
|
||||||
if($bracket == 0 and not $main_ended) {
|
if($bracket == 0 and not $main_ended) {
|
||||||
$break = $line_number - 1;
|
$main_end = $line_number - 1;
|
||||||
$main_ended = 1;
|
$main_ended = 1;
|
||||||
last;
|
last;
|
||||||
}
|
}
|
||||||
@ -86,7 +123,8 @@ sub execute {
|
|||||||
last if $line =~ m/^\(gdb\) \$\d+ = "Ok."/;
|
last if $line =~ m/^\(gdb\) \$\d+ = "Ok."/;
|
||||||
}
|
}
|
||||||
|
|
||||||
gdb $in, "break $break\n";
|
gdb $in, "break $main_start\n";
|
||||||
|
gdb $in, "break $main_end\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\n";
|
||||||
@ -96,41 +134,21 @@ sub execute {
|
|||||||
if($line =~ m/^Breakpoint \d+, main/) {
|
if($line =~ m/^Breakpoint \d+, main/) {
|
||||||
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) {
|
||||||
print "no output, checking locals\n" if $debug >= 5;
|
$locals_end = getlocals();
|
||||||
gdb $in, "print \"Go.\"\ninfo locals\nprint \"Ok.\"\n";
|
|
||||||
|
|
||||||
while(my $peep = <$out>) {
|
my $sep = '';
|
||||||
chomp $peep;
|
foreach my $var (keys %$locals_end) {
|
||||||
last if $peep =~ m/\(gdb\) \$\d+ = "Go."/;
|
print "checking local $var...\n" if $debug >= 4;
|
||||||
|
if ($locals_start->{$var} ne $locals_end->{$var}) {
|
||||||
# fix this
|
$local_vars .= "$sep$var = $locals_end->{$var}";
|
||||||
$peep =~ s/^\d+: (.*?) =/$1 =/;
|
$sep = '; ';
|
||||||
print "$opening$peep$closing";
|
|
||||||
$got_output = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
my $result = "";
|
|
||||||
my $vars = "";
|
|
||||||
my $varsep = "";
|
|
||||||
|
|
||||||
while(my $line = <$out>) {
|
|
||||||
chomp $line;
|
|
||||||
print "got: [$line]\n" if $debug >= 5;
|
|
||||||
last if $line =~ m/\(gdb\) \$\d+ = "Ok."/;
|
|
||||||
if($line =~ m/([^=]+)=\s+(.*)/) {
|
|
||||||
$vars .= "$varsep$1= $2";
|
|
||||||
$varsep = "; ";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$result =~ s/^\s+//;
|
|
||||||
$result =~ s/\s+$//;
|
|
||||||
|
|
||||||
$vars =~ s/\(gdb\)\s*//g;
|
|
||||||
$local_vars = $vars if length $vars;
|
|
||||||
}
|
}
|
||||||
|
} elsif ($line =~ m/^$main_start\s+/) {
|
||||||
|
$locals_start = getlocals();
|
||||||
}
|
}
|
||||||
|
|
||||||
gdb $in, "cont\n";
|
gdb $in, "cont\n";
|
||||||
@ -260,15 +278,18 @@ sub execute {
|
|||||||
|
|
||||||
while (my $line = <$out>) {
|
while (my $line = <$out>) {
|
||||||
chomp $line;
|
chomp $line;
|
||||||
print "-- print-last-statement: read [$line]\n" if $debug;
|
|
||||||
$line =~ s/^\(gdb\)\s*//;
|
$line =~ s/^\(gdb\)\s*//;
|
||||||
if ($line =~ m/^\$\d+ = "Ok."/) {
|
if ($line =~ m/^\$\d+ = "Ok."/) {
|
||||||
last;
|
last;
|
||||||
} elsif ($line =~ m/^\$\d+ = (.*)/) {
|
} elsif ($line =~ s/\$\d+ = (.*)$//) {
|
||||||
unless ($1 eq 'void' || $args eq $1) {
|
unless ($1 eq 'void' || $args eq $1) {
|
||||||
$last_statement = "$args = $1";
|
$last_statement = "$args = $1";
|
||||||
print "got last statement [$last_statement]\n" if $debug;
|
print "got last statement [$last_statement]\n" if $debug;
|
||||||
}
|
}
|
||||||
|
if (length $line) {
|
||||||
|
print "$line\n";
|
||||||
|
$got_output = 1;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$line =~ s/\$\d+ = \d+$//;
|
$line =~ s/\$\d+ = \d+$//;
|
||||||
print "$line\n";
|
print "$line\n";
|
||||||
|
Loading…
Reference in New Issue
Block a user