Skip to content

Instantly share code, notes, and snippets.

@Gerzer
Last active December 9, 2020 23:54
Show Gist options
  • Save Gerzer/55bd30dfa9e0e279b1d80da191001fef to your computer and use it in GitHub Desktop.
Save Gerzer/55bd30dfa9e0e279b1d80da191001fef to your computer and use it in GitHub Desktop.
Easily run Valgrind on a remote machine
#!/bin/bash
user="" # Server user
address="" # Server address
ssh $user@$address << ENDSSH
cd ~/
mkdir valgrind/
ENDSSH
scp *.cpp $user@$address:~/valgrind/
scp *.h $user@$address:~/valgrind/
arguments=""
state=0
for argument in "$@"; do
if [ "$argument" = "-" ]; then
state=1
continue
fi
if [ -f "$argument" ]; then
scp "$argument" $user@$address:~/valgrind/
if [ $state -eq 0 ]; then
filename=$(basename "$argument")
arguments="$arguments $filename"
fi
elif [ $state -eq 0 ]; then
arguments="$arguments $argument"
fi
done
ssh $user@$address << ENDSSH
cd ~/valgrind/
clang++ -g -O3 -Wall -Wextra -o test *.cpp
valgrind --leak-check=full --show-reachable=yes ./test $arguments &> valgrind.log
ENDSSH
scp $user@$address:~/valgrind/valgrind.log ./
ssh $user@$address << ENDSSH
rm -rf ~/valgrind/
ENDSSH
clear
cat valgrind.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment