diff options
author | Jonathan CHang <jonathan34c@gmail.com> | 2022-07-18 19:13:19 +0300 |
---|---|---|
committer | Jonathan CHang <jonathan34c@gmail.com> | 2022-07-18 23:30:17 +0300 |
commit | b1dd19e685ba9f658d84be03a06ac365ff92730c (patch) | |
tree | ddf70aa0cad5ca505420bcab57a6ac91763a4340 | |
parent | 7bda4714d11e86bd878f446b3d484c592d9324f2 (diff) |
Provide listed assembly for debugger session
5 files changed, 173 insertions, 6 deletions
diff --git a/Mono.Debugging.Soft/SoftDebuggerSession.cs b/Mono.Debugging.Soft/SoftDebuggerSession.cs index ecd28ca..5661168 100644 --- a/Mono.Debugging.Soft/SoftDebuggerSession.cs +++ b/Mono.Debugging.Soft/SoftDebuggerSession.cs @@ -49,7 +49,8 @@ using Mono.Debugging.Evaluation; using StackFrame = Mono.Debugger.Soft.StackFrame; using System.Collections.Immutable;
-
+using Assembly = Mono.Debugging.Client.Assembly; + namespace Mono.Debugging.Soft { public class SoftDebuggerSession : DebuggerSession @@ -2248,9 +2249,8 @@ namespace Mono.Debugging.Soft if (events.Length > 1 && events.Any (a => a.Assembly != asm)) throw new InvalidOperationException ("Simultaneous AssemblyLoadEvent for multiple assemblies"); - OnAssemblyLoaded(asm.Location); - - RegisterAssembly(asm); + HandleAssemblyLoaded (asm); + RegisterAssembly (asm); bool isExternal; isExternal = !UpdateAssemblyFilters (asm) && userAssemblyNames != null;
@@ -2260,6 +2260,43 @@ namespace Mono.Debugging.Soft } } + private void HandleAssemblyLoaded (AssemblyMirror asm) + { + var symbolStatus = string.Empty; + var assemblyName = string.Empty; + var hasSymbol = false; + var name = asm.GetName (); + var assemblyObject = asm.GetAssemblyObject (); + if (!asm.IsDynamic) { + var metaData = asm.GetMetadata (); + symbolStatus = metaData.MainModule.HasSymbols == true ? "Symbol loaded" : "Skipped loading symbols"; + assemblyName = metaData.MainModule.Name; + hasSymbol = metaData.MainModule.HasSymbols; + } else { + symbolStatus = "Skipped loading symbol (dynamic)"; + assemblyName = "Dynamic assembly"; + hasSymbol = false; + } + var assembly = new Assembly ( + assemblyName, + asm.Location, + true, + hasSymbol, + symbolStatus, + "", + -1, + name.Version.Major.ToString (), + // TODO: module time stamp + "", + assemblyObject.Address.ToString (), + string.Format ("[{0}]{1}", asm.VirtualMachine.TargetProcess.Id, asm.VirtualMachine.TargetProcess.ProcessName), + asm.Domain.FriendlyName, + asm.VirtualMachine.TargetProcess.Id + ); + + OnAssemblyLoaded (assembly); + } + void RegisterAssembly (AssemblyMirror asm) { var domain = vm.Version.AtLeast (2, 45) ? asm.Domain : asm.GetAssemblyObject ().Domain; diff --git a/Mono.Debugging/Mono.Debugging.Client/Assembly.cs b/Mono.Debugging/Mono.Debugging.Client/Assembly.cs new file mode 100644 index 0000000..4a9ad60 --- /dev/null +++ b/Mono.Debugging/Mono.Debugging.Client/Assembly.cs @@ -0,0 +1,79 @@ +// +// Assembly.cs +// +// Author: +// Jonathan Chang <t-jochang@microsoft.com> +// +// Copyright (c) 2022 +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +using System; +namespace Mono.Debugging.Client +{ + public class Assembly + { + public Assembly (string name, string path, bool optimized, bool userCode, string symbolStatus, string symbolFile, int? order, string version, string timestamp, string address, string process, string appdomain, long? processId) + { + Name = name; + Path = path; + Optimized = optimized; + SymbolStatus = symbolStatus; + SymbolFile = symbolFile; + Order = order.GetValueOrDefault (-1); + TimeStamp = timestamp; + Address = address; + Process = process; + AppDomain = appdomain; + Version = version; + UserCode = userCode; + ProcessId = processId; + + } + public Assembly (string path) + { + Path = path; + } + + public string Name { get; private set; } + + public string Path { get; private set; } + + public bool Optimized { get; private set; } + + public bool UserCode { get; private set; } + + public string SymbolStatus { get; private set; } + + public string SymbolFile { get; private set; } + + public int Order { get; private set; } = -1; + + public string Version { get; private set; } + + public string TimeStamp { get; private set; } + + public string Address { get; private set; } + + public string Process { get; private set; } + + public string AppDomain { get; private set; } + + public long? ProcessId { get; private set; } = -1; + } +}
\ No newline at end of file diff --git a/Mono.Debugging/Mono.Debugging.Client/AssemblyEventArgs.cs b/Mono.Debugging/Mono.Debugging.Client/AssemblyEventArgs.cs index 7d119f2..c97f79c 100644 --- a/Mono.Debugging/Mono.Debugging.Client/AssemblyEventArgs.cs +++ b/Mono.Debugging/Mono.Debugging.Client/AssemblyEventArgs.cs @@ -30,13 +30,24 @@ namespace Mono.Debugging.Client { public class AssemblyEventArgs : EventArgs { + public AssemblyEventArgs (Assembly assembly) + { + Location = assembly.Path; + Assembly = assembly; + } + public AssemblyEventArgs (string location) { Location = location; + Assembly = new Assembly (location); } public string Location { get; private set; } + + public Assembly Assembly { + get; private set; + } } } diff --git a/Mono.Debugging/Mono.Debugging.Client/DebuggerSession.cs b/Mono.Debugging/Mono.Debugging.Client/DebuggerSession.cs index c6a0fee..32ca3ff 100644 --- a/Mono.Debugging/Mono.Debugging.Client/DebuggerSession.cs +++ b/Mono.Debugging/Mono.Debugging.Client/DebuggerSession.cs @@ -32,6 +32,7 @@ using System.Collections.Generic; using Mono.Debugging.Backend; using Mono.Debugging.Evaluation; +using System.Linq; namespace Mono.Debugging.Client { @@ -49,6 +50,7 @@ namespace Mono.Debugging.Client { readonly Dictionary<BreakEvent, BreakEventInfo> breakpoints = new Dictionary<BreakEvent, BreakEventInfo> (); readonly Dictionary<string, string> resolvedExpressionCache = new Dictionary<string, string> (); + private readonly List<Assembly> assemblies = new List<Assembly> (); readonly InternalDebuggerSession frontend; readonly object slock = new object (); readonly object breakpointStoreLock = new object (); @@ -301,6 +303,26 @@ namespace Mono.Debugging.Client } /// <summary> + /// Gets assemblies from the debugger session. + /// </summary> + public Assembly[] GetAssemblies () + { + lock (assemblies) { + return assemblies.ToArray (); + } + } + + /// <summary> + /// Gets assemblies from the debugger session but filter by the specific process ID . + /// </summary> + internal Assembly[] GetAssemblies (long processId) + { + lock (assemblies) { + return assemblies.Where (a => a.ProcessId == processId).ToArray (); + } + } + + /// <summary> /// Gets or sets the breakpoint store for the debugger session. /// </summary> public BreakpointStore Breakpoints { @@ -1302,9 +1324,19 @@ namespace Mono.Debugging.Client internal protected void OnAssemblyLoaded (string assemblyLocation) { - AssemblyLoaded?.Invoke (this, new AssemblyEventArgs (assemblyLocation)); + var assembly = new Assembly (assemblyLocation); + OnAssemblyLoaded (assembly); } - + + internal protected void OnAssemblyLoaded (Assembly assembly) + { + lock (assemblies) { + assemblies.Add (assembly); + } + + AssemblyLoaded?.Invoke (this, new AssemblyEventArgs (assembly)); + } + internal protected void SetBusyState (BusyStateEventArgs args) { BusyStateChanged?.Invoke (this, args); diff --git a/Mono.Debugging/Mono.Debugging.Client/ProcessInfo.cs b/Mono.Debugging/Mono.Debugging.Client/ProcessInfo.cs index 99c80f5..5ba023a 100644 --- a/Mono.Debugging/Mono.Debugging.Client/ProcessInfo.cs +++ b/Mono.Debugging/Mono.Debugging.Client/ProcessInfo.cs @@ -78,5 +78,13 @@ namespace Mono.Debugging.Client { return session.GetThreads (id); } + + /// <summary> + /// Gets assemblies from the debugger session that matches the process ID. + /// </summary> + public Assembly[] GetAssemblies () + { + return session.GetAssemblies (id); + } } } |