[Mono-bugs] [Bug 52709][Nor] Changed - System.Diagnostics.Debug methods unexpected behaviour when DEBUG defined

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Fri, 9 Jan 2004 14:52:15 -0500 (EST)

Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by t7@pobox.com.


--- shadow/52709	2004-01-09 14:02:49.000000000 -0500
+++ shadow/52709.tmp.14027	2004-01-09 14:52:15.000000000 -0500
@@ -89,6 +89,73 @@
 Looks to me (unsure) that DEBUG needs to be defined when the runtime
 is built for them to output anything.
 Is that the entended behaviour? i.e. that the System.Diagnostic
 classes are for diagnosing the runtime during its development rather
 than for the use of application developers?
+------- Additional Comments From t7@pobox.com  2004-01-09 14:52 -------
+Continuing my investigation (/confusion); The mono class lib
+documentation has a System.Diagnostics.ConditionalAttribute that has
+an example:
+"using System;
+using System.Diagnostics;
+public class MyClass { 
+  [ConditionalAttribute("DEBUG")] 
+  public static void Display() { 
+    Console.WriteLine("Compiled with DEBUG"); 
+  }
+public class TestCondition { 
+  public static void Main() { 
+    Console.WriteLine("How was this compiled?"); 
+    MyClass.Display(); 
+    Console.WriteLine("<eop>"); 
+  }
+When this code is compiled with the compilation-variable DEBUG defined
+at the callsite [...]"
+When I compile this example, it outputs the string 'Compiled with
+DEBUG' even if I don't define DEBUG - even if I add #undef DEBUG at
+the top.
+Obviously that isn't correct.
+However, if I change the code from
+[ConditionalAttribute("DEBUG")] to [Conditional("DEBUG")] it
+does appear to work as advertized.
+(I'm not sure what the difference is between [Conditional("DEBUG")]
+and [ConditionalAttribute("DEBUG")], if any? - are they different
+attribute classes?)
+The [Conditional("DEBUG")] form is what appears in the source of the
+Debug class methods, so I don't understand why it doesn't work.
+If I seperate the code into two classes
+so that I can independently compile the call and called methods
+with and without DEBUG defined in each,
+it sort-of works.
+If DEBUG is defined at the call site, it outputs.  If it isn't
+defined, it doesn't output (as expected).
+However, if I define DEBUG in the compilation unit of the
+method implementation, it always outputs, regardless of the
+definition or not of DEBUG at the call-site.
+(I'm assuming that DEBUG is only visible to the compiler? If it is
+a symbol that gets into the assembly, then perhaps that is
+understandable, as I'm compiling with
+mcs example1.cs example2.cs
+where example1.cs contains the TestCondition class and
+example2.cs contains the MyClass class)
+Given this behaviour, I have no idea why the calls to Debug.WriteLine
+don't output.
+Any ideas?