Improved disassembler a bit

db4
Slava Pestov 2008-02-14 20:27:04 -06:00
parent f944f2b20c
commit 15ba74aaf8
2 changed files with 32 additions and 19 deletions

View File

@ -1 +1,2 @@
Slava Pestov
Jorge Acereda Macia

View File

@ -1,31 +1,43 @@
! Copyright (C) 2008 Slava Pestov, Jorge Acereda Macia.
! See http://factorcode.org/license.txt for BSD license.
USING: io.files io words alien kernel math.parser alien.syntax
io.launcher system assocs arrays ;
io.launcher system assocs arrays sequences namespaces qualified
regexp system math ;
QUALIFIED: unix
IN: tools.disassembler
GENERIC: make-disassemble-cmd ( word -- file )
: in-file "gdb-in.txt" resource-path ;
: out-file "gdb-out.txt" resource-path ;
GENERIC: make-disassemble-cmd ( obj -- )
M: word make-disassemble-cmd
word-xt 2array make-disassemble-cmd ;
word-xt cell - 2array make-disassemble-cmd ;
M: pair make-disassemble-cmd
"gdb.txt" resource-path [
[
"disassemble " write
[ number>string write bl ] each
] with-file-out
] keep ;
in-file [
"attach " write
unix:getpid number>string print
: run-gdb ( cmds -- output )
"disassemble " write
[ number>string write bl ] each
] with-file-out ;
: run-gdb ( -- lines )
[
+closed+ +stdin+ set
[
"gdb" ,
vm ,
getpid number>string ,
"-x" , ,
"-batch" ,
] { } make +arguments+ set
] { } make-assoc <process-stream> contents ;
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' )
[ dup CHAR: \t = [ drop CHAR: \s ] when ] map ;
: disassemble ( word -- )
make-disassemble-cmd run-gdb write ;
make-disassemble-cmd run-gdb
[ relevant? ] subset [ tabs>spaces ] map [ print ] each ;