Changeset 12518


Ignore:
Timestamp:
03/04/10 14:52:35 (11 years ago)
Author:
Mark Evenson
Message:

*DISASSEMBLER* may now contain a function to return the disassembler command.

If *DISASSEMBLER* contains a function it specifies the command string
to use for the DISASSEMBLE primitive by taking an argument for the
pathname containing the class bytes and returning the string of a
command that will output a representation to standard output. We also
change the default suffix of the temporary file to ".class". All of
this now enables "javap" to be used as the dissambler with the
following assignment (in "~/.abclrc" for example):

(setf *disassembler*

(lambda (p)

(let ((class (make-pathname :name (pathname-name p)))

(path (directory-namestring p)))

(format nil "javap -c -l -verbose -classpath ~A ~A" path class))))

It might be nice in the future if ABCL had a default value of
*DISASSEMBLER* that would actually probe the filesystem for the
existence of the various disassmemblers for fallback strategies.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/abcl/src/org/armedbear/lisp/disassemble_class_bytes.java

    r12288 r12518  
    5454            byte[] bytes = (byte[]) ((JavaObject)arg).getObject();
    5555            try {
    56                 File file = File.createTempFile("abcl", null, null);
     56                File file = File.createTempFile("abcl", ".class", null);
    5757                FileOutputStream out = new FileOutputStream(file);
    5858                out.write(bytes);
    5959                out.close();
    6060                LispObject disassembler = _DISASSEMBLER_.symbolValue();
     61                StringBuffer command = new StringBuffer();
    6162                if (disassembler instanceof AbstractString) {
    62                     StringBuffer sb = new StringBuffer(disassembler.getStringValue());
    63                     sb.append(' ');
    64                     sb.append(file.getPath());
    65                     ShellCommand sc = new ShellCommand(sb.toString(), null, null);
    66                     sc.run();
    67                     file.delete();
    68                     return new SimpleString(sc.getOutput());
    69                 } else
     63                    command.append(disassembler.getStringValue());
     64                    command.append(" ");
     65                    command.append(file.getPath());
     66                } else if (disassembler instanceof Operator) {
     67                    Pathname p = Pathname.makePathname(file);
     68                    LispObject commandResult = disassembler.execute(p);
     69                    command.append(commandResult.getStringValue());
     70                } else {
    7071                    return new SimpleString("No disassembler is available.");
    71             }
    72             catch (IOException e) {
     72                }                       
     73                ShellCommand sc = new ShellCommand(command.toString(), null, null);
     74                sc.run();
     75                file.delete();
     76                return new SimpleString(sc.getOutput());
     77            } catch (IOException e) {
    7378                Debug.trace(e);
    7479            }
Note: See TracChangeset for help on using the changeset viewer.