55// The Debugger class is a part of the System.Diagnostics package
66// and is used for communicating with a debugger.
77
8- using System ;
9- using System . IO ;
10- using System . Collections ;
11- using System . Reflection ;
128using System . Runtime . CompilerServices ;
13- using System . Security ;
14- using System . Runtime . Versioning ;
159
1610namespace System . Diagnostics
1711{
18- // No data, does not need to be marked with the serializable attribute
19- public sealed class Debugger
12+ public static class Debugger
2013 {
21- // This should have been a static class, but wasn't as of v3.5. Clearly, this is
22- // broken. We'll keep this in V4 for binary compat, but marked obsolete as error
23- // so migrated source code gets fixed.
24- [ Obsolete ( "Do not create instances of the Debugger class. Call the static methods directly on this type instead" , true ) ]
25- public Debugger ( )
26- {
27- // Should not have been instantiable - here for binary compatibility in V4.
28- }
29-
3014 // Break causes a breakpoint to be signalled to an attached debugger. If no debugger
31- // is attached, the user is asked if he wants to attach a debugger. If yes, then the
15+ // is attached, the user is asked if he wants to attach a debugger. If yes, then the
3216 // debugger is launched.
33- [ MethodImplAttribute ( MethodImplOptions . NoInlining ) ]
34- public static void Break ( )
35- {
36- // Causing a break is now allowed.
37- BreakInternal ( ) ;
38- }
17+ [ MethodImpl ( MethodImplOptions . NoInlining ) ]
18+ public static void Break ( ) => BreakInternal ( ) ;
3919
40- private static void BreakCanThrow ( )
41- {
42- BreakInternal ( ) ;
43- }
20+ // The VM depends on this private method.
21+ private static void BreakCanThrow ( ) => BreakInternal ( ) ;
4422
45- [ MethodImplAttribute ( MethodImplOptions . InternalCall ) ]
23+ [ MethodImpl ( MethodImplOptions . InternalCall ) ]
4624 private static extern void BreakInternal ( ) ;
4725
4826 // Launch launches & attaches a debugger to the process. If a debugger is already attached,
49- // nothing happens.
27+ // nothing happens.
5028 //
51- public static bool Launch ( )
52- {
53- if ( Debugger . IsAttached )
54- return ( true ) ;
55-
56- // Causing the debugger to launch is now allowed.
57- return ( LaunchInternal ( ) ) ;
58- }
29+ public static bool Launch ( ) => IsAttached ? true : LaunchInternal ( ) ;
5930
6031 // This class implements code:ICustomDebuggerNotification and provides a type to be used to notify
61- // the debugger that execution is about to enter a path that involves a cross-thread dependency.
62- // See code:NotifyOfCrossThreadDependency for more details.
63- private class CrossThreadDependencyNotification : ICustomDebuggerNotification
64- {
65- // constructor
66- public CrossThreadDependencyNotification ( )
67- {
68- }
69- }
70-
71- // Do not inline the slow path
72- [ MethodImplAttribute ( MethodImplOptions . NoInlining ) ]
73- private static void NotifyOfCrossThreadDependencySlow ( )
74- {
75- CrossThreadDependencyNotification notification = new CrossThreadDependencyNotification ( ) ;
76- CustomNotification ( notification ) ;
77- }
78-
79- // Sends a notification to the debugger to indicate that execution is about to enter a path
80- // involving a cross thread dependency. A debugger that has opted into this type of notification
81- // can take appropriate action on receipt. For example, performing a funceval normally requires
82- // freezing all threads but the one performing the funceval. If the funceval requires execution on
83- // more than one thread, as might occur in remoting scenarios, the funceval will block. This
84- // notification will apprise the debugger that it will need to slip a thread or abort the funceval
85- // in such a situation. The notification is subject to collection after this function returns.
86- //
32+ // the debugger that execution is about to enter a path that involves a cross-thread dependency.
33+ // See code:NotifyOfCrossThreadDependency for more details.
34+ private class CrossThreadDependencyNotification : ICustomDebuggerNotification { }
35+
36+ // Do not inline the slow path
37+ [ MethodImpl ( MethodImplOptions . NoInlining ) ]
38+ private static void NotifyOfCrossThreadDependencySlow ( ) =>
39+ CustomNotification ( new CrossThreadDependencyNotification ( ) ) ;
40+
41+ // Sends a notification to the debugger to indicate that execution is about to enter a path
42+ // involving a cross thread dependency. A debugger that has opted into this type of notification
43+ // can take appropriate action on receipt. For example, performing a funceval normally requires
44+ // freezing all threads but the one performing the funceval. If the funceval requires execution on
45+ // more than one thread, as might occur in remoting scenarios, the funceval will block. This
46+ // notification will apprise the debugger that it will need to slip a thread or abort the funceval
47+ // in such a situation. The notification is subject to collection after this function returns.
48+ //
8749 public static void NotifyOfCrossThreadDependency ( )
8850 {
89- if ( Debugger . IsAttached )
51+ if ( IsAttached )
9052 {
9153 NotifyOfCrossThreadDependencySlow ( ) ;
9254 }
9355 }
9456
95- [ MethodImplAttribute ( MethodImplOptions . InternalCall ) ]
57+ [ MethodImpl ( MethodImplOptions . InternalCall ) ]
9658 private static extern bool LaunchInternal ( ) ;
9759
9860 // Returns whether or not a debugger is attached to the process.
9961 //
10062 public static extern bool IsAttached
10163 {
102- [ MethodImplAttribute ( MethodImplOptions . InternalCall ) ]
64+ [ MethodImpl ( MethodImplOptions . InternalCall ) ]
10365 get ;
10466 }
10567
@@ -108,26 +70,26 @@ public static extern bool IsAttached
10870 // An attached debugger can enable or disable which messages will
10971 // actually be reported to the user through the COM+ debugger
11072 // services API. This info is communicated to the runtime so only
111- // desired events are actually reported to the debugger.
73+ // desired events are actually reported to the debugger.
11274 //
11375 // Constant representing the default category
114- public static readonly String DefaultCategory = null ;
76+ public static readonly string DefaultCategory = null ;
11577
11678 // Posts a message for the attached debugger. If there is no
11779 // debugger attached, has no effect. The debugger may or may not
118- // report the message depending on its settings.
119- [ MethodImplAttribute ( MethodImplOptions . InternalCall ) ]
120- public static extern void Log ( int level , String category , String message ) ;
80+ // report the message depending on its settings.
81+ [ MethodImpl ( MethodImplOptions . InternalCall ) ]
82+ public static extern void Log ( int level , string category , string message ) ;
12183
12284 // Checks to see if an attached debugger has logging enabled
123- //
124- [ MethodImplAttribute ( MethodImplOptions . InternalCall ) ]
85+ //
86+ [ MethodImpl ( MethodImplOptions . InternalCall ) ]
12587 public static extern bool IsLogging ( ) ;
12688
12789 // Posts a custom notification for the attached debugger. If there is no
12890 // debugger attached, has no effect. The debugger may or may not
129- // report the notification depending on its settings.
130- [ MethodImplAttribute ( MethodImplOptions . InternalCall ) ]
91+ // report the notification depending on its settings.
92+ [ MethodImpl ( MethodImplOptions . InternalCall ) ]
13193 private static extern void CustomNotification ( ICustomDebuggerNotification data ) ;
13294 }
13395}
0 commit comments