Last active
February 5, 2025 11:42
-
-
Save vogelsgesang/572b04dc1d447776964fb7e40fd8b261 to your computer and use it in GitHub Desktop.
Launches an executable under lldb-server and prints the URL to connect to this server from VSCode; see https://github.com/llvm/llvm-project/pull/125843
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Utility urlencode <string> | |
# https://gist.github.com/cdown/1163649 | |
urlencode() { | |
old_lc_collate=$LC_COLLATE | |
LC_COLLATE=C | |
local length="${#1}" | |
for (( i = 0; i < length; i++ )); do | |
local c="${1:$i:1}" | |
case $c in | |
[a-zA-Z0-9.~_-]) printf '%s' "$c" ;; | |
*) printf '%%%02X' "'$c" ;; | |
esac | |
done | |
LC_COLLATE=$old_lc_collate | |
} | |
# Find an unused port | |
# https://unix.stackexchange.com/questions/55913/whats-the-easiest-way-to-find-an-unused-local-port | |
read LOWERPORT UPPERPORT < /proc/sys/net/ipv4/ip_local_port_range | |
while : | |
do | |
PORT="`shuf -i $LOWERPORT-$UPPERPORT -n 1`" | |
ss -lpn | grep -q ":$PORT " || break | |
done | |
# See https://github.com/llvm/llvm-project/pull/125843 | |
CWD=`pwd` | |
LAUNCH_CONFIG="{\"request\":\"attach\",\"cwd\":\"$CWD\",\"program\":\"$1\",\"attachCommands\":[\"gdb-remote 127.0.0.1:$PORT\"]}" | |
DEBUG_URL="vscode://llvm-vs-code-extensions.lldb-dap/launch/config?config=$(urlencode "$LAUNCH_CONFIG")" | |
echo "Visual studio code debugger URL: $DEBUG_URL" | |
lldb-server gdbserver :$PORT -- $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment