@@ -41,8 +41,6 @@ class ManagedCallback
41
41
bool isInCallback ;
42
42
DebuggerPausedEventArgs pausedEventArgs ;
43
43
44
- Thread threadToReport ; // TODO: Remove
45
-
46
44
[ Debugger . Tests . Ignore ]
47
45
public Process Process {
48
46
get { return process ; }
@@ -61,9 +59,14 @@ public ManagedCallback(Process process)
61
59
// The reason for the accumulation is that several pause callbacks
62
60
// can happen "at the same time" in the debugee.
63
61
// The event will be raised as soon as the callback queue is drained.
64
- DebuggerPausedEventArgs GetPausedEventArgs ( )
62
+ DebuggerPausedEventArgs RequestPause ( Thread thread )
65
63
{
66
- return pausedEventArgs ?? ( pausedEventArgs = new DebuggerPausedEventArgs ( process ) ) ;
64
+ pauseOnNextExit = true ;
65
+ if ( pausedEventArgs == null ) {
66
+ pausedEventArgs = new DebuggerPausedEventArgs ( process ) ;
67
+ pausedEventArgs . Thread = thread ;
68
+ }
69
+ return pausedEventArgs ;
67
70
}
68
71
69
72
void EnterCallback ( string name , ICorDebugProcess pProcess )
@@ -100,7 +103,6 @@ void EnterCallback(string name, ICorDebugAppDomain pAppDomain)
100
103
void EnterCallback ( string name , ICorDebugThread pThread )
101
104
{
102
105
EnterCallback ( name , pThread . GetProcess ( ) ) ;
103
- threadToReport = process . GetThread ( pThread ) ;
104
106
}
105
107
106
108
void ExitCallback ( )
@@ -120,9 +122,6 @@ void ExitCallback()
120
122
121
123
process . DisableAllSteppers ( ) ;
122
124
if ( pausedEventArgs != null ) {
123
- pausedEventArgs . Thread = threadToReport ;
124
- threadToReport = null ;
125
-
126
125
// Raise the pause event outside the callback
127
126
// Warning: Make sure that process in not resumed in the meantime
128
127
DebuggerPausedEventArgs e = pausedEventArgs ; // Copy for capture
@@ -173,8 +172,7 @@ public void StepComplete(ICorDebugAppDomain pAppDomain, ICorDebugThread pThread,
173
172
}
174
173
} else {
175
174
// User-code method
176
- pauseOnNextExit = true ;
177
- GetPausedEventArgs ( ) . Break = true ;
175
+ RequestPause ( thread ) . Break = true ;
178
176
process . TraceMessage ( " - pausing in user code" ) ;
179
177
}
180
178
@@ -187,16 +185,16 @@ public void Breakpoint(ICorDebugAppDomain pAppDomain, ICorDebugThread pThread, I
187
185
EnterCallback ( "Breakpoint" , pThread ) ;
188
186
189
187
Breakpoint breakpoint = process . Debugger . GetBreakpoint ( corBreakpoint ) ;
188
+ Thread thread = process . GetThread ( pThread ) ;
189
+
190
190
// Could be one of Process.tempBreakpoints
191
191
// The breakpoint might have just been removed
192
192
if ( breakpoint != null ) {
193
- GetPausedEventArgs ( ) . BreakpointsHit . Add ( breakpoint ) ;
193
+ RequestPause ( thread ) . BreakpointsHit . Add ( breakpoint ) ;
194
194
} else {
195
- GetPausedEventArgs ( ) . Break = true ;
195
+ RequestPause ( thread ) . Break = true ;
196
196
}
197
197
198
- pauseOnNextExit = true ;
199
-
200
198
ExitCallback ( ) ;
201
199
}
202
200
@@ -210,26 +208,22 @@ public void BreakpointSetError(ICorDebugAppDomain pAppDomain, ICorDebugThread pT
210
208
public void Break ( ICorDebugAppDomain pAppDomain , ICorDebugThread pThread )
211
209
{
212
210
EnterCallback ( "Break" , pThread ) ;
213
-
214
- pauseOnNextExit = true ;
215
- GetPausedEventArgs ( ) . Break = true ;
211
+ RequestPause ( process . GetThread ( pThread ) ) . Break = true ;
216
212
ExitCallback ( ) ;
217
213
}
218
214
219
215
public void ControlCTrap ( ICorDebugProcess pProcess )
220
216
{
221
217
EnterCallback ( "ControlCTrap" , pProcess ) ;
222
-
223
- pauseOnNextExit = true ;
224
- GetPausedEventArgs ( ) . Break = true ;
218
+ RequestPause ( null ) . Break = true ;
225
219
ExitCallback ( ) ;
226
220
}
227
221
228
222
public void Exception ( ICorDebugAppDomain pAppDomain , ICorDebugThread pThread , int unhandled )
229
223
{
230
224
// Exception2 is used in .NET Framework 2.0
231
225
232
- if ( process . DebuggeeVersion . StartsWith ( "v1." ) ) {
226
+ if ( process . DebuggeeVersion . StartsWith ( "v1." , StringComparison . Ordinal ) ) {
233
227
// Forward the call to Exception2, which handles EnterCallback and ExitCallback
234
228
ExceptionType exceptionType = ( unhandled != 0 ) ? ExceptionType . Unhandled : ExceptionType . FirstChance ;
235
229
Exception2 ( pAppDomain , pThread , null , 0 , ( CorDebugExceptionCallbackType ) exceptionType , 0 ) ;
@@ -311,8 +305,7 @@ public void DebuggerError(ICorDebugProcess pProcess, int errorHR, uint errorCode
311
305
throw new DebuggerException ( errorText ) ;
312
306
313
307
try {
314
- pauseOnNextExit = true ;
315
- GetPausedEventArgs ( ) . Break = true ;
308
+ RequestPause ( null ) . Break = true ;
316
309
ExitCallback ( ) ;
317
310
} catch ( COMException ) {
318
311
} catch ( InvalidComObjectException ) {
@@ -550,9 +543,7 @@ public void Exception2(ICorDebugAppDomain pAppDomain, ICorDebugThread pThread, I
550
543
// (I have managed to create a test application to trigger it)
551
544
Thread thread = process . GetThread ( pThread ) ;
552
545
thread . CurrentExceptionType = exceptionType ;
553
- GetPausedEventArgs ( ) . ExceptionsThrown . Add ( thread ) ;
554
-
555
- pauseOnNextExit = true ;
546
+ RequestPause ( thread ) . ExceptionsThrown . Add ( thread ) ;
556
547
}
557
548
558
549
ExitCallback ( ) ;
0 commit comments