You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

38 lines
1.2 KiB

#!/bin/sh
#
# Remote container entrypoint.
#
# codelldb binds to 127.0.0.1 only (no --host flag), so socat forwards
# connections from 0.0.0.0:13000 to codelldb on 127.0.0.1:13001.
#
# The developer station's nvim-dap connects to port 13000 and sends DAP
# launch/attach requests. After each session ends, codelldb exits; this
# loop restarts both processes so the developer can reconnect without
# restarting the container.
set -eu
EXTERNAL_PORT="${DAP_PORT:-13000}"
INTERNAL_PORT=13001
ADAPTER="/opt/codelldb/extension/adapter/codelldb"
while true; do
echo "[remote] codelldb DAP server on :${EXTERNAL_PORT} (forwarded to 127.0.0.1:${INTERNAL_PORT})..."
# socat forwards external TCP to codelldb's localhost listener.
socat TCP-LISTEN:"${EXTERNAL_PORT}",reuseaddr,fork \
TCP:127.0.0.1:"${INTERNAL_PORT}" &
SOCAT_PID=$!
# Give socat a moment to bind before codelldb starts accepting.
sleep 0.2
# codelldb handles one --multi-session instance; exits when client disconnects.
"$ADAPTER" --port "$INTERNAL_PORT" --multi-session
kill "$SOCAT_PID" 2>/dev/null || true
wait "$SOCAT_PID" 2>/dev/null || true
echo "[remote] DAP session ended. Restarting in 1 second..."
sleep 1
done