Index: frysk-core/frysk/proc/LinuxTask.java =================================================================== RCS file: /cvs/frysk/frysk-core/frysk/proc/LinuxTask.java,v retrieving revision 1.30 diff -u -r1.30 LinuxTask.java --- frysk-core/frysk/proc/LinuxTask.java 20 Jul 2006 15:58:38 -0000 1.30 +++ frysk-core/frysk/proc/LinuxTask.java 31 Jul 2006 09:14:48 -0000 @@ -44,11 +44,7 @@ import frysk.sys.PtraceByteBuffer; import frysk.sys.Sig; import frysk.sys.Signal; -import lib.elf.Elf; -import lib.elf.ElfEMachine; -import lib.elf.ElfCommand; -import lib.elf.ElfEHeader; -import lib.elf.ElfException; + import inua.eio.ByteBuffer; import inua.eio.ByteOrder; import java.util.logging.Level; @@ -57,11 +53,10 @@ * Linux implementation of Task. */ -public class LinuxTask - extends Task +public class LinuxTask extends Task { private long ptraceOptions = 0; - + // XXX: For moment wire in standard 32-bit little-endian memory // map. This will be replaced by a memory map created using // information from /proc/PID/maps. @@ -70,25 +65,27 @@ // XXX: For writing at least, PTRACE must be used as /proc/mem // cannot be written to. memory = new PtraceByteBuffer (id.id, PtraceByteBuffer.Area.DATA, - 0xffffffffl); + 0xffffffffl); memory.order (ByteOrder.LITTLE_ENDIAN); // XXX: For moment wire in a standard 32-bit little-endian // register set. - registerBank = new ByteBuffer[] { - new PtraceByteBuffer (id.id, PtraceByteBuffer.Area.USR) - }; + registerBank = new ByteBuffer[] + { + new PtraceByteBuffer (id.id, PtraceByteBuffer.Area.USR) + }; + registerBank[0].order (ByteOrder.LITTLE_ENDIAN); } - + /** * Create a new unattached Task. */ - LinuxTask (Proc proc, TaskId id) - throws Task.TaskException + LinuxTask (Proc proc, TaskId id) throws Task.TaskException { super (proc, id); setupMapsXXX (); } + /** * Create a new attached clone of Task. */ @@ -98,6 +95,7 @@ super (task, clone); setupMapsXXX (); } + /** * Create a new attached main Task of Proc. */ @@ -107,7 +105,7 @@ super (proc, attached); setupMapsXXX (); } - + /** * Must inject disappeared events back into the event loop so that * they can be processed in sequence. Calling @@ -117,44 +115,52 @@ private void postDisappearedEvent (final Throwable arg) { logger.log (Level.FINE, "{0} postDisappearedEvent\n", this); - Manager.eventLoop.add (new TaskEvent () + Manager.eventLoop.add (new TaskEvent () { - Throwable w = arg; - public void execute () - { - processDisappearedEvent (w); - } + Throwable w = arg; + public void execute () + { + processDisappearedEvent (w); + } }); } - + protected void sendContinue (int sig) { logger.log (Level.FINE, "{0} sendContinue\n", this); - try { - Ptrace.cont (getTid (), sig); - } - catch (Errno.Esrch e) { - postDisappearedEvent (e); - } + try + { + Ptrace.cont (getTid (), sig); + } + catch (Errno.Esrch e) + { + postDisappearedEvent (e); + } } - protected void sendSyscallContinue(int sig){ + + protected void sendSyscallContinue(int sig) + { logger.log(Level.FINE, "{0} sendSyscallContinue\n", this); - try { - Ptrace.sysCall (getTid (), sig); - } - catch (Errno.Esrch e) { - postDisappearedEvent (e); - } + try + { + Ptrace.sysCall (getTid (), sig); + } + catch (Errno.Esrch e) + { + postDisappearedEvent (e); + } } protected void sendStepInstruction (int sig) { logger.log (Level.FINE, "{0} sendStepInstruction\n", this); - try { - Ptrace.singleStep (getTid (), sig); - } - catch (Errno.Esrch e) { - postDisappearedEvent (e); - } + try + { + Ptrace.singleStep (getTid (), sig); + } + catch (Errno.Esrch e) + { + postDisappearedEvent (e); + } } protected void sendStop () { @@ -164,33 +170,38 @@ protected void sendSetOptions () { logger.log (Level.FINE, "{0} sendSetOptions\n", this); - try { - // XXX: Should be selecting the trace flags based on the - // contents of .observers. - ptraceOptions |= Ptrace.optionTraceClone (); - ptraceOptions |= Ptrace.optionTraceFork (); - ptraceOptions |= Ptrace.optionTraceExit (); - // ptraceOptions |= Ptrace.optionTraceSysgood (); not set by default - ptraceOptions |= Ptrace.optionTraceExec (); - Ptrace.setOptions (getTid (), ptraceOptions); - } - catch (Errno.Esrch e) { - postDisappearedEvent (e); - } + try + { + // XXX: Should be selecting the trace flags based on the + // contents of .observers. + ptraceOptions |= Ptrace.optionTraceClone (); + ptraceOptions |= Ptrace.optionTraceFork (); + ptraceOptions |= Ptrace.optionTraceExit (); + // ptraceOptions |= Ptrace.optionTraceSysgood (); not set by default + ptraceOptions |= Ptrace.optionTraceExec (); + Ptrace.setOptions (getTid (), ptraceOptions); + } + catch (Errno.Esrch e) + { + postDisappearedEvent (e); + } } protected void sendAttach () { logger.log (Level.FINE, "{0} sendAttach\n", this); - try { - Ptrace.attach (getTid ()); - } - catch (Errno.Eperm e) { - logger.log (Level.FINE, "{" + e.toString () - + "} Cannot attach to process\n"); - } - catch (Errno.Esrch e) { - postDisappearedEvent (e); - } + try + { + Ptrace.attach (getTid ()); + } + catch (Errno.Eperm e) + { + logger.log (Level.FINE, "{" + e.toString () + + "} Cannot attach to process\n"); + } + catch (Errno.Esrch e) + { + postDisappearedEvent (e); + } } protected void sendDetach (int sig) { @@ -198,37 +209,18 @@ Ptrace.detach (getTid (), sig); } - // Keep this around in an instance variable; it might be useful for - // diggging various things out of the executable. - private Elf elfFile; - - protected Isa sendrecIsa () - throws Task.TaskException + protected Isa sendrecIsa () throws Task.TaskException { logger.log (Level.FINE, "{0} sendrecIsa\n", this); - try - { - elfFile = new Elf(getTid(), ElfCommand.ELF_C_READ); - } - catch (ElfException e) - { - throw (TaskException) - (new TaskException("getting task's executable").initCause(e)); - } - - ElfEHeader header = elfFile.getEHeader(); - // XXX hardcoded until we have a factory for producing Isa objects - if (header.machine == ElfEMachine.EM_386) - { - return LinuxIa32.isaSingleton (); - } - else if (header.machine == ElfEMachine.EM_X86_64) + IsaFactory factory = IsaFactory.getFactory(); + + try { - return LinuxEMT64.isaSingleton (); + return factory.getIsa(id.id); } - else + catch (RuntimeException e) { - throw new TaskException("Unknown machine type " + header.machine); + throw (TaskException) (new TaskException("").initCause(e)); } } @@ -244,5 +236,4 @@ ptraceOptions &= ~(Ptrace.optionTraceSysgood ()); this.sendSetOptions(); } - }