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
/
dbi.h
1536 lines (1296 loc) · 49.8 KB
/
dbi.h
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
//////////////////////////////////////////////////////////////////////////////
// DBI implementation declarations
#pragma once
#pragma warning(push)
#pragma warning(disable:4200)
// header of the DBI Stream
// section contribution version, before V60 there was no section version
enum {
DBISCImpvV60 = 0xeffe0000 + 19970605,
DBISCImpv = DBISCImpvV60,
DBISCImpv2 = 0xeffe0000 + 20140516,
};
struct OMAP_DATA {
DWORD rva;
DWORD rvaTo;
};
// For type mismatch detection (TMD)
typedef struct TMD_INFO TMD_INFO;
typedef TMD_INFO *PTMD_INFO;
struct TMD_INFO {
PTMD_INFO next;
TI ti; // type index in final PDB being produced
USHORT imod;
wchar_t * wszSrc;
DWORD line;
};
typedef struct TMD TMD;
typedef TMD *PTMD;
struct TMD {
PTMD next;
PTMD_INFO pInfo;
};
// Support for bit vector operations
#ifndef BITSPERBYTE
#define BITSPERBYTE (8)
#endif /* BITSPERBYTE */
struct BITVEC {
public:
BITVEC() {
cbits = 0;
bv = 0;
}
~BITVEC() {
if (bv)
delete [] bv;
}
BOOL fAlloc(size_t _cbits) {
// Protect against interger overflow
if (_cbits > s_cbMaxAlloc) {
return FALSE;
}
bv = (unsigned char *) new (zeroed) CHAR[(_cbits + BITSPERBYTE - 1) / BITSPERBYTE];
if (bv) {
cbits = _cbits;
return TRUE;
}
return FALSE;
}
BOOL fTestBit(size_t index) {
assert(bv);
if (index >= cbits)
return FALSE;
else
return ((bv[index / BITSPERBYTE] >> (index % BITSPERBYTE)) & 1);
}
BOOL fSetBit(size_t index) {
assert(bv);
if (index >= cbits)
return FALSE;
else
bv[index / BITSPERBYTE] |= (1 << (index % BITSPERBYTE));
return TRUE;
}
private:
unsigned char *bv;
size_t cbits;
};
// header of the DBI Stream
struct DBIHdr {
SN snGSSyms;
SN snPSSyms;
SN snSymRecs;
CB cbGpModi; // size of rgmodi substream
CB cbSC; // size of Section Contribution substream
CB cbSecMap;
CB cbFileInfo;
DBIHdr()
{
snGSSyms = snNil;
snPSSyms = snNil;
snSymRecs = snNil;
cbGpModi = 0;
cbSC = 0;
cbSecMap = 0;
cbFileInfo = 0;
}
};
enum {
DBIImpvV41 = 930803,
DBIImpvV50 = 19960307,
DBIImpvV60 = 19970606,
DBIImpvV70 = 19990903,
DBIImpvV110 = 20091201,
DBIImpv = DBIImpvV70,
};
struct NewDBIHdr {
enum {
hdrSignature = -1,
hdrVersion = DBIImpv,
};
// unchanged since fInit
ULONG verSignature;
// only used in finit or fSave
ULONG verHdr;
// protected by m_csForHdr
AGE age;
// protected by m_csForPGSI
SN snGSSyms;
// protected by m_csForHdr
union {
struct {
USHORT usVerPdbDllMin : 8; // minor version and
USHORT usVerPdbDllMaj : 7; // major version and
USHORT fNewVerFmt : 1; // flag telling us we have rbld stored elsewhere (high bit of original major version)
} vernew; // that built this pdb last.
struct {
USHORT usVerPdbDllRbld: 4;
USHORT usVerPdbDllMin : 7;
USHORT usVerPdbDllMaj : 5;
} verold;
USHORT usVerAll;
};
// protected by m_csForPGSI
SN snPSSyms;
// protected by m_csForHdr
USHORT usVerPdbDllBuild; // build version of the pdb dll
// that built this pdb last.
// protected by m_csForSymRec
SN snSymRecs;
// protected by m_csForHdr
USHORT usVerPdbDllRBld; // rbld version of the pdb dll
// that built this pdb last.
// protected by m_csForMods;
CB cbGpModi; // size of rgmodi substream
// protected by m_csSecContrib
CB cbSC; // size of Section Contribution substream
// only used in fInit or fSave
CB cbSecMap;
CB cbFileInfo;
CB cbTSMap; // size of the Type Server Map substream
ULONG iMFC; // index of MFC type server
CB cbDbgHdr; // size of optional DbgHdr info appended to the end of the stream
CB cbECInfo; // number of bytes in EC substream, or 0 if EC no EC enabled Mods
// protected by m_csForHdr
struct _flags {
USHORT fIncLink:1; // true if linked incrmentally (really just if ilink thunks are present)
USHORT fStripped:1; // true if PDB::CopyTo stripped the private data out
USHORT fCTypes:1; // true if this PDB is using CTypes.
USHORT unused:13; // reserved, must be 0.
} flags;
USHORT wMachine; // machine type
ULONG rgulReserved[ 1 ]; // pad out to 64 bytes for future growth.
NewDBIHdr()
{
memset(this, 0, sizeof(*this));
verSignature = ULONG(hdrSignature);
verHdr = ULONG(hdrVersion);
snGSSyms = snNil;
snPSSyms = snNil;
snSymRecs = snNil;
}
NewDBIHdr(const DBIHdr & dbihdrOld)
{
memset(this, 0, sizeof(*this));
verSignature = ULONG(hdrSignature);
verHdr = ULONG(hdrVersion);
snGSSyms = dbihdrOld.snGSSyms;
snPSSyms = dbihdrOld.snPSSyms;
snSymRecs = dbihdrOld.snSymRecs;
cbGpModi = dbihdrOld.cbGpModi;
cbSC = dbihdrOld.cbSC;
cbSecMap = dbihdrOld.cbSecMap;
cbFileInfo = dbihdrOld.cbFileInfo;
}
NewDBIHdr &
operator=(const DBIHdr & dbihdrOld)
{
snGSSyms = dbihdrOld.snGSSyms;
snPSSyms = dbihdrOld.snPSSyms;
snSymRecs = dbihdrOld.snSymRecs;
cbGpModi = dbihdrOld.cbGpModi;
cbSC = dbihdrOld.cbSC;
cbSecMap = dbihdrOld.cbSecMap;
cbFileInfo = dbihdrOld.cbFileInfo;
cbECInfo = 0;
return *this;
}
// protected by m_csForHdr
void SetPdbVersion(int verMaj, int verMin, int verBuild, int verRbld)
{
vernew.fNewVerFmt = 1;
vernew.usVerPdbDllMaj = verMaj;
vernew.usVerPdbDllMin = verMin;
usVerPdbDllBuild = verBuild;
usVerPdbDllRBld = verRbld;
}
};
// Make sure our version bitfields and unions don't consume more than a USHORT.
cassert(offsetof(NewDBIHdr,snPSSyms) - offsetof(NewDBIHdr,usVerAll) == sizeof(USHORT));
// optional header is stored at the end of the DBI stream
// Its presence is denoted by a nonzero value in the
// cbDbgHdr field of NewDBIHdr
struct DbgDataHdr {
SN rgSnDbg[dbgtypeMax];
DbgDataHdr()
{
memset(this, 0, sizeof(*this));
for (int i=0; i<dbgtypeMax; i++) {
rgSnDbg[i] = snNil;
}
}
BOOL fInUse()
{
// return TRUE if at least one dbg-data stream is in use
for (int i=0; i<dbgtypeMax; i++)
if (rgSnDbg[i] != snNil)
return TRUE;
return FALSE;
}
};
// helper class to use to encapsulate the 16 to 32-bit widening information
struct CvtSyms {
BOOL _fConverting;
Buffer _bufSyms;
Array<OffMap> _rgOffMap;
static BOOL
fCompOffMap(OffMap * pOffMap, void * off)
{
// safe cast for Win64; void * off is really an OFF, always 32bits.
return ULONG(int_ptr_t(off)) <= pOffMap->offOld;
}
CvtSyms() : _fConverting(FALSE) { }
BOOL
fConverting() const { return _fConverting; }
BOOL &
fConverting() { return _fConverting; }
Buffer &
bufSyms() { return _bufSyms; }
Array<OffMap> &
rgOffMap() { return _rgOffMap; }
OFF
offSymNewForOffSymOld(ULONG offSymOld)
{
if (!_fConverting) {
return offSymOld;
}
// binary search for the old=>new mapping
unsigned
iOffMap = _rgOffMap.binarySearch(fCompOffMap, PV(uint_ptr_t(offSymOld)));
OffMap &
offmap = _rgOffMap[iOffMap];
// we expect a match to be found, but stale symbols in the globals from
// incremental links do appear and we might as well not update them, in
// order to not confuse the issue.
if (offmap.offOld == offSymOld) {
return offmap.offNew;
}
return offSymOld;
}
};
class CvtStSymsToSz {
// Symbol offset map specially for converting from
// ST symbols to SZ symbols in a mod. The array simply
// holds differences in _rgOffMap, since most of the
// symbols retain the length, except for S_COMPILE2
// and S_OBJNAME, which can expand on translation
Array<OffMap> _rgOffMap; // Holds the map
BOOL _fValid; // TRUE if the map is in _rgOffMap
public :
CvtStSymsToSz()
{
_fValid = FALSE;
}
Array<OffMap> &rgOffMap()
{
return _rgOffMap;
}
BOOL fValid()
{
return _fValid;
}
BOOL SetValid()
{
return _fValid = TRUE;
}
OFF offSymNewForOffSymOld(ULONG offSymOld)
{
assert(_fValid);
for(int i=_rgOffMap.size() - 1; i>=0; i--) {
if (_rgOffMap[i].offOld <= offSymOld) {
OffMap offmap = _rgOffMap[i];
return offSymOld + (offmap.offNew - offmap.offOld);
}
}
return offSymOld;
}
};
struct TSM {
DWORD reserved; //TPI* pServer; // currently open type map
TI tiBase; // server base
// following is a description of a type server from LF_TYPESERVER
SIG signature; // signature
AGE age; // age of database used by this module
char szNamePath[]; // name and reference path for a PDB
SZ szName() { return szNamePath; }
SZ szPath() { return szNamePath+strlen(szName()) + 1; }
TI ti() { return tiBase; }
PB pbEnd() {
return pbAlign(PB(szPath()) + strlen(szPath()) + 1);
}
void* operator new (size_t size, Buffer& bufTsm, _In_z_ SZ szName, _In_z_ SZ szPath);
TSM(SIG sig_, AGE age_, _In_z_ SZ szName_, _In_z_ SZ szPath_, TI tiMin_)
: tiBase(tiMin_), signature(sig_), age(age_)
{
memcpy(szName(), szName_, strlen(szName_) + 1);
memcpy(szPath(), szPath_, strlen(szPath_) + 1);
}
};
inline void* TSM::operator new(size_t size, Buffer& bufTsm, SZ szName_, SZ szPath_)
{
if (!szName_ || !szPath_)
return 0;
PB pb;
size_t cb = cbAlign(size + strlen(szName_) + 1 + strlen(szPath_) + 1);
return bufTsm.Reserve(CB(cb), &pb) ? pb : 0;
}
#ifdef PDB_TYPESERVER
struct OPDB { // open type servers - all pdb's are opened readonly
PDB * ppdb;
OPDB * next;
TPI* ptpi;
OPDB(PDB* ppdb_, TPI * ptpi_, OPDB *next_ = 0) : ppdb(ppdb_), ptpi(ptpi_), next(next_) {}
~OPDB() {
if (ptpi != 0)
ptpi->Close();
if (ppdb != 0)
ppdb->Close();
}
};
#endif
struct MemBlock {
DWORD rva;
DWORD cb;
MemBlock(DWORD _rva = 0, DWORD _cb = 0)
: rva(_rva), cb(_cb)
{
assert(rva + cb >= rva);
}
bool in(DWORD _rva) {
return rva <= _rva && _rva - rva < cb;
}
};
class Dbg1;
class Dbg1Data;
enum SPD { // Symbol Packing Dispensation
spdIdentical, // name exists in global scope and is identical
spdMismatch, // name exists in global scope but doesn't match
spdAdded, // name nonexistent in global scope, was added.
spdInvalid // operation failed completely
};
// Get rid of the helper macro and suppress the deprecated warning
//
#if defined(QueryModFromAddr)
#undef QueryModFromAddr
#endif
typedef int (__cdecl *PFN_DBGCMP)(const void*, const void*);
#pragma warning(push)
#pragma warning(disable : 4996)
struct DBI1 : public DBICommon { // DBI (debug information) implemenation
public:
INTV QueryInterfaceVersion(); // mts safe
IMPV QueryImplementationVersion(); // mts safe
BOOL DeleteMod(SZ_CONST szModule); // mts safe
#if 0 // NYI
BOOL QueryCountMod(long *pcMod);
#endif
BOOL QueryNextMod(Mod* pmod, Mod** ppmodNext); // mts safe
BOOL OpenGlobals(OUT GSI** ppgsi);
BOOL OpenPublics(OUT GSI** ppgsi);
BOOL AddSec(ISECT isect, USHORT flags, OFF off, CB cb);
BOOL AddPublic(SZ_CONST szPublic, ISECT isect, OFF off);
BOOL RemovePublic(SZ_CONST szPublic);
BOOL QueryModFromAddr(ISECT isect, OFF off, OUT Mod** ppmod,
OUT ISECT * pisect, OUT OFF* poff, OUT CB* pcb);
BOOL QueryModFromAddr2(ISECT isect, long off, OUT Mod** ppmod,
OUT ISECT* pisect, OUT long* poff, OUT long* pcb,
OUT ULONG * pdwCharacteristics);
BOOL QueryModFromAddrEx(USHORT isect, DWORD off, OUT Mod** ppmod,
OUT USHORT* pisect, OUT ULONG* pisectCoff, OUT ULONG* poff,
OUT ULONG* pcb, OUT ULONG * pdwCharacteristics);
BOOL QueryAddrForSec(OUT USHORT* pisect, OUT long* poff,
IMOD imod, long cb, DWORD dwDataCrc, DWORD dwRelocCrc);
BOOL QueryAddrForSecEx(OUT USHORT* pisect, OUT long* poff, IMOD imod,
long cb, DWORD dwDataCrc, DWORD dwRelocCrc, DWORD dwCharacteristics);
BOOL QuerySupportsEC();
BOOL FStripped();
BOOL QuerySecMap(OUT PB pb, CB* pcb);
BOOL QueryFileInfo(OUT PB pb, CB* pcb);
BOOL QueryFileInfo2(OUT PB pb, CB* pcb);
void DumpMods();
void DumpSecContribs();
void DumpSecMap();
BOOL Close();
BOOL AddThunkMap(OFF* poffThunkMap, UINT nThunks, CB cbSizeOfThunk,
SO* psoSectMap, UINT nSects, ISECT isectThunkTable, OFF offThunkTable);
#ifdef PDB_MT
#pragma message(MTS_MESSAGE("Not thread safe - EnumSC use of bufSC is not MTS"))
#endif
BOOL getEnumContrib(OUT Enum** ppenum);
BOOL getEnumContrib2(OUT Enum** ppenum);
wchar_t * szGetTsInfo(PTYPE pts, wchar_t *szNameBuf, wchar_t *szFullMapped, SIG70 *pSig70, AGE *pAge);
BOOL QueryTypeServer(ITSM itsm, OUT TPI** pptpi);
BOOL QueryItsmForTi(TI ti, OUT ITSM* ptpi);
BOOL QueryNextItsm(ITSM itsm, OUT ITSM *inext);
BOOL QueryLazyTypes();
BOOL SetLazyTypes(BOOL fLazy); // lazy is default and can only be turned off
void FlushTypeServers();
BOOL FindTypeServers(OUT EC* pec, _Out_opt_cap_(cbErrMax) OUT char szError[cbErrMax]);
void DumpTypeServers();
AGE QueryAge() const {
MTS_PROTECT(m_csForHdr);
return dbihdr.age;
}
void * QueryHeader() const {
// This is not thread safe. The server use QueryHeader2
return PV(&dbihdr);
}
BOOL QueryHeader2(CB cb, PB pb, CB *pcbOut) {
dassert(pcbOut);
MTS_PROTECT(m_csForHdr);
*pcbOut = sizeof(dbihdr);
if (pb) {
if (cb < sizeof(dbihdr)) {
return FALSE;
}
memcpy(pb, &dbihdr, sizeof(dbihdr));
}
return TRUE;
}
BOOL OpenDbg(DBGTYPE dbgtype, OUT Dbg **ppdbg);
BOOL QueryDbgTypes(OUT DBGTYPE *pdbgtype, OUT long* pcDbgtype);
BOOL QueryPdb(OUT PDB** pppdb);
BOOL AddLinkInfo(IN PLinkInfo);
BOOL QueryLinkInfo(PLinkInfo, OUT long * pcb);
BOOL OpenModW(const wchar_t* szModule, const wchar_t* szFile, OUT Mod** ppmod);
BOOL DeleteModW(const wchar_t* szModule);
BOOL AddPublicW(const wchar_t* szPublic, USHORT isect, long off, CV_pubsymflag_t cvpsf =0);
BOOL QueryTypeServerByPdbW(const wchar_t* szPdb, OUT ITSM* pitsm);
BOOL AddLinkInfoW(IN PLinkInfoW);
BOOL AddPublic2(const char* szPublic, USHORT isect, long off, CV_pubsymflag_t cvpsf =0);
USHORT QueryMachineType() const;
void SetMachineType(USHORT wMachine);
BOOL QueryNoOfMods(long *cMods) {
*cMods = imodMac;
return TRUE;
}
BOOL QueryMods(Mod **ppmodNext, long cMods);
BOOL QueryImodFromAddr(USHORT isect, long off, OUT IMOD* pimod,
OUT USHORT* pisect, OUT long* poff, OUT long* pcb,
OUT ULONG * pdwCharacteristics);
BOOL QueryImodFromAddrEx(USHORT isect, ULONG off, OUT IMOD* pimod,
OUT USHORT* pisect, OUT ULONG* pisectCoff, OUT ULONG* poff,
OUT ULONG* pcb, OUT ULONG * pdwCharacteristics);
BOOL OpenModFromImod(USHORT imod, OUT Mod **ppmod) {
return openModByImod(imodForXimod(imod), ppmod);
}
BOOL QueryModTypeRef(IMOD imod, MODTYPEREF *pmtr);
BOOL FAddSourceMappingItem(
const wchar_t * szMapTo,
const wchar_t * szMapFrom,
ULONG grFlags
);
BOOL FSetPfnNotePdbUsed(void *, DBI::PFNNOTEPDBUSED);
BOOL FSetPfnNoteTypeMismatch(void *, DBI::PFNNOTETYPEMISMATCH);
BOOL FSetPfnTmdTypeFilter(void *, DBI::PFNTMDTYPEFILTER);
BOOL FCTypes();
BOOL FSetPfnQueryCallback(void *, PFNDBIQUERYCALLBACK);
void RemoveDataForRva(ULONG rva, ULONG cb);
void SetSCVersion2() { fSCv2 = true; }
void UnsetSCVersion2() { fSCv2 = false; }
private:
// Helper functions
template<typename T>
BOOL QueryImodFromAddrHelper(USHORT isect, ULONG off, OUT IMOD* pimod,
OUT USHORT* pisect, OUT ULONG* pisectCoff, OUT ULONG* poff,
OUT ULONG* pcb, OUT ULONG * pdwCharacteristics);
DWORD SizeOfSCEntry()
{
size_t cb = fSCv2 ? sizeof(SC2) : sizeof(SC);
return (DWORD) cb;
}
BOOL QueryTypeServerByPdbUTF8(const char* szPdb, OUT ITSM* piTsm);
static PLinkInfo GetUTF8LinkInfo(PLinkInfo pli);
static PLinkInfo GetUTF8LinkInfo(PLinkInfoW pli);
#ifdef PDB_TYPESERVER
// used in PDB1::OpenDBIEx()
void SetFindFunc(PfnFindDebugInfoFile pfn_) {
m_pfnFindDIF = pfn_;
}
void GetFindFunc(PfnFindDebugInfoFile *pfn_) {
*pfn_ = m_pfnFindDIF;
}
#endif
BOOL ReportTypeMismatches();
// used by GSI1 and PSGSI1 inits and DBI1::fixupRefSymsForImod
BOOL fReadSymRecs();
BOOL fConvertSymRecs(CB); // used in fReadSymRecs()
#ifdef PDB_DEFUNCT_V8
BOOL fConvertSymRecsToSZ(CB);
BOOL fReadAllGlobals();
#endif
// used in fReadSymRec and fReadSymRecPage and DBI1::offForSym
bool fValidPsym(PSYM psym)
{
MTS_ASSERT(m_csForSymRec);
// Verifies that the pointer itself is contained; not the contents
// of the symbol record pointed to.
//
PB pbBase = bufSymRecs.Start();
return
reinterpret_cast<PB>(psym) >= pbBase &&
reinterpret_cast<PB>(psym) - pbBase <
(fWrite ? bufSymRecs.Size() : ppdb1->pmsf->GetCbStream(dbihdr.snSymRecs));
}
//======================
// used by GSI1
//======================
OFF offForSym(PSYM psym) // mts safe
{
MTS_PROTECT(m_csForSymRec);
assert(psym);
expect(bufSymRecs.Contains(psym));
if (fValidPsym(psym)) {
return static_cast<OFF>(reinterpret_cast<PB>(psym) - bufSymRecs.Start());
}
else {
return static_cast<OFF>(-1);
}
}
BOOL fpsymFromOff(OFF off, PSYM *ppsym);
BOOL fAddSym(PSYM psymIn, OUT PSYM* psymOut);
//=========================
// used by GSI1 and PSGSI1
//=========================
BOOL fReadSymRec(PSYM);
//======================
// used by Mod1
//======================
// used in Mod1::fInit()
BOOL invalidateSCforMod(IMOD imod);
inline SZ szObjFile(IMOD imod);
inline SZ szModule(IMOD imod);
inline CB cbSyms(IMOD imod);
inline CB cbLines(IMOD imod);
inline CB cbC13Lines(IMOD imod);
inline SN Sn(IMOD imod);
bool InitFrameDataStream();
bool AddFrameData(FRAMEDATA* pframe, DWORD n);
bool LoadFrameData();
bool SaveFrameData();
void fixupRefSymsForImod(unsigned imod, CvtSyms &);
// used in Mod1::fUpdateSecContrib()
BOOL addSecContrib(SC2& scIn);
// used in Mod1::QuerySrcFile, Mod1::QueryPdbFile and DBI1::DumpMods
BOOL srcForImod(unsigned imod, _Out_z_cap_(_MAX_PATH) char szSrcFile[ _MAX_PATH ], long* pcb); // mts safe
BOOL pdbForImod(unsigned imod, _Out_z_cap_(_MAX_PATH) char szPdbFile[ _MAX_PATH ], long* pcb); // mts safe
// used in Mod1::fProcessSyms()
BOOL setSrcForImod(unsigned imod, SZ_CONST szSrcFile); // mts safe
BOOL setPdbForImod(unsigned imod, SZ_CONST szPdbFile); // mts safe
inline BOOL packRefToGS (PSYM psym, IMOD imod, OFF off, OFF *poff);
inline BOOL packRefToGSForMiniPDB (const char *sz, WORD imod, DWORD isectCoff,
bool fLocal, bool fData, bool fUDT, bool fLabel,
bool fConst);
inline BOOL packSymToGS (PSYM psym, OFF *poff);
inline BOOL packSymSPD (PSYM, OFF*, SPD &);
inline BOOL packTokenRefToGS (PSYM psym, IMOD imod, OFF off, OFF *poff);
// used in AddPublic* in DBI1 and MOD1
inline BOOL packSymToPS (PSYM psym);
inline BOOL removeGlobalRefsForMod(IMOD imod);
//==========================
// Type server helpers
//==========================
// used by Mod1::AddTypes
BOOL fGetTmts(PTYPE pts, UTFSZ_CONST szObjFile, TM** pptm, BOOL fQueryOnly);
// used by DBI1::fGetTmts
BOOL fOpenTmts(const wchar_t *szName, const SIG70& sig70, AGE age, UTFSZ_CONST szObjFile, TM** pptm, AGE &agePdb);
// used by DBI1::fOpenTmts and DBI1::QueryTypeServer
BOOL fOpenPdb(const SIG70& sig70, AGE age, const wchar_t *szName, UTFSZ_CONST szObjFile, PDB** pppdb, BOOL fQuery=FALSE);
BOOL fGetTmpct(PTYPE ppc, TMPCT** pptmpct);
BOOL fAddTmpct(lfEndPreComp* pepc, TI tiPreComp, SZ_CONST szModule, TMPCT* ptmpct);
BOOL fUpdateTmpct(SZ_CONST szModule, SZ_CONST szInternalName, TM* ptm);
BOOL fFindTm(OTM* potm, const wchar_t *szName, const SIG70& sig70, AGE age, TI tiPreComp, TM** pptm);
static void fixSymRecs (void* pdbi, void* pOld, void* pNew);
ITSM ItsmFromTi(TI ti) {
return (ITSM)(ti>>24);
}
#ifdef PDB_TYPESERVER
BOOL AddTypeServer(SIG, AGE, SZ, SZ, OUT ITSM *pitsm);
TI TiForTiItsm(TI ti, ITSM itsm) {
assert((ti & (0xff<<24)) == 0);
return CV_IS_PRIMITIVE(ti) ? ti : ((itsm<<24) | ti);
}
TI ConvertItem(TI ti, ITSM itsm) {
return TiForTiItsm(OriginalTi(ti), itsm);
}
TI OriginalTi(TI ti) {
return ti & 0x00ffffff;
}
#endif //PDB_TYPESERVER
#ifdef INSTRUMENTED
void DumpSymbolPages();
#endif
void SetIncLink() { // mark this as an incremental link build
MTS_PROTECT(m_csForHdr);
dbihdr.flags.fIncLink = true;
}
void SetStripped(bool f) {
MTS_PROTECT(m_csForHdr);
dbihdr.flags.fStripped = f;
}
// Used by Dbg1
Dbg1Data *fGetDbgData(int iDbg, ULONG cbElement, PFN_DBGCMP pfn);
BOOL fSaveDbgData(int iDbg, Buffer &buffer);
protected:
friend PDB1;
DBI1(PDB1* ppdb1_, BOOL fWrite_, bool fCTypes_, bool fTypeMismatch_);
~DBI1();
BOOL fInit(BOOL fCreate);
BOOL fSave();
BOOL fCheckReadWriteMode(BOOL fWrite);
BOOL openModByImod(IMOD imod, OUT Mod** ppmod);
// used in DBI1::OpenModW
IMOD imodForModNameW(const wchar_t* szModule, const wchar_t* szObjFile);
MODI* pmodiForImod(IMOD imod) {
MTS_ASSERT(m_csForMods);
return (0 <= imod && imod < imodMac) ? rgpmodi[imod] : 0;
}
void NoteModCloseForImod(IMOD imod);
BOOL initFileInfo(IMOD imod, IFILE ifileMac);
BOOL addFileInfo(IMOD imod, IFILE ifile, SZ_CONST szFile);
BOOL addFilename(SZ_CONST szFile, ICH *pich);
static void fixBufGpmodi(void* pDBI1, void* pOld, void* pNew);
static void fixBufBase(void* pv, void* pvOld, void* pvNew);
BOOL fValidateSnDbg(SN *psnDbg);
MSF * getpmsf() {return ppdb1->pmsf;}
#ifdef PDB_DEFUNCT_V8
BOOL fLoadImageHeader(IMAGE_SEPARATE_DEBUG_HEADER *pImageHeader);
#endif
// used in DBI1::QuerySupportsEC()
BOOL fEnCSymbolsPresent();
BOOL IsLinkedIncrementally();
// used in DBI1::fSave()
BOOL fWriteModi(Buffer &);
// used by DBI1::Close(), PDB1::OpenDBIEx, PDB1::CreateDBI
BOOL internal_Close(); // do hard close
private:
typedef NMT NMT_CTG; // contiguous name table. Current
// behavior of NMT is contiguous.
#pragma pack(push, 1)
typedef struct {
IMOD imod;
DWORD dwDataCrc;
DWORD dwRelocCrc;
CB cb;
DWORD dwCharacteristics;
} IModSec;
#pragma pack(pop)
enum {impv = DBIImpv};
// unchange since open
PDB1* ppdb1; // PDB that opened me
// used only when fWrite, always exclusive write for DBI
OTM* potmTSHead; // list of open TMTSs
OTM* potmPCTHead; // list of open TMPCTs
// protected by m_csForMods;
IMOD imodMac; // next available IMOD
#ifndef PDB_MT
IMOD imodLastQNM; // imod last found by QueryNextMod
IMOD imodLastFMN; // imod last found by imodForModName
#endif
// protected by m_csForMods;
Buffer bufGpmodi; // buffer backing gpmodi, the catenation of the modi
Buffer bufRgpmodi; // buffer backing rgpmodi, to map imod to pmodi
// protected by m_csSecContribs
Buffer bufSC; // buffer for section contribution info
// unchanged since open/init
OFF offSC; // offset in dbistream where sec contribs begin
// protected by m_csSecContribs - used only by DBI1::QueryAddrForSec
// Maps from IModSec to index in seccontribs.
// The first one has zero characteristics in the key.
// Both used by EnC.
typedef HashClassCRC<IModSec> hcSC;
Map<IModSec, DWORD, hcSC> mpSecToSC_ZeroChar;
Map<IModSec, DWORD, hcSC> mpSecToSC;
// Used by QueryAddrForSecEx() and QueryAddrForSec()
BOOL DBI1::fCreateSecToSCMap(Map<IModSec, DWORD, hcSC> & map, IMOD imod, bool fZeroChar);
// if in write mode, it's always exclusive
// if in read mode, bufSecMap doesn't change after fInit
Buffer bufSecMap; // buffer for section map
// protected by m_csForMods
Buffer bufFilenames; // buffer of modules' contributor filenames
// protected by m_csSecContribs
PB pbscEnd; // end of valid SC entries
bool fSCv2; // sec contrib entry contains coff section #
// protected by m_csForMods
MODI** rgpmodi; // module information for imod in [0..imodMac).
// protected by m_csForPGSI
GSI1* pgsiGS; // gsi of global syms
PSGSI1* pgsiPS; // gsi of public syms
// protected by m_csForSymRec
VirtualBuffer bufSymRecs; // buffer for symbol recs (publics and globals)
BITVEC* pbvSymRecPgs; // bit vector that gives the pages loaded
unsigned cSymRecPgs; // count of pages of symrecs
#ifdef PDB_DEFUNCT_V8
size_t m_cbSymRecs; // cached count of bytes of symbols in stream.
#endif
Array< FRAMEDATA >
m_rgFrameData; // array of frame data from Dbg newFPO stream
Array< MemBlock >
m_rgrvaRemovals;// array of frame data from Dbg newFPO stream
Dbg* pdbgFrameData;
// protected by mulitple CS
NewDBIHdr dbihdr; // new header
// protected by m_csForDbg
DbgDataHdr dbghdr; // debug data header (for FPO, OMAP, FIXUP, etc)
// protected by m_csForSymRec (except for using cvtsyms.fConverting(), which is unchanged since fInit)
CvtSyms cvtsyms; // info for conversions
WidenTi * pwti; // our conversion interface
ISet isetModConverted; // keep track of modules that have been converted
// already.
#ifdef PDB_TYPESERVER
InBuf<TSM> bufTSMap; // buffer for type server map
ArrayPtrBuf<TPI>
bufTSMServer; // buffer for type server pointers
OPDB * popdbHead; // list of open type server pdb's
PfnFindDebugInfoFile m_pfnFindDIF; // callback to help find files
#endif
// protected by m_csForMods
NMT nmtEC;
static const char
c_szLinkInfoStr[]; // stream name where we store LinkInfo
#ifdef PDB_TYPESERVER
BOOL fInsertPdb(PDB* ppdb, TPI* ptpi) // insert a new pdb,tpi
{
return (popdbHead = new OPDB(ppdb, ptpi, popdbHead)) != 0;
}
void ClosePdbs()
{
for (OPDB* popdb = popdbHead; popdb != 0; popdb = popdbHead) {
popdbHead = popdb->next;
delete popdb;
}
}
BOOL FindValidate(const char *szPDB, const char *szObjFile);
ITSM itsmMfcFromSzPdbName(SZ_CONST szPdb, UINT iTsmCur);
#endif
// protected by m_csForMods - used only in DBI1::addFilename
NMT_CTG nmtFileInfo; // so we can _quickly_ reload/add files!
// unchanged since open/init
BOOL fWrite;
BOOL fSCCleared;
bool m_fCTypes;
bool m_fTypeMismatch;
// protected by m_csForFrameData
BOOL fFrameDataLoaded;
#ifdef _DEBUG
bool fFrameDataAdded;
#endif
#ifdef PDB_DEFUNCT_V8
BOOL fGlobalsConverted; // TRUE if this is 6.0 PDB and
// we have converted globals to 7.0
#endif
// protected by m_csForMods - used by DBI1::imodForModNameW
Buffer bufNames; // Unicode module names
struct ModNames {
size_t offwszName;
size_t offwszFile;
};
Array< ModNames > rgModNames;
#ifdef PDB_MT
mutable CriticalSection m_csSecContribs;
mutable CriticalSection m_csForPGSI;
mutable CriticalSection m_csForNameMap;
mutable CriticalSection m_csForMods;
mutable CriticalSection m_csForSymRec;
mutable CriticalSection m_csForHdr;
mutable CriticalSection m_csForDbg;
mutable CriticalSection m_csForFrameData;
mutable CriticalSection m_csForTpi;
mutable CriticalSection m_csForIpi;
mutable CriticalSection m_csForOTM;
mutable CriticalSection m_csForTmd;
#endif
Dbg1Data *rgOpenedDbg[dbgtypeMax];
BOOL fDbgDataVerified[dbgtypeMax];
// verify the debug data -- so far only called by DBI1::fGetDbgData() in dbi.cpp
BOOL VerifyDbgData(Buffer * buf, int dbgtype)
{
if (fDbgDataVerified[dbgtype])
return TRUE;
PB pbStart = buf->Start(), pbEnd = buf->End();
switch(dbgtype)
{
case dbgtypeNewFPO:
{
NameMap * pnmap = ppdb1->m_pnamemap;
// If we haven't read in name map, skip verifying now.
if (!pnmap)
break;
fDbgDataVerified[dbgtype] = TRUE;
PB pb = pbStart;
while(pb != pbEnd) {
NI ni = ((FRAMEDATA *)pb)->frameFunc;
if (!pnmap->isValidNi(ni)) {
return FALSE;
}
pb += sizeof(FRAMEDATA);
if (pb > pbEnd) {
return FALSE;
}
}