home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / jËzyki_programowania / clisp / src / archive / clisp.faslsp.lha / disassem.lsp < prev    next >
Lisp/Scheme  |  1996-04-15  |  2KB  |  53 lines

  1. ;; Disassemble some machine code.
  2. ;; Bruno Haible 1995
  3.  
  4. ;; This is in a separate file so you can easily customize it to your needs.
  5.  
  6. (in-package "COMPILER")
  7.  
  8. #+(or UNIX WIN32-UNIX)
  9. (defun disassemble-machine-code (program-name pid address)
  10.   ; This uses gdb.
  11.   (let ((tempfilename (format nil "/tmp/gdbcomm~D" pid))
  12.         (outfilename (format nil "/tmp/gdbdis~D" pid)))
  13.     (with-open-file (f tempfilename :direction :output)
  14.       (format f "set height 100000~%")   ; inhibit pausing after every 23 lines
  15.                                          ; (remove this if your gdb doesn't understand it)
  16.       (format f "attach ~D~%" pid)       ; attach to the lisp.run process
  17.       (format f "x/10000i ~A~%" address) ; disassemble
  18.       (format f "detach~%")              ; let lisp.run continue
  19.       (format f "quit~%")                ; quit the debugger
  20.     )
  21.     ; Run gdb, capture only the lines beginning with 0x and remove the first line.
  22.     ; Let lisp.run continue (just in case the debugger didn't detach properly).
  23.     (shell (format nil "~A -n -batch -x ~A ~A < /dev/null | grep '^0' | sed -e 1d > ~A ; kill -CONT ~D"
  24.                         "gdb" tempfilename program-name outfilename pid
  25.     )      )
  26.     (delete-file tempfilename)
  27.     ; Now let the user view the listing.
  28.     (shell (format nil "~A ~A" (or (sys::getenv "PAGER") "more") outfilename))
  29.     (delete-file outfilename)
  30.   )
  31.   #| ; This uses SunOS dbx. (Untested.)
  32.   (let ((tempfilename (format nil "/tmp/dbxcomm~D" pid)))
  33.     (with-open-file (f tempfilename :direction :output)
  34.       (format f "~A/100i~%" address) ; disassemble
  35.       (format f "detach~%")          ; let lisp.run continue
  36.       (format f "quit~%")            ; quit the debugger
  37.     )
  38.     (shell (format nil "~A -s ~A ~A ~D" "dbx" tempfilename program-name pid))
  39.   )
  40.   |#
  41.   #| ; This uses AIX dbx. (Untested.)
  42.   (let ((tempfilename (format nil "/tmp/dbxcomm~D" pid)))
  43.     (with-open-file (f tempfilename :direction :output)
  44.       (format f "~A/100i~%" address) ; disassemble
  45.       (format f "detach~%")          ; let lisp.run continue
  46.       (format f "quit~%")            ; quit the debugger
  47.     )
  48.     (shell (format nil "~A -c ~A -a ~D ~A" "dbx" tempfilename pid program-name))
  49.   )
  50.   |#
  51.   (values)
  52. )
  53.