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-14 21:38:46 -05:00
|
|
|
regexp system math sequences.lib ;
|
2008-02-14 21:27:04 -05:00
|
|
|
QUALIFIED: unix
|
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-14 21:27:04 -05:00
|
|
|
word-xt cell - 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
|
|
|
|
unix:getpid number>string print
|
|
|
|
|
|
|
|
"disassemble " write
|
|
|
|
[ number>string write bl ] each
|
|
|
|
] with-file-out ;
|
|
|
|
|
|
|
|
: 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 ;
|
|
|
|
|
|
|
|
: relevant? ( line -- ? )
|
|
|
|
R/ 0x.*:.*/ matches? ;
|
|
|
|
|
|
|
|
: tabs>spaces ( str -- str' )
|
2008-02-14 21:38:46 -05:00
|
|
|
CHAR: \t CHAR: \s replace ;
|
2008-02-14 18:56:47 -05:00
|
|
|
|
|
|
|
: disassemble ( word -- )
|
2008-02-14 21:27:04 -05:00
|
|
|
make-disassemble-cmd run-gdb
|
|
|
|
[ relevant? ] subset [ tabs>spaces ] map [ print ] each ;
|