| 
									
										
										
										
											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-09-10 21:07:00 -04:00
										 |  |  | io.launcher system assocs arrays sequences namespaces make | 
					
						
							|  |  |  | qualified system math compiler.generator.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 | 
					
						
							| 
									
										
										
										
											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-16 23:17:41 -05:00
										 |  |  |     in-file ascii [ | 
					
						
							| 
									
										
										
										
											2008-02-14 21:27:04 -05:00
										 |  |  |         "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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-13 04:51:25 -04:00
										 |  |  | M: method-spec make-disassemble-cmd | 
					
						
							|  |  |  |     first2 method make-disassemble-cmd ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-06 20:28:47 -04:00
										 |  |  | : 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 | 
					
						
							| 
									
										
										
										
											2008-02-16 23:17:41 -05:00
										 |  |  |     out-file ascii file-lines ;
 | 
					
						
							| 
									
										
										
										
											2008-02-14 21:27:04 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-09 20:43:46 -04: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 | 
					
						
							| 
									
										
										
										
											2008-02-15 03:12:40 -05:00
										 |  |  |     [ tabs>spaces ] map [ print ] each ;
 |