Ejemplo n.º 1
0
        public override DbgRawMetadata Create(DbgRuntime runtime, bool isFileLayout, byte[] moduleBytes)
        {
            if (runtime is null)
            {
                throw new ArgumentNullException(nameof(runtime));
            }
            if (moduleBytes is null)
            {
                throw new ArgumentNullException(nameof(moduleBytes));
            }

            var state = runtime.GetOrCreateData <RuntimeState>();

            lock (state.LockObj) {
                var rawMd = new DbgRawMetadataImpl(moduleBytes, isFileLayout);
                try {
                    state.OtherMetadata.Add(rawMd);
                }
                catch {
                    rawMd.Release();
                    throw;
                }
                return(rawMd);
            }
        }
Ejemplo n.º 2
0
        internal void NotifyRuntimesChanged_DbgThread(DbgRuntime runtime)
        {
            bool raiseDebuggingChanged;

            DbgThread[] removedThreads;
            lock (lockObj) {
                var newDebugging = CalculateDebugging_NoLock();
                raiseDebuggingChanged = !StringArrayEquals(debugging, newDebugging);
                if (raiseDebuggingChanged)
                {
                    debugging = newDebugging;
                }
                runtime.ThreadsChanged -= DbgRuntime_ThreadsChanged;
                var threadsList = new List <DbgThread>();
                for (int i = threads.Count - 1; i >= 0; i--)
                {
                    var thread = threads[i];
                    if (thread.Runtime == runtime)
                    {
                        threadsList.Add(thread);
                        threads.RemoveAt(i);
                    }
                }
                removedThreads = threadsList.ToArray();
            }
            if (removedThreads.Length != 0)
            {
                ThreadsChanged?.Invoke(this, new DbgCollectionChangedEventArgs <DbgThread>(removedThreads, added: false));
            }
            if (raiseDebuggingChanged)
            {
                OnPropertyChanged(nameof(Debugging));
            }
            if (!(runtime is null))
                RuntimesChanged?.Invoke(this, new DbgCollectionChangedEventArgs <DbgRuntime>(runtime, added: false)); }
Ejemplo n.º 3
0
        public override DbgEvaluationContext CreateContext(DbgRuntime runtime, DbgCodeLocation location, DbgEvaluationContextOptions options, TimeSpan funcEvalTimeout, CancellationToken cancellationToken)
        {
            if (runtime == null)
            {
                throw new ArgumentNullException(nameof(runtime));
            }
            if (runtime.RuntimeKindGuid != RuntimeKindGuid)
            {
                throw new ArgumentException();
            }
            if (funcEvalTimeout == TimeSpan.Zero)
            {
                funcEvalTimeout = DefaultFuncEvalTimeout;
            }
            var context = new DbgEvaluationContextImpl(this, runtime, funcEvalTimeout, options);

            try {
                engineLanguage.InitializeContext(context, location, cancellationToken);
            }
            catch {
                context.Close();
                throw;
            }
            return(context);
        }
Ejemplo n.º 4
0
 public override DbgObjectId[] GetObjectIds(DbgRuntime runtime)
 {
     if (runtime == null)
     {
         throw new ArgumentNullException(nameof(runtime));
     }
     return(GetRuntimeObjectIdService(runtime).GetObjectIds());
 }
Ejemplo n.º 5
0
 DbgRuntimeObjectIdService GetRuntimeObjectIdService(DbgRuntime runtime)
 {
     return(runtime.GetOrCreateData <DbgRuntimeObjectIdService>(() => {
         var service = new DbgRuntimeObjectIdServiceImpl(runtime, GetEngineObjectIdFactory(runtime.Guid));
         service.ObjectIdsChanged += DbgRuntimeObjectIdService_ObjectIdsChanged;
         return service;
     }));
 }
Ejemplo n.º 6
0
 public override DbgObjectId?GetObjectId(DbgRuntime runtime, uint id)
 {
     if (runtime is null)
     {
         throw new ArgumentNullException(nameof(runtime));
     }
     return(GetRuntimeObjectIdService(runtime).GetObjectId(id));
 }
Ejemplo n.º 7
0
 DbgValueNode[] CreateResult(DbgRuntime runtime, DbgEngineValueNode[] result, int expectedLength)
 {
     if (result.Length != expectedLength)
     {
         throw new InvalidOperationException();
     }
     return(DbgValueNodeUtils.ToValueNodeArray(Language, runtime, result));
 }
Ejemplo n.º 8
0
 public override bool ShowNativeCode(DbgRuntime runtime, DbgCodeLocation location, string title)
 {
     if (!dbgNativeCodeProvider.Value.TryGetNativeCode(runtime, location, GetNativeCodeOptions(), out var result))
     {
         return(false);
     }
     Show(result, title);
     return(true);
 }
