more and better documentation and some reorganisation
[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" >> gdbinit
15 #       ;; rax = cfa of called word
16 #       ;; rsi = cell* of next forth word
17 #       ;; [$rsp] = from where the call was
18
19 cat <<EOF >> gdbinit
20 commands $((NBR+1))
21 print (void*) \$rsp
22 print (((char*)(*(((void**)\$rax)-2)))+32)
23 print (void*) \$rsi
24 continue
25 end
26 EOF
27
28 DS="$(grep "${PFX}DS_TOP:" rrqforth.map | sed 's/ .*//')"
29 RS="$(grep "${PFX}RS_TOP:" rrqforth.map | sed 's/ .*//')"
30 cat <<EOF >> gdbinit
31 display *(void**)\$rsp@(((void*)$DS-\$rsp)/8)+1
32 display *(void**)\$rbp@(((void*)$RS-\$rbp)/8)+1
33 display (void*)\$rax
34 display (void*)\$rsi
35
36 define si
37     stepi
38     x/2i \$pc
39     python gdb.execute("shell ./grepline.sh rrqforth.map " + str(gdb.parse_and_eval("\$pc")))
40 end
41
42 define map
43     if \$argc == 1
44         python gdb.execute("shell ./grepline.sh rrqforth.map \$arg0" + " 1 " )
45     else
46         python gdb.execute("shell ./grepline.sh rrqforth.map \$arg0" + " 1 " + "\$arg1" )
47     end
48 end
49 EOF
50
51 exec gdb -x gdbinit rrqforth