/* 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.DotNet.Code; using dnSpy.Contracts.Debugger.Evaluation; namespace dnSpy.Contracts.Debugger.DotNet.Evaluation { /// /// Method debug info used by a .NET debugger language. An instance of this class is attached to /// a , see /// and /// public sealed class DbgLanguageDebugInfo { /// /// Gets the method debug info /// public DbgMethodDebugInfo MethodDebugInfo { get; } /// /// Gets the method token /// public int MethodToken { get; } /// /// Gets the method local variables signature token /// public int LocalVarSigTok { get; } /// /// Gets the method version number, a 1-based number /// public int MethodVersion { get; } /// /// Gets the IL offset /// public uint ILOffset { get; } /// /// Constructor /// /// Method debug info /// Method token /// Method local variables signature token /// Method version number, a 1-based number /// IL offset public DbgLanguageDebugInfo(DbgMethodDebugInfo methodDebugInfo, int methodToken, int localVarSigTok, int methodVersion, uint ilOffset) { if (methodVersion < 1) throw new ArgumentOutOfRangeException(nameof(methodVersion)); MethodDebugInfo = methodDebugInfo ?? throw new ArgumentNullException(nameof(methodDebugInfo)); MethodToken = methodToken; LocalVarSigTok = localVarSigTok; MethodVersion = methodVersion; ILOffset = ilOffset; } } /// /// Extension methods /// public static class DbgLanguageDebugInfoExtensions { /// /// Gets the debug info or null if there's none /// /// Context /// public static DbgLanguageDebugInfo? TryGetLanguageDebugInfo(this DbgEvaluationContext context) { if (context.TryGetData(out var info)) return info; return null; } /// /// Gets the debug info and throws if there is none /// /// Context /// public static DbgLanguageDebugInfo GetLanguageDebugInfo(this DbgEvaluationContext context) { if (context.TryGetData(out var info)) return info; throw new InvalidOperationException(); } /// /// Attaches to /// /// Context /// Debug info public static void SetLanguageDebugInfo(DbgEvaluationContext context, DbgLanguageDebugInfo debugInfo) => context.GetOrCreateData(() => debugInfo); } }