Browse Source

fix bug in Process.OnModuleLoaded: ModuleLoaded event was not fired if BreakInMain was active and executable had no symbols

+ add support for BreakInMain in executables without symbols
pull/48/head
Siegfried Pammer 12 years ago
parent
commit
6e343f32ab
  1. 4
      src/AddIns/Debugger/Debugger.Core/Breakpoint.cs
  2. 16
      src/AddIns/Debugger/Debugger.Core/Module.cs
  3. 25
      src/AddIns/Debugger/Debugger.Core/Process.cs
  4. 7
      src/AddIns/Debugger/Debugger.Core/TypeSystemExtensions.cs

4
src/AddIns/Debugger/Debugger.Core/Breakpoint.cs

@ -72,8 +72,8 @@ namespace Debugger
foreach(var symbolSource in module.Process.Debugger.SymbolSources) { foreach(var symbolSource in module.Process.Debugger.SymbolSources) {
var seq = symbolSource.GetSequencePoint(module, this.FileName, this.Line, this.Column); var seq = symbolSource.GetSequencePoint(module, this.FileName, this.Line, this.Column);
if (seq != null) { if (seq != null) {
ICorDebugFunction corFuction = module.CorModule.GetFunctionFromToken(seq.MethodDefToken); ICorDebugFunction corFunction = module.CorModule.GetFunctionFromToken(seq.MethodDefToken);
ICorDebugFunctionBreakpoint corBreakpoint = corFuction.GetILCode().CreateBreakpoint((uint)seq.ILOffset); ICorDebugFunctionBreakpoint corBreakpoint = corFunction.GetILCode().CreateBreakpoint((uint)seq.ILOffset);
corBreakpoint.Activate(enabled ? 1 : 0); corBreakpoint.Activate(enabled ? 1 : 0);
corBreakpoints.Add(corBreakpoint); corBreakpoints.Add(corBreakpoint);
} }

16
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] [Debugger.Tests.Ignore]
public ISymUnmanagedReader SymReader { public ISymUnmanagedReader SymReader {
get { get {

25
src/AddIns/Debugger/Debugger.Core/Process.cs

@ -85,7 +85,7 @@ namespace Debugger
} }
public string Filename { get; private set; } public string Filename { get; private set; }
internal Process(NDebugger debugger, ICorDebugProcess corProcess, string filename, string workingDirectory) internal Process(NDebugger debugger, ICorDebugProcess corProcess, string filename, string workingDirectory)
{ {
this.debugger = debugger; this.debugger = debugger;
@ -561,7 +561,7 @@ namespace Debugger
} }
} }
#region Break at begining #region Break at beginning
int lastAssignedModuleOrderOfLoading = 0; int lastAssignedModuleOrderOfLoading = 0;
@ -570,21 +570,22 @@ namespace Debugger
module.OrderOfLoading = lastAssignedModuleOrderOfLoading++; module.OrderOfLoading = lastAssignedModuleOrderOfLoading++;
module.AppDomain.InvalidateCompilation(); module.AppDomain.InvalidateCompilation();
if (this.BreakInMain) { if (BreakInMain) {
if (module.SymReader == null) return; // No symbols
try { try {
// create a BP at entry point // create a BP at entry point
uint entryPoint = module.SymReader.GetUserEntryPoint(); uint entryPoint = module.GetEntryPoint();
if (entryPoint == 0) return; // no EP if (entryPoint != 0) { // no EP
var corBreakpoint = module.CorModule.GetFunctionFromToken(entryPoint).CreateBreakpoint(); var corBreakpoint = module.CorModule
corBreakpoint.Activate(1); .GetFunctionFromToken(entryPoint)
this.tempBreakpoints.Add(corBreakpoint); .CreateBreakpoint();
corBreakpoint.Activate(1);
tempBreakpoints.Add(corBreakpoint);
BreakInMain = false;
}
} catch { } catch {
// the app does not have an entry point - COM exception // the app does not have an entry point - COM exception
} }
this.BreakInMain = false;
} }
if (this.ModuleLoaded != null) { if (this.ModuleLoaded != null) {

7
src/AddIns/Debugger/Debugger.Core/TypeSystemExtensions.cs

@ -26,9 +26,10 @@ namespace Debugger
#region Module Loading #region Module Loading
static ConditionalWeakTable<IUnresolvedAssembly, ModuleMetadataInfo> weakTable = new ConditionalWeakTable<IUnresolvedAssembly, ModuleMetadataInfo>(); static ConditionalWeakTable<IUnresolvedAssembly, ModuleMetadataInfo> weakTable = new ConditionalWeakTable<IUnresolvedAssembly, ModuleMetadataInfo>();
class ModuleMetadataInfo internal class ModuleMetadataInfo
{ {
public readonly Module Module; public readonly Module Module;
public readonly Mono.Cecil.ModuleDefinition CecilModule;
Dictionary<IUnresolvedEntity, uint> metadataTokens = new Dictionary<IUnresolvedEntity, uint>(); Dictionary<IUnresolvedEntity, uint> metadataTokens = new Dictionary<IUnresolvedEntity, uint>();
Dictionary<uint, IUnresolvedMethod> tokenToMethod = new Dictionary<uint, IUnresolvedMethod>(); Dictionary<uint, IUnresolvedMethod> tokenToMethod = new Dictionary<uint, IUnresolvedMethod>();
Dictionary<IUnresolvedMember, ITypeReference[]> localVariableTypes = new Dictionary<IUnresolvedMember, ITypeReference[]>(); Dictionary<IUnresolvedMember, ITypeReference[]> localVariableTypes = new Dictionary<IUnresolvedMember, ITypeReference[]>();
@ -38,7 +39,7 @@ namespace Debugger
public ModuleMetadataInfo(Module module, Mono.Cecil.ModuleDefinition cecilModule) public ModuleMetadataInfo(Module module, Mono.Cecil.ModuleDefinition cecilModule)
{ {
this.Module = module; this.Module = module;
this.CecilModule = cecilModule;
typeRefLoader = new CecilLoader(); typeRefLoader = new CecilLoader();
typeRefLoader.SetCurrentModule(cecilModule); typeRefLoader.SetCurrentModule(cecilModule);
} }
@ -160,7 +161,7 @@ namespace Debugger
return asm; return asm;
} }
static ModuleMetadataInfo GetInfo(IAssembly assembly) internal static ModuleMetadataInfo GetInfo(IAssembly assembly)
{ {
ModuleMetadataInfo info; ModuleMetadataInfo info;
if (!weakTable.TryGetValue(assembly.UnresolvedAssembly, out info)) if (!weakTable.TryGetValue(assembly.UnresolvedAssembly, out info))

Loading…
Cancel
Save