diff options
author | Raymaekers Luca <raymaekers.luca@gmail.com> | 2024-10-22 13:28:37 +0200 |
---|---|---|
committer | Raymaekers Luca <raymaekers.luca@gmail.com> | 2024-10-22 13:28:44 +0200 |
commit | 56bbfce22cc0f0b567f650167f82ce3f7d90e625 (patch) | |
tree | 490dd7ed046f515aabb06aeadd8a16bcdda8f898 /bin | |
parent | 7778716142a2bbe688fcbf0fa73e4c8f06a38c17 (diff) |
checkpoint
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/extra/gdbcore | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/bin/extra/gdbcore b/bin/extra/gdbcore new file mode 100755 index 0000000..24c058a --- /dev/null +++ b/bin/extra/gdbcore @@ -0,0 +1,57 @@ +#!/bin/sh + +# Open the latest core file for program with gdb +# RETURN VALUES +# 0 - success +# 1 - if the program was not found or not executable +# 2 - if the user did aborted +# 3 - zstd failed +# 4 - wrong usage + +if [ "$#" -lt 1 ]; then + >&2 printf 'usage: fcore <program>\n' +fi + +prog="$1" +if [ ! -x "$prog" ]; then + prog="$(which "$prog" 2>/dev/null)" + [ -x "$prog" ] || exit 1 +fi + +# Directory where corefiles are located +coredir=/var/lib/systemd/coredump +# Temporary file listing core files location, later used as location for the corefile +tmp="$(mktemp)" + +find "$coredir" -name "core.${prog##*/}*" -printf '%f %TF %TT\n' > "$tmp" + +choice="$(sed \ + -e 's/\.[0-9]\+$//' \ + -e 's/^core\.//' \ + -e 's/\.[0-9]\+\.[0-9a-f]\+\.[0-9]\+\.[0-9]\+\.zst / /' \ + "$tmp" | + awk '{print NR ".", "[" $3,$2"]", $1}' | + sort -k 2 -k 3 -r | + fzf -0 --with-nth=2..)" +if [ -z "$choice" ]; then + rm "$tmp" + exit 2 +fi + +nr="${choice%%.*}" +line="$(sed -n "${nr}p" "$tmp")" +corefile="$coredir"/"${line%% *}" + +if [ ! -f "$corefile" ]; then + rm -f "$tmp" + exit 1 +fi + +if ! zstd -d "$corefile" -f -o "$tmp" 2>/dev/null; then + rm -f "$tmp" + exit 3 +fi + +gdb "$prog" "$tmp" + +rm -f "$tmp" |