]> gitweb.factorcode.org Git - factor.git/blob - basis/tools/disassembler/gdb/gdb.factor
72a75983d4e8b0de16c02fec5b94da11a5f57d42
[factor.git] / basis / tools / disassembler / gdb / gdb.factor
1 ! Copyright (C) 2008, 2010 Slava Pestov, Jorge Acereda Macia.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors io io.encodings.ascii io.files io.files.temp
4 io.launcher locals make math math.parser namespaces
5 tools.disassembler.private ;
6 IN: tools.disassembler.gdb
7
8 SINGLETON: gdb-disassembler
9
10 <PRIVATE
11
12 TR: tabs>spaces "\t" "\s" ;
13
14 : in-file ( -- path ) "gdb-in.txt" temp-file ;
15
16 : out-file ( -- path ) "gdb-out.txt" temp-file ;
17
18 :: make-disassemble-cmd ( from to -- )
19     in-file ascii [
20         "attach " write
21         (current-process) number>string print
22         "x/" write to from - 4 / number>string write
23         "i" write bl from number>string write
24     ] with-file-writer ;
25
26 : run-gdb ( -- lines )
27     <process>
28         +closed+ >>stdin
29         out-file >>stdout
30         [ "gdb" , "-x" , in-file , "-batch" , ] { } make >>command
31     try-process
32     out-file ascii file-lines ;
33
34 PRIVATE>
35
36 M: gdb-disassembler disassemble*
37     make-disassemble-cmd run-gdb [ tabs>spaces print ] each ;
38
39 gdb-disassembler disassembler-backend set-global