/*
Copyright (C) 2014-2019 de4dot@gmail.com
This file is part of dnSpy
dnSpy is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
dnSpy is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with dnSpy. If not, see .
*/
using System;
using dnSpy.Contracts.Debugger.Breakpoints.Code;
using dnSpy.Contracts.Debugger.Code;
using dnSpy.Contracts.Debugger.Engine.CallStack;
using dnSpy.Contracts.Debugger.Engine.Steppers;
namespace dnSpy.Contracts.Debugger.Engine {
///
/// A debug engine contains all the logic to control the debugged process
///
public abstract class DbgEngine : DbgObject {
///
/// How was the debugged process started?
///
public abstract DbgStartKind StartKind { get; }
///
/// Contains properties used to create a . This property is called
/// after the engine has connected and just before the instance is
/// created.
///
public abstract DbgEngineRuntimeInfo RuntimeInfo { get; }
///
/// Gets all debug tags, see
///
public abstract string[] DebugTags { get; }
///
/// What is being debugged. This is shown in the UI (eg. Processes window)
///
public abstract string[] Debugging { get; }
///
/// Called when the engine can start or attach to the debugged process. This method is called shortly after
/// this instance gets created by a call to .
/// It must send a message when it has connected to the program or
/// if it failed.
///
/// Same options that were passed to
public abstract void Start(DebugProgramOptions options);
///
/// Raised when there's a new message. It can be raised on any thread.
///
public abstract event EventHandler? Message;
///
/// Creates a instance. It's called by the runtime constructor.
///
/// Runtime instance
///
public abstract DbgInternalRuntime CreateInternalRuntime(DbgRuntime runtime);
///
/// Called when its connected message has been received by
///
/// Object factory
/// Runtime
public abstract void OnConnected(DbgObjectFactory objectFactory, DbgRuntime runtime);
///
/// Pauses the debugged program, if it's not already paused. This is an asynchronous method.
/// Once the program is paused (even if it already was paused), message
/// must be sent.
///
public abstract void Break();
///
/// Lets the program run again. This is an asynchronous method. No message is sent.
///
public abstract void Run();
///
/// Terminates the debugged program. This is an asynchronous method.
///
/// This method gets called when the user chooses Terminate All from the Debug menu
///
/// When the program has been terminated or detached, message
/// must be sent.
///
public abstract void Terminate();
///
/// true if the engine can detach from the debugged program without terminating it.
///
public abstract bool CanDetach { get; }
///
/// Detaches from the debugged program. If it's not possible, the program must be terminated.
/// This is an asynchronous method.
///
/// This method gets called when the user chooses Detach All from the Debug menu.
///
/// When the program has been terminated or detached, message
/// must be sent.
///
public abstract void Detach();
///
/// Freezes the thread
///
/// Thread
public abstract void Freeze(DbgThread thread);
///
/// Thaws the thread
///
/// Thread
public abstract void Thaw(DbgThread thread);
///
/// Removes all breakpoints. There's no guarantee that this method will be called to delete all bound breakpoints.
/// To always get notified when a bound breakpoint gets deleted, add custom data that implements
/// when creating the bound breakpoint, see eg.
///
/// Modules
/// Bound breakpoints
/// If false, remove breakpoints that exist in , and if true,
/// remove breakpoints that exist in and all breakpoints not in a
public abstract void RemoveBreakpoints(DbgModule[] modules, DbgBoundCodeBreakpoint[] boundBreakpoints, bool includeNonModuleBreakpoints);
///
/// Adds all breakpoints. To get notified when a bound breakpoint gets deleted, add custom data that implements
/// when creating the bound breakpoint, see eg.
///
/// Modules
/// Breakpoint locations. The engine can ignore non-supported locations.
/// If false, add breakpoints that exist in , and if true,
/// add breakpoints that exist in and all breakpoints not in a
public abstract void AddBreakpoints(DbgModule[] modules, DbgCodeLocation[] locations, bool includeNonModuleBreakpoints);
///
/// Creates a stack walker
///
/// Thread created by this engine
///
public abstract DbgEngineStackWalker CreateStackWalker(DbgThread thread);
///
/// Creates a stepper
///
/// Thread to step
///
public abstract DbgEngineStepper CreateStepper(DbgThread thread);
///
/// Sets a new instruction pointer
///
/// Thread
/// New location
public abstract void SetIP(DbgThread thread, DbgCodeLocation location);
///
/// Checks if can be called
///
/// Thread
/// New location
///
public abstract bool CanSetIP(DbgThread thread, DbgCodeLocation location);
}
///
/// Start kind
///
public enum DbgStartKind {
///
/// The program was started by the debugger
///
Start,
///
/// The debugger attached to the program after it was started by someone else
///
Attach,
}
}