-
Notifications
You must be signed in to change notification settings - Fork 101
/
DbgEngContext.cs
759 lines (638 loc) · 28.1 KB
/
DbgEngContext.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
using System;
namespace MS.Dbg
{
/// <summary>
/// Represents a DbgEng.dll context.
/// </summary>
/// <remarks>
/// DbgEng.dll has a concept of "context": what is the current "system", the
/// current process within that system, the current thread within that process, and
/// the current frame within that thread. When you run a debugger command, it
/// operates against the current context (so you don't have to specify which
/// system, process, thread, and frame for every command). This class represents
/// that context as a single object to help simplify things (so you don't have to
/// keep track of the four possible values separately). It is represented textually
/// by a 4-tuple: [s, p, t, f] ([system, process, thread, frame]).
///
/// Some parts of a context may be unspecified, represented by the value
/// DEBUG_ANY_ID (-1). A context with one or more unspecified components could mean
/// different things depending on the context (haha). For instance, if I wanted to
/// specify the context of a particular frame relative to the current system,
/// process, and thread, I could use the context [-1,-1,-1, 7]. In this context,
/// the unspecified values mean "relative to the current context".
///
/// An unspecified part of a DbgEngContext might also mean that there /is/ no such
/// context. For instance, if I ask the debugger to give me the current context,
/// and it gives me [0,2,-1,-1], that means that the current context is system 0,
/// process 2, but that it has no current thread or frame context).
///
/// Note that it is valid for a context to represent a "system", but not any
/// particular process, thread, or frame ([0,-1,-1,-1]); and it is valid for a
/// context to represent "no context" ([-1,-1,-1,-1]).
/// </remarks>
public class DbgEngContext : IEquatable< DbgEngContext >, IComparable< DbgEngContext >
{
public const uint DEBUG_ANY_ID = unchecked( (uint) 0xffffffff );
/// <summary>
/// Indicates which DbgEng.dll "system id" the context represents.
/// </summary>
/// <remarks>
/// <para>
/// DbgEng.dll can be connected to multiple targets: dumps, live processes and
/// kernel targets. It groups these targets into "systems": each dump lives in
/// a separate "system", each kernel target lives in a separate "system", but
/// there can be multiple live processes in a single "system".
/// </para>
/// <para>
/// A value of 0xffffffff (DEBUG_ANY_ID) means the index is unspecified,
/// indicating the current system index, or /no/ system index (such as if the
/// debugger is not connected to any system).
/// </para>
/// </remarks>
public readonly uint SystemIndex;
/// <summary>
/// Indicates which DbgEng.dll "process id" the context represents.
/// </summary>
/// <remarks>
/// <para>
/// Within a single "system", DbgEng.dll can be connected to multiple live
/// processes. N.B. The dbgeng.dll process id is not the same as the OS
/// process id.
/// </para>
/// <para>
/// A value of 0xffffffff (DEBUG_ANY_ID) means the index is unspecified,
/// indicating the current process index, or /no/ process index (such as if the
/// debugger has no current process).
/// </para>
/// </remarks>
public readonly ulong ProcessIndexOrAddress;
/// <summary>
/// Indicates which DbgEng.dll "thread id" the context represents.
/// </summary>
/// <remarks>
/// <para>
/// N.B. The dbgeng.dll thread id is not the same as the OS thread id.
/// </para>
/// <para>
/// A value of 0xffffffff (DEBUG_ANY_ID) means the index is unspecified,
/// indicating the current thread index, or /no/ thread index (such as if the
/// debugger has no current thread).
/// </para>
/// </remarks>
public readonly ulong ThreadIndexOrAddress;
/// <summary>
/// Indicates a particular frame in a thread's stack.
/// </summary>
/// <remarks>
/// <para>
/// A value of 0xffffffff (DEBUG_ANY_ID) means the index is unspecified,
/// indicating the current frame index, or /no/ frame index.
/// </para>
/// </remarks>
public readonly uint FrameIndex;
public readonly bool? IsKernelContext;
/// <summary>
/// Returns ProcessIndexOrAddress, ensuring that it is a ProcessIndex (and not
/// an address). (i.e. it must be specified, and it must be user-mode)
/// </summary>
public uint RequireUModeProcessIndex()
{
if( ProcessIndexOrAddress == DEBUG_ANY_ID )
{
throw new DbgProviderException( "Process index is required.",
"ProcessIndexRequired",
System.Management.Automation.ErrorCategory.InvalidData,
this );
}
if( (IsKernelContext.HasValue && IsKernelContext.Value) ||
((ProcessIndexOrAddress & 0xffffffff00000000) != 0) )
{
throw new DbgProviderException( "Process index (user-mode) is required.",
"ProcessIndexRequired_notUserMode",
System.Management.Automation.ErrorCategory.InvalidData,
this );
}
return (uint) ProcessIndexOrAddress;
} // end RequireUModeProcessIndex()
/// <summary>
/// Indicates the current system, process, thread, and frame; alternatively,
/// represents NO system, process, thread, or frame.
/// </summary>
public static readonly DbgEngContext CurrentOrNone = new DbgEngContext( DEBUG_ANY_ID,
DEBUG_ANY_ID,
DEBUG_ANY_ID,
DEBUG_ANY_ID,
null );
/// <summary>
/// Creates a DbgEngContext that represents the current process, thread, and
/// frame in the specified system (unless the systemIndex is DEBUG_ANY_ID).
/// </summary>
public DbgEngContext( uint systemIndex )
: this( systemIndex, DEBUG_ANY_ID, DEBUG_ANY_ID, DEBUG_ANY_ID, null )
{
}
public DbgEngContext( uint systemIndex, bool isKernel )
: this( systemIndex, DEBUG_ANY_ID, DEBUG_ANY_ID, DEBUG_ANY_ID, isKernel )
{
}
/// <summary>
/// Creates a DbgEngContext that represents the current thread and frame in the
/// specified system and process (unless any of the specified indexes are
/// DEBUG_ANY_ID).
/// </summary>
public DbgEngContext( uint systemIndex,
uint processIndex )
: this( systemIndex, processIndex, DEBUG_ANY_ID, DEBUG_ANY_ID )
{
}
private static bool? _LooksLikeAddress( ulong idOrAddr )
{
if( idOrAddr == DEBUG_ANY_ID )
return null;
return 0 != (0xffffffff00000000 & idOrAddr);
}
private static bool? _EitherLooksLikeAddress( ulong idOrAddr1, ulong idOrAddr2 )
{
bool? b = _LooksLikeAddress( idOrAddr1 );
if( null == b )
b = _LooksLikeAddress( idOrAddr2 );
return b;
}
public DbgEngContext( uint systemIndex,
ulong processIndexOrAddress )
: this( systemIndex,
processIndexOrAddress,
DEBUG_ANY_ID,
DEBUG_ANY_ID,
_LooksLikeAddress( processIndexOrAddress ) )
{
}
/// <summary>
/// Creates a DbgEngContext that represents the current frame in the specified
/// system, process, and thread (unless any of the specified indexes are
/// DEBUG_ANY_ID).
/// </summary>
public DbgEngContext( uint systemIndex,
uint processIndex,
uint threadIndex )
: this( systemIndex, processIndex, threadIndex, DEBUG_ANY_ID )
{
}
/// <summary>
/// Creates a fully-specified DbgEngContext that represents a particular
/// system, process, thread, and frame (unless any of the indexes are
/// DEBUG_ANY_ID).
/// </summary>
public DbgEngContext( uint systemIndex,
uint processIndex,
uint threadIndex,
uint frameIndex )
: this( systemIndex,
processIndex,
threadIndex,
frameIndex,
false )
{
} // end constructor
private DbgEngContext( uint systemIndex,
uint processIndex,
uint threadIndex,
uint frameIndex,
bool isKernelContext )
{
SystemIndex = systemIndex;
ProcessIndexOrAddress = processIndex;
ThreadIndexOrAddress = threadIndex;
FrameIndex = frameIndex;
IsKernelContext = isKernelContext;
} // end constructor
public DbgEngContext( uint systemIndex,
ulong processAddress,
ulong threadAddress,
uint frameIndex )
: this( systemIndex,
processAddress,
threadAddress,
frameIndex,
_EitherLooksLikeAddress( processAddress, threadAddress ) )
{
}
internal DbgEngContext( uint systemIndex,
ulong processIndexOrAddress,
ulong threadIndexOrAddress,
uint frameIndex,
bool? isKernelContext )
{
SystemIndex = systemIndex;
ProcessIndexOrAddress = processIndexOrAddress;
ThreadIndexOrAddress = threadIndexOrAddress;
FrameIndex = frameIndex;
IsKernelContext = isKernelContext;
} // end constructor
/// <summary>
/// Returns true if none of the indexes are unspecified (DEBUG_ANY_ID).
/// </summary>
public bool IsFullySpecified
{
get
{
bool isFullySpecified = (SystemIndex != DEBUG_ANY_ID) &&
(ProcessIndexOrAddress != DEBUG_ANY_ID) &&
(ThreadIndexOrAddress != DEBUG_ANY_ID) &&
(FrameIndex != DEBUG_ANY_ID);
if( isFullySpecified )
{
Util.Assert( IsKernelContext != null );
}
return isFullySpecified;
}
} // end property IsFullySpecified
/// <summary>
/// If any indexes that are specified (!= DEBUG_ANY_ID) come after an unspecified index
/// (DEBUG_ANY_ID), this returns true.
/// </summary>
/// <remarks>
/// Note that a non-fully-specified context (for example: {0, 0, DEBUG_ANY_ID, DEBUG_ANY_ID}) does
/// not count as relative: "relative" here means relative to the current
/// context, not relative to an absolute context (a context of {0, 0, DEBUG_ANY_ID, DEBUG_ANY_ID}
/// would be relative to the absolute context of system 0, process 0; whereas a
/// context of {0, DEBUG_ANY_ID, 0, 0} would be relative to whatever the current process
/// is in system 0).
/// </remarks>
public bool IsRelative
{
get
{
bool foundUnspecifiedIndex = false;
if( SystemIndex == DEBUG_ANY_ID )
foundUnspecifiedIndex = true;
if( ProcessIndexOrAddress == DEBUG_ANY_ID )
foundUnspecifiedIndex = true;
else if( foundUnspecifiedIndex )
return true;
if( ThreadIndexOrAddress == DEBUG_ANY_ID )
foundUnspecifiedIndex = true;
else if( foundUnspecifiedIndex )
return true;
if( (FrameIndex != DEBUG_ANY_ID) && foundUnspecifiedIndex )
return true;
return false;
}
} // end property IsRelative
#region IEquatable< DbgEngContext > Members
public bool Equals( DbgEngContext other )
{
if( null == other )
return false;
return (SystemIndex == other.SystemIndex) &&
(ProcessIndexOrAddress == other.ProcessIndexOrAddress) &&
(ThreadIndexOrAddress == other.ThreadIndexOrAddress) &&
(FrameIndex == other.FrameIndex) &&
(IsKernelContext == other.IsKernelContext);
} // end Equals( other )
#endregion IEquatable< DbgEngContext >
public override bool Equals( object obj )
{
return Equals( obj as DbgEngContext );
}
public override int GetHashCode()
{
// We'll spread the indexes out across the 32 bits of the result:
//
// User mode or not specified:
// SystemIndex: 5 bits
// ProcessIndex: 5 bits
// ThreadIndex: 11 bits
// FrameIndex: 11 bits
//
// Kernel mode:
// SystemIndex: 4 bits
// ProcessIndex: 11 bits (taken from proc addr >> 8)
// ThreadIndex: 11 bits (taken from thread addr >> 8)
// FrameIndex: 6 bits
int hash;
if( IsKernelContext.HasValue && IsKernelContext.Value )
{
hash = ((int) SystemIndex & 0x00f) << 28
+ (((int) ProcessIndexOrAddress >> 8) & 0x6ff) << 17
+ (((int) ThreadIndexOrAddress >> 8) & 0x6ff) << 6
+ ((int) FrameIndex & 0x03f);
}
else
{
hash = ((int) SystemIndex & 0x01f) << 27
+ ((int) ProcessIndexOrAddress & 0x01f) << 22
+ ((int) ThreadIndexOrAddress & 0x6ff) << 11
+ ((int) FrameIndex & 0x6ff);
}
return hash;
} // end GetHashCode()
public static bool operator ==( DbgEngContext dec1, DbgEngContext dec2 )
{
if( null == (object) dec1 )
return (null == (object) dec2);
return dec1.Equals( dec2 );
}
public static bool operator !=( DbgEngContext dec1, DbgEngContext dec2 )
{
return !(dec1 == dec2);
}
#region IComparable< DbgEngContext > Members
public int CompareTo( DbgEngContext other )
{
int result = 0;
result = SystemIndex.CompareTo( other.SystemIndex );
if( 0 != result )
return result;
result = IsKernelContext.HasValue.CompareTo( other.IsKernelContext.HasValue );
if( 0 != result )
return result;
if( IsKernelContext.HasValue )
{
result = IsKernelContext.Value.CompareTo( other.IsKernelContext.Value );
if( 0 != result )
return result;
}
result = ProcessIndexOrAddress.CompareTo( other.ProcessIndexOrAddress );
if( 0 != result )
return result;
result = ThreadIndexOrAddress.CompareTo( other.ThreadIndexOrAddress );
if( 0 != result )
return result;
result = FrameIndex.CompareTo( other.FrameIndex );
return result;
} // end CompareTo( other )
#endregion IComparable< DbgEngContext >
bool TryCombine( DbgEngContext other, out DbgEngContext combined )
{
combined = null;
uint sId, fId;
ulong pId, tId;
bool? iskc;
if( SystemIndex == DEBUG_ANY_ID )
sId = other.SystemIndex;
else if( other.SystemIndex == DEBUG_ANY_ID )
sId = SystemIndex;
else if( SystemIndex == other.SystemIndex )
sId = SystemIndex;
else
return false; // they conflict
if( IsKernelContext == null )
iskc = other.IsKernelContext;
else if( other.IsKernelContext == null )
iskc = IsKernelContext;
else if( IsKernelContext.Value == other.IsKernelContext.Value )
iskc = IsKernelContext;
else
return false; // they conflict
if( ProcessIndexOrAddress == DEBUG_ANY_ID )
pId = other.ProcessIndexOrAddress;
else if( other.ProcessIndexOrAddress == DEBUG_ANY_ID )
pId = ProcessIndexOrAddress;
else if( ProcessIndexOrAddress == other.ProcessIndexOrAddress )
pId = ProcessIndexOrAddress;
else
return false; // they conflict
if( ThreadIndexOrAddress == DEBUG_ANY_ID )
tId = other.ThreadIndexOrAddress;
else if( other.ThreadIndexOrAddress == DEBUG_ANY_ID )
tId = ThreadIndexOrAddress;
else if( ThreadIndexOrAddress == other.ThreadIndexOrAddress )
tId = ThreadIndexOrAddress;
else
return false; // they conflict
if( FrameIndex == DEBUG_ANY_ID )
fId = other.FrameIndex;
else if( other.FrameIndex == DEBUG_ANY_ID )
fId = FrameIndex;
else if( FrameIndex == other.FrameIndex )
fId = FrameIndex;
else
return false; // they conflict
if( (sId == SystemIndex) &&
(pId == ProcessIndexOrAddress) &&
(tId == ThreadIndexOrAddress) &&
(fId == FrameIndex) &&
(iskc == IsKernelContext) )
{
// They were the same.
combined = this;
}
else
{
// They were complementary
combined = new DbgEngContext( sId, pId, tId, fId, iskc );
}
return true;
} // end TryCombine()
public bool IsStrictSuperSetOf( DbgEngContext other )
{
bool foundDifference = false;
if( SystemIndex != other.SystemIndex )
{
if( DEBUG_ANY_ID == SystemIndex )
return false; // 'other' has a component we don't have
else if( DEBUG_ANY_ID != other.SystemIndex )
return false; // they conflict
foundDifference = true;
}
if( IsKernelContext != other.IsKernelContext )
{
if( null == IsKernelContext )
return false; // 'other' has a component we don't have
else if( null != other.IsKernelContext )
return false; // they conflict
foundDifference = true;
}
if( ProcessIndexOrAddress != other.ProcessIndexOrAddress )
{
if( DEBUG_ANY_ID == ProcessIndexOrAddress )
return false; // 'other' has a component we don't have
else if( DEBUG_ANY_ID != other.ProcessIndexOrAddress )
return false; // they conflict
foundDifference = true;
}
if( ThreadIndexOrAddress != other.ThreadIndexOrAddress )
{
if( DEBUG_ANY_ID == ThreadIndexOrAddress )
return false; // 'other' has a component we don't have
else if( DEBUG_ANY_ID != other.ThreadIndexOrAddress )
return false; // they conflict
foundDifference = true;
}
if( FrameIndex != other.FrameIndex )
{
if( DEBUG_ANY_ID == FrameIndex )
return false; // 'other' has a component we don't have
else if( DEBUG_ANY_ID != other.FrameIndex )
return false; // they conflict
foundDifference = true;
}
return foundDifference;
} // end IsStrictSuperSetOf()
public override string ToString()
{
var sb = new System.Text.StringBuilder( 50 );
sb.Append( "DbgEngContext: [" );
if( DEBUG_ANY_ID == SystemIndex )
sb.Append( "-1," );
else
sb.Append( SystemIndex.ToString( "x" ).PadLeft( 2 ) ).Append( ',' );
if( DEBUG_ANY_ID == ProcessIndexOrAddress )
sb.Append( "-1," );
else
sb.Append( ProcessIndexOrAddress.ToString( "x" ).PadLeft( 2 ) ).Append( ',' );
if( DEBUG_ANY_ID == ThreadIndexOrAddress )
sb.Append( " -1," );
else
sb.Append( ThreadIndexOrAddress.ToString( "x" ).PadLeft( 3 ) ).Append( ',' );
if( DEBUG_ANY_ID == FrameIndex )
sb.Append( " -1" );
else
sb.Append( FrameIndex.ToString( "x" ).PadLeft( 3 ) );
if( IsKernelContext.HasValue )
{
if( IsKernelContext.Value )
sb.Append( " (km)]" );
else
sb.Append( " (um)]" );
}
else
{
sb.Append( " (--)]" );
}
return sb.ToString();
} // end ToString()
/// <summary>
/// Returns a [potentially new] context representing just the system and
/// process portions of the context. If the context does not represent a
/// process, this will throw an InvalidOperationException. Use
/// TryAsProcessContext for a non-throwing alternative.
///
/// Consider whether this is actually the right method, or if you actually want
/// AsTargetContext.
/// </summary>
public DbgEngContext AsProcessContext()
{
DbgEngContext ctx;
if( !TryAsProcessContext( out ctx ) )
throw new InvalidOperationException( "The context is not specific enough to represent a process." );
return ctx;
} // end AsProcessContext()
/// <summary>
/// Attempts to convert this to a context representing just the system and
/// process portions of the context. If the context does not represent a
/// process, this will return false.
///
/// Consider whether this is actually the right method, or if you actually want
/// TryAsTargetContext.
/// </summary>
public bool TryAsProcessContext( out DbgEngContext asProcessContext )
{
asProcessContext = null;
if( (DEBUG_ANY_ID == SystemIndex) ||
(DEBUG_ANY_ID == ProcessIndexOrAddress) )
{
return false;
}
if( (DEBUG_ANY_ID == ThreadIndexOrAddress) &&
(DEBUG_ANY_ID == FrameIndex) )
{
asProcessContext = this;
return true;
}
asProcessContext = new DbgEngContext( SystemIndex, ProcessIndexOrAddress );
return true;
} // end TryAsProcessContext()
/// <summary>
/// Returns a [potentially new] context representing just the system
/// portion of the context.
/// </summary>
public DbgEngContext AsSystemContext()
{
DbgEngContext ctx;
if( !TryAsSystemContext( out ctx ) )
throw new InvalidOperationException( "The context is not specific enough to represent a system." );
return ctx;
} // end AsSystemContext()
/// <summary>
/// Attempts to convert this to a context representing just the system
/// portion of the context. If the context does not represent a
/// system, this will return false.
/// </summary>
public bool TryAsSystemContext( out DbgEngContext asSystemContext )
{
asSystemContext = null;
if( DEBUG_ANY_ID == SystemIndex )
{
return false;
}
if( (DEBUG_ANY_ID == ProcessIndexOrAddress) &&
(DEBUG_ANY_ID == ThreadIndexOrAddress) &&
(DEBUG_ANY_ID == FrameIndex) )
{
asSystemContext = this;
return true;
}
asSystemContext = new DbgEngContext( SystemIndex, DEBUG_ANY_ID, DEBUG_ANY_ID, DEBUG_ANY_ID, IsKernelContext );
return true;
} // end TryAsSystemContext()
/// <summary>
/// Returns a [potentially new] context representing either just the system and
/// process portions of the context (for a user-mode context), or just the
/// system portion (for kernel mode). If the context does not represent a
/// target, this will throw an InvalidOperationException. Use
/// TryAsTargetContext for a non-throwing alternative.
/// </summary>
public DbgEngContext AsTargetContext()
{
DbgEngContext ctx;
if( !TryAsTargetContext( out ctx ) )
throw new InvalidOperationException( "The context is not specific enough to represent a target." );
return ctx;
} // end AsTargetContext()
/// <summary>
/// Attempts to convert this to a context representing either just the system
/// and process portions of the context (for a user-mode context), or just the
/// system portion (for kernel mode). If the context does not represent a
/// target, this will return false.
/// </summary>
public bool TryAsTargetContext( out DbgEngContext asTargetContext )
{
asTargetContext = null;
if( IsKernelContext.HasValue && IsKernelContext.Value )
{
return TryAsSystemContext( out asTargetContext );
}
else
{
return TryAsProcessContext( out asTargetContext );
}
} // end TryAsTargetContext()
public DbgEngContext WithoutFrameIndex()
{
if( DEBUG_ANY_ID == FrameIndex )
{
return this;
}
return new DbgEngContext( SystemIndex,
ProcessIndexOrAddress,
ThreadIndexOrAddress,
DEBUG_ANY_ID,
IsKernelContext );
} // end WithoutFrameIndex()
public DbgEngContext WithoutThreadOrFrameIndex()
{
if( (DEBUG_ANY_ID == FrameIndex) &&
(DEBUG_ANY_ID == ThreadIndexOrAddress) )
{
return this;
}
return new DbgEngContext( SystemIndex,
ProcessIndexOrAddress,
DEBUG_ANY_ID,
DEBUG_ANY_ID,
IsKernelContext );
} // end WithoutThreadOrFrameIndex()
} // end class DbgEngContext
}