Last active
August 22, 2022 22:52
-
-
Save vogelsgesang/d803377b8b143164961e08e58f5186c0 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
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/vadimcn/vscode-lldb/blob/master/MANUAL.md#debugging-externally-launched-code | |
LAUNCH_CONFIG="{\"request\":\"custom\",\"targetCreateCommands\":[\"target create $1\"],\"processCreateCommands\":[\"gdb-remote 127.0.0.1:$PORT\"]}" | |
DEBUG_URL="vscode://vadimcn.vscode-lldb/launch/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