This repository has been archived by the owner on Apr 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 273
/
mod.cpp
4943 lines (4055 loc) · 140 KB
/
mod.cpp
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
//////////////////////////////////////////////////////////////////////////////
// PDB Debug Information API Mod Implementation
#include "pdbimpl.h"
#include "dbiimpl.h"
#include <stdio.h>
#include "comenvi.h"
#include "cvhelper.h"
#include "utf8.h"
#include "debug_s.h"
#include "cvlines.h"
#include "set.h"
static void setDSRError(PDB1 * ppdb1, DSR_EC ec) {
static EC xlateDsrEcToPdbEc[] = {
EC_OK,
EC_USAGE,
EC_OUT_OF_MEMORY,
EC_CORRUPT,
EC_CORRUPT,
};
cassert(_countof(xlateDsrEcToPdbEc) == DSR_EC_MAX);
assert(ec < DSR_EC_MAX);
ppdb1->setLastError(xlateDsrEcToPdbEc[ec]);
};
// Declarations of some functions defined in sttosz.cpp
CB ConvertSymRecFmMBCSToUTF8(PSYM psymSrc, PSYM psymDest, CB cbDest);
BOOL fConvertSymRecStToSz(PB pbSrc, CB cbSrc, PB pbDest, CB *pcbDest, Array<OffMap>& rgOffMap);
BOOL fConvertSymRecStToSzWithSig(PB pbSrc, CB cbSrc, CvtSyms& cvtsyms);
Mod1::Mod1(PDB1* ppdb1_, DBI1* pdbi1_, IMOD imod_)
: ppdb1(ppdb1_), pdbi1(pdbi1_), ptm(0), imod(imod_), fSymsAdded_S(FALSE),
pwti(0), fECSymSeen(false), fAddLines(FALSE), fSymsAdded_T(FALSE),
fCoffToC13Failed(false), snType(snNil), snId(snNil), imodTypeRef(imodNil),
fOwnTM(0), fRefTM(0), fOwnTMR(0), fOwnTMPCT(0), fRefTMPCT(0),
fSymsNeedStringTableFixup(false), fSymRecordsVerified(false),
fHasTypeRef(FALSE)
#ifdef PDB_TYPESERVER
, itsm(0)
#endif
{
instrumentation(pdbi1->info.cModules++);
}
BOOL Mod1::fInit()
{
MTS_ASSERT(pdbi1->m_csForMods);
if (pdbi1->fWrite) {
assert(!pdbi1->cvtsyms.fConverting());
MODI* pmodi = pdbi1->pmodiForImod(imod);
if (pmodi) {
// invalidate the section contribution for this module
pmodi->sc.isect = isectNil;
if (!pdbi1->invalidateSCforMod(imod))
return FALSE
;
// We anticipate the new group of symbols will be the same
// size as last time.
expect(fAlign(cbSyms()));
if (cbSyms() > 0 && !bufSyms.SetInitAlloc(cbSyms())) {
ppdb1->setOOMError();
return FALSE;
}
}
if (!fInitRefBuffer(&rbufC13Lines)) {
return FALSE;
}
if (!initFileInfo(0)) {
// clear the file info as well
return FALSE;
}
}
else {
CB cbModStream = cbStream();
CB cbModSyms = cbSyms();
CB cbModLines = cbLines();
CB cbModC13Lines = cbC13Lines();
if (cbModStream < cbModSyms ||
cbModStream - cbModSyms < cbModLines ||
cbModStream - cbModSyms - cbModLines < cbModC13Lines) {
ppdb1->setCorruptError();
return FALSE;
}
}
if (cvtsyms.fConverting() = pdbi1->cvtsyms.fConverting()) {
if (pwti || WidenTi::fCreate(pwti, 1, wtiSymsNB10)) {
return TRUE;
}
ppdb1->setOOMError();
return FALSE;
}
if (!pdbi1->fWrite && ppdb1->m_fNoTypeMerge) {
MODTYPEREF mtr = {0};
if (!pdbi1->QueryModTypeRef(imod, &mtr)) {
return FALSE;
}
if (mtr.rectyp != S_MOD_TYPEREF) {
fNoType = 1;
return TRUE;
}
if (mtr.fOwnTMR) {
fOwnTMR = 1;
snType = (SN) mtr.word0;
if (mtr.fRefTMPCT) {
fRefTMPCT = 1;
imodTypeRef = mtr.word1;
}
if (mtr.fOwnTMPCT) {
fOwnTMPCT = 1;
//snZ7Pch = *(unsigned short *) (pbEnd + sizeof(unsigned short));
}
}
else if (mtr.fOwnTM) {
fOwnTM = 1;
snType = mtr.word0;
snId = mtr.word1;
}
else if (mtr.fRefTM) {
fRefTM = 1;
imodTypeRef = mtr.word0;
}
else {
assert(mtr.fNone);
fNoType = 1;
}
}
return TRUE;
}
Mod1::~Mod1()
{
if (ptm) {
assert(pdbi1->fWrite || ppdb1->FLazy() || ppdb1->FMinimal());
ptm->endMod();
}
if (pwti)
pwti->release();
}
INTV Mod1::QueryInterfaceVersion()
{
return intv;
}
IMPV Mod1::QueryImplementationVersion()
{
return impv;
}
BOOL Mod1::QuerySupportsEC()
{
// We don't support EnC on ST PDB's anymore
if (!IS_SZ_FORMAT_PDB(ppdb1))
return FALSE;
MTS_PROTECT(pdbi1->m_csForMods);
MODI *pmodi = pdbi1->pmodiForImod(imod);
return pmodi && pmodi->fECEnabled;
}
BOOL Mod1::EnCNeedReloadCompilerGeneratedPDB()
{
assert(ppdb1->m_fMinimalDbgInfo);
assert(ptm != NULL);
return (!ptm->IsTMR() && !ptm->IsTMEQTS() && ptm->PPdbFrom() == NULL);
}
BOOL Mod1::EnCReleaseCompilerGeneratedPDB(BYTE* pbTypes, DWORD cb)
{
assert(ppdb1->m_fMinimalDbgInfo);
if (ptm == NULL) {
BOOL fRet = GetTmts(pbTypes, cb, &ptm, true);
if (ptm == NULL) {
return fRet;
}
}
assert(!ptm->IsTMEQTS() && !ptm->IsTMR());
TMTS *ptmts = (TMTS *) ptm;
// Do nothing if already closed
if (ptmts->PPdbFrom() == NULL) {
return TRUE;
}
ptmts->ClosePdbFrom();
return TRUE;
}
BOOL Mod1::EnCReloadCompilerGeneratedPDB(BYTE* pbTypes, DWORD cb)
{
dassert(pbTypes);
dassert(ppdb1->m_fMinimalDbgInfo);
dassert(ptm != NULL);
dassert(!ptm->IsTMR() && !ptm->IsTMEQTS());
PTYPE pts = (PTYPE) (pbTypes + sizeof(ULONG));
SafeStackAllocator<0x210> allocator;
wchar_t *szT = allocator.Alloc<wchar_t>(pts->len);
wchar_t *szFullMapped = allocator.Alloc<wchar_t>(_MAX_PATH);
if (NULL == szT || NULL == szFullMapped) {
ppdb1->setOOMError();
return FALSE;
}
SIG70 sig70;
AGE age;
const wchar_t * szTSName = pdbi1->szGetTsInfo(pts, szT, szFullMapped, &sig70, &age);
if (szTSName == NULL) {
return FALSE;
}
PDB* ppdbFrom;
if (!pdbi1->fOpenPdb(sig70, age, szTSName, szObjFile(), &ppdbFrom)) {
return FALSE;
}
TMTS *ptmts = (TMTS *)ptm;
return ptmts->fInit(ppdbFrom);
}
BOOL Mod1::GetTmts(BYTE* pbTypes, DWORD cb, TM** pptm, BOOL fQueryOnly)
{
// check for c7 signature - cannot handle pre c7
ULONG sig = *(ULONG*)pbTypes;
assert(IS_SZ_FORMAT_PDB(ppdb1));
if (sig != CV_SIGNATURE_C7 &&
sig != CV_SIGNATURE_C11 &&
sig != CV_SIGNATURE_C13)
{
ppdb1->setCorruptError();
return FALSE;
}
pbTypes += sizeof(ULONG);
cb -= sizeof(ULONG);
if (cb == 0) {
// If there are no types, bail now... The compiler sometimes emits
// just the CV_SIGNATURE_C7 DWORD.
return TRUE;
}
fHasTypeRef = TRUE;
PTYPE ptype = (PTYPE) pbTypes;
if (SZLEAFIDX(ptype->leaf) == LF_TYPESERVER) {
lfTypeServer* pts = (lfTypeServer*)&ptype->leaf;
if (pdbi1->QueryLazyTypes() && sig == CV_SIGNATURE_C11) {
// using lazy types, just register the type server
#ifdef PDB_TYPESERVER
#if 0 // We got rid of creating type servers long time ago ...
char szName[ _MAX_PATH ];
return pdbi1->AddTypeServer(pts->signature, pts->age,
szFromSt(szName, (ST)pts->name), szObjFile(), &itsm);
#endif
#else
// We should never be here, 'cause we don't
// use Lazy types anymore, hence no change
assert(FALSE);
#endif
}
else {
pdbi1->fGetTmts(ptype, szObjFile(), pptm, fQueryOnly);
}
}
else if (ptype->leaf == LF_TYPESERVER2)
{
pdbi1->fGetTmts(ptype, szObjFile(), pptm, fQueryOnly);
}
else {
assert(fQueryOnly == false);
TPI* ptpi = pdbi1->GetTpi();
TPI* pipi = pdbi1->GetIpi();
if (ptpi != NULL) {
if (*pptm = new (ppdb1) TMR(ppdb1, pdbi1, ptpi, pipi)) {
if (!((TMR*) *pptm)->fInit(pbTypes, cb, szModule(), sig)) {
delete *pptm;
*pptm = NULL;
}
}
}
}
if (!fQueryOnly && (*pptm == NULL)) {
return FALSE;
}
return TRUE;
}
BOOL Mod1::AddTypes(PB pbTypes, CB cb)
{
dassert(pbTypes);
if (ptm != NULL) {
if (EnCNeedReloadCompilerGeneratedPDB()) {
return EnCReloadCompilerGeneratedPDB(pbTypes, cb);
}
else {
// The linker might do this if it has two module of the same name in one lib
ppdb1->setLastError(EC_TOO_MANY_MOD_ADDTYPE);
return FALSE;
}
}
#if 0
if (fSymsAdded){
ppdb1->setUsageError();
return FALSE;
}
#endif
BOOL fRet = GetTmts(pbTypes, cb, &ptm, false);
if (ptm == NULL) {
return fRet;
}
if (ppdb1->m_fNoTypeMerge && ptm->Imod() == imodNil) {
ptm->SetImod(imod);
if (ptm->IsTmpctOwner()) {
((TMR *) ptm)->Ptmpct()->SetImod(imod);
}
}
return TRUE;
}
BOOL Mod1::AddTimeStamp(DWORD timestamp)
{
if (!pdbi1->fWrite) {
ppdb1->setUsageError();
return FALSE;
}
dwTimeStamp = timestamp;
return TRUE;
}
int
Mod1::ExceptionFilter(DWORD ec, _EXCEPTION_POINTERS *pei, Mod1 * pmod1)
{
if (ec == VcppException(ERROR_SEVERITY_ERROR, ERROR_MOD_NOT_FOUND) ||
ec == VcppException(ERROR_SEVERITY_ERROR, ERROR_PROC_NOT_FOUND)) {
// Handle this exception
assert(pei);
assert(pei->ExceptionRecord);
assert(pei->ExceptionRecord->ExceptionInformation[0]);
// Report the missing/bad dll error
PDelayLoadInfo pdli = PDelayLoadInfo(pei->ExceptionRecord->ExceptionInformation[0]);
pmod1->ReportDelayLoadError(ec, pdli);
return EXCEPTION_EXECUTE_HANDLER;
}
return EXCEPTION_CONTINUE_SEARCH;
}
void
Mod1::ReportDelayLoadError(DWORD ec, PDelayLoadInfo pdli)
{
assert(pdli);
char szErr[_MAX_PATH * 2];
// It was a delay-load exception.
if (ec == VcppException(ERROR_SEVERITY_ERROR, ERROR_MOD_NOT_FOUND)) {
sprintf_s(szErr, _countof(szErr), "'%s'", pdli->szDll);
}
else {
const char * sz;
char szord[sizeof(" (ordinal)") + 17];
// if it's an ordinal, compose the string "ordinal xx",
// otherwise just pass in the name of the missing entrypoint.
if (pdli->dlp.fImportByName) {
sz = pdli->dlp.szProcName;
}
else {
char szVal[17];
sz = szord;
sprintf_s(szord, sizeof(szord), "%d%s", pdli->dlp.dwOrdinal, szVal, " (ordinal)");
}
sprintf_s(szErr, _countof(szErr), "'%s'!'%s'", pdli->szDll, sz);
}
ppdb1->setLastError(EC_NOT_FOUND, szErr);
}
bool Mod1::CheckFCreateReader(PB pb, CB cb, IDebugSSectionReader** ppReader, DWORD sig)
{
#ifdef BSC_DLL
return false; // We don't want msbscxx.dll to be dependent on msobj71.dll
#else
DWORD ec;
DSR_EC dsr_ec;
__try { // make sure that ole libs are present
if (!IDebugSSectionReader::FCreateReader(pb, cb, ppReader, sig, &dsr_ec)) {
setDSRError(ppdb1, dsr_ec);
return false;
}
return true;
}
__except (ExceptionFilter(ec = GetExceptionCode(), GetExceptionInformation(), this)) {
return false;
}
#endif
}
bool Mod1::CheckFCreateWriter(bool flag, IDebugSSectionWriter** ppWriter, DWORD sig, bool flag2)
{
#ifdef BSC_DLL
return false; // We don't want msbscxx.dll to be dependent on msobj71.dll
#else
DWORD ec;
__try { // make sure that ole libs are present
return IDebugSSectionWriter::FCreateWriter(flag, ppWriter, sig, flag2);
}
__except (ExceptionFilter(ec = GetExceptionCode(), GetExceptionInformation(), this)) {
return false;
}
#endif
}
template <class Type>
BOOL AppendSubSectionToBuffer(Type & buffer, IDebugSSubSection * pSubSection)
{
PB pbSec = NULL;
DWORD cbSec = static_cast<DWORD>(pSubSection->GetRawBytes(&pbSec));
if (!buffer.Append(pbSec, cbSec)) {
return FALSE;
}
if (!buffer.AppendFmt("f", (int)dcbAlign(static_cast<size_t>(buffer.Size())))) {
return FALSE;
}
return TRUE;
}
BOOL Mod1::MergeTypes(PB pb, DWORD cb)
{
if (!pdbi1->fWrite) {
ppdb1->setUsageError();
return FALSE;
}
if (ptm == NULL) {
return TRUE;
}
if (!fSymsAdded_T) {
fSymsAdded_T = TRUE;
sigSyms_T = *(ULONG*) pb;
}
if (sigSyms_T != CV_SIGNATURE_C11 && sigSyms_T != CV_SIGNATURE_C13) {
// Return an error code to let the linker know that we can't do
// early type merging in this case.
return FALSE;
}
if ((sigSyms_T == CV_SIGNATURE_C13) && (*(ULONG*) pb != CV_SIGNATURE_C13)) {
ppdb1->setCorruptError();
return FALSE;
}
if (sigSyms_T == CV_SIGNATURE_C13) {
COMRefPtr<IDebugSSectionReader> pReader;
if (!CheckFCreateReader(pb, cb, &pReader, CV_SIGNATURE_C13)) {
return FALSE;
}
COMRefPtr<IDebugSSubSectionEnum> pEnum;
if (!pReader->GetSectionEnum(&pEnum)) {
setDSRError(ppdb1, pReader->GetLastError());
return FALSE;
}
while (pEnum->Next()) {
COMRefPtr<IDebugSSubSection> pSubSection;
pEnum->Get(&pSubSection);
if (pSubSection == NULL) {
setDSRError(ppdb1, pReader->GetLastError());
return FALSE;
}
PB pbSec = NULL;
DWORD cbSec = 0;
if (pSubSection->Type() != DEBUG_S_SYMBOLS) {
continue;
}
cbSec = static_cast<DWORD>(pSubSection->GetData(&pbSec));
PSYM psymNext;
PB pbMac = pbSec + cbSec;
for (PSYM psym = (PSYM) pbSec; (PB) psym < pbMac; psym = psymNext) {
psymNext = (PSYM) pbEndSym(psym);
if ((PB) psymNext > pbMac) {
ppdb1->setCorruptError();
return FALSE;
}
if (ptm && ptm->IsTmpctOwner() && (psym->rectyp == S_OBJNAME)) {
UTFSZ_CONST szObj = szCopy((char *) ((OBJNAMESYM *) psym)->name);
if (!pdbi1->fUpdateTmpct(szModule(), szObj, ptm)) {
return FALSE;
}
}
if (!packType(psym)) {
return FALSE;
}
}
}
}
else {
assert(sigSyms_T == CV_SIGNATURE_C11);
PSYM psymNext;
PB pbMac = pb + cb;
PB pbMin = (*(ULONG *) pb == CV_SIGNATURE_C11) ? pb + sizeof(ULONG) : pb;
for (PSYM psym = (PSYM) pbMin; (PB) psym < pbMac; psym = psymNext) {
psymNext = (PSYM) pbEndSym(psym);
if ((PB) psymNext > pbMac) {
ppdb1->setCorruptError();
return FALSE;
}
if (ptm && ptm->IsTmpctOwner() && (psym->rectyp == S_OBJNAME_ST)) {
UTFSZ_CONST szObj = szCopySt((char *) ((OBJNAMESYM *) psym)->name);
if (!pdbi1->fUpdateTmpct(szModule(), szObj, ptm)) {
return FALSE;
}
}
if (!packType(psym)) {
return FALSE;
}
}
}
return TRUE;
}
BOOL Mod1::fAddModTypeRefSym()
{
if (!ppdb1->m_fNoTypeMerge) {
return TRUE;
}
MODTYPEREF mtr = {0};
mtr.rectyp = S_MOD_TYPEREF;
mtr.reclen = sizeof(MODTYPEREF) - sizeof(unsigned short);
if (!ptm) {
mtr.fNone = 1;
}
else if (ptm->IsTMR()) {
assert(ptm->Imod() == imod);
mtr.fOwnTMR = 1;
if (ptm->IsTmpctOwner()) {
mtr.fOwnTMPCT = 1;
}
else if (((TMR *) ptm)->Ptmpct()) {
mtr.fRefTMPCT = 1;
mtr.word1 = ((TMR *) ptm)->Ptmpct()->Imod();
}
}
else if (ptm->Imod() == imod) {
mtr.fOwnTM = 1;
}
else {
mtr.fRefTM = 1;
mtr.word0 = ptm->Imod();
}
return AddJustSymbols((PB) &mtr, sizeof(MODTYPEREF), false);
}
BOOL Mod1::fAddSymRefToGSI(PB pb, DWORD cb, DWORD isectCoff)
{
assert(pdbi1->fWrite);
assert(IS_SZ_FORMAT_PDB(ppdb1));
dassert(pb);
DWORD sig = *(DWORD *) pb;
if (sig == CV_SIGNATURE_C7 ||
sig == CV_SIGNATURE_C11 ||
sig == CV_SIGNATURE_C13) {
pb += sizeof(DWORD);
cb -= sizeof(DWORD);
}
int iLevel = 0;
PSYM psymMac = (PSYM) (pb + cb);
for (PSYM psym = (PSYM) pb; psym < psymMac; psym = (PSYM) pbEndSym(psym)) {
if (((PB) psym) + cbForSym(psym) > (PB) psymMac) {
ppdb1->setCorruptError();
return FALSE;
}
bool fLocal = false;
switch (psym->rectyp) {
case S_GPROC16:
case S_GPROCMIPS:
case S_GPROCIA64:
case S_LPROC16:
#if defined(CC_DP_CXX)
case S_LPROC32_DPC:
#endif // CC_DP_CXX
case S_LPROCMIPS:
case S_LPROCIA64:
case S_GPROCMIPS_ID:
case S_GPROCIA64_ID:
#if defined(CC_DP_CXX)
case S_LPROC32_DPC_ID:
#endif // CC_DP_CXX
case S_LPROCMIPS_ID:
case S_LPROCIA64_ID:
case S_BLOCK16:
case S_BLOCK32:
case S_WITH16:
case S_WITH32:
case S_THUNK16:
case S_THUNK32:
case S_SEPCODE:
case S_GMANPROC:
case S_LMANPROC:
case S_INLINESITE2:
case S_INLINESITE:
assert(iLevel >= 0);
iLevel++;
break;
case S_END:
case S_INLINESITE_END:
case S_PROC_ID_END:
iLevel--;
break;
/*--
typedef struct REFMINIPDB {
unsigned short reclen; // Record length
unsigned short rectyp; // S_REF_MINIPDB
union {
unsigned long isectCoff; // coff section
CV_typ_t typind; // type index
};
unsigned short imod; // mod index
unsigned short fLocal : 1; // reference to local (vs. global) func or data
unsigned short fData : 1; // reference to data (vs. func)
unsigned short fUDT : 1; // reference to UDT
unsigned short fLabel : 1; // reference to label
unsigned short fConst : 1; // reference to const
unsigned short reserved : 11; // reserved, must be zero
unsigned char name[1]; // zero terminated name string
} REFMINIPDB;
--*/
case S_UDT:
{
UDTSYM *psymUdt = (UDTSYM *) psym;
bool fPrimitive = CV_IS_PRIMITIVE(psymUdt->typind);
assert((imod >> CodeViewInfo::ComboID::ImodBitWidth) == 0);
assert((psymUdt->typind >> CodeViewInfo::ComboID::IndexBitWidth) == 0);
if (!fPrimitive) {
assert(ptm != NULL);
if (ptm->fTiMapped(psymUdt->typind)) {
break;
}
}
if (!pdbi1->packRefToGSForMiniPDB((char *) psymUdt->name,
imod + 1,
fPrimitive ? isectCoff : psymUdt->typind,
(iLevel != 0) ? true : false,
fPrimitive ? true : false,
fPrimitive ? false : true,
false,
false)) {
return FALSE;
}
}
break;
case S_CONSTANT:
{
if (iLevel != 0) {
break;
}
ST st;
if (!fGetSymName(psym, &st)) {
assert(false);
return FALSE;
}
if (!pdbi1->packRefToGSForMiniPDB(st,
imod + 1,
isectCoff,
false,
false,
false,
false,
true)) {
return FALSE;
}
}
break;
case S_LPROC32:
case S_LPROC32_ID:
fLocal = true;
// fall through
case S_GPROC32:
case S_GPROC32_ID:
if (iLevel == 0) {
if (!pdbi1->packRefToGSForMiniPDB((char *) ((PROCSYM32 *) psym)->name,
imod + 1,
isectCoff,
fLocal,
false,
false,
false,
false)) {
return FALSE;
}
}
assert(iLevel >= 0);
iLevel++;
break;
case S_LDATA32:
fLocal = true;
// fall through
case S_GDATA32:
if (iLevel != 0) {
break;
}
if (!pdbi1->packRefToGSForMiniPDB((char *) ((DATASYM32 *) psym)->name,
imod + 1,
isectCoff,
fLocal,
true,
false,
false,
false)) {
return FALSE;
}
break;
case S_LTHREAD32:
fLocal = true;
// fall through
case S_GTHREAD32:
if (iLevel != 0) {
break;
}
if (!pdbi1->packRefToGSForMiniPDB((char *) ((THREADSYM32 *) psym)->name,
imod + 1,
isectCoff,
fLocal,
true,
false,
false,
false)) {
return FALSE;
}
break;
#if 0
case S_LABEL32:
if (iLevel != 0) {
break;
}
if (!pdbi1->packRefToGSForMiniPDB((char *) ((LABELSYM32 *) psym)->name,
imod + 1,
isectCoff,
fLocal,
false,
false,
true,
false)) {
return FALSE;
}
break;
#endif
default:
break;
}
}
assert(iLevel == 0);
return TRUE;
}
BOOL Mod1::AddSymbols(PB pbSym, CB cb)
{
return fAddSymbols(pbSym, cb, 0);
}
BOOL Mod1::AddSymbols2(PB pbSym, DWORD cb, DWORD isectCoff)
{
return fAddSymbols(pbSym, cb, isectCoff);
}
BOOL Mod1::fAddSymbols(PB pbSym, DWORD cb, DWORD isectCoff)
{
if (!pdbi1->fWrite) {
ppdb1->setUsageError();
return FALSE;
}
ULONG sigSymsT = sigSyms_S;
if (!fSymsAdded_S) {
sigSymsT = *(ULONG*)pbSym;
}
if (sigSymsT == CV_SIGNATURE_C13) {
if (!fSymsAdded_S) {
if (!AddJustSymbols(pbSym, sizeof(ULONG), false)) {
return FALSE;
}
if (!fAddModTypeRefSym()) {
return FALSE;
}
}
assert(fSymsAdded_S);
if (*(ULONG*) pbSym != CV_SIGNATURE_C13) {
ppdb1->setCorruptError();
return FALSE;
}
COMRefPtr<IDebugSSectionReader> pReader;
if (!CheckFCreateReader(pbSym, cb, &pReader, CV_SIGNATURE_C13)) {
return FALSE;
}
COMRefPtr<IDebugSSubSectionEnum> pEnum;
if (!pReader->GetSectionEnum(&pEnum)) {
setDSRError(ppdb1, pReader->GetLastError());
return FALSE;
}
while (pEnum->Next()) {
COMRefPtr<IDebugSSubSection> pSubSection;
pEnum->Get(&pSubSection);
if (pSubSection == NULL) {
setDSRError(ppdb1, pReader->GetLastError());
return FALSE;
}
PB pbSec = NULL;
DWORD cbSec = 0;
switch (pSubSection->Type()) {
case DEBUG_S_SYMBOLS: // add to symbols substream
cbSec = static_cast<DWORD>(pSubSection->GetData(&pbSec));
if (ppdb1->m_fMinimalDbgInfo) {
if (!fAddSymRefToGSI(pbSec, cbSec, isectCoff)) {
return FALSE;
}
break;
}
if (!AddJustSymbols(pbSec, cbSec, ppdb1->m_fNoTypeMerge)) {
return FALSE;
}
break;
case DEBUG_S_FRAMEDATA:
if (!AppendSubSectionToBuffer(bufC13Fpo, pSubSection)) {
ppdb1->setOOMError();
return FALSE;
}
break;
case DEBUG_S_STRINGTABLE:
if (!AppendSubSectionToBuffer(bufC13Strings, pSubSection)) {
ppdb1->setOOMError();
return FALSE;
}
break;
case DEBUG_S_CROSSSCOPEIMPORTS:
case DEBUG_S_CROSSSCOPEEXPORTS:
case DEBUG_S_INLINEELINES:
if (ppdb1->m_fMinimalDbgInfo) {
break;
}
case DEBUG_S_LINES:
case DEBUG_S_COFF_SYMBOL_RVA:
case DEBUG_S_FUNC_MDTOKEN_MAP:
case DEBUG_S_FILECHKSMS:
case DEBUG_S_IL_LINES:
case DEBUG_S_TYPE_MDTOKEN_MAP:
case DEBUG_S_MERGED_ASSEMBLYINPUT:
// ### TODO: process file names here?
if (!AppendSubSectionToBuffer(*rbufC13Lines, pSubSection)) {
ppdb1->setOOMError();
return FALSE;
}
break;
default:
break; // just ignore subsections that we don't understand
}
}
return TRUE;
}
else
{ // !CV_SIGNATURE_C13
return AddJustSymbols(pbSym, cb, ppdb1->m_fNoTypeMerge);
}
}
BOOL Mod1::RemoveGlobalRefs()
{
if (!pdbi1->fWrite || !ppdb1->m_fMinimalDbgInfo) {
ppdb1->setUsageError();
return FALSE;
}
return pdbi1->removeGlobalRefsForMod(imod + 1);
}