java.lang.Object
com.ibm.j9ddr.corereaders.tdump.zebedee.le.FunctionEmulator
This class acts as a more convenient way of using the
Emulator
class.
Because it is in the LE package it adds the following benefits:
- it knows the XPLINK calling conventions
- sets up the stack automatically
- can obtain a function address and environment from a function name
- provides tracing including function entry and exit
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
This interface is similar to Emulator.CallbackFunction except that it adds the ability to set the return value from the function (which is XPLINK specific).static class
This exception can be thrown by callback functions which want to call the overridden function.class
This class represents a called function.class
Describes a trace entry -
Constructor Summary
ConstructorsConstructorDescriptionFunctionEmulator
(AddressSpace space, long functionEntryPoint, long functionEnv) Create a new FunctionEmulator.FunctionEmulator
(AddressSpace space, String functionName) Create a new FunctionEmulator. -
Method Summary
Modifier and TypeMethodDescriptionlong
Register a dummy return address.long
getArgument
(int argNumber) Gets the given function argument.Returns the root of the call tree.Returns the current function.Returns theEmulator
object we use.Returns the MutableAddressSpace used by the emulator.long
Return the xplink stack floor.Return a list of the instruction trace entriesvoid
overrideFunction
(long functionEntryPoint, FunctionEmulator.CallbackFunction callback) Allows the given function to be "overridden".void
overrideFunction
(String functionName, long returnValue) void
overrideFunction
(String functionName, long retVal, boolean protect) void
overrideFunction
(String functionName, FunctionEmulator.CallbackFunction callback) Allows the given function to be "overridden".void
void
Run the emulator and record any called functions as newDllFunction
s.long
Registers a callback function.long
run()
Now run the emulator.long
run
(long functionPointer) Run the emulator using the supplied xplink C function pointer.long
Run the emulator using the supplied xplink C function.void
Run all paths of the function.void
setArgument
(int argNumber, int value) Sets the given function argument.void
setArgument
(int argNumber, long value) Sets the given function argument.void
setBranchInstructionTracing
(boolean branchInstructionTrace) Turn branch instruction tracing on or off.void
Turn call tree capturing on.void
setInstructionRecording
(boolean instructionRecord) Turn instruction recording on or off.void
setInstructionTracing
(boolean instructionTrace) Turn instruction tracing on or off.void
setPrintOffsets
(boolean printOffsets) Include instruction offsets from the start of the function when tracing.
-
Constructor Details
-
FunctionEmulator
public FunctionEmulator(AddressSpace space, String functionName) throws IOException, NoSuchMethodException Create a new FunctionEmulator.- Parameters:
space
- the AddressSpace containing the code and data we are to usefunctionName
- the name of the function to call- Throws:
NoSuchMethodException
- if the given function can't be foundIOException
-
FunctionEmulator
public FunctionEmulator(AddressSpace space, long functionEntryPoint, long functionEnv) throws IOException, NoSuchMethodException Create a new FunctionEmulator. This is a raw form where the address of the function entry point and env are supplied. Note that the so-called "environment" pointer is not required by all functions. It is the value that is stored in R5. If you do need to know it you can sometimes find it by looking in the DSA of the function to find the saved value (assuming the dump has the function in one of the stacks!).- Parameters:
space
- the AddressSpace containing the code and data we are to usefunctionEntryPoint
- the address of the function entry pointfunctionEnv
- the address of the "environment" for the function (not all functions require this to be set)- Throws:
NoSuchMethodException
- if the given function can't be foundIOException
-
-
Method Details
-
getStackFloor
public long getStackFloor()Return the xplink stack floor. Be careful with this. -
createDummyReturnAddress
Register a dummy return address. When this is branched to we simply stop the emulator- Throws:
IOException
-
setPrintOffsets
public void setPrintOffsets(boolean printOffsets) Include instruction offsets from the start of the function when tracing. XXX doesn't yet work for called functions -
setInstructionTracing
public void setInstructionTracing(boolean instructionTrace) Turn instruction tracing on or off. A trace of all instructions executed will be sent to System.out. -
setInstructionRecording
public void setInstructionRecording(boolean instructionRecord) Turn instruction recording on or off. A trace of all instructions executed will be saved. -
getTraceEntries
Return a list of the instruction trace entries -
setBranchInstructionTracing
public void setBranchInstructionTracing(boolean branchInstructionTrace) Turn branch instruction tracing on or off. A trace of all branch instructions executed will be sent to System.out. -
setCallTreeCapture
public void setCallTreeCapture()Turn call tree capturing on. The call tree may be retrieved withgetCallTreeRoot()
. -
getCallTreeRoot
Returns the root of the call tree.setCallTreeCapture()
must have been called prior to the emulator having run. These routines can be used to obtain the actual call tree during a run of the emulator. Note that the root function is a dummy one. -
getCurrentFunction
Returns the current function. User callbacks can make use of this. -
getEmulator
Returns theEmulator
object we use. -
setArgument
public void setArgument(int argNumber, int value) Sets the given function argument.- Parameters:
argNumber
- the number of the argument to be set, starting at one (XXX currently limited to a max of 3)value
- the value of the argument
-
setArgument
public void setArgument(int argNumber, long value) Sets the given function argument.- Parameters:
argNumber
- the number of the argument to be set, starting at one (XXX currently limited to a max of 3)value
- the value of the argument
-
getArgument
public long getArgument(int argNumber) Gets the given function argument. To be used from callback functions.- Parameters:
argNumber
- the number of the argument to be got, starting at one
-
getMutableAddressSpace
Returns the MutableAddressSpace used by the emulator. This can be used by users wishing to allocate space for input arguments for instance. -
registerCallbackFunction
Registers a callback function.- Returns:
- the address of the linkage pointer. This is what you put in place of a C function pointer.
-
overrideFunction
public void overrideFunction(String functionName, FunctionEmulator.CallbackFunction callback) throws IOException, NoSuchMethodException Allows the given function to be "overridden". The supplied callback function will be called rather than the real one.- Parameters:
functionName
- the name of the function to overridecallback
- the user function that will be called rather than the real one- Throws:
IOException
NoSuchMethodException
-
overrideFunction
public void overrideFunction(long functionEntryPoint, FunctionEmulator.CallbackFunction callback) throws IOException, NoSuchMethodException Allows the given function to be "overridden". The supplied callback function will be called rather than the real one. This is the raw version of overrideFunction that takes the address of the function.- Parameters:
functionEntryPoint
- the address of the function entry pointcallback
- the user function that will be called rather than the real one- Throws:
IOException
NoSuchMethodException
-
overrideFunction
-
overrideFunction
-
run
Now run the emulator. This method returns when the emulated function returns.- Returns:
- the return value from the function (if any)
- Throws:
IOException
-
run
Run the emulator using the supplied xplink C function pointer. This method returns when the emulated function returns.- Returns:
- the return value from the function (if any)
- Throws:
IOException
-
run
Run the emulator using the supplied xplink C function. This method returns when the emulated function returns.- Returns:
- the return value from the function (if any)
- Throws:
IOException
NoSuchMethodException
-
recordCalledFunctions
Run the emulator and record any called functions as newDllFunction
s. The purpose of this method is to obtain the entry points for functions which are not in the export list for a DLL. The emulator is run and any functions called are saved as fake DllFunction entries which may then be obtained usingDll.getFunction(java.lang.String)
.- Throws:
IOException
-
recordAllCalledFunctions
- Throws:
IOException
-
runAllPaths
Run all paths of the function. This is used for disassembly.- Throws:
IOException
-