]> gitweb.factorcode.org Git - factor.git/blob - basis/tools/disassembler/disassembler.factor
dabdaaaa7caba5a5486a5732fb271ee204b9d155
[factor.git] / basis / tools / disassembler / disassembler.factor
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 ;
7 IN: tools.disassembler
8
9 : in-file ( -- path ) "gdb-in.txt" temp-file ;
10
11 : out-file ( -- path ) "gdb-out.txt" temp-file ;
12
13 GENERIC: make-disassemble-cmd ( obj -- )
14
15 M: word make-disassemble-cmd
16     word-xt code-format - 2array make-disassemble-cmd ;
17
18 M: pair make-disassemble-cmd
19     in-file ascii [
20         "attach " write
21         current-process-handle number>string print
22         "disassemble " write
23         [ number>string write bl ] each
24     ] with-file-writer ;
25
26 M: method-spec make-disassemble-cmd
27     first2 method make-disassemble-cmd ;
28
29 : gdb-binary ( -- string ) "gdb" ;
30
31 : run-gdb ( -- lines )
32     <process>
33         +closed+ >>stdin
34         out-file >>stdout
35         [ gdb-binary , "-x" , in-file , "-batch" , ] { } make >>command
36     try-process
37     out-file ascii file-lines ;
38
39 TR: tabs>spaces "\t" "\s" ;
40
41 : disassemble ( obj -- )
42     make-disassemble-cmd run-gdb
43     [ tabs>spaces ] map [ print ] each ;