Ejemplo n.º 9
0
        IEnumerable <DbgRuntimeNativeCodeProvider> GetProviders(DbgRuntime runtime)
        {
            var checkedProviders = new List <DbgRuntimeNativeCodeProvider>();

            foreach (var lz in dbgRuntimeNativeCodeProviders)
            {
                var guidString = lz.Metadata.Guid;
                if (guidString == null)
                {
                    continue;
                }
                bool b = Guid.TryParse(guidString, out var guid);
                Debug.Assert(b);
                if (!b)
                {
                    continue;
                }
                if (guid != runtime.Guid)
                {
                    continue;
                }
                var provider = lz.Value;
                if (checkedProviders.Contains(provider))
                {
                    continue;
                }
                checkedProviders.Add(provider);
                yield return(provider);
            }

            foreach (var lz in dbgRuntimeNativeCodeProviders)
            {
                var guidString = lz.Metadata.RuntimeKindGuid;
                if (guidString == null)
                {
                    continue;
                }
                bool b = Guid.TryParse(guidString, out var guid);
                Debug.Assert(b);
                if (!b)
                {
                    continue;
                }
                if (guid != runtime.RuntimeKindGuid)
                {
                    continue;
                }
                var provider = lz.Value;
                if (checkedProviders.Contains(provider))
                {
                    continue;
                }
                checkedProviders.Add(provider);
                yield return(provider);
            }
        }
Ejemplo n.º 10
0
            internal void RemoveAllBoundBreakpoints_DbgThread(DbgRuntime runtime)
            {
                Dispatcher.VerifyAccess();
                var boundBreakpoints = BoundCodeBreakpointsService.RemoveBoundBreakpoints_DbgThread(runtime);

                foreach (var bp in boundBreakpoints)
                {
                    bp.Close(Dispatcher);
                }
            }
Ejemplo n.º 11
0
        public override DbgAssemblyInfoProvider Create(DbgRuntime runtime)
        {
            var engine = DbgEngineImpl.TryGetEngine(runtime);

            if (engine != null)
            {
                return(new DbgAssemblyInfoProviderImpl(engine));
            }
            return(null);
        }
Ejemplo n.º 12
0
        public override DebuggerRuntime2 Create(DbgRuntime runtime)
        {
            var state = StateWithKey <State> .GetOrCreate(runtime, this);

            if (state.DebuggerRuntime == null)
            {
                state.DebuggerRuntime = new DebuggerRuntimeImpl(dbgObjectIdService, runtime.GetDotNetRuntime(), runtime.Process.PointerSize, dotNetClassHookFactories);
            }
            return(state.DebuggerRuntime);
        }
Ejemplo n.º 13
0
 public DbgEvaluationContextImpl(DbgLanguage language, DbgRuntime runtime, TimeSpan funcEvalTimeout, DbgEvaluationContextOptions options)
 {
     lockObj                 = new object();
     Language                = language ?? throw new ArgumentNullException(nameof(language));
     Runtime                 = runtime ?? throw new ArgumentNullException(nameof(runtime));
     FuncEvalTimeout         = funcEvalTimeout;
     Options                 = options;
     continueContext         = new DbgContinueContext();
     continueContext.Closed += DbgContinueContext_Closed;
     runtime.CloseOnContinue(continueContext);
 }
Ejemplo n.º 14
0
        public static DbgValueNode[] ToValueNodeArray(DbgLanguage language, DbgRuntime runtime, DbgEngineValueNode[] engineNodes)
        {
            var nodes = new DbgValueNode[engineNodes.Length];

            for (int i = 0; i < nodes.Length; i++)
            {
                nodes[i] = new DbgValueNodeImpl(language, runtime, engineNodes[i]);
            }
            runtime.CloseOnContinue(nodes);
            return(nodes);
        }
Ejemplo n.º 15
0
        public override DbgDynamicModuleProvider?Create(DbgRuntime runtime)
        {
            var engine = DbgEngineImpl.TryGetEngine(runtime);

            if (!(engine is null))
            {
                return(runtime.GetOrCreateData(() => new DbgDynamicModuleProviderImpl(engine)));
            }

            return(null);
        }
