Skip to content

Commit

Permalink
IsRunningInDebugMode method fixed - Version 1.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
mjebrahimi committed Jan 21, 2024
1 parent c262b21 commit de60bbf
Showing 1 changed file with 9 additions and 20 deletions.
29 changes: 9 additions & 20 deletions src/BenchmarkDotNet/BenchmarkAutoRunner.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// Do not remove this, it is needed to retain calls to conditional methods in release builds
#define DEBUG

using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Reports;
using BenchmarkDotNet.Running;
using BenchmarkDotNetVisualizer.Utilities;
Expand Down Expand Up @@ -152,21 +149,13 @@ private static void PrintMessages()
/// </returns>
public static bool IsRunningInDebugMode()
{
//NOTE: #if Directives does not work because applies in compile-time not run-time
//#if DEBUG
//return true;
//#else
//return false;
//#endif
RunIfDebug();
return debugging;
}

[Conditional("DEBUG")]
private static void RunIfDebug()
{
debugging = true;
//NOTE: #if DEBUG or [Conditional("DEBUG")] don't work for libraries because these are applied in compile-time not run-time
var customAttributes = Assembly.GetEntryAssembly()!.GetCustomAttributes(typeof(DebuggableAttribute), false);
if (customAttributes?.Length == 1)
{
var attribute = (DebuggableAttribute)customAttributes[0];
return attribute.IsJITOptimizerDisabled && attribute.IsJITTrackingEnabled;
}
return false;
}

private static bool debugging;
}

0 comments on commit de60bbf

Please sign in to comment.