Skip to content

Commit

Permalink
fix running gdb with executable scripts, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
acheronfail committed Jan 12, 2024
1 parent fae1aec commit fae1615
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
18 changes: 10 additions & 8 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ docker-push: docker-build
docker push {{tag}}

docker-measure what:
docker run --rm -ti --platform 'linux/amd64' -v "$PWD:{{mount}}" {{tag}} just measure {{what}}
docker run --privileged --rm -ti --platform 'linux/amd64' -v "$PWD:{{mount}}" {{tag}} just measure {{what}}

docker-measure-all:
docker run --rm -ti --platform 'linux/amd64' -v "$PWD:{{mount}}" {{tag}} just measure-all
docker run --privileged --rm -ti --platform 'linux/amd64' -v "$PWD:{{mount}}" {{tag}} just measure-all

_all:
just -l | grep -v 'build-all' | grep 'build-' | cut -d'-' -f2- | xargs
Expand Down Expand Up @@ -58,7 +58,7 @@ run what:

measure what:
#!/usr/bin/env bash
set -euxo pipefail
set -euo pipefail
just build {{what}}
slow_langs=(
cobol
Expand All @@ -81,6 +81,8 @@ measure what:
fi
done

set -x

mkdir -p results
out="results/{{what}}.json"

Expand All @@ -91,7 +93,7 @@ measure what:
jq '. += {"size":"'"$(cat SIZE)"'"}' "$out" | sponge "$out"
fi

gdb -return-child-result --command rss.gdb --args $(cat CMD) >/dev/null
gdb --command rss.gdb --args $(cat CMD) >/dev/null
jq '. += {"rss":'$(( $(rg -oPr '$1' 'Rss:\s*(\d+)' ./rss.txt) * 1024 ))'}' "$out" | sponge "$out"

measure-all:
Expand Down Expand Up @@ -200,7 +202,7 @@ build-scala: (_check "scalac scala") && (_size "count.class" "count$.class" "cou
scalac -version > VERSION 2>&1
scala -version >> VERSION 2>&1
scalac count.scala
echo 'scala count {{i}}' > CMD
echo 'bash '$(which scala)' count {{i}}' > CMD

build-kotlin: (_check "kotlinc java") && (_size "count.jar") (_sizet "bytecode")
kotlinc -version > VERSION 2>&1
Expand Down Expand Up @@ -254,7 +256,7 @@ build-php: (_check "php")
build-erlang: (_check "erlc erl") && (_size "count.beam") (_sizet "bytecode")
erl -eval '{ok, Version} = file:read_file(filename:join([code:root_dir(), "releases", erlang:system_info(otp_release), "OTP_VERSION"])), io:fwrite(Version), halt().' -noshell > VERSION
erlc count.erl
echo 'erl -noshell -s count start {{i}}' > CMD
echo 'sh '$(which erl)' -noshell -s count start {{i}}' > CMD

build-crystal: (_check "crystal")
crystal version | xargs > VERSION
Expand All @@ -277,7 +279,7 @@ build-julia: (_check "julia")

build-coffeescript: (_check "coffee")
coffee --version > VERSION
echo 'coffee ./count.coffee {{i}}' > CMD
echo 'node '$(which coffee)' ./count.coffee {{i}}' > CMD

build-nim: (_check "nim") && (_size "count")
nim --version | head -1 > VERSION
Expand All @@ -287,7 +289,7 @@ build-nim: (_check "nim") && (_size "count")
build-prolog: (_check "swipl") && (_size "count")
swipl --version > VERSION
swipl -s count.pro -g "main" -t halt -- 1
echo './count {{i}}' > CMD
echo 'sh ./count {{i}}' > CMD

build-smalltalk: (_check "gst")
gst --version | head -1 > VERSION
Expand Down
14 changes: 8 additions & 6 deletions rss.gdb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# run this with:

# catch program exit
catch syscall exit
catch syscall exit exit_group
condition 1 $_thread == 1
run

# capture program pid
Expand All @@ -12,8 +13,9 @@ end
# while it's still running, extract rss from /proc
eval "shell cat /proc/%d/smaps_rollup > rss.txt", $pid

# allow program to exit, and exit gdb
# when gdb is run with the `-return-child-result` flag it will cause gdb to exit
# with the same code the child did
continue
exit
# TODO: rather than just terminating here it would be nice to let the program
# continue and allow `-return-child-result` to set the exit code to catch any
# unexpected errors. But weird things happen with multithreaded programs.
# An alternative could be to check that the value in `$rdi` is `0`, since we're
# catching the exit syscalls.
quit

0 comments on commit fae1615

Please sign in to comment.