aboutsummaryrefslogtreecommitdiff
path: root/Scripts
diff options
context:
space:
mode:
Diffstat (limited to 'Scripts')
-rw-r--r--Scripts/lldb-dap-proxy.pl23
-rw-r--r--Scripts/main.js19
2 files changed, 33 insertions, 9 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 @@
1#!/usr/bin/perl 1#!/usr/bin/perl
2use strict; 2use strict;
3use warnings; 3use warnings;
4use Fcntl qw(O_WRONLY O_APPEND O_CREAT O_NOFOLLOW);
4use IPC::Open3; 5use IPC::Open3;
5use IO::Select; 6use IO::Select;
6use JSON::PP; 7use JSON::PP;
@@ -13,7 +14,7 @@ my @adapter_args = @ARGV > 2 ? @ARGV[2 .. $#ARGV] : ();
13sub log_msg { 14sub log_msg {
14 return unless defined $log_path; 15 return unless defined $log_path;
15 my ($msg) = @_; 16 my ($msg) = @_;
16 open(my $fh, '>>', $log_path) or return; 17 sysopen(my $fh, $log_path, O_WRONLY | O_APPEND | O_CREAT | O_NOFOLLOW, 0600) or return;
17 my @t = gmtime(time); 18 my @t = gmtime(time);
18 printf $fh "[%04d-%02d-%02dT%02d:%02d:%02dZ] %s\n", 19 printf $fh "[%04d-%02d-%02dT%02d:%02d:%02dZ] %s\n",
19 $t[5] + 1900, $t[4] + 1, $t[3], $t[2], $t[1], $t[0], $msg; 20 $t[5] + 1900, $t[4] + 1, $t[3], $t[2], $t[1], $t[0], $msg;
@@ -41,8 +42,8 @@ if ($@) {
41 42
42binmode($_, ':raw') for \*STDIN, \*STDOUT, $child_in, $child_out, $child_err; 43binmode($_, ':raw') for \*STDIN, \*STDOUT, $child_in, $child_out, $child_err;
43 44
44$SIG{INT} = sub { kill 'INT', $pid }; 45$SIG{INT} = sub { log_msg('received SIGINT'); kill 'INT', $pid };
45$SIG{TERM} = sub { kill 'TERM', $pid }; 46$SIG{TERM} = sub { log_msg('received SIGTERM'); kill 'TERM', $pid };
46 47
47my $json = JSON::PP->new->utf8; 48my $json = JSON::PP->new->utf8;
48 49
@@ -63,8 +64,15 @@ LOOP: while ($sel->count > 0) {
63 unless (defined $n && $n > 0) { 64 unless (defined $n && $n > 0) {
64 $sel->remove($fh); 65 $sel->remove($fh);
65 my $fn = fileno($fh); 66 my $fn = fileno($fh);
66 close($child_in) if $fn == $stdin_fn; 67 if ($fn == $stdin_fn) {
67 last LOOP if $fn == $child_out_fn; # adapter stdout closing ends the session 68 log_msg('stdin closed');
69 close($child_in);
70 } elsif ($fn == $child_out_fn) {
71 log_msg('adapter stdout closed');
72 last LOOP;
73 } else {
74 log_msg('adapter stderr closed');
75 }
68 next; 76 next;
69 } 77 }
70 my $fn = fileno($fh); 78 my $fn = fileno($fh);
@@ -82,6 +90,7 @@ LOOP: while ($sel->count > 0) {
82} 90}
83 91
84waitpid($pid, 0); 92waitpid($pid, 0);
93log_msg(sprintf 'adapter exited status=%d signal=%d', $? >> 8, $? & 127);
85# $? encodes exit code in the high byte and terminating signal in the low 7 bits. 94# $? encodes exit code in the high byte and terminating signal in the low 7 bits.
86# Re-raise the signal so the parent sees a signal-killed exit rather than exit(0). 95# Re-raise the signal so the parent sees a signal-killed exit rather than exit(0).
87my $signal = $? & 127; 96my $signal = $? & 127;
@@ -90,6 +99,7 @@ if ($signal) {
90 kill $signal, $$; 99 kill $signal, $$;
91 sleep 1; 100 sleep 1;
92} 101}
102log_msg(sprintf 'proxy exit code=%d', $? >> 8);
93exit($? >> 8); 103exit($? >> 8);
94 104
95sub flush_dap { 105sub flush_dap {
@@ -119,7 +129,7 @@ sub flush_dap {
119 syswrite($dest, 'Content-Length: ' . length($out) . "\r\n\r\n"); 129 syswrite($dest, 'Content-Length: ' . length($out) . "\r\n\r\n");
120 syswrite($dest, $out); 130 syswrite($dest, $out);
121 } else { 131 } else {
122 log_msg('non-json message forwarded'); 132 log_msg(sprintf 'non-json message forwarded%s', $@ ? " error=$@" : ' reason=not-a-hash');
123 syswrite($dest, 'Content-Length: ' . $body_len . "\r\n\r\n"); 133 syswrite($dest, 'Content-Length: ' . $body_len . "\r\n\r\n");
124 syswrite($dest, $body); 134 syswrite($dest, $body);
125 } 135 }
@@ -157,6 +167,7 @@ sub rewrite_client_message {
157 command => $command, 167 command => $command,
158 arguments => $msg->{arguments}, 168 arguments => $msg->{arguments},
159 }; 169 };
170 log_msg(sprintf 'client seq map %s=>%s', $orig, $rewrite);
160 } 171 }
161 $msg->{seq} = $rewrite; 172 $msg->{seq} = $rewrite;
162 } 173 }
diff --git a/Scripts/main.js b/Scripts/main.js
index 1058dfe..d9aac14 100644
--- a/Scripts/main.js
+++ b/Scripts/main.js
@@ -12,6 +12,7 @@ const CONFIG_KEYS = {
12 zlsEnabled: `${EXTENSION_ID}.zls.enabled`, 12 zlsEnabled: `${EXTENSION_ID}.zls.enabled`,
13 zlsBuildOnSave: `${EXTENSION_ID}.zls.build-on-save`, 13 zlsBuildOnSave: `${EXTENSION_ID}.zls.build-on-save`,
14 zlsDebug: `${EXTENSION_ID}.zls.debug`, 14 zlsDebug: `${EXTENSION_ID}.zls.debug`,
15 lldbDapDebug: `${EXTENSION_ID}.debug-adapter.debug`,
15}; 16};
16 17
17let languageServer = null; 18let languageServer = null;
@@ -264,7 +265,7 @@ function lldbDapProxyPath() {
264} 265}
265 266
266function debugAdapterLogPath() { 267function debugAdapterLogPath() {
267 return "/tmp/zig-lldb-dap-proxy.log"; 268 return nova.path.join(nova.extension.globalStoragePath, "lldb-dap-proxy.log");
268} 269}
269 270
270function issueNormalizerScriptPath() { 271function issueNormalizerScriptPath() {
@@ -806,12 +807,24 @@ class ZigTaskAssistant {
806 const action = new TaskDebugAdapterAction("zig-lldb-dap"); 807 const action = new TaskDebugAdapterAction("zig-lldb-dap");
807 action.transport = "stdio"; 808 action.transport = "stdio";
808 action.command = "/usr/bin/perl"; 809 action.command = "/usr/bin/perl";
809 action.args = [lldbDapProxyPath(), lldbDapPath, debugAdapterLogPath()]; 810 const debugLog = getBooleanConfigValue(CONFIG_KEYS.lldbDapDebug, false);
811 let logPath;
812 if (debugLog) {
813 try {
814 const p = debugAdapterLogPath();
815 const dir = nova.path.dirname(p);
816 if (!nova.fs.stat(dir)) nova.fs.mkdir(dir);
817 logPath = p;
818 } catch (_) {}
819 }
820 action.args = logPath
821 ? [lldbDapProxyPath(), lldbDapPath, logPath]
822 : [lldbDapProxyPath(), lldbDapPath];
810 action.debugRequest = "launch"; 823 action.debugRequest = "launch";
811 action.env = { 824 action.env = {
812 DYLD_FRAMEWORK_PATH: lldbFrameworkPaths().join(":"), 825 DYLD_FRAMEWORK_PATH: lldbFrameworkPaths().join(":"),
813 NOVA_ZIG_LLDB_DAP_PATH: lldbDapPath, 826 NOVA_ZIG_LLDB_DAP_PATH: lldbDapPath,
814 NOVA_ZIG_DEBUG_LOG: debugAdapterLogPath(), 827 ...(logPath ? { NOVA_ZIG_DEBUG_LOG: logPath } : {}),
815 }; 828 };
816 action.debugArgs = { 829 action.debugArgs = {
817 program: programPath, 830 program: programPath,