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. 21
      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 @@ -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);
}

16
src/AddIns/Debugger/Debugger.Core/Module.cs

@ -64,6 +64,22 @@ namespace Debugger @@ -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 {

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

@ -561,7 +561,7 @@ namespace Debugger @@ -561,7 +561,7 @@ namespace Debugger
}
}
#region Break at begining
#region Break at beginning
int lastAssignedModuleOrderOfLoading = 0;
@ -570,21 +570,22 @@ namespace Debugger @@ -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();
uint entryPoint = module.GetEntryPoint();
if (entryPoint != 0) { // no EP
var corBreakpoint = module.CorModule
.GetFunctionFromToken(entryPoint)
.CreateBreakpoint();
corBreakpoint.Activate(1);
this.tempBreakpoints.Add(corBreakpoint);
tempBreakpoints.Add(corBreakpoint);
BreakInMain = false;
}
} catch {
// the app does not have an entry point - COM exception
}
this.BreakInMain = false;
}
if (this.ModuleLoaded != null) {

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

@ -26,9 +26,10 @@ namespace Debugger @@ -26,9 +26,10 @@ namespace Debugger
#region Module Loading
static ConditionalWeakTable<IUnresolvedAssembly, ModuleMetadataInfo> weakTable = new ConditionalWeakTable<IUnresolvedAssembly, ModuleMetadataInfo>();
class ModuleMetadataInfo
internal class ModuleMetadataInfo
{
public readonly Module Module;
public readonly Mono.Cecil.ModuleDefinition CecilModule;
Dictionary<IUnresolvedEntity, uint> metadataTokens = new Dictionary<IUnresolvedEntity, uint>();
Dictionary<uint, IUnresolvedMethod> tokenToMethod = new Dictionary<uint, IUnresolvedMethod>();
Dictionary<IUnresolvedMember, ITypeReference[]> localVariableTypes = new Dictionary<IUnresolvedMember, ITypeReference[]>();
@ -38,7 +39,7 @@ namespace Debugger @@ -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 @@ -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))

Loading…
Cancel
Save