From bbe70afa2d2869227f24c3f6199f0cbcb072a4be Mon Sep 17 00:00:00 2001 From: Pauli Date: Tue, 12 Jun 2018 20:42:12 +0300 Subject: [PATCH 1/3] Add strace support to the linux dfhack script --- package/linux/dfhack | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/package/linux/dfhack b/package/linux/dfhack index 68de25245..07fe62a06 100755 --- a/package/linux/dfhack +++ b/package/linux/dfhack @@ -91,6 +91,11 @@ case "$1" in LD_PRELOAD="$PRELOAD_LIB" setarch "$setarch_arch" -R valgrind $DF_CALLGRIND_OPTS --tool=callgrind --separate-threads=yes --dump-instr=yes --instr-atstart=no --log-file=callgrind.log ./libs/Dwarf_Fortress "$@" ret=$? ;; + --strace) + shift + strace -f setarch "$setarch_arch" -R env LD_PRELOAD="$PRELOAD_LIB" ./libs/Dwarf_Fortress "$@" 2> strace.log + ret=$? + ;; *) setarch "$setarch_arch" -R env LD_PRELOAD="$PRELOAD_LIB" ./libs/Dwarf_Fortress "$@" ret=$? From 69b42d5ecf0bdfb2a693fabf4b348736eeafe370 Mon Sep 17 00:00:00 2001 From: Pauli Date: Tue, 12 Jun 2018 20:44:21 +0300 Subject: [PATCH 2/3] Support DF command line arguments with gdb --- package/linux/dfhack | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/package/linux/dfhack b/package/linux/dfhack index 07fe62a06..17a3eea4a 100755 --- a/package/linux/dfhack +++ b/package/linux/dfhack @@ -68,11 +68,8 @@ setarch_arch=$(cat hack/dfhack_setarch.txt || printf i386) case "$1" in -g | --gdb) shift - echo "set environment LD_LIBRARY_PATH $LD_LIBRARY_PATH" > gdbcmd.tmp - echo "set environment LD_PRELOAD $PRELOAD_LIB" >> gdbcmd.tmp - echo "set environment MALLOC_PERTURB_ 45" >> gdbcmd.tmp - echo "set startup-with-shell off" >> gdbcmd.tmp - gdb $DF_GDB_OPTS -x gdbcmd.tmp ./libs/Dwarf_Fortress "$@" + echo "set exec-wrapper env LD_LIBRARY_PATH='$LD_LIBRARY_PATH' LD_PRELOAD='$PRELOAD_LIB' MALLOC_PERTURB_=45" > gdbcmd.tmp + gdb $DF_GDB_OPTS -x gdbcmd.tmp --args ./libs/Dwarf_Fortress "$@" rm gdbcmd.tmp ret=$? ;; From cfb646f5768fdf24dfcc0ff3fe372c775101a84e Mon Sep 17 00:00:00 2001 From: Pauli Date: Tue, 12 Jun 2018 20:45:47 +0300 Subject: [PATCH 3/3] Add gdbserver support to linux dfhack script It use set envinronment because * I couldn't get exec-wrapper to work correctly * Even with shell remote gdb doesn't support spaces in arguments --- package/linux/dfhack | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/package/linux/dfhack b/package/linux/dfhack index 17a3eea4a..008f691cf 100755 --- a/package/linux/dfhack +++ b/package/linux/dfhack @@ -73,6 +73,34 @@ case "$1" in rm gdbcmd.tmp ret=$? ;; + -r | --remotegdb) + shift + if [ "$#" -gt 0 ]; then + echo "****" + echo "gdbserver doesn't support spaces in arguments." + echo "If your world gen name has spaces you need to remove spaces from the name in data/init/world_gen.txt" + echo "****" + fi + echo "set environment LD_LIBRARY_PATH $LD_LIBRARY_PATH" > gdbcmd.tmp + echo "set environment LD_PRELOAD $PRELOAD_LIB" >> gdbcmd.tmp + echo "set environment MALLOC_PERTURB_ 45" >> gdbcmd.tmp + echo "set startup-with-shell off" >> gdbcmd.tmp + echo "target extended-remote localhost:12345" >> gdbcmd.tmp + echo "set remote exec-file ./libs/Dwarf_Fortress" >> gdbcmd.tmp + # For some reason gdb ignores sysroot setting if it is from same file as + # target extended-remote command + echo "set sysroot /" > gdbcmd_sysroot.tmp + gdb $DF_GDB_OPTS -x gdbcmd.tmp -x gdbcmd_sysroot.tmp --args ./libs/Dwarf_Fortress "$@" + rm gdbcmd.tmp gdbcmd_sysroot.tmp + ret=$? + ;; + -s | --gdbserver) # -s for server + shift + echo "Starting gdbserver in multi mode." + echo "To exit the gdbserver you can enter 'monitor exit' command to gdb or use kill signal" + gdbserver --multi localhost:12345 + ret=$? + ;; -h | --helgrind) shift LD_PRELOAD="$PRELOAD_LIB" setarch "$setarch_arch" -R valgrind $DF_HELGRIND_OPTS --tool=helgrind --log-file=helgrind.log ./libs/Dwarf_Fortress "$@"