Browse Source

Ignore code marked with DebuggerStepThroughAttribute or DebuggerNonUserCodeAttribute

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@3155 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
David Srbecký 17 years ago
parent
commit
0fae4ba16b
  1. 31
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Module.cs
  2. 2
      src/AddIns/Misc/Debugger/Debugger.Tests/Project/Debugger.Tests.csproj
  3. 28
      src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/DebuggerAttributes.cs

31
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Module.cs

@ -172,6 +172,37 @@ namespace Debugger @@ -172,6 +172,37 @@ namespace Debugger
symReader = metaData.GetSymReader(fullPath, null);
JMCStatus = SymbolsLoaded;
FindNonUserCode();
}
/// <summary>
/// Finds all classes and methods marked with DebuggerNonUserCode attribute
/// and it marks them for JMC so that they are not stepped into
/// </summary>
void FindNonUserCode()
{
if (this.SymbolsLoaded) {
foreach(CustomAttributeProps ca in metaData.EnumCustomAttributeProps(0, 0)) {
MemberRefProps constructorMethod = metaData.GetMemberRefProps(ca.Type);
TypeRefProps attributeType = metaData.GetTypeRefProps(constructorMethod.DeclaringType);
if (attributeType.Name == "System.Diagnostics.DebuggerStepThroughAttribute" ||
attributeType.Name == "System.Diagnostics.DebuggerNonUserCodeAttribute")
{
if (ca.Owner >> 24 == 0x02) { // TypeDef
ICorDebugClass2 corClass = corModule.GetClassFromToken(ca.Owner).CastTo<ICorDebugClass2>();
corClass.SetJMCStatus(0 /* false */);
this.Process.TraceMessage("Class {0} marked as non-user code", metaData.GetTypeDefProps(ca.Owner).Name);
}
if (ca.Owner >> 24 == 0x06) { // MethodDef
ICorDebugFunction2 corFunction = corModule.GetFunctionFromToken(ca.Owner).CastTo<ICorDebugFunction2>();
corFunction.SetJMCStatus(0 /* false */);
MethodProps methodProps = metaData.GetMethodProps(ca.Owner);
this.Process.TraceMessage("Function {0}.{1} marked as non-user code", metaData.GetTypeDefProps(methodProps.ClassToken).Name, methodProps.Name);
}
}
}
}
}
public void ApplyChanges(byte[] metadata, byte[] il)

2
src/AddIns/Misc/Debugger/Debugger.Tests/Project/Debugger.Tests.csproj

@ -26,7 +26,7 @@ @@ -26,7 +26,7 @@
<DefineConstants>DEBUG;TRACE;TEST_CODE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DefineConstants>TRACE</DefineConstants>
<DefineConstants>TRACE;TEST_CODE</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />

28
src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/DebuggerAttributes.cs

@ -17,6 +17,7 @@ namespace Debugger.Tests.TestPrograms @@ -17,6 +17,7 @@ namespace Debugger.Tests.TestPrograms
System.Diagnostics.Debug.WriteLine("Start");
System.Diagnostics.Debugger.Break();
Internal();
IgnoredClass.Internal();
System.Diagnostics.Debug.WriteLine("End");
}
@ -25,11 +26,22 @@ namespace Debugger.Tests.TestPrograms @@ -25,11 +26,22 @@ namespace Debugger.Tests.TestPrograms
{
System.Diagnostics.Debug.WriteLine("Internal");
}
[DebuggerNonUserCode]
public class IgnoredClass
{
public static void Internal()
{
System.Diagnostics.Debug.WriteLine("Internal");
}
}
}
}
#if TEST_CODE
namespace Debugger.Tests {
using NUnit.Framework;
using Debugger.Wrappers.CorDebug;
using Debugger.Wrappers.MetaData;
public partial class DebuggerTests
@ -38,17 +50,13 @@ namespace Debugger.Tests { @@ -38,17 +50,13 @@ namespace Debugger.Tests {
public void DebuggerAttributes()
{
StartTest("DebuggerAttributes.cs");
process.SelectedStackFrame.StepOver();
process.SelectedStackFrame.StepInto();
process.SelectedStackFrame.StepInto();
Module module = process.SelectedStackFrame.MethodInfo.Module;
foreach(ModuleRefProps mRef in module.MetaData.EnumModuleRefProps()) {
Assert.AreEqual(process.SelectedStackFrame.MethodInfo.Name, "Main");
process.SelectedStackFrame.StepInto();
Assert.AreEqual(process.SelectedStackFrame.MethodInfo.Name, "Main");
}
uint typeRef = module.MetaData.FindTypeRef(0, "System.Diagnostics.DebuggerStepThroughAttribute");
foreach(CustomAttributeProps ca in module.MetaData.EnumCustomAttributeProps(0, 0)) {
MemberRefProps memProps = module.MetaData.GetMemberRefProps(ca.Type);
TypeRefProps typeDefProps = module.MetaData.GetTypeRefProps(memProps.DeclaringType);
}
EndTest();
}
}
@ -68,8 +76,10 @@ namespace Debugger.Tests { @@ -68,8 +76,10 @@ namespace Debugger.Tests {
<LogMessage>Start\r\n</LogMessage>
<DebuggingPaused>Break</DebuggingPaused>
<DebuggingPaused>StepComplete</DebuggingPaused>
<LogMessage>Internal\r\n</LogMessage>
<DebuggingPaused>StepComplete</DebuggingPaused>
<LogMessage>Internal\r\n</LogMessage>
<DebuggingPaused>StepComplete</DebuggingPaused>
<LogMessage>End\r\n</LogMessage>
<ProcessExited />
</Test>

Loading…
Cancel
Save