/* 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.Linq; using dnSpy.Contracts.Debugger.Breakpoints.Code; using dnSpy.Contracts.Metadata; namespace dnSpy.Contracts.Debugger.DotNet.Breakpoints.Code { /// /// Creates breakpoints and tracepoints /// public abstract class DbgDotNetBreakpointFactory { /// /// Creates an enabled breakpoint. If there's already a breakpoint at the location, null is returned. /// /// Module /// Token of a method within the module /// IL offset of the breakpoint within the method body /// public DbgCodeBreakpoint? Create(ModuleId module, uint token, uint offset) => Create(module, token, offset, new DbgCodeBreakpointSettings { IsEnabled = true }); /// /// Creates an enabled tracepoint. If there's already a breakpoint at the location, null is returned. /// /// Module /// Token of a method within the module /// IL offset of the tracepoint within the method body /// Message /// public DbgCodeBreakpoint? CreateTracepoint(ModuleId module, uint token, uint offset, string message) => Create(module, token, offset, new DbgCodeBreakpointSettings { IsEnabled = true, Trace = new DbgCodeBreakpointTrace(message, @continue: true) }); /// /// Creates a breakpoint or a tracepoint. If there's already a breakpoint at the location, null is returned. /// /// Module /// Token of a method within the module /// IL offset of the breakpoint within the method body /// Breakpoint settings /// public DbgCodeBreakpoint? Create(ModuleId module, uint token, uint offset, DbgCodeBreakpointSettings settings) => Create(new[] { new DbgDotNetBreakpointInfo(module, token, offset, settings) }).FirstOrDefault(); /// /// Creates breakpoints or tracepoints. Duplicate breakpoints are ignored. /// /// Breakpoint infos /// public abstract DbgCodeBreakpoint[] Create(DbgDotNetBreakpointInfo[] breakpoints); /// /// Returns an existing breakpoint or null if none exists /// /// Module /// Token of a method within the module /// IL offset of the breakpoint within the method body /// public abstract DbgCodeBreakpoint? TryGetBreakpoint(ModuleId module, uint token, uint offset); } /// /// Contains all required data to create a breakpoint /// public readonly struct DbgDotNetBreakpointInfo { /// /// Module /// public ModuleId Module { get; } /// /// Token of a method within the module /// public uint Token { get; } /// /// IL offset of the breakpoint within the method body /// public uint Offset { get; } /// /// Breakpoint settings /// public DbgCodeBreakpointSettings Settings { get; } /// /// Constructor /// /// Module /// Token of a method within the module /// IL offset of the breakpoint within the method body /// Breakpoint settings public DbgDotNetBreakpointInfo(ModuleId module, uint token, uint offset, DbgCodeBreakpointSettings settings) { Module = module; Token = token; Offset = offset; Settings = settings; } } }