Ejemplo n.º 16
0
        public DbgValueNodeImpl(DbgLanguage language, DbgRuntime runtime, DbgEngineValueNode engineValueNode)
        {
            Runtime              = runtime ?? throw new ArgumentNullException(nameof(runtime));
            Language             = language ?? throw new ArgumentNullException(nameof(language));
            this.engineValueNode = engineValueNode ?? throw new ArgumentNullException(nameof(engineValueNode));
            var engineValue = engineValueNode.Value;

            if (!(engineValue is null))
            {
                value = new DbgValueImpl(runtime, engineValue);
            }
        string GetRequiredAssemblyFilename(DbgRuntime runtime)
        {
            switch (GetClrVersion(runtime))
            {
            case ClrVersion.CLR2:
            case ClrVersion.CLR4:           return("System.Core.dll");

            case ClrVersion.CoreCLR:        return("System.Linq.dll");

            default:                                        throw new InvalidOperationException();
            }
        }
Ejemplo n.º 18
0
 public ClassLoaderImpl(UIDispatcher uiDispatcher, Lazy <IDocumentTreeView> documentTreeView, Lazy <IDocumentTabService> documentTabService, Lazy <ShowModuleLoaderService> showModuleLoaderService, Lazy <IMessageBoxService> messageBoxService, DbgRuntime runtime, DbgDynamicModuleProvider dbgDynamicModuleProvider)
 {
     lockObj                       = new object();
     this.uiDispatcher             = uiDispatcher ?? throw new ArgumentNullException(nameof(uiDispatcher));
     this.documentTreeView         = documentTreeView ?? throw new ArgumentNullException(nameof(documentTreeView));
     this.documentTabService       = documentTabService ?? throw new ArgumentNullException(nameof(documentTabService));
     this.showModuleLoaderService  = showModuleLoaderService ?? throw new ArgumentNullException(nameof(showModuleLoaderService));
     this.messageBoxService        = messageBoxService ?? throw new ArgumentNullException(nameof(messageBoxService));
     this.runtime                  = runtime ?? throw new ArgumentNullException(nameof(runtime));
     this.dbgDynamicModuleProvider = dbgDynamicModuleProvider ?? throw new ArgumentNullException(nameof(dbgDynamicModuleProvider));
     loadedClasses                 = new Dictionary <DbgModule, HashSet <uint> >();
 }
 ClrVersion GetClrVersion(DbgRuntime runtime)
 {
     if (runtime.Guid == PredefinedDbgRuntimeGuids.DotNetCore_Guid)
     {
         return(ClrVersion.CoreCLR);
     }
     if (enumerableType.AppDomain.CorLib.GetName().Version == new Version(2, 0, 0, 0))
     {
         return(ClrVersion.CLR2);
     }
     return(ClrVersion.CLR4);
 }
        string GetRequiredAssemblyFullName(DbgRuntime runtime)
        {
            switch (GetClrVersion(runtime))
            {
            case ClrVersion.CLR2:           return("System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");

            case ClrVersion.CLR4:           return("System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");

            case ClrVersion.CoreCLR:        return("System.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");

            default:                                        throw new InvalidOperationException();
            }
        }
Ejemplo n.º 21
0
 public DbgExceptionImpl(DbgRuntime runtime, DbgExceptionId id, DbgExceptionEventFlags flags, string message, DbgThread thread, DbgModule module)
 {
     if (id.IsDefaultId)
     {
         throw new ArgumentException();
     }
     Runtime = runtime ?? throw new ArgumentNullException(nameof(runtime));
     Id      = id;
     Flags   = flags;
     Message = message;
     Thread  = thread;
     Module  = module;
 }
Ejemplo n.º 22
0
 internal DbgEngine TryGetEngine(DbgRuntime runtime)
 {
     lock (lockObj) {
         foreach (var info in engineInfos)
         {
             if (info.Runtime == runtime)
             {
                 return(info.Engine);
             }
         }
     }
     return(null);
 }
		public override DbgBoundCodeBreakpoint[] RemoveBoundBreakpoints_DbgThread(DbgRuntime runtime) {
			dbgDispatcherProvider.VerifyAccess();
			var list = new List<DbgBoundCodeBreakpoint>();
			lock (lockObj) {
				foreach (var bp in breakpoints) {
					foreach (var boundBreakpoint in bp.BoundBreakpoints) {
						if (boundBreakpoint.Runtime == runtime)
							list.Add(boundBreakpoint);
					}
				}
			}
			var res = list.ToArray();
			RemoveBoundBreakpoints_DbgThread(res);
			return res;
		}
Ejemplo n.º 24
0
        public DbgValueNodeImpl(DbgLanguage language, DbgRuntime runtime, DbgEngineValueNode engineValueNode)
        {
            Runtime              = runtime ?? throw new ArgumentNullException(nameof(runtime));
            Language             = language ?? throw new ArgumentNullException(nameof(language));
            this.engineValueNode = engineValueNode ?? throw new ArgumentNullException(nameof(engineValueNode));
            var engineValue = engineValueNode.Value;

            if (engineValue is not null)
            {
                value = new DbgValueImpl(runtime, engineValue);
            }
            else if (!engineValueNode.IsReadOnly)
            {
                throw new InvalidOperationException();
            }
        }
Ejemplo n.º 25
0
 DbgEvaluationResult CreateResult(DbgRuntime runtime, DbgEngineEvaluationResult result)
 {
     if (result.Error != null)
     {
         return(new DbgEvaluationResult(PredefinedEvaluationErrorMessagesHelper.GetErrorMessage(result.Error), result.FormatSpecifiers, result.Flags));
     }
     try {
         var value = new DbgValueImpl(runtime, result.Value);
         runtime.CloseOnContinue(value);
         return(new DbgEvaluationResult(value, result.FormatSpecifiers, result.Flags));
     }
     catch {
         runtime.Process.DbgManager.Close(result.Value);
         throw;
     }
 }
Ejemplo n.º 26
0
        public override DbgRawMetadata Create(DbgRuntime runtime, bool isFileLayout, ulong moduleAddress, int moduleSize)
        {
            if (runtime is null)
            {
                throw new ArgumentNullException(nameof(runtime));
            }
            if (moduleAddress == 0)
            {
                throw new ArgumentOutOfRangeException(nameof(moduleAddress));
            }
            if (moduleSize <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(moduleSize));
            }

            var state = runtime.GetOrCreateData <RuntimeState>();

            lock (state.LockObj) {
                if (state.Dict.TryGetValue(moduleAddress, out var rawMd))
                {
                    if (rawMd.TryAddRef() is not null)
                    {
                        if (rawMd.IsFileLayout != isFileLayout || rawMd.Size != moduleSize)
                        {
                            rawMd.Release();
                            throw new InvalidOperationException();
                        }
                        return(rawMd);
                    }
                    state.Dict.Remove(moduleAddress);
                }

                rawMd = new DbgRawMetadataImpl(runtime.Process, isFileLayout, moduleAddress, moduleSize);
                try {
                    state.Dict.Add(moduleAddress, rawMd);
                }
                catch {
                    rawMd.Release();
                    throw;
                }
                return(rawMd);
            }
        }
