fixed (comma)
[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
19 cat <<EOF >> gdbinit
20 commands $((NBR+1))
21 print (void*) \$rsp
22 print (void*) \$rsi
23 print (char*)((*((void**)(*((void**)\$rsi)-16)))+32)
24 end
25 EOF
26
27 DS="$(grep "${PFX}DS_TOP:" rrqforth.map | sed 's/ .*//')"
28 RS="$(grep "${PFX}RS_TOP:" rrqforth.map | sed 's/ .*//')"
29 cat <<EOF >> gdbinit
30 display *(void**)\$rsp@(((void*)$DS-\$rsp)/8)+1
31 display *(void**)\$rbp@(((void*)$RS-\$rbp)/8)+1
32 display (void*)\$rax
33 display (void*)\$rsi
34
35 define si
36     stepi
37     x/2i \$pc
38     python gdb.execute("shell ./grepline.sh rrqforth.map " + str(gdb.parse_and_eval("\$pc")))
39 end
40
41 define map
42     if \$argc == 1
43         python gdb.execute("shell ./grepline.sh rrqforth.map \$arg0" + " 1 " )
44     else
45         python gdb.execute("shell ./grepline.sh rrqforth.map \$arg0" + " 1 " + "\$arg1" )
46     end
47 end
48 EOF
49
50 exec gdb -x gdbinit rrqforth