public static DbgBoundCodeBreakpointMessage ToDbgBoundCodeBreakpointMessage(this DbgEngineBoundCodeBreakpointMessage message) { if (message.Arguments != null) { switch (message.Kind) { case DbgEngineBoundCodeBreakpointMessageKind.None: return(DbgBoundCodeBreakpointMessage.None); case DbgEngineBoundCodeBreakpointMessageKind.CustomWarning: if (message.Arguments.Length == 1 && message.Arguments[0] != null) { return(new DbgBoundCodeBreakpointMessage(DbgBoundCodeBreakpointSeverity.Warning, message.Arguments[0])); } break; case DbgEngineBoundCodeBreakpointMessageKind.CustomError: if (message.Arguments.Length == 1 && message.Arguments[0] != null) { return(new DbgBoundCodeBreakpointMessage(DbgBoundCodeBreakpointSeverity.Error, message.Arguments[0])); } break; case DbgEngineBoundCodeBreakpointMessageKind.FunctionNotFound: if (message.Arguments.Length == 1 && message.Arguments[0] != null) { return(new DbgBoundCodeBreakpointMessage(DbgBoundCodeBreakpointSeverity.Error, string.Format(dnSpy_Debugger_Resources.BreakpointMessage_TheFunctionCanNotBeFound, message.Arguments[0]))); } break; case DbgEngineBoundCodeBreakpointMessageKind.CouldNotCreateBreakpoint: if (message.Arguments.Length == 0) { return(new DbgBoundCodeBreakpointMessage(DbgBoundCodeBreakpointSeverity.Error, dnSpy_Debugger_Resources.BreakpointMessage_CouldNotCreateBreakpoint)); } break; default: Debug.Fail($"Unknown message kind: {message.Kind}"); break; } } Debug.Fail($"Invalid message"); return(new DbgBoundCodeBreakpointMessage(DbgBoundCodeBreakpointSeverity.Error, "???")); }
static DbgEngineBoundCodeBreakpointMessage GetBoundBreakpointMessage(DnCodeBreakpoint bp) { switch (bp.Error) { case DnCodeBreakpointError.None: return(DbgEngineBoundCodeBreakpointMessage.CreateNoError()); case DnCodeBreakpointError.FunctionNotFound: return(DbgEngineBoundCodeBreakpointMessage.CreateFunctionNotFound(GetFunctionName(bp))); case DnCodeBreakpointError.OtherError: case DnCodeBreakpointError.CouldNotCreateBreakpoint: return(DbgEngineBoundCodeBreakpointMessage.CreateCouldNotCreateBreakpoint()); default: Debug.Fail($"Unknown error: {bp.Error}"); goto case DnCodeBreakpointError.OtherError; }
void EnableBreakpoints(ModuleMirror monoModule, DbgModule module, List <DbgDotNetCodeLocation> moduleLocations) { debuggerThread.VerifyAccess(); if (moduleLocations.Count == 0) { return; } var createdBreakpoints = new DbgBoundCodeBreakpointInfo <BoundBreakpointData> [moduleLocations.Count]; var reflectionModule = module.GetReflectionModule(); var state = module.GetOrCreateData <TypeLoadBreakpointState>(); for (int i = 0; i < createdBreakpoints.Length; i++) { var location = moduleLocations[i]; const ulong address = DbgObjectFactory.BoundBreakpointNoAddress; DbgEngineBoundCodeBreakpointMessage msg; var method = reflectionModule.ResolveMethod((int)location.Token, DmdResolveOptions.None); if ((object)method == null) { msg = DbgEngineBoundCodeBreakpointMessage.CreateFunctionNotFound(GetFunctionName(location.Module, location.Token)); } else { msg = state.IsTypeLoaded(method.DeclaringType.MetadataToken) ? DbgEngineBoundCodeBreakpointMessage.CreateCustomWarning(dnSpy_Debugger_DotNet_Mono_Resources.CanNotSetABreakpointWhenProcessIsPaused) : DbgEngineBoundCodeBreakpointMessage.CreateNoError(); } var bpData = new BoundBreakpointData(this, location.Module); createdBreakpoints[i] = new DbgBoundCodeBreakpointInfo <BoundBreakpointData>(location, module, address, msg, bpData); } var boundBreakpoints = objectFactory.Create(createdBreakpoints.ToArray()); foreach (var ebp in boundBreakpoints) { if (!ebp.BoundCodeBreakpoint.TryGetData(out BoundBreakpointData bpData)) { Debug.Assert(ebp.BoundCodeBreakpoint.IsClosed); continue; } bpData.EngineBoundCodeBreakpoint = ebp; if (bpData.Breakpoint != null) { bpData.Breakpoint.Tag = bpData; } } for (int i = 0; i < boundBreakpoints.Length; i++) { var boundBp = boundBreakpoints[i]; var location = (DbgDotNetCodeLocation)boundBp.BoundCodeBreakpoint.Breakpoint.Location; var method = reflectionModule.ResolveMethod((int)location.Token, DmdResolveOptions.None); if ((object)method == null) { continue; } state.AddBreakpoint(method.DeclaringType.MetadataToken, boundBp, () => EnableBreakpointCore(module, method, boundBp, location)); } }