Annotation of gforth/dis-gdb.fs, revision 1.14

1.1       anton       1: \ dis-gdb.fs   disassembler using gdb
                      2: \
1.14    ! anton       3: \ Copyright (C) 2004,2007,2008,2010,2011 Free Software Foundation, Inc.
1.1       anton       4: 
                      5: \ This file is part of Gforth.
                      6: 
                      7: \ Gforth is free software; you can redistribute it and/or
                      8: \ modify it under the terms of the GNU General Public License
1.5       anton       9: \ as published by the Free Software Foundation, either version 3
1.1       anton      10: \ of the License, or (at your option) any later version.
                     11: 
                     12: \ This program is distributed in the hope that it will be useful,
                     13: \ but WITHOUT ANY WARRANTY; without even the implied warranty of
                     14: \ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     15: \ GNU General Public License for more details.
                     16: 
                     17: \ You should have received a copy of the GNU General Public License
1.5       anton      18: \ along with this program. If not, see http://www.gnu.org/licenses/.
1.1       anton      19: 
1.4       anton      20: : append-extend-string ( addr1 u1 addr2 u2 -- addr3 u1+u2 )
                     21:     \ append string2 to string1 with dynamic memory reallocation.
                     22:     swap >r dup >r extend-mem ( to addr3 u1+u2 r: addr2 u2 )
1.1       anton      23:     rot r> r> rot rot chars move ;
                     24: 
1.12      anton      25: defer gdb-addr-sep-char ( -- c )
                     26: 
                     27: ',' constant #comma
                     28: 
                     29: : check-gdb-syntax ( -- c )
                     30:     \ gdb-7.0 and earlier do what we want with "disassemble addr1 addr2"
                     31:     \ gdb-7.1 and later only work with         "disaesemble addr1,addr2"
                     32:     \ try the old syntax to see if it works
1.13      pazsan     33:     s" gdb -ex 'disassemble 0 1' -ex 'quit' 2>/dev/null" r/o open-pipe throw
1.12      anton      34:     dup slurp-fid rot close-pipe throw drop
1.13      pazsan     35:     s" Dump of assembler code from" search nip nip if
1.12      anton      36:         ['] bl
                     37:     else
                     38:         ['] #comma
                     39:     then
                     40:     dup is gdb-addr-sep-char
                     41:     execute ;
                     42: 
                     43: ' check-gdb-syntax is gdb-addr-sep-char
                     44: 
1.1       anton      45: : disasm-gdb { addr u -- }
                     46:     base @ >r hex
1.12      anton      47:     s\" type mktemp >/dev/null && type gdb >/dev/null && file=`mktemp -t gforthdis.XXXXXXXXXX` && file2=`mktemp -t gforthdis.XXXXXXXXXX` && echo \"set verbose off\nset logging file $file\nset logging on\ndisas " save-mem ( addr u addr1 u1 )
                     48:     addr 0 <<# gdb-addr-sep-char hold # #s 'x hold # #> append-extend-string #>>
1.1       anton      49:     addr u + 0 <<# # #s 'x hold # #> append-extend-string #>>
                     50:     r> base ! cr
1.7       anton      51:     s\" \nset logging off\nquit\n\" >$file2 && gdb -nx -q -p `ps -p $$ -o ppid=` -x $file2 2>/dev/null >/dev/null && rm $file2 && grep -v \"of assembler\" $file && rm $file" append-extend-string
1.1       anton      52:     2dup (system) 2swap drop free throw throw if
                     53:        addr u dump
                     54:     endif ;
                     55: 
                     56: ' disasm-gdb is discode

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>