Skip to content

Commit

Permalink
Add support for Just My Code debugging (refs #97)
Browse files Browse the repository at this point in the history
Just My Code is implemented in two ways to aid in debugging:
* Option to step over code in system modules
* Option to step only into code from the primary module
  • Loading branch information
ElektroKill committed Jul 18, 2022
1 parent 2fb1df7 commit bbd89a3
Show file tree
Hide file tree
Showing 7 changed files with 183 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,7 @@ void StartCore(CorDebugStartDebuggingOptions options) {
Debug2.Assert(dbgOptions.Filename is not null);

dbgOptions.DebugOptions.IgnoreBreakInstructions = false;
dbgOptions.DebugOptions.StepperJMC = debuggerSettings.EnableJustMyCodeDebugging;

// Disable NGEN image loading for Windows 8.x store apps. No effect on desktop apps.
if (debuggerSettings.SuppressJITOptimization_SystemModules)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,16 @@ namespace dnSpy.Debugger.DotNet.CorDebug.Impl {
sealed class DebugOptionsProviderImpl : DebugOptionsProvider {
readonly bool suppressJITOptimization_SystemModules;
readonly bool suppressJITOptimization_ProgramModules;
readonly bool enableJMC;
readonly bool stepOverSystemModules;
readonly bool onlyStepIntoPrimaryModule;

public DebugOptionsProviderImpl(DebuggerSettings debuggerSettings) {
suppressJITOptimization_SystemModules = debuggerSettings.SuppressJITOptimization_SystemModules;
suppressJITOptimization_ProgramModules = debuggerSettings.SuppressJITOptimization_ProgramModules;
enableJMC = debuggerSettings.EnableJustMyCodeDebugging;
stepOverSystemModules = debuggerSettings.StepOverCodeInSystemModules;
onlyStepIntoPrimaryModule = debuggerSettings.OnlyStepIntoCodeInPrimaryModule;
}

public override CorDebugJITCompilerFlags GetDesiredNGENCompilerFlags(DnProcess process) =>
Expand Down Expand Up @@ -63,7 +69,22 @@ static bool IsInDirOrSubDir(string dir, string filename) {
return filename.StartsWith(dir, StringComparison.OrdinalIgnoreCase);
}

bool IsJustMyCode(DnModule module) => true;
bool setJMCForMainModule;

bool IsJustMyCode(DnModule module) {
if (!enableJMC)
return true;
if (stepOverSystemModules)
return IsProgramModule(module);
if (onlyStepIntoPrimaryModule) {
if (setJMCForMainModule || !IsProgramModule(module))
return false;
setJMCForMainModule = true;
return true;
}

return true;
}

public override ModuleLoadOptions GetModuleLoadOptions(DnModule module) {
ModuleLoadOptions options = default;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
Expand All @@ -26,36 +26,36 @@
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
Expand Down Expand Up @@ -1338,6 +1338,15 @@ Do you wish to continue?</value>
<data name="DbgSettings_EnableManagedDebuggingAssistants" xml:space="preserve">
<value>Enable Managed Debugging Assistants (MDA)</value>
</data>
<data name="DbgSettings_EnableJustMyCodeDebugging" xml:space="preserve">
<value>Enable Just My Code debugging support</value>
</data>
<data name="DbgSettings_StepOverCodeInSystemModules" xml:space="preserve">
<value>Step over code in system modules</value>
</data>
<data name="DbgSettings_OnlyStepIntoCodeInPrimaryModule" xml:space="preserve">
<value>Only step into code located in primary module</value>
</data>
<data name="DebugStepProcessError" xml:space="preserve">
<value>Could not step: {0}</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,57 @@ public override bool EnableManagedDebuggingAssistants {
}
bool enableManagedDebuggingAssistants = true;

public override bool EnableJustMyCodeDebugging {
get {
lock (lockObj)
return enableJustMyCodeDebugging;
}
set {
bool modified;
lock (lockObj) {
modified = enableJustMyCodeDebugging != value;
enableJustMyCodeDebugging = value;
}
if (modified)
OnPropertyChanged(nameof(EnableJustMyCodeDebugging));
}
}
bool enableJustMyCodeDebugging = false;

public override bool StepOverCodeInSystemModules {
get {
lock (lockObj)
return stepOverCodeInSystemModules;
}
set {
bool modified;
lock (lockObj) {
modified = stepOverCodeInSystemModules != value;
stepOverCodeInSystemModules = value;
}
if (modified)
OnPropertyChanged(nameof(StepOverCodeInSystemModules));
}
}
bool stepOverCodeInSystemModules = false;

public override bool OnlyStepIntoCodeInPrimaryModule {
get {
lock (lockObj)
return onlyStepIntoCodeInPrimaryModule;
}
set {
bool modified;
lock (lockObj) {
modified = onlyStepIntoCodeInPrimaryModule != value;
onlyStepIntoCodeInPrimaryModule = value;
}
if (modified)
OnPropertyChanged(nameof(OnlyStepIntoCodeInPrimaryModule));
}
}
bool onlyStepIntoCodeInPrimaryModule = false;

public override bool HighlightChangedVariables {
get {
lock (lockObj)
Expand Down Expand Up @@ -640,6 +691,9 @@ public DebuggerSettingsBase CopyTo(DebuggerSettingsBase other) {
other.IgnoreBreakInstructions = IgnoreBreakInstructions;
other.BreakAllProcesses = BreakAllProcesses;
other.EnableManagedDebuggingAssistants = EnableManagedDebuggingAssistants;
other.EnableJustMyCodeDebugging = EnableJustMyCodeDebugging;
other.StepOverCodeInSystemModules = StepOverCodeInSystemModules;
other.OnlyStepIntoCodeInPrimaryModule = OnlyStepIntoCodeInPrimaryModule;
other.HighlightChangedVariables = HighlightChangedVariables;
other.ShowRawStructureOfObjects = ShowRawStructureOfObjects;
other.SortParameters = SortParameters;
Expand Down Expand Up @@ -691,6 +745,9 @@ sealed class DebuggerSettingsImpl : DebuggerSettingsBase {
IgnoreBreakInstructions = sect.Attribute<bool?>(nameof(IgnoreBreakInstructions)) ?? IgnoreBreakInstructions;
BreakAllProcesses = sect.Attribute<bool?>(nameof(BreakAllProcesses)) ?? BreakAllProcesses;
EnableManagedDebuggingAssistants = sect.Attribute<bool?>(nameof(EnableManagedDebuggingAssistants)) ?? EnableManagedDebuggingAssistants;
EnableJustMyCodeDebugging = sect.Attribute<bool?>(nameof(EnableJustMyCodeDebugging)) ?? EnableJustMyCodeDebugging;
StepOverCodeInSystemModules = sect.Attribute<bool?>(nameof(StepOverCodeInSystemModules)) ?? StepOverCodeInSystemModules;
OnlyStepIntoCodeInPrimaryModule = sect.Attribute<bool?>(nameof(OnlyStepIntoCodeInPrimaryModule)) ?? OnlyStepIntoCodeInPrimaryModule;
HighlightChangedVariables = sect.Attribute<bool?>(nameof(HighlightChangedVariables)) ?? HighlightChangedVariables;
ShowRawStructureOfObjects = sect.Attribute<bool?>(nameof(ShowRawStructureOfObjects)) ?? ShowRawStructureOfObjects;
SortParameters = sect.Attribute<bool?>(nameof(SortParameters)) ?? SortParameters;
Expand Down Expand Up @@ -731,6 +788,9 @@ void DebuggerSettingsImpl_PropertyChanged(object? sender, PropertyChangedEventAr
sect.Attribute(nameof(IgnoreBreakInstructions), IgnoreBreakInstructions);
sect.Attribute(nameof(BreakAllProcesses), BreakAllProcesses);
sect.Attribute(nameof(EnableManagedDebuggingAssistants), EnableManagedDebuggingAssistants);
sect.Attribute(nameof(EnableJustMyCodeDebugging), EnableJustMyCodeDebugging);
sect.Attribute(nameof(StepOverCodeInSystemModules), StepOverCodeInSystemModules);
sect.Attribute(nameof(OnlyStepIntoCodeInPrimaryModule), OnlyStepIntoCodeInPrimaryModule);
sect.Attribute(nameof(HighlightChangedVariables), HighlightChangedVariables);
sect.Attribute(nameof(ShowRawStructureOfObjects), ShowRawStructureOfObjects);
sect.Attribute(nameof(SortParameters), SortParameters);
Expand Down
Loading

0 comments on commit bbd89a3

Please sign in to comment.