diff options
Diffstat (limited to 'Scripts/lldb-dap-proxy.pl')
| -rw-r--r-- | Scripts/lldb-dap-proxy.pl | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/Scripts/lldb-dap-proxy.pl b/Scripts/lldb-dap-proxy.pl index 5f545b1..beb6eaa 100644 --- a/Scripts/lldb-dap-proxy.pl +++ b/Scripts/lldb-dap-proxy.pl @@ -1,6 +1,7 @@ #!/usr/bin/perl use strict; use warnings; +use Fcntl qw(O_WRONLY O_APPEND O_CREAT O_NOFOLLOW); use IPC::Open3; use IO::Select; use JSON::PP; @@ -13,7 +14,7 @@ my @adapter_args = @ARGV > 2 ? @ARGV[2 .. $#ARGV] : (); sub log_msg { return unless defined $log_path; my ($msg) = @_; - open(my $fh, '>>', $log_path) or return; + sysopen(my $fh, $log_path, O_WRONLY | O_APPEND | O_CREAT | O_NOFOLLOW, 0600) or return; my @t = gmtime(time); printf $fh "[%04d-%02d-%02dT%02d:%02d:%02dZ] %s\n", $t[5] + 1900, $t[4] + 1, $t[3], $t[2], $t[1], $t[0], $msg; @@ -41,8 +42,8 @@ if ($@) { binmode($_, ':raw') for \*STDIN, \*STDOUT, $child_in, $child_out, $child_err; -$SIG{INT} = sub { kill 'INT', $pid }; -$SIG{TERM} = sub { kill 'TERM', $pid }; +$SIG{INT} = sub { log_msg('received SIGINT'); kill 'INT', $pid }; +$SIG{TERM} = sub { log_msg('received SIGTERM'); kill 'TERM', $pid }; my $json = JSON::PP->new->utf8; @@ -63,8 +64,15 @@ LOOP: while ($sel->count > 0) { unless (defined $n && $n > 0) { $sel->remove($fh); my $fn = fileno($fh); - close($child_in) if $fn == $stdin_fn; - last LOOP if $fn == $child_out_fn; # adapter stdout closing ends the session + if ($fn == $stdin_fn) { + log_msg('stdin closed'); + close($child_in); + } elsif ($fn == $child_out_fn) { + log_msg('adapter stdout closed'); + last LOOP; + } else { + log_msg('adapter stderr closed'); + } next; } my $fn = fileno($fh); @@ -82,6 +90,7 @@ LOOP: while ($sel->count > 0) { } waitpid($pid, 0); +log_msg(sprintf 'adapter exited status=%d signal=%d', $? >> 8, $? & 127); # $? encodes exit code in the high byte and terminating signal in the low 7 bits. # Re-raise the signal so the parent sees a signal-killed exit rather than exit(0). my $signal = $? & 127; @@ -90,6 +99,7 @@ if ($signal) { kill $signal, $$; sleep 1; } +log_msg(sprintf 'proxy exit code=%d', $? >> 8); exit($? >> 8); sub flush_dap { @@ -119,7 +129,7 @@ sub flush_dap { syswrite($dest, 'Content-Length: ' . length($out) . "\r\n\r\n"); syswrite($dest, $out); } else { - log_msg('non-json message forwarded'); + log_msg(sprintf 'non-json message forwarded%s', $@ ? " error=$@" : ' reason=not-a-hash'); syswrite($dest, 'Content-Length: ' . $body_len . "\r\n\r\n"); syswrite($dest, $body); } @@ -157,6 +167,7 @@ sub rewrite_client_message { command => $command, arguments => $msg->{arguments}, }; + log_msg(sprintf 'client seq map %s=>%s', $orig, $rewrite); } $msg->{seq} = $rewrite; } |
