Skip to content

Instantly share code, notes, and snippets.

@omajid
Last active December 20, 2022 22:24
Show Gist options
  • Save omajid/414ed2bbcf54ae5d259960898533541c to your computer and use it in GitHub Desktop.
Save omajid/414ed2bbcf54ae5d259960898533541c to your computer and use it in GitHub Desktop.
test-dotnet-dump-analyze-dumpalc
#!/usr/bin/env bash
# Check whether dotnet-dump, and its subcommands like `ps`, `collect`
# and `analyze` are working
if [ -f /etc/profile ]; then
source /etc/profile
fi
# Enable "unofficial strict mode" only after loading /etc/profile
# because that usually contains lots of "errors".
set -euo pipefail
IFS=$'\n\t'
set -x
echo " >>> Installing dotnet-dump"
dotnet tool uninstall -g dotnet-dump || true
dotnet tool install -g dotnet-dump
no_server=("/nodeReuse:false" "/p:UseSharedCompilation=false" "/p:UseRazorBuildServer=false")
echo " >>> Running test application"
rm -rf TestDir
mkdir TestDir
cd TestDir
dotnet new web
sed -i -e 's|.UseStartup|.UseUrls("http://localhost:5000").UseStartup|' Program.cs
dotnet build "${no_server[@]}"
dotnet bin/Debug/net*/TestDir.dll &
run_pid=$!
sleep 5
echo " >>> Creating a dump"
dotnet dump collect --type full --output "coredump.${run_pid}" --process-id "${run_pid}" | tee run.pid
kill "${run_pid}" || ( sleep 1; kill -9 "${run_pid}" )
coredump="coredump.${run_pid}"
test -f "${coredump}"
echo " >>> Testing dotnet dump analyze subcommands"
dotnet dump analyze "${coredump}" --command 'clrstack -a' --command 'exit' > dump.out
cat dump.out
grep -E 'this \([^)]+\) = 0x[0-9a-f]+' dump.out
addr=$(grep -E 'this \([^)]+\) = 0x[0-9a-f]+' dump.out | cut -d'=' -f2 | head -1)
dotnet dump analyze "${coredump}" --command "dumpalc $addr" --command 'exit' > dump.out
cat dump.out
echo "PASS"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment