forked from maraf/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctioninfo.cpp
More file actions
2518 lines (2100 loc) · 78.1 KB
/
functioninfo.cpp
File metadata and controls
2518 lines (2100 loc) · 78.1 KB
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
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
//*****************************************************************************
//
// File: DebuggerModule.cpp
//
// Stuff for tracking DebuggerModules.
//
//*****************************************************************************
#include "stdafx.h"
#include "../inc/common.h"
#include "eeconfig.h" // This is here even for retail & free builds...
#include "vars.hpp"
#include <limits.h>
#include "ilformatter.h"
#include "debuginfostore.h"
#include "../../vm/methoditer.h"
#ifndef DACCESS_COMPILE
bool DbgIsSpecialILOffset(DWORD offset)
{
LIMITED_METHOD_CONTRACT;
return (offset == (ULONG) ICorDebugInfo::PROLOG ||
offset == (ULONG) ICorDebugInfo::EPILOG ||
offset == (ULONG) ICorDebugInfo::NO_MAPPING);
}
// Helper to use w/ the debug stores.
BYTE* InteropSafeNew(void * , size_t cBytes)
{
BYTE * p = new (interopsafe, nothrow) BYTE[cBytes];
return p;
}
//
// This is only fur internal debugging.
//
#ifdef LOGGING
static void _dumpVarNativeInfo(ICorDebugInfo::NativeVarInfo* vni)
{
WRAPPER_NO_CONTRACT;
LOG((LF_CORDB, LL_INFO1000000, "Var %02d: 0x%04x-0x%04x vlt=",
vni->varNumber,
vni->startOffset, vni->endOffset,
vni->loc.vlType));
switch (vni->loc.vlType)
{
case ICorDebugInfo::VLT_REG:
LOG((LF_CORDB, LL_INFO1000000, "REG reg=%d\n", vni->loc.vlReg.vlrReg));
break;
case ICorDebugInfo::VLT_REG_BYREF:
LOG((LF_CORDB, LL_INFO1000000, "REG_BYREF reg=%d\n", vni->loc.vlReg.vlrReg));
break;
case ICorDebugInfo::VLT_STK:
LOG((LF_CORDB, LL_INFO1000000, "STK reg=%d off=0x%04x (%d)\n",
vni->loc.vlStk.vlsBaseReg,
vni->loc.vlStk.vlsOffset,
vni->loc.vlStk.vlsOffset));
break;
case ICorDebugInfo::VLT_STK_BYREF:
LOG((LF_CORDB, LL_INFO1000000, "STK_BYREF reg=%d off=0x%04x (%d)\n",
vni->loc.vlStk.vlsBaseReg,
vni->loc.vlStk.vlsOffset,
vni->loc.vlStk.vlsOffset));
break;
case ICorDebugInfo::VLT_REG_REG:
LOG((LF_CORDB, LL_INFO1000000, "REG_REG reg1=%d reg2=%d\n",
vni->loc.vlRegReg.vlrrReg1,
vni->loc.vlRegReg.vlrrReg2));
break;
case ICorDebugInfo::VLT_REG_STK:
LOG((LF_CORDB, LL_INFO1000000, "REG_STK reg=%d basereg=%d off=0x%04x (%d)\n",
vni->loc.vlRegStk.vlrsReg,
vni->loc.vlRegStk.vlrsStk.vlrssBaseReg,
vni->loc.vlRegStk.vlrsStk.vlrssOffset,
vni->loc.vlRegStk.vlrsStk.vlrssOffset));
break;
case ICorDebugInfo::VLT_STK_REG:
LOG((LF_CORDB, LL_INFO1000000, "STK_REG basereg=%d off=0x%04x (%d) reg=%d\n",
vni->loc.vlStkReg.vlsrStk.vlsrsBaseReg,
vni->loc.vlStkReg.vlsrStk.vlsrsOffset,
vni->loc.vlStkReg.vlsrStk.vlsrsOffset,
vni->loc.vlStkReg.vlsrReg));
break;
case ICorDebugInfo::VLT_STK2:
LOG((LF_CORDB, LL_INFO1000000, "STK_STK reg=%d off=0x%04x (%d)\n",
vni->loc.vlStk2.vls2BaseReg,
vni->loc.vlStk2.vls2Offset,
vni->loc.vlStk2.vls2Offset));
break;
case ICorDebugInfo::VLT_FPSTK:
LOG((LF_CORDB, LL_INFO1000000, "FPSTK reg=%d\n",
vni->loc.vlFPstk.vlfReg));
break;
case ICorDebugInfo::VLT_FIXED_VA:
LOG((LF_CORDB, LL_INFO1000000, "FIXED_VA offset=%d (%d)\n",
vni->loc.vlFixedVarArg.vlfvOffset,
vni->loc.vlFixedVarArg.vlfvOffset));
break;
default:
LOG((LF_CORDB, LL_INFO1000000, "???\n"));
break;
}
}
#endif
#if defined(FEATURE_EH_FUNCLETS)
void DebuggerJitInfo::InitFuncletAddress()
{
CONTRACTL
{
NOTHROW;
GC_NOTRIGGER;
}
CONTRACTL_END;
m_funcletCount = (int)g_pEEInterface->GetFuncletStartOffsets((const BYTE*)m_addrOfCode, NULL, 0);
if (m_funcletCount == 0)
{
_ASSERTE(m_rgFunclet == NULL);
return;
}
m_rgFunclet = (DWORD*)(new (interopsafe, nothrow) DWORD[m_funcletCount]);
// All bets are off for stepping this method.
if (m_rgFunclet == NULL)
{
m_funcletCount = 0;
return;
}
// This will get the offsets relative to the parent method start as if
// the funclet was in contiguous memory (i.e. not hot/cold split).
g_pEEInterface->GetFuncletStartOffsets((const BYTE*)m_addrOfCode, m_rgFunclet, m_funcletCount);
}
//
// DebuggerJitInfo::GetFuncletOffsetByIndex()
//
// Given a funclet index, return its starting offset.
//
// parameters: index - index of the funclet
//
// return value: starting offset of the specified funclet, or -1 if the index is invalid
//
DWORD DebuggerJitInfo::GetFuncletOffsetByIndex(int index)
{
LIMITED_METHOD_CONTRACT;
if (index < 0 || index >= m_funcletCount)
{
return (-1);
}
return m_rgFunclet[index];
}
//
// DebuggerJitInfo::GetFuncletIndex()
//
// Given an offset or an absolute address, return the index of the funclet containing it.
//
// parameters: offsetOrAddr - an offset or an absolute address in the method
// mode - whether the first argument is an offset or an absolute address
//
// return value: the index of the funclet containing the specified offset or address,
// or -1 if it's invalid
//
int DebuggerJitInfo::GetFuncletIndex(CORDB_ADDRESS offsetOrAddr, GetFuncletIndexMode mode)
{
WRAPPER_NO_CONTRACT;
DWORD offset = 0;
if (mode == GFIM_BYOFFSET)
{
offset = (DWORD)offsetOrAddr;
}
// If the address doesn't fall in any of the funclets (or if the
// method doesn't have any funclet at all), then return PARENT_METHOD_INDEX.
// <TODO>
// What if there's an overflow?
// </TODO>
if (!m_codeRegionInfo.IsMethodAddress((const BYTE *)(mode == GFIM_BYOFFSET ? (size_t)m_codeRegionInfo.OffsetToAddress(offset) : offsetOrAddr)))
{
return PARENT_METHOD_INDEX;
}
if ( ( m_funcletCount == 0 ) ||
( (mode == GFIM_BYOFFSET) && (offset < m_rgFunclet[0]) ) ||
( (mode == GFIM_BYADDRESS) && (offsetOrAddr < (size_t)m_codeRegionInfo.OffsetToAddress(m_rgFunclet[0])) ) )
{
return PARENT_METHOD_INDEX;
}
for (int i = 0; i < m_funcletCount; i++)
{
if (i == (m_funcletCount - 1))
{
return i;
}
else if ( ( (mode == GFIM_BYOFFSET) && (offset < m_rgFunclet[i+1]) ) ||
( (mode == GFIM_BYADDRESS) && (offsetOrAddr < (size_t)m_codeRegionInfo.OffsetToAddress(m_rgFunclet[i+1])) ) )
{
return i;
}
}
UNREACHABLE();
}
#endif // FEATURE_EH_FUNCLETS
// It is entirely possible that we have multiple sequence points for the
// same IL offset (because of funclets, optimization, etc.). Just to be
// uniform in all cases, let's return the sequence point with the smallest
// native offset if fWantFirst is TRUE.
#if defined(FEATURE_EH_FUNCLETS)
#define ADJUST_MAP_ENTRY(_map, _wantFirst) \
if ((_wantFirst)) \
for ( ; (_map) > m_sequenceMap && (((_map)-1)->ilOffset == (_map)->ilOffset); (_map)--); \
else \
for ( ; (_map) < m_sequenceMap + (m_sequenceMapCount-1) && (((_map)+1)->ilOffset == (_map)->ilOffset); (_map)++);
#else
#define ADJUST_MAP_ENTRY(_map, _wantFirst)
#endif // FEATURE_EH_FUNCLETS
DebuggerJitInfo::DebuggerJitInfo(DebuggerMethodInfo *minfo, NativeCodeVersion nativeCodeVersion) :
m_nativeCodeVersion(nativeCodeVersion),
m_pLoaderModule(nativeCodeVersion.GetMethodDesc()->GetLoaderModule()),
m_jitComplete(false),
#ifdef FEATURE_METADATA_UPDATER
m_encBreakpointsApplied(false),
#endif //FEATURE_METADATA_UPDATER
m_methodInfo(minfo),
m_addrOfCode((CORDB_ADDRESS)NULL),
m_sizeOfCode(0), m_prevJitInfo(NULL), m_nextJitInfo(NULL),
m_lastIL(0),
m_sequenceMap(NULL),
m_sequenceMapCount(0),
m_callsiteMap(NULL),
m_callsiteMapCount(0),
m_sequenceMapSorted(false),
m_varNativeInfo(NULL), m_varNativeInfoCount(0),
m_fAttemptInit(false)
#if defined(FEATURE_EH_FUNCLETS)
,m_rgFunclet(NULL)
, m_funcletCount(0)
#endif // defined(FEATURE_EH_FUNCLETS)
{
WRAPPER_NO_CONTRACT;
// A DJI is just the debugger's cache of interesting information +
// various debugger-specific state for a method (like Enc).
// So only be createing DJIs when a debugger is actually attached.
// The profiler also piggy-backs on the DJIs.
// @Todo - the managed stackwalker in the BCL also builds on DJIs.
//_ASSERTE(CORDebuggerAttached() || CORProfilerPresent());
_ASSERTE(minfo);
m_encVersion = minfo->GetCurrentEnCVersion();
_ASSERTE(m_encVersion >= CorDB_DEFAULT_ENC_FUNCTION_VERSION);
LOG((LF_CORDB,LL_EVERYTHING, "DJI::DJI: created at %p\n", this));
// Debugger doesn't track LightWeight codegen methods.
// We should never even be creating a DJI for one.
_ASSERTE(!m_nativeCodeVersion.GetMethodDesc()->IsDynamicMethod());
}
DebuggerILToNativeMap *DebuggerJitInfo::MapILOffsetToMapEntry(SIZE_T offset, BOOL *exact, BOOL fWantFirst)
{
CONTRACTL
{
NOTHROW;
GC_NOTRIGGER;
MODE_ANY;
CAN_TAKE_LOCK; // GetSequenceMapCount calls LazyInitBounds() which can eventually
// call ExecutionManager::IncrementReader
}
CONTRACTL_END;
// Ideally we should be able to assert this, since the binary search in this function
// assumes that the sequence points are sorted by IL offset (NO_MAPPING, PROLOG, and EPILOG
// are actually -1, -2, and -3, respectively). However, the sequence points in pdb's use
// -1 to mean "end of the method", which is different from our semantics of using 0.
// _ASSERTE(offset != NO_MAPPING && offset != PROLOG && offset != EPILOG);
//
// Binary search for matching map element.
//
DebuggerILToNativeMap *mMin = GetSequenceMap();
DebuggerILToNativeMap *mMax = mMin + GetSequenceMapCount();
_ASSERTE(m_sequenceMapSorted);
_ASSERTE( mMin < mMax ); //otherwise we have no code
if (exact)
{
*exact = FALSE;
}
if (mMin)
{
while (mMin + 1 < mMax)
{
_ASSERTE(mMin>=m_sequenceMap);
DebuggerILToNativeMap *mMid = mMin + ((mMax - mMin)>>1);
_ASSERTE(mMid>=m_sequenceMap);
if (offset == mMid->ilOffset)
{
if (exact)
{
*exact = TRUE;
}
ADJUST_MAP_ENTRY(mMid, fWantFirst);
return mMid;
}
else if (offset < mMid->ilOffset && mMid->ilOffset != (ULONG) ICorDebugInfo::PROLOG)
{
mMax = mMid;
}
else
{
mMin = mMid;
}
}
if (exact && offset == mMin->ilOffset)
{
*exact = TRUE;
}
ADJUST_MAP_ENTRY(mMin, fWantFirst);
}
return mMin;
}
void DebuggerJitInfo::InitILToNativeOffsetIterator(ILToNativeOffsetIterator &iterator, SIZE_T ilOffset)
{
WRAPPER_NO_CONTRACT;
iterator.Init(this, ilOffset);
}
DebuggerJitInfo::NativeOffset DebuggerJitInfo::MapILOffsetToNative(DebuggerJitInfo::ILOffset ilOffset)
{
CONTRACTL
{
NOTHROW;
GC_NOTRIGGER;
}
CONTRACTL_END;
NativeOffset resultOffset;
DebuggerILToNativeMap *map = MapILOffsetToMapEntry(ilOffset.m_ilOffset, &(resultOffset.m_fExact));
#if defined(FEATURE_EH_FUNCLETS)
// See if we want the map entry for the parent.
if (ilOffset.m_funcletIndex <= PARENT_METHOD_INDEX)
{
#endif // FEATURE_EH_FUNCLETS
PREFIX_ASSUME( map != NULL );
LOG((LF_CORDB, LL_INFO10000, "DJI::MILOTN: ilOffset 0x%zx to nat 0x%x exact:%s (Entry IL Off:0x%x)\n",
ilOffset.m_ilOffset, map->nativeStartOffset, (resultOffset.m_fExact ? "true" : "false"), map->ilOffset));
resultOffset.m_nativeOffset = map->nativeStartOffset;
#if defined(FEATURE_EH_FUNCLETS)
}
else
{
// funcletIndex is guaranteed to be >= 0 at this point.
if (ilOffset.m_funcletIndex > (m_funcletCount - 1))
{
resultOffset.m_fExact = FALSE;
resultOffset.m_nativeOffset = ((SIZE_T)-1);
}
else
{
// Initialize the funclet range.
// ASSUMES that funclets are contiguous which they currently are...
DWORD funcletStartOffset = GetFuncletOffsetByIndex(ilOffset.m_funcletIndex);
DWORD funcletEndOffset;
if (ilOffset.m_funcletIndex < (m_funcletCount - 1))
{
funcletEndOffset = GetFuncletOffsetByIndex(ilOffset.m_funcletIndex + 1);
}
else
{
funcletEndOffset = (DWORD)m_sizeOfCode;
}
SIZE_T ilTargetOffset = map->ilOffset;
DebuggerILToNativeMap *mapEnd = GetSequenceMap() + GetSequenceMapCount();
for (; map < mapEnd && map->ilOffset == ilTargetOffset; map++)
{
if ((map->nativeStartOffset >= funcletStartOffset) &&
(map->nativeStartOffset < funcletEndOffset))
{
// This is the normal case where the start offset falls in
// the range of the funclet.
resultOffset.m_nativeOffset = map->nativeStartOffset;
break;
}
}
if (map == mapEnd || map->ilOffset != ilTargetOffset)
{
resultOffset.m_fExact = FALSE;
resultOffset.m_nativeOffset = ((SIZE_T)-1);
}
}
}
#endif // FEATURE_EH_FUNCLETS
return resultOffset;
}
DebuggerJitInfo::ILToNativeOffsetIterator::ILToNativeOffsetIterator()
{
LIMITED_METHOD_CONTRACT;
m_dji = NULL;
m_currentILOffset.m_ilOffset = INVALID_IL_OFFSET;
#ifdef FEATURE_EH_FUNCLETS
m_currentILOffset.m_funcletIndex = PARENT_METHOD_INDEX;
#endif
}
void DebuggerJitInfo::ILToNativeOffsetIterator::Init(DebuggerJitInfo* dji, SIZE_T ilOffset)
{
WRAPPER_NO_CONTRACT;
m_dji = dji;
m_currentILOffset.m_ilOffset = ilOffset;
#ifdef FEATURE_EH_FUNCLETS
m_currentILOffset.m_funcletIndex = PARENT_METHOD_INDEX;
#endif
m_currentNativeOffset = m_dji->MapILOffsetToNative(m_currentILOffset);
}
bool DebuggerJitInfo::ILToNativeOffsetIterator::IsAtEnd()
{
LIMITED_METHOD_CONTRACT;
return (m_currentILOffset.m_ilOffset == INVALID_IL_OFFSET);
}
SIZE_T DebuggerJitInfo::ILToNativeOffsetIterator::Current(BOOL* pfExact)
{
LIMITED_METHOD_CONTRACT;
if (pfExact != NULL)
{
*pfExact = m_currentNativeOffset.m_fExact;
}
return m_currentNativeOffset.m_nativeOffset;
}
SIZE_T DebuggerJitInfo::ILToNativeOffsetIterator::CurrentAssertOnlyOne(BOOL* pfExact)
{
WRAPPER_NO_CONTRACT;
SIZE_T nativeOffset = Current(pfExact);
Next();
_ASSERTE(IsAtEnd());
return nativeOffset;
}
void DebuggerJitInfo::ILToNativeOffsetIterator::Next()
{
#if defined(FEATURE_EH_FUNCLETS)
NativeOffset tmpNativeOffset;
for (m_currentILOffset.m_funcletIndex += 1;
m_currentILOffset.m_funcletIndex < m_dji->GetFuncletCount();
m_currentILOffset.m_funcletIndex++)
{
tmpNativeOffset = m_dji->MapILOffsetToNative(m_currentILOffset);
if (tmpNativeOffset.m_nativeOffset != ((SIZE_T)-1) &&
tmpNativeOffset.m_nativeOffset != m_currentNativeOffset.m_nativeOffset)
{
m_currentNativeOffset = tmpNativeOffset;
break;
}
}
if (m_currentILOffset.m_funcletIndex == m_dji->GetFuncletCount())
{
m_currentILOffset.m_ilOffset = INVALID_IL_OFFSET;
}
#else // !FEATURE_EH_FUNCLETS
m_currentILOffset.m_ilOffset = INVALID_IL_OFFSET;
#endif // !FEATURE_EH_FUNCLETS
}
// SIZE_T DebuggerJitInfo::MapSpecialToNative(): Maps something like
// a prolog to a native offset.
// CordDebugMappingResult mapping: Mapping type to be looking for.
// SIZE_T which: Which one. <TODO>For now, set to zero. <@todo Later, we'll
// change this to some value that we get back from MapNativeToILOffset
// to indicate which of the (possibly multiple epilogs) that may
// be present.</TODO>
SIZE_T DebuggerJitInfo::MapSpecialToNative(CorDebugMappingResult mapping,
SIZE_T which,
BOOL *pfAccurate)
{
CONTRACTL
{
NOTHROW;
GC_NOTRIGGER;
PRECONDITION(NULL != pfAccurate);
}
CONTRACTL_END;
LOG((LF_CORDB, LL_INFO10000, "DJI::MSTN map:0x%x which:0x%x\n", mapping, which));
bool fFound;
SIZE_T cFound = 0;
DebuggerILToNativeMap *m = GetSequenceMap();
DebuggerILToNativeMap *mEnd = m + GetSequenceMapCount();
if (m)
{
while(m < mEnd)
{
_ASSERTE(m>=GetSequenceMap());
fFound = false;
if (DbgIsSpecialILOffset(m->ilOffset))
cFound++;
if (cFound == which)
{
_ASSERTE( (mapping == MAPPING_PROLOG &&
m->ilOffset == (ULONG) ICorDebugInfo::PROLOG) ||
(mapping == MAPPING_EPILOG &&
m->ilOffset == (ULONG) ICorDebugInfo::EPILOG) ||
((mapping == MAPPING_NO_INFO || mapping == MAPPING_UNMAPPED_ADDRESS) &&
m->ilOffset == (ULONG) ICorDebugInfo::NO_MAPPING)
);
(*pfAccurate) = TRUE;
LOG((LF_CORDB, LL_INFO10000, "DJI::MSTN found mapping to nat:0x%x\n",
m->nativeStartOffset));
return m->nativeStartOffset;
}
m++;
}
}
LOG((LF_CORDB, LL_INFO10000, "DJI::MSTN No mapping found :(\n"));
(*pfAccurate) = FALSE;
return 0;
}
#if defined(FEATURE_EH_FUNCLETS)
//
// DebuggerJitInfo::MapILOffsetToNativeForSetIP()
//
// This function maps an IL offset to a native offset, taking into account cloned finallys and nested EH clauses.
//
// parameters: offsetILTo - the destination IP, in IL offset
// funcletIndexFrom - the funclet index of the source IP
// pEHRT - tree structure for keeping track of EH clause information
// pExact - pointer for returning whether the mapping is exact or not
//
// return value: destination IP, in native offset
//
SIZE_T DebuggerJitInfo::MapILOffsetToNativeForSetIP(SIZE_T offsetILTo, int funcletIndexFrom,
EHRangeTree* pEHRT, BOOL* pExact)
{
CONTRACTL
{
NOTHROW;
GC_NOTRIGGER;
MODE_ANY;
}
CONTRACTL_END;
DebuggerILToNativeMap* pMap = MapILOffsetToMapEntry(offsetILTo, pExact, TRUE);
DebuggerILToNativeMap* pMapEnd = GetSequenceMap() + GetSequenceMapCount();
_ASSERTE(pMap == m_sequenceMap ||
(pMap - 1)->ilOffset == (ULONG)ICorDebugInfo::NO_MAPPING ||
(pMap - 1)->ilOffset == (ULONG)ICorDebugInfo::PROLOG ||
(pMap - 1)->ilOffset == (ULONG)ICorDebugInfo::EPILOG ||
pMap->ilOffset > (pMap - 1)->ilOffset);
SIZE_T offsetNatTo = pMap->nativeStartOffset;
if (m_funcletCount == 0 ||
pEHRT == NULL ||
FAILED(pEHRT->m_hrInit))
{
return offsetNatTo;
}
// Multiple sequence points may have the same IL offset, which means that the code is duplicated in
// multiple funclets and/or in the parent method. If the destination offset maps to multiple sequence
// points (and hence to multiple funclets), we try to find the a sequence point which is in the same
// funclet as the source sequence point. If we can't find one, then the operation is going to fail
// anyway, so we just return the first sequence point we find.
for (DebuggerILToNativeMap* pMapCur = pMap + 1;
(pMapCur < pMapEnd) && (pMapCur->ilOffset == pMap->ilOffset);
pMapCur++)
{
int funcletIndexTo = GetFuncletIndex(pMapCur->nativeStartOffset, DebuggerJitInfo::GFIM_BYOFFSET);
if (funcletIndexFrom == funcletIndexTo)
{
return pMapCur->nativeStartOffset;
}
}
return offsetNatTo;
}
#endif // FEATURE_EH_FUNCLETS
// void DebuggerJitInfo::MapILRangeToMapEntryRange(): MIRTMER
// calls MapILOffsetToNative for the startOffset (putting the
// result into start), and the endOffset (putting the result into end).
// SIZE_T startOffset: IL offset from beginning of function.
// SIZE_T endOffset: IL offset from beginning of function,
// or zero to indicate that the end of the function should be used.
// DebuggerILToNativeMap **start: Contains start & end
// native offsets that correspond to startOffset. Set to NULL if
// there is no mapping info.
// DebuggerILToNativeMap **end: Contains start & end native
// offsets that correspond to endOffset. Set to NULL if there
// is no mapping info.
void DebuggerJitInfo::MapILRangeToMapEntryRange(SIZE_T startOffset,
SIZE_T endOffset,
DebuggerILToNativeMap **start,
DebuggerILToNativeMap **end)
{
CONTRACTL
{
NOTHROW;
GC_NOTRIGGER;
}
CONTRACTL_END;
LOG((LF_CORDB, LL_INFO1000000,
"DJI::MIRTMER: IL 0x%04x-0x%04x\n",
startOffset, endOffset));
if (GetSequenceMapCount() == 0)
{
*start = NULL;
*end = NULL;
return;
}
*start = MapILOffsetToMapEntry(startOffset);
//
// end points to the last range that endOffset maps to, not past
// the last range.
// We want to return the last IL, and exclude the epilog
if (endOffset == 0)
{
*end = GetSequenceMap() + GetSequenceMapCount() - 1;
_ASSERTE(*end>=m_sequenceMap);
while ( ((*end)->ilOffset == (ULONG) ICorDebugInfo::EPILOG||
(*end)->ilOffset == (ULONG) ICorDebugInfo::NO_MAPPING)
&& (*end) > m_sequenceMap)
{
(*end)--;
_ASSERTE(*end>=m_sequenceMap);
}
}
else
*end = MapILOffsetToMapEntry(endOffset - 1, NULL
BIT64_ARG(FALSE));
_ASSERTE(*end>=m_sequenceMap);
LOG((LF_CORDB, LL_INFO1000000,
"DJI::MIRTMER: IL 0x%04x-0x%04x --> 0x%04x 0x%08x-0x%08x\n"
" --> 0x%04x 0x%08x-0x%08x\n",
startOffset, endOffset,
(*start)->ilOffset,
(*start)->nativeStartOffset, (*start)->nativeEndOffset,
(*end)->ilOffset,
(*end)->nativeStartOffset, (*end)->nativeEndOffset));
}
// @dbgtodo Microsoft inspection: This function has been replicated in DacDbiStructures so
// this version can be deleted when inspection is complete.
// DWORD DebuggerJitInfo::MapNativeOffsetToIL(): Given a native
// offset for the DebuggerJitInfo, compute
// the IL offset from the beginning of the same method.
// Returns: Offset of the IL instruction that contains
// the native offset,
// SIZE_T nativeOffset: [IN] Native Offset
// CorDebugMappingResult *map: [OUT] explains the
// quality of the matching & special cases
// SIZE_T which: It's possible to have multiple EPILOGs, or
// multiple unmapped regions within a method. This opaque value
// specifies which special region we're talking about. This
// param has no meaning if map & (MAPPING_EXACT|MAPPING_APPROXIMATE)
// Basically, this gets handed back to MapSpecialToNative, later.
DWORD DebuggerJitInfo::MapNativeOffsetToIL(SIZE_T nativeOffsetToMap,
CorDebugMappingResult *map,
DWORD *which,
BOOL skipPrologs)
{
CONTRACTL
{
NOTHROW;
GC_NOTRIGGER;
PRECONDITION(map != NULL);
PRECONDITION(which != NULL);
}
CONTRACTL_END;
DWORD nativeOffset = (DWORD)nativeOffsetToMap;
(*which) = 0;
DebuggerILToNativeMap *m = GetSequenceMap();
DebuggerILToNativeMap *mEnd = m + GetSequenceMapCount();
LOG((LF_CORDB,LL_INFO10000,"DJI::MNOTI: nativeOffset = 0x%x\n", nativeOffset));
if (m)
{
while (m < mEnd)
{
_ASSERTE(m>=m_sequenceMap);
#ifdef LOGGING
if (m->ilOffset == (ULONG) ICorDebugInfo::PROLOG )
LOG((LF_CORDB,LL_INFO10000,"DJI::MNOTI: m->natStart:0x%x m->natEnd:0x%x il:PROLOG\n", m->nativeStartOffset, m->nativeEndOffset));
else if (m->ilOffset == (ULONG) ICorDebugInfo::EPILOG )
LOG((LF_CORDB,LL_INFO10000,"DJI::MNOTI: m->natStart:0x%x m->natEnd:0x%x il:EPILOG\n", m->nativeStartOffset, m->nativeEndOffset));
else if (m->ilOffset == (ULONG) ICorDebugInfo::NO_MAPPING)
LOG((LF_CORDB,LL_INFO10000,"DJI::MNOTI: m->natStart:0x%x m->natEnd:0x%x il:NO MAP\n", m->nativeStartOffset, m->nativeEndOffset));
else
LOG((LF_CORDB,LL_INFO10000,"DJI::MNOTI: m->natStart:0x%x m->natEnd:0x%x il:0x%x src:0x%x\n", m->nativeStartOffset, m->nativeEndOffset, m->ilOffset, m->source));
#endif // LOGGING
if (m->ilOffset == (ULONG) ICorDebugInfo::PROLOG ||
m->ilOffset == (ULONG) ICorDebugInfo::EPILOG ||
m->ilOffset == (ULONG) ICorDebugInfo::NO_MAPPING)
{
(*which)++;
}
if (nativeOffset >= m->nativeStartOffset
&& ((m->nativeEndOffset == 0 &&
m->ilOffset != (ULONG) ICorDebugInfo::PROLOG)
|| nativeOffset < m->nativeEndOffset))
{
ULONG ilOff = m->ilOffset;
if( m->ilOffset == (ULONG) ICorDebugInfo::PROLOG )
{
if (skipPrologs && nativeOffset < m->nativeEndOffset)
{
// If the caller requested to skip prologs, we simply restart the walk
// with the offset set to the end of the prolog.
nativeOffset = m->nativeEndOffset;
continue;
}
ilOff = 0;
(*map) = MAPPING_PROLOG;
LOG((LF_CORDB,LL_INFO10000,"DJI::MNOTI: MAPPING_PROLOG\n"));
}
else if (m->ilOffset == (ULONG) ICorDebugInfo::NO_MAPPING)
{
ilOff = 0;
(*map) = MAPPING_UNMAPPED_ADDRESS ;
LOG((LF_CORDB,LL_INFO10000,"DJI::MNOTI:MAPPING_"
"UNMAPPED_ADDRESS\n"));
}
else if( m->ilOffset == (ULONG) ICorDebugInfo::EPILOG )
{
ilOff = m_lastIL;
(*map) = MAPPING_EPILOG;
LOG((LF_CORDB,LL_INFO10000,"DJI::MNOTI:MAPPING_EPILOG\n"));
}
else if (nativeOffset == m->nativeStartOffset)
{
(*map) = MAPPING_EXACT;
LOG((LF_CORDB,LL_INFO10000,"DJI::MNOTI:MAPPING_EXACT\n"));
}
else
{
(*map) = MAPPING_APPROXIMATE;
LOG((LF_CORDB,LL_INFO10000,"DJI::MNOTI:MAPPING_"
"APPROXIMATE\n"));
}
return ilOff;
}
m++;
}
}
(*map) = MAPPING_NO_INFO;
LOG((LF_CORDB,LL_INFO10000,"DJI::MNOTI:NO_INFO\n"));
return 0;
}
/******************************************************************************
*
******************************************************************************/
DebuggerJitInfo::~DebuggerJitInfo()
{
TRACE_FREE(m_sequenceMap);
if (m_sequenceMap != NULL)
{
DeleteInteropSafe(((BYTE *)m_sequenceMap));
}
TRACE_FREE(m_varNativeInfo);
if (m_varNativeInfo != NULL)
{
DeleteInteropSafe(m_varNativeInfo);
}
#if defined(FEATURE_EH_FUNCLETS)
if (m_rgFunclet)
{
DeleteInteropSafe(m_rgFunclet);
m_rgFunclet = NULL;
}
#endif // FEATURE_EH_FUNCLETS
#ifdef _DEBUG
// Trash pointers to garbage.
// Don't null out since there may be runtime checks against NULL.
// Set to a non-null random pointer value that will cause an immediate AV on deref.
m_methodInfo = (DebuggerMethodInfo*) 0x1;
m_prevJitInfo = (DebuggerJitInfo*) 0x01;
m_nextJitInfo = (DebuggerJitInfo*) 0x01;
#endif
LOG((LF_CORDB,LL_EVERYTHING, "DJI::~DJI : deleted at 0x%p\n", this));
}
// Lazy initialize the Debugger-Jit-Info
void DebuggerJitInfo::LazyInitBounds()
{
CONTRACTL
{
NOTHROW;
GC_NOTRIGGER;
PRECONDITION(ThisMaybeHelperThread());
PRECONDITION(!g_pDebugger->HasDebuggerDataLock());
} CONTRACTL_END;
// Only attempt lazy-init once
if (m_fAttemptInit)
return;
EX_TRY
{
LOG((LF_CORDB, LL_EVERYTHING, "DJI::LazyInitBounds: this=0x%p Initing\n", this));
// Should have already been jitted
_ASSERTE(this->m_jitComplete);
MethodDesc * mdesc = this->m_nativeCodeVersion.GetMethodDesc();
DebugInfoRequest request;
_ASSERTE(this->m_addrOfCode != (CORDB_ADDRESS)NULL); // must have address to disambguate the Enc cases.
// Caller already resolved generics when they craeted the DJI, so we don't need to repeat.
// Note the MethodDesc may not yet have the jitted info, so we'll also use the starting address we got in the jit complete callback.
request.InitFromStartingAddr(mdesc, (PCODE)this->m_addrOfCode);
// Bounds info.
ULONG32 cMap = 0;
ICorDebugInfo::OffsetMapping *pMap = NULL;
ULONG32 cVars = 0;
ICorDebugInfo::NativeVarInfo *pVars = NULL;
BOOL fSuccess = DebugInfoManager::GetBoundariesAndVars(
request,
InteropSafeNew, NULL, // allocator
&cMap, &pMap,
&cVars, &pVars);
LOG((LF_CORDB,LL_EVERYTHING, "DJI::LazyInitBounds: this=%p GetBoundariesAndVars success=%s\n",
this, (fSuccess ? "true" : "false")));
Debugger::DebuggerDataLockHolder debuggerDataLockHolder(g_pDebugger);
if (!m_fAttemptInit)
{
if (fSuccess)
{
this->SetBoundaries(cMap, pMap);
this->SetVars(cVars, pVars);
}
m_fAttemptInit = true;
}
else
{
DeleteInteropSafe(pMap);
DeleteInteropSafe(pVars);
}
// DebuggerDataLockHolder out of scope - release implied
}
EX_CATCH
{
LOG((LF_CORDB,LL_WARNING, "DJI::LazyInitBounds: this=%p Exception was thrown and caught\n", this));
// Just catch the exception. The DJI maps may or may-not be initialized,
// but they should still be in a consistent state, so we should be ok.
}
EX_END_CATCH(SwallowAllExceptions)
}
/******************************************************************************
* SetVars() takes ownership of pVars
******************************************************************************/
void DebuggerJitInfo::SetVars(ULONG32 cVars, ICorDebugInfo::NativeVarInfo *pVars)
{
LIMITED_METHOD_CONTRACT;
_ASSERTE(m_varNativeInfo == NULL);
m_varNativeInfo = pVars;
m_varNativeInfoCount = cVars;
LOG((LF_CORDB, LL_INFO1000000, "D::sV: var count is %d\n",
m_varNativeInfoCount));
#ifdef LOGGING
for (unsigned int i = 0; i < m_varNativeInfoCount; i++)
{
ICorDebugInfo::NativeVarInfo* vni = &(m_varNativeInfo[i]);
_dumpVarNativeInfo(vni);
}
#endif
}
CHECK DebuggerJitInfo::Check() const
{
LIMITED_METHOD_CONTRACT;
CHECK_OK;
}
// Invariants for a DebuggerJitInfo
// These should always be true at any well defined point.
CHECK DebuggerJitInfo::Invariant() const
{
LIMITED_METHOD_CONTRACT;
CHECK((m_sequenceMapCount == 0) == (m_sequenceMap == NULL));
CHECK(m_methodInfo != NULL);
CHECK(m_nativeCodeVersion.GetMethodDesc() != NULL);
CHECK_OK;
}
#if !defined(DACCESS_COMPILE)