1 ! Copyright (C) 2008 Slava Pestov, Jorge Acereda Macia.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: io.files io words alien kernel math.parser alien.syntax
4 io.launcher system assocs arrays sequences namespaces make
5 qualified system math compiler.generator.fixup
6 io.encodings.ascii accessors generic tr ;
9 : in-file ( -- path ) "gdb-in.txt" temp-file ;
11 : out-file ( -- path ) "gdb-out.txt" temp-file ;
13 GENERIC: make-disassemble-cmd ( obj -- )
15 M: word make-disassemble-cmd
16 word-xt code-format - 2array make-disassemble-cmd ;
18 M: pair make-disassemble-cmd
21 current-process-handle number>string print
23 [ number>string write bl ] each
26 M: method-spec make-disassemble-cmd
27 first2 method make-disassemble-cmd ;
29 : gdb-binary ( -- string ) "gdb" ;
31 : run-gdb ( -- lines )
35 [ gdb-binary , "-x" , in-file , "-batch" , ] { } make >>command
37 out-file ascii file-lines ;
39 TR: tabs>spaces "\t" "\s" ;
41 : disassemble ( obj -- )
42 make-disassemble-cmd run-gdb
43 [ tabs>spaces ] map [ print ] each ;