From 41359b0c84fd853e856cd21c0aca6c1691a09597 Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Mon, 31 Jan 2022 09:12:11 -0800 Subject: [PATCH] Minor clean-up --- applets/compiler_vm/guest/bin/guest-gdb | 30 ++++++++----------- .../host/lib/Languages/_default.pm | 5 ++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/applets/compiler_vm/guest/bin/guest-gdb b/applets/compiler_vm/guest/bin/guest-gdb index 520e70f3..9e0764b7 100755 --- a/applets/compiler_vm/guest/bin/guest-gdb +++ b/applets/compiler_vm/guest/bin/guest-gdb @@ -211,8 +211,7 @@ sub compare_locals($old, $new) { foreach my $local (@$new) { my ($ident, $value) = @$local; - $ht{$ident} //= ''; # set non-existing key to empty string - if ($ht{$ident} ne $value) { + if (!exists $ht{$ident} || $ht{$ident} ne $value) { push @modified, [$ident, $value]; } } @@ -272,13 +271,13 @@ sub get_main_start_end($context) { # this line isn't part of main() yet next if $line < $start; - # blank out contents of string and char literals + # blank out contents of string and char literals so we don't count + # any braces within $code =~ s/(?:\"((?:\\\"|(?!\").)*)\")/'"' . ('-' x length $1) . '"'/ge; $code =~ s/(?:\'((?:\\\'|(?!\').)*)\')/"'" . ('-' x length $1) . "'"/ge; - while ($code =~ /(.)/g) { - my $char = $1; - + my @chars = split //, $code; + foreach my $char (@chars) { if ($char eq '{') { $braces++; } elsif ($char eq '}') { @@ -441,17 +440,11 @@ sub handle_program_exit($context, $data) { sub handle_program_signal($context, $data) { my $locals = locals_to_string(get_locals($context)); - my $text = "Program received signal $data->{'signal-name'}, $data->{'signal-meaning'} "; - - if ($data->{frame}->{func} eq '??') { - $text .= "in ?? "; - } else { - $text .= "in $data->{frame}->{func} "; - } - my $args = args_to_string($data->{frame}->{args}); - $text .= "($args) "; + my $text = "Program received signal $data->{'signal-name'}, $data->{'signal-meaning'} "; + + $text .= "in $data->{frame}->{func} ($args) "; my $line; @@ -475,11 +468,14 @@ sub handle_program_signal($context, $data) { } } - $text .= "called by $trace->{func} $trace->{args} at statement: $line "; + $text .= "called by $trace->{func} $trace->{args} "; + $text .= "at statement: $line " if $line; } if (length $locals) { $text .= "" + } else { + $text =~ s/\s+$//; } print_gdb_output($context, $text); @@ -510,8 +506,6 @@ sub dispatch_gdbmi_output($context, $output) { RESULT , \&handle_result_output, ); - print STDERR "dispatch: ", Dumper($output), "\n" if $debug >= 3; - $dispatch{$output->{_type}}->($context, $output); } diff --git a/applets/compiler_vm/host/lib/Languages/_default.pm b/applets/compiler_vm/host/lib/Languages/_default.pm index ca24e2df..a25ac089 100755 --- a/applets/compiler_vm/host/lib/Languages/_default.pm +++ b/applets/compiler_vm/host/lib/Languages/_default.pm @@ -87,9 +87,8 @@ sub preprocess_code { my $state = NORMAL; my $escaped = 0; - while($self->{code} =~ m/(.)/gs) { - my $ch = $1; - + my @chars = split //, $self->{code}; + foreach my $ch (@chars) { given ($ch) { when ('\\') { if($escaped == 0) {