Class DebugSession
- java.lang.Object
-
- com.tonic.analysis.execution.debug.DebugSession
-
public final class DebugSession extends Object
Interactive stepping debugger over aBytecodeEngine, driving breakpoints, step modes, and state snapshots for listeners.
-
-
Constructor Summary
Constructors Constructor Description DebugSession(BytecodeContext context)Creates an idle session with a fresh breakpoint manager.DebugSession(BytecodeContext context, BreakpointManager breakpointManager)Creates an idle session using the given breakpoint manager.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddBreakpoint(Breakpoint bp)Adds a breakpoint to the session's manager.voidaddListener(DebugEventListener listener)Registers a debug event listener.List<Breakpoint>getBreakpoints()List<StackFrame>getCallStack()StackFramegetCurrentFrame()DebugStategetCurrentState()BytecodeEnginegetEngine()BytecodeResultgetResult()Returns the final execution result.DebugSessionStategetState()booleanisPaused()booleanisRunning()booleanisStopped()voidpause()Requests a pause of a running execution at the next instruction boundary.voidremoveBreakpoint(Breakpoint bp)Removes a breakpoint from the session's manager.voidremoveListener(DebugEventListener listener)Unregisters a debug event listener.DebugStateresume()Resumes free-running execution until a breakpoint, pause request, or completion.DebugStaterunToCursor(int pc)Runs until the current method reaches the given pc.voidsetLocalValue(int slot, ConcreteValue value)Overwrites a local variable slot in the current frame while paused.voidsetStackValue(int index, ConcreteValue value)Overwrites an operand stack entry in the current frame while paused.voidstart(MethodEntry method, ConcreteValue... args)Initializes the engine with the method's initial frame and pauses before the first instruction.DebugStatestepInto()Executes a single instruction, pausing inside any invoked method.DebugStatestepOut()Runs until the current frame returns to its caller.DebugStatestepOver()Executes one instruction without pausing inside deeper frames.voidstop()Terminates the session, interrupting the engine and notifying listeners.
-
-
-
Constructor Detail
-
DebugSession
public DebugSession(BytecodeContext context)
Creates an idle session with a fresh breakpoint manager.- Parameters:
context- the execution configuration- Throws:
IllegalArgumentException- if context is null
-
DebugSession
public DebugSession(BytecodeContext context, BreakpointManager breakpointManager)
Creates an idle session using the given breakpoint manager.- Parameters:
context- the execution configurationbreakpointManager- the breakpoint registry to use- Throws:
IllegalArgumentException- if context or breakpointManager is null
-
-
Method Detail
-
getEngine
public BytecodeEngine getEngine()
- Returns:
- the engine
-
getState
public DebugSessionState getState()
- Returns:
- the state
-
start
public void start(MethodEntry method, ConcreteValue... args)
Initializes the engine with the method's initial frame and pauses before the first instruction.- Parameters:
method- the method to debugargs- argument values for the initial frame- Throws:
IllegalStateException- if the session was already started
-
stop
public void stop()
Terminates the session, interrupting the engine and notifying listeners.- Throws:
IllegalStateException- if the session was never started
-
pause
public void pause()
Requests a pause of a running execution at the next instruction boundary.- Throws:
IllegalStateException- if the session is not running
-
resume
public DebugState resume()
Resumes free-running execution until a breakpoint, pause request, or completion.- Returns:
- the state when execution pauses or finishes
- Throws:
IllegalStateException- if the session is idle, stopped, or already running
-
stepInto
public DebugState stepInto()
Executes a single instruction, pausing inside any invoked method.- Returns:
- the state when execution pauses or finishes
- Throws:
IllegalStateException- if the session is idle, stopped, or already running
-
stepOver
public DebugState stepOver()
Executes one instruction without pausing inside deeper frames.- Returns:
- the state when execution pauses or finishes
- Throws:
IllegalStateException- if the session is idle, stopped, or already running
-
stepOut
public DebugState stepOut()
Runs until the current frame returns to its caller.- Returns:
- the state when execution pauses or finishes
- Throws:
IllegalStateException- if the session is idle, stopped, or already running
-
runToCursor
public DebugState runToCursor(int pc)
Runs until the current method reaches the given pc.- Parameters:
pc- the target program counter- Returns:
- the state when execution pauses or finishes
- Throws:
IllegalStateException- if the session cannot step or has no current frame
-
isRunning
public boolean isRunning()
- Returns:
- true if the session is running
-
isPaused
public boolean isPaused()
- Returns:
- true if the session is paused
-
isStopped
public boolean isStopped()
- Returns:
- true if the session is stopped
-
getCurrentState
public DebugState getCurrentState()
- Returns:
- a freshly built snapshot of the session's execution state
-
getResult
public BytecodeResult getResult()
Returns the final execution result.- Returns:
- the result of the finished execution
- Throws:
IllegalStateException- if the session is not stopped
-
addBreakpoint
public void addBreakpoint(Breakpoint bp)
Adds a breakpoint to the session's manager.- Parameters:
bp- the breakpoint to add
-
removeBreakpoint
public void removeBreakpoint(Breakpoint bp)
Removes a breakpoint from the session's manager.- Parameters:
bp- the breakpoint to remove
-
getBreakpoints
public List<Breakpoint> getBreakpoints()
- Returns:
- a copy of all registered breakpoints
-
getCurrentFrame
public StackFrame getCurrentFrame()
- Returns:
- the frame on top of the call stack, or null if not started or empty
-
getCallStack
public List<StackFrame> getCallStack()
- Returns:
- a snapshot of the current call stack, empty if not started
-
setLocalValue
public void setLocalValue(int slot, ConcreteValue value)Overwrites a local variable slot in the current frame while paused.- Parameters:
slot- the local variable slotvalue- the replacement value- Throws:
IllegalStateException- if the session is not paused or there is no current frameIllegalArgumentException- if value is null
-
setStackValue
public void setStackValue(int index, ConcreteValue value)Overwrites an operand stack entry in the current frame while paused.- Parameters:
index- the stack entry indexvalue- the replacement value- Throws:
IllegalStateException- if the session is not paused or there is no current frameIllegalArgumentException- if value is null
-
addListener
public void addListener(DebugEventListener listener)
Registers a debug event listener.- Parameters:
listener- the listener to add; ignored if null
-
removeListener
public void removeListener(DebugEventListener listener)
Unregisters a debug event listener.- Parameters:
listener- the listener to remove; ignored if null
-
-