factor/basis/tools/disassembler/disassembler.factor

44 lines
1.2 KiB
Factor
Raw Normal View History

2008-02-14 21:27:04 -05:00
! Copyright (C) 2008 Slava Pestov, Jorge Acereda Macia.
! See http://factorcode.org/license.txt for BSD license.
2008-02-14 18:56:47 -05:00
USING: io.files io words alien kernel math.parser alien.syntax
io.launcher system assocs arrays sequences namespaces make
2008-10-13 15:01:33 -04:00
qualified system math compiler.codegen.fixup
io.encodings.ascii accessors generic tr ;
2008-02-14 18:56:47 -05:00
IN: tools.disassembler
2008-06-08 16:32:55 -04:00
: in-file ( -- path ) "gdb-in.txt" temp-file ;
2008-02-14 21:27:04 -05:00
2008-06-08 16:32:55 -04:00
: out-file ( -- path ) "gdb-out.txt" temp-file ;
2008-02-14 21:27:04 -05:00
GENERIC: make-disassemble-cmd ( obj -- )
2008-02-14 18:56:47 -05:00
M: word make-disassemble-cmd
word-xt code-format - 2array make-disassemble-cmd ;
2008-02-14 18:56:47 -05:00
M: pair make-disassemble-cmd
in-file ascii [
2008-02-14 21:27:04 -05:00
"attach " write
current-process-handle number>string print
2008-02-14 21:27:04 -05:00
"disassemble " write
[ number>string write bl ] each
] with-file-writer ;
2008-02-14 21:27:04 -05:00
2008-03-13 04:51:25 -04:00
M: method-spec make-disassemble-cmd
first2 method make-disassemble-cmd ;
: gdb-binary ( -- string ) "gdb" ;
2008-03-30 13:21:44 -04:00
2008-02-14 21:27:04 -05:00
: run-gdb ( -- lines )
2008-03-06 21:44:52 -05:00
<process>
+closed+ >>stdin
out-file >>stdout
2008-03-30 13:21:44 -04:00
[ gdb-binary , "-x" , in-file , "-batch" , ] { } make >>command
2008-03-06 21:44:52 -05:00
try-process
out-file ascii file-lines ;
2008-02-14 21:27:04 -05:00
TR: tabs>spaces "\t" "\s" ;
2008-02-14 18:56:47 -05:00
2008-03-11 20:51:58 -04:00
: disassemble ( obj -- )
2008-02-14 21:27:04 -05:00
make-disassemble-cmd run-gdb
[ tabs>spaces ] map [ print ] each ;