Ejemplo n.º 27
0
        internal (DbgRuntime runtime, bool hasMoreRuntimes) Remove_DbgThread(DbgEngine engine)
        {
            DbgRuntime runtime = null;
            bool       hasMoreRuntimes;

            lock (lockObj) {
                for (int i = 0; i < engineInfos.Count; i++)
                {
                    var info = engineInfos[i];
                    if (info.Engine == engine)
                    {
                        UpdateRuntime_DbgThread(null);
                        runtime = info.Runtime;
                        engineInfos.RemoveAt(i);
                        break;
                    }
                }
                hasMoreRuntimes = engineInfos.Count > 0;
            }
            return(runtime, hasMoreRuntimes);
        }
Ejemplo n.º 28
0
        public override bool CanGetNativeCode(DbgRuntime runtime, DbgCodeLocation location)
        {
            if (runtime == null)
            {
                throw new ArgumentNullException(nameof(runtime));
            }
            if (location == null)
            {
                throw new ArgumentNullException(nameof(location));
            }

            foreach (var provider in GetProviders(runtime))
            {
                if (provider.CanGetNativeCode(runtime, location))
                {
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 29
0
        public override bool TryGetNativeCode(DbgRuntime runtime, DbgCodeLocation location, DbgNativeCodeOptions options, out GetNativeCodeResult result)
        {
            if (runtime == null)
            {
                throw new ArgumentNullException(nameof(runtime));
            }
            if (location == null)
            {
                throw new ArgumentNullException(nameof(location));
            }

            foreach (var provider in GetProviders(runtime))
            {
                if (provider.TryGetNativeCode(runtime, location, options, out result))
                {
                    return(true);
                }
            }

            result = default;
            return(false);
        }
Ejemplo n.º 30
0
        DbgCreateValueNodeResult[] CreateResult(DbgRuntime runtime, DbgEngineValueNode[] results)
        {
            if (results.Length == 0)
            {
                return(Array.Empty <DbgCreateValueNodeResult>());
            }
            var res = new DbgCreateValueNodeResult[results.Length];

            try {
                for (int i = 0; i < res.Length; i++)
                {
                    var result    = results[i];
                    var valueNode = new DbgValueNodeImpl(Language, runtime, result);
                    runtime.CloseOnContinue(valueNode);
                    res[i] = new DbgCreateValueNodeResult(valueNode, result.CausesSideEffects);
                }
            }
            catch {
                runtime.Process.DbgManager.Close(res.Select(a => a.ValueNode).Where(a => !(a is null)));
                throw;
            }
            return(res);
        }