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
|
2008-02-14 21:27:04 -05:00
|
|
|
io.launcher system assocs arrays sequences namespaces qualified
|
2008-02-16 02:52:22 -05:00
|
|
|
system math generator.fixup ;
|
2008-02-14 18:56:47 -05:00
|
|
|
IN: tools.disassembler
|
|
|
|
|
2008-02-14 21:27:04 -05:00
|
|
|
: in-file "gdb-in.txt" resource-path ;
|
|
|
|
|
|
|
|
: out-file "gdb-out.txt" resource-path ;
|
|
|
|
|
|
|
|
GENERIC: make-disassemble-cmd ( obj -- )
|
2008-02-14 18:56:47 -05:00
|
|
|
|
|
|
|
M: word make-disassemble-cmd
|
2008-02-15 03:12:40 -05:00
|
|
|
word-xt code-format - 2array make-disassemble-cmd ;
|
2008-02-14 18:56:47 -05:00
|
|
|
|
|
|
|
M: pair make-disassemble-cmd
|
2008-02-14 21:27:04 -05:00
|
|
|
in-file [
|
|
|
|
"attach " write
|
2008-02-15 00:29:06 -05:00
|
|
|
current-process-handle number>string print
|
2008-02-14 21:27:04 -05:00
|
|
|
"disassemble " write
|
|
|
|
[ number>string write bl ] each
|
2008-02-15 23:20:31 -05:00
|
|
|
] with-file-writer ;
|
2008-02-14 21:27:04 -05:00
|
|
|
|
|
|
|
: run-gdb ( -- lines )
|
2008-02-14 18:56:47 -05:00
|
|
|
[
|
|
|
|
+closed+ +stdin+ set
|
2008-02-14 21:27:04 -05:00
|
|
|
out-file +stdout+ set
|
|
|
|
[ "gdb" , "-x" , in-file , "-batch" , ] { } make +arguments+ set
|
|
|
|
] { } make-assoc run-process drop
|
|
|
|
out-file file-lines ;
|
|
|
|
|
|
|
|
: tabs>spaces ( str -- str' )
|
2008-02-15 20:23:38 -05:00
|
|
|
{ { CHAR: \t CHAR: \s } } substitute ;
|
2008-02-14 18:56:47 -05:00
|
|
|
|
|
|
|
: disassemble ( word -- )
|
2008-02-14 21:27:04 -05:00
|
|
|
make-disassemble-cmd run-gdb
|
2008-02-15 03:12:40 -05:00
|
|
|
[ tabs>spaces ] map [ print ] each ;
|