update
[rrq/rrqforth.git] / debug.sh
1 #!/bin/bash
2
3 PFX='0x[0-9a-f]* rrqforth.asm:[0-9]*[ ]*'
4
5
6 grep "${PFX}do" rrqforth.map | sed 's/ .*//;s/^/break */' > gdbinit
7
8 NBR=$(wc -l < gdbinit)
9
10 I=1
11 while [ $I -lt $NBR ] ; do echo disable $I ; I=$((I+1)) ; done >> gdbinit
12
13 RET=( $(grep -w ret rrqforth.map | sed 's/ .*//') )
14 echo "break *${RET[0]}" >> gdbinit
15 #       ;; rax = cfa of called word
16 #       ;; rsi = cell* of next forth word
17 #       ;; [$rsp] = from where the call was
18 cat <<EOF >> gdbinit
19 commands $((NBR+1))
20 print (void*) \$rsp
21 print (void*) \$rsi
22 print (char*)((*((void**)(*((void**)\$rsi)-16)))+32)
23 end
24 EOF
25
26 echo disable $NBR >> gdbinit
27 echo disable $((NBR+1)) >> gdbinit
28
29
30 DS="$(grep "${PFX}DS_TOP:" rrqforth.map | sed 's/ .*//')"
31 RS="$(grep "${PFX}RS_TOP:" rrqforth.map | sed 's/ .*//')"
32 cat <<EOF >> gdbinit
33 display *(void**)\$rsp@(((void*)$DS-\$rsp)/8)+1
34 display *(void**)\$rbp@(((void*)$RS-\$rbp)/8)+1
35 display (void*)\$rax
36 display (void*)\$rsi
37
38 define si
39     stepi
40     x/2i \$pc
41     python gdb.execute("shell ./grepline.sh rrqforth.map " + str(gdb.parse_and_eval("\$pc")))
42 end
43
44 define map
45     if \$argc == 1
46         python gdb.execute("shell ./grepline.sh rrqforth.map \$arg0" + " 1 " )
47     else
48         python gdb.execute("shell ./grepline.sh rrqforth.map \$arg0" + " 1 " + "\$arg1" )
49     end
50 end
51 EOF
52
53 exec gdb -x gdbinit rrqforth