diff --git a/src/AddIns/Debugger/Debugger.Core/Breakpoint.cs b/src/AddIns/Debugger/Debugger.Core/Breakpoint.cs index d36f9f3f18..05b0c5ed99 100644 --- a/src/AddIns/Debugger/Debugger.Core/Breakpoint.cs +++ b/src/AddIns/Debugger/Debugger.Core/Breakpoint.cs @@ -72,8 +72,8 @@ namespace Debugger foreach(var symbolSource in module.Process.Debugger.SymbolSources) { var seq = symbolSource.GetSequencePoint(module, this.FileName, this.Line, this.Column); if (seq != null) { - ICorDebugFunction corFuction = module.CorModule.GetFunctionFromToken(seq.MethodDefToken); - ICorDebugFunctionBreakpoint corBreakpoint = corFuction.GetILCode().CreateBreakpoint((uint)seq.ILOffset); + ICorDebugFunction corFunction = module.CorModule.GetFunctionFromToken(seq.MethodDefToken); + ICorDebugFunctionBreakpoint corBreakpoint = corFunction.GetILCode().CreateBreakpoint((uint)seq.ILOffset); corBreakpoint.Activate(enabled ? 1 : 0); corBreakpoints.Add(corBreakpoint); } diff --git a/src/AddIns/Debugger/Debugger.Core/Module.cs b/src/AddIns/Debugger/Debugger.Core/Module.cs index 5234c880ca..c00bd21b75 100644 --- a/src/AddIns/Debugger/Debugger.Core/Module.cs +++ b/src/AddIns/Debugger/Debugger.Core/Module.cs @@ -64,6 +64,22 @@ namespace Debugger } } + [Debugger.Tests.Ignore] + public uint GetEntryPoint() + { + try { + if (symReader != null) + return symReader.GetUserEntryPoint(); + var info = TypeSystemExtensions.GetInfo(Assembly); + var ep = info.CecilModule.EntryPoint; + if (ep != null) + return ep.MetadataToken.ToUInt32(); + return 0; + } catch { + return 0; + } + } + [Debugger.Tests.Ignore] public ISymUnmanagedReader SymReader { get { diff --git a/src/AddIns/Debugger/Debugger.Core/Process.cs b/src/AddIns/Debugger/Debugger.Core/Process.cs index 1d3645c597..cab1ad89a0 100644 --- a/src/AddIns/Debugger/Debugger.Core/Process.cs +++ b/src/AddIns/Debugger/Debugger.Core/Process.cs @@ -85,7 +85,7 @@ namespace Debugger } public string Filename { get; private set; } - + internal Process(NDebugger debugger, ICorDebugProcess corProcess, string filename, string workingDirectory) { this.debugger = debugger; @@ -561,7 +561,7 @@ namespace Debugger } } - #region Break at begining + #region Break at beginning int lastAssignedModuleOrderOfLoading = 0; @@ -570,21 +570,22 @@ namespace Debugger module.OrderOfLoading = lastAssignedModuleOrderOfLoading++; module.AppDomain.InvalidateCompilation(); - if (this.BreakInMain) { - if (module.SymReader == null) return; // No symbols - + if (BreakInMain) { try { // create a BP at entry point - uint entryPoint = module.SymReader.GetUserEntryPoint(); - if (entryPoint == 0) return; // no EP - var corBreakpoint = module.CorModule.GetFunctionFromToken(entryPoint).CreateBreakpoint(); - corBreakpoint.Activate(1); - this.tempBreakpoints.Add(corBreakpoint); + uint entryPoint = module.GetEntryPoint(); + if (entryPoint != 0) { // no EP + var corBreakpoint = module.CorModule + .GetFunctionFromToken(entryPoint) + .CreateBreakpoint(); + corBreakpoint.Activate(1); + tempBreakpoints.Add(corBreakpoint); + + BreakInMain = false; + } } catch { // the app does not have an entry point - COM exception } - - this.BreakInMain = false; } if (this.ModuleLoaded != null) { diff --git a/src/AddIns/Debugger/Debugger.Core/TypeSystemExtensions.cs b/src/AddIns/Debugger/Debugger.Core/TypeSystemExtensions.cs index 3804036706..f6ae107034 100644 --- a/src/AddIns/Debugger/Debugger.Core/TypeSystemExtensions.cs +++ b/src/AddIns/Debugger/Debugger.Core/TypeSystemExtensions.cs @@ -26,9 +26,10 @@ namespace Debugger #region Module Loading static ConditionalWeakTable weakTable = new ConditionalWeakTable(); - class ModuleMetadataInfo + internal class ModuleMetadataInfo { public readonly Module Module; + public readonly Mono.Cecil.ModuleDefinition CecilModule; Dictionary metadataTokens = new Dictionary(); Dictionary tokenToMethod = new Dictionary(); Dictionary localVariableTypes = new Dictionary(); @@ -38,7 +39,7 @@ namespace Debugger public ModuleMetadataInfo(Module module, Mono.Cecil.ModuleDefinition cecilModule) { this.Module = module; - + this.CecilModule = cecilModule; typeRefLoader = new CecilLoader(); typeRefLoader.SetCurrentModule(cecilModule); } @@ -160,7 +161,7 @@ namespace Debugger return asm; } - static ModuleMetadataInfo GetInfo(IAssembly assembly) + internal static ModuleMetadataInfo GetInfo(IAssembly assembly) { ModuleMetadataInfo info; if (!weakTable.TryGetValue(assembly.UnresolvedAssembly, out info))