Skip to content

Commit de60bbf

Browse files
committed
IsRunningInDebugMode method fixed - Version 1.0.3
1 parent c262b21 commit de60bbf

1 file changed

Lines changed: 9 additions & 20 deletions

File tree

src/BenchmarkDotNet/BenchmarkAutoRunner.cs

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
// Do not remove this, it is needed to retain calls to conditional methods in release builds
2-
#define DEBUG
3-
4-
using BenchmarkDotNet.Configs;
1+
using BenchmarkDotNet.Configs;
52
using BenchmarkDotNet.Reports;
63
using BenchmarkDotNet.Running;
74
using BenchmarkDotNetVisualizer.Utilities;
@@ -152,21 +149,13 @@ private static void PrintMessages()
152149
/// </returns>
153150
public static bool IsRunningInDebugMode()
154151
{
155-
//NOTE: #if Directives does not work because applies in compile-time not run-time
156-
//#if DEBUG
157-
//return true;
158-
//#else
159-
//return false;
160-
//#endif
161-
RunIfDebug();
162-
return debugging;
163-
}
164-
165-
[Conditional("DEBUG")]
166-
private static void RunIfDebug()
167-
{
168-
debugging = true;
152+
//NOTE: #if DEBUG or [Conditional("DEBUG")] don't work for libraries because these are applied in compile-time not run-time
153+
var customAttributes = Assembly.GetEntryAssembly()!.GetCustomAttributes(typeof(DebuggableAttribute), false);
154+
if (customAttributes?.Length == 1)
155+
{
156+
var attribute = (DebuggableAttribute)customAttributes[0];
157+
return attribute.IsJITOptimizerDisabled && attribute.IsJITTrackingEnabled;
158+
}
159+
return false;
169160
}
170-
171-
private static bool debugging;
172161
}

0 commit comments

Comments
 (0)