Skip to content

Commit

Permalink
Fix gdb logfile command overwriting the old logfile
Browse files Browse the repository at this point in the history
on my debian laptop with peda it seems like
the gdb internal log command clears out the logfile before writing to it
that is bad because we lose the previous crash log
and also the manually written header with the commit
hash

So this commit makes sure that no matter the gdb setup it will
only append and never delete old logs
  • Loading branch information
ChillerDragon committed Feb 16, 2025
1 parent 9ea6f3d commit dd6ff6d
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/include/gdb_loop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ then
err "failed to get commit hash"
exit 1
fi

gdb_tmp_log_header="$p/full_gdb.header.txt.tmp"
gdb_tmp_log_gdb="$p/full_gdb.gdb.txt.tmp"

read -rd '' GDB_CMD << EOF
$CFG_ENV_RUNTIME gdb -ex='set confirm off' \
-ex='set pagination off' \
Expand All @@ -100,7 +104,7 @@ $CFG_ENV_RUNTIME gdb -ex='set confirm off' \
-ex='set logging on' \
-ex=bt \
-ex='set logging off' \
-ex="set logging file $p/full_gdb.txt" \
-ex="set logging file $gdb_tmp_log_gdb" \
-ex='set logging on' \
-ex='echo (gdb) bt full\\n' -ex='bt full' \
-ex='echo (gdb) info registers\\n' -ex='info registers' \
Expand All @@ -124,11 +128,17 @@ start_ts=$(date '+%Y-%m-%d %H:%M:%S')
echo "gdb ./bin/backup/$(get_commit) $gdb_corefile"
echo "objdump -dCS -M intel bin/backup/$(get_commit) > ./lib/tmp/debug.asm && vim ./lib/tmp/debug.asm"
echo "python -c 'print(hex(0xbabe + 10))'"
} >> "$p/full_gdb.txt"
} >> "$gdb_tmp_log_header"
echo ""
eval "$GDB_CMD"
echo ""
log "executed: '$GDB_CMD'"

cat "$gdb_tmp_log_header" >> "$p/full_gdb.txt"
rm "$gdb_tmp_log_header"
cat "$gdb_tmp_log_gdb" >> "$p/full_gdb.txt"
rm "$gdb_tmp_log_gdb"

stop_ts=$(date '+%Y-%m-%d %H:%M:%S')
echo "\\============= server stop $stop_ts =============/" >> "$p/full_gdb.txt"
echo "/============= server start $start_ts =============\\" > "$p/raw_gdb.txt"
Expand Down

0 comments on commit dd6ff6d

Please sign in to comment.