/*
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 System.Collections.Generic;
using System.Collections.ObjectModel;
namespace dnSpy.Contracts.Debugger {
///
/// A runtime in a process
///
public abstract class DbgRuntime : DbgObject {
///
/// Gets the process
///
public abstract DbgProcess Process { get; }
///
/// Gets the process unique runtime id. There must be exactly one such id per process.
///
public abstract RuntimeId Id { get; }
///
/// Gets the runtime GUID, see
///
public abstract Guid Guid { get; }
///
/// Gets the runtime kind GUID, see
///
public abstract Guid RuntimeKindGuid { get; }
///
/// Gets the runtime name
///
public abstract string Name { get; }
///
/// Gets all runtime tags
///
public abstract ReadOnlyCollection Tags { get; }
///
/// Gets the runtime object created by the debug engine
///
public abstract DbgInternalRuntime InternalRuntime { get; }
///
/// Gets all app domains
///
public abstract DbgAppDomain[] AppDomains { get; }
///
/// Raised when is changed
///
public abstract event EventHandler>? AppDomainsChanged;
///
/// Gets all modules
///
public abstract DbgModule[] Modules { get; }
///
/// Raised when is changed
///
public abstract event EventHandler>? ModulesChanged;
///
/// Gets all threads
///
public abstract DbgThread[] Threads { get; }
///
/// Raised when is changed
///
public abstract event EventHandler>? ThreadsChanged;
///
/// Gets the break infos, it gets updated when the runtime breaks and cleared when it continues.
///
public abstract ReadOnlyCollection BreakInfos { get; }
///
/// Closes just before the runtime continues (or when it gets closed if it never continues)
///
/// Object
public abstract void CloseOnContinue(DbgObject obj);
///
/// Closes just before the runtime continues (or when it gets closed if it never continues)
///
/// Objects
public abstract void CloseOnContinue(IEnumerable objs);
///
/// Closes when the runtime closes
///
/// Object
public void CloseOnExit(DbgObject obj) => CloseOnExit(new[] { obj ?? throw new ArgumentNullException(nameof(obj)) });
///
/// Closes when the runtime closes
///
/// Objects
public abstract void CloseOnExit(IEnumerable objs);
///
/// Closes when the runtime closes
///
/// Object
public void CloseOnExit(IDisposable obj) => CloseOnExit(new[] { obj ?? throw new ArgumentNullException(nameof(obj)) });
///
/// Closes when the runtime closes
///
/// Objects
public abstract void CloseOnExit(IEnumerable objs);
}
///
/// Break info kind
///
public enum DbgBreakInfoKind {
///
/// Unknown break reason
///
Unknown,
///
/// We've connected to the debugged process
///
Connected,
///
/// It's paused due to some debug message. is a
///
Message,
}
///
/// Break info
///
public readonly struct DbgBreakInfo {
///
/// Gets the kind
///
public DbgBreakInfoKind Kind { get; }
///
/// Gets the data, see for more info
///
public object? Data { get; }
///
/// Constructor
///
/// Kind
/// Data
public DbgBreakInfo(DbgBreakInfoKind kind, object? data) {
Kind = kind;
Data = data;
}
///
/// Constructor
///
/// Debug message
public DbgBreakInfo(DbgMessageEventArgs message) {
Kind = DbgBreakInfoKind.Message;
Data = message ?? throw new ArgumentNullException(nameof(message));
}
///
/// ToString()
///
///
public override string ToString() {
switch (Kind) {
case DbgBreakInfoKind.Unknown:
case DbgBreakInfoKind.Connected:
default:
return Kind.ToString();
case DbgBreakInfoKind.Message:
return $"Debug message: {((DbgMessageEventArgs)Data!).Kind}";
}
}
}
}