#!/bin/bash # # winedbg-eclipse - winedbg wrapper for Eclipse IDE # # 2012-04-14 first draft # GDB=gdb SETSID=setsid MKTEMPU="mktemp --tmpdir -u winedbg-eclipse.XXXXXXXXXX" TRACEFILE="$HOME/winedbg-eclipse.log" # debug with installed wine WINECMD=/usr/bin/wine WINEBINARY=/usr/bin/wine # debug with wine sources #export WINEPREFIX=~/.winetest # don't mess up my ~/.wine #WINEBUILDDIR="/media/ARCHLINUXOLD/1/builds/wine/src/wine" #WINECMD="$WINEBUILDDIR/wine" #WINEBINARY="$WINEBUILDDIR/loader/wine" set -e case "$*" in "--version") exec $GDB "$@" ;; "--interpreter mi2 --nx") ;; *) echo unknown arguments: "$@" >&2 exit 1 ;; esac fn_commandfilter() { while read -r s; do printf 'you wrote: %s\n' "$s" >&3 set -- $s case "$1" in *-file-exec-and-symbols) echo "recognized command: -file-exec-and-symbols" >&3 s="$1 $WINEBINARY" printf 'I send: %s\n' "$s" >&3 printf '%s\n' "$s" [ "$2" != "--thread-group" ] || shift 2 file=$2 # need to send 'target remote' immediatly, so breakpoints properly restored fifo=`$MKTEMPU` mkfifo $fifo set -- "$WINECMD" winedbg --gdb --no-start "$file" echo "executing command: $SETSID" "$@" "$fifo &" >&3 # run winedbg protected from C^c $SETSID "$@" $fifo 2>&1 & winedbg_pid=$! echo "waiting 10 seconds for 'target remote'" >&3 { sleep 10 echo "wait timeout. killing winedbg" >&3 kill $winedbg_pid } & killer_pid=$! while read -r s <$fifo ; do printf 'winedbg: %s\n' "$s" >&3 case "$s" in "target "*) #s="$numcmd-target-select ${s/target /}" printf 'I send: %s\n' "$s" >&3 printf '%s\n' "$s" break; ;; esac done kill $killer_pid echo "reading winedbg in background" >&3 while read -r s <$fifo ; do printf 'winedbg: %s\n' "$s" >&3 done & rm $fifo continue ;; *-exec-run) echo "recognized command: -exec-run" >&3 # dummy command because eclipse expects $numcmd^done numcmd=${s/-*/} echo $numcmd^done >&4 continue ;; esac printf 'I send: %s\n' "$s" >&3 printf '%s\n' "$s" done } exec 3>>"$TRACEFILE" # save original stdout for fake GDB replies exec 4>&1 { echo -------------------------------------- echo echo echo } >&3 fifo=`$MKTEMPU` echo "mkfifo $fifo" >&3 mkfifo $fifo fn_commandfilter <&0 >$fifo & commandfilter_pid=$! trap 'kill $commandfilter_pid 2>/dev/null' EXIT trap 'echo INT 1 >&3' INT exec 5<$fifo rm $fifo $GDB "$@" <&5 #| { #trap 'echo INT 3 >&3' INT #while read -r s; do # printf 'GDB replies: %s\n' "$s" >&3 # printf '%s\n' "$s" #done #}