/*
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;
namespace dnSpy.Contracts.Debugger.Engine {
///
/// A class that can update a
///
public abstract class DbgEngineBoundCodeBreakpoint {
///
/// Gets the bound breakpoint
///
public abstract DbgBoundCodeBreakpoint BoundCodeBreakpoint { get; }
///
/// Removes this bound breakpoint
///
public abstract void Remove();
///
/// Removes bound breakpoints
///
/// Breakpoints to remove
public abstract void Remove(DbgEngineBoundCodeBreakpoint[] breakpoints);
///
/// Properties to update
///
[Flags]
public enum UpdateOptions {
///
/// No option is enabled
///
None = 0,
///
/// Update
///
Module = 0x00000001,
///
/// Update
///
Address = 0x00000002,
///
/// Update
///
Message = 0x00000004,
}
///
/// Updates
///
/// New value
public void UpdateModule(DbgModule module) => Update(UpdateOptions.Module, module: module);
///
/// Updates
///
/// New value
public void UpdateAddress(ulong address) => Update(UpdateOptions.Address, address: address);
///
/// Updates
///
/// New value
public void UpdateMessage(DbgEngineBoundCodeBreakpointMessage message) => Update(UpdateOptions.Message, message: message);
///
/// Updates properties
///
/// Options
/// New value
/// New value
/// New value
public abstract void Update(UpdateOptions options, DbgModule? module = null, ulong address = 0, DbgEngineBoundCodeBreakpointMessage message = default);
}
///
/// Bound breakpoint message kind
///
public enum DbgEngineBoundCodeBreakpointMessageKind {
///
/// No warning or error, the breakpoint will break when hit
///
None,
///
/// Custom warning message
///
CustomWarning,
///
/// Custom error message
///
CustomError,
///
/// Function wasn't found
///
FunctionNotFound,
///
/// A breakpoint could not be created
///
CouldNotCreateBreakpoint,
}
///
/// Bound breakpoint message
///
public readonly struct DbgEngineBoundCodeBreakpointMessage {
///
/// Message kind
///
public DbgEngineBoundCodeBreakpointMessageKind Kind { get; }
///
/// Arguments
///
public string[] Arguments { get; }
DbgEngineBoundCodeBreakpointMessage(DbgEngineBoundCodeBreakpointMessageKind kind, string[] arguments) {
Kind = kind;
Arguments = arguments ?? throw new ArgumentNullException(nameof(arguments));
}
///
/// Creates a no-error message
///
///
public static DbgEngineBoundCodeBreakpointMessage CreateNoError() =>
new DbgEngineBoundCodeBreakpointMessage(DbgEngineBoundCodeBreakpointMessageKind.None, Array.Empty());
///
/// Creates a custom warning message
///
/// Message
///
public static DbgEngineBoundCodeBreakpointMessage CreateCustomWarning(string message) =>
new DbgEngineBoundCodeBreakpointMessage(DbgEngineBoundCodeBreakpointMessageKind.CustomWarning, new[] { message ?? throw new ArgumentNullException(nameof(message)) });
///
/// Creates a custom error message
///
/// Message
///
public static DbgEngineBoundCodeBreakpointMessage CreateCustomError(string message) =>
new DbgEngineBoundCodeBreakpointMessage(DbgEngineBoundCodeBreakpointMessageKind.CustomError, new[] { message ?? throw new ArgumentNullException(nameof(message)) });
///
/// Creates a function-not-found message
///
/// Name of function
///
public static DbgEngineBoundCodeBreakpointMessage CreateFunctionNotFound(string function) =>
new DbgEngineBoundCodeBreakpointMessage(DbgEngineBoundCodeBreakpointMessageKind.FunctionNotFound, new[] { function ?? throw new ArgumentNullException(nameof(function)) });
///
/// Creates a could-not-create-breakpoint message
///
///
public static DbgEngineBoundCodeBreakpointMessage CreateCouldNotCreateBreakpoint() =>
new DbgEngineBoundCodeBreakpointMessage(DbgEngineBoundCodeBreakpointMessageKind.CouldNotCreateBreakpoint, Array.Empty());
}
}