Skip to content

Commit b290e1e

Browse files
committed
cleanup after CV4 removal
- consolidate CodeView enumerators to cv4.d - use LF_* symbols instead of numeric values - remove dead code for OEM types (overlapping existing other record ids) - combine some declarations with initialization that are no longer conditional
1 parent e0ef787 commit b290e1e

4 files changed

Lines changed: 79 additions & 146 deletions

File tree

compiler/src/dmd/backend/cgcv.d

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -193,18 +193,16 @@ int cv_namestring(ubyte* p, const(char)* name, int length = -1)
193193
@trusted
194194
debtyp_t* debtyp_alloc(uint length)
195195
{
196-
debtyp_t* d;
197-
uint pad = 0;
198-
199196
//printf("len = %u, x%x\n", length, length);
200197
// length+2 must lie on 4 byte boundary
201-
pad = ((length + 2 + 3) & ~3) - (length + 2);
198+
uint pad = ((length + 2 + 3) & ~3) - (length + 2);
202199
length += pad;
203200

204201
if (length > ushort.max)
205202
err_nomem();
206203

207-
const len = debtyp_t.sizeof - (d.data).sizeof + length;
204+
const len = debtyp_t.sizeof - debtyp_t.data.sizeof + length;
205+
debtyp_t* d;
208206
debug
209207
{
210208
d = cast(debtyp_t*) mem_malloc(len /*+ 1*/);
@@ -324,8 +322,7 @@ idx_t cv_numdebtypes()
324322

325323
@trusted
326324
void cv_init()
327-
{ debtyp_t* d;
328-
325+
{
329326
//printf("cv_init()\n");
330327

331328
// Initialize statics
@@ -404,12 +401,7 @@ void cv_init()
404401
cgcv.FD_code = 0x10;
405402
}
406403

407-
int flags;
408-
__gshared ushort[5] memmodel = [0,0x100,0x20,0x120,0x120];
409-
char[1 + (VERSION).sizeof] version_;
410-
ubyte[8 + (version_).sizeof] debsym;
411-
412-
// Put out signature indicating CV4 format
404+
// Put out signature indicating CV8 format
413405
cgcv.signature = 4;
414406
cgcv.deb_offset = 0x1000;
415407
cgcv.sz_idx = 4;
@@ -604,29 +596,23 @@ private uint cv4_symtypidx(Symbol* s)
604596
uint cv4_typidx(type* t)
605597
{ uint typidx;
606598
uint u;
607-
uint next;
608599
uint key;
609600
debtyp_t* d;
610601
targ_size_t size;
611-
tym_t tym;
612-
tym_t tycv;
613602
tym_t tymnext;
614603
type* tv;
615-
uint dt;
616-
uint attribute;
617-
ubyte call;
618604

619605
//printf("cv4_typidx(%p)\n",t);
620606
if (!t)
621607
return dttab4[TYint]; // assume int
622608
type_debug(t);
623-
next = cv4_typidx(t.Tnext);
624-
tycv = t.Tty;
625-
tym = tybasic(tycv);
609+
uint next = cv4_typidx(t.Tnext);
610+
tym_t tycv = t.Tty;
611+
tym_t tym = tybasic(tycv);
626612
tycv &= mTYconst | mTYvolatile | mTYimmutable;
627-
attribute = 0;
613+
uint attribute = 0;
628614
L1:
629-
dt = dttab4[tym];
615+
uint dt = dttab4[tym];
630616
switch (tym)
631617
{
632618
case TYllong:
@@ -700,7 +686,7 @@ L1:
700686
attribute |= 0x200;
701687
tycv = 0;
702688
d = debtyp_alloc(10);
703-
TOWORD(d.data.ptr,0x1002);
689+
TOWORD(d.data.ptr,LF_POINTER_V2);
704690
TOLONG(d.data.ptr + 2,next);
705691
// see https://github.com/Microsoft/microsoft-pdb/blob/master/include/cvinfo.h#L1514
706692
// add size and pointer type (PTR_64 or PTR_NEAR32)
@@ -754,7 +740,7 @@ L1:
754740
next = dttab4[TYuchar]; // use ubyte instead
755741

756742
d = debtyp_alloc(10 + u + 1);
757-
TOWORD(d.data.ptr,0x1503);
743+
TOWORD(d.data.ptr,LF_ARRAY_V3);
758744
TOLONG(d.data.ptr + 2,next);
759745
TOLONG(d.data.ptr + 6,idxtype);
760746
d.data.ptr[10 + u] = 0; // no name
@@ -776,12 +762,9 @@ L1:
776762
case TYjfunc:
777763
case TYifunc:
778764
{
779-
param_t* p;
780765
uint nparam;
781-
idx_t paramidx;
782-
783-
call = cv4_callconv(t);
784-
paramidx = cv4_arglist(t,&nparam);
766+
ubyte call = cv4_callconv(t);
767+
idx_t paramidx = cv4_arglist(t,&nparam);
785768

786769
// Construct an LF_PROCEDURE
787770
d = debtyp_alloc(2 + 4 + 1 + 1 + 2 + 4);
@@ -866,7 +849,7 @@ L1:
866849
modifier = (tycv & (mTYconst | mTYimmutable)) ? 1 : 0;
867850
modifier |= (tycv & mTYvolatile) ? 2 : 0;
868851
d = debtyp_alloc(8);
869-
TOWORD(d.data.ptr,0x1001);
852+
TOWORD(d.data.ptr,LF_MODIFIER_V2);
870853
TOLONG(d.data.ptr + 2,typidx);
871854
TOWORD(d.data.ptr + 6,modifier);
872855
typidx = cv_debtyp(d);

compiler/src/dmd/backend/cv4.d

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
/**
2-
* CodeView 4 symbolic debug info declarations
2+
* CodeView symbolic debug info declarations
33
*
44
* See "Microsoft Symbol and Type OMF" document
55
*
6+
* See https://github.com/microsoft/microsoft-pdb/tree/master/include
7+
* for a more complete set of publicly available definitions
8+
*
69
* Compiler implementation of the
710
* $(LINK2 https://www.dlang.org, D programming language).
811
*
@@ -15,8 +18,6 @@ module dmd.backend.cv4;
1518

1619
// Online documentation: https://dlang.org/phobos/dmd_backend_cv4.html
1720

18-
enum OEM = 0x42; // Digital Mars OEM number (picked at random)
19-
2021
// Symbol Indices
2122
enum
2223
{
@@ -82,7 +83,7 @@ enum
8283
S_FUNCINFO_V2 = 0x1012,
8384
S_COMPILAND_V2 = 0x1013,
8485

85-
S_COMPILAND_V3 = 0x1101,
86+
S_OBJNAME_V3 = 0x1101,
8687
S_THUNK_V3 = 0x1102,
8788
S_BLOCK_V3 = 0x1103,
8889
S_LABEL_V3 = 0x1105,
@@ -103,8 +104,16 @@ enum
103104
S_SUBSECTINFO_V3 = 0x1137,
104105
S_ENTRYPOINT_V3 = 0x1138,
105106
S_SECUCOOKIE_V3 = 0x113A,
106-
S_MSTOOLINFO_V3 = 0x113C,
107-
S_MSTOOLENV_V3 = 0x113D,
107+
108+
S_COMPILE3 = 0x113C, // compile flags, language and compiler version
109+
S_ENVBLOCK = 0x113D, // build environment block
110+
S_BUILDINFO = 0x114C, // reference to an LF_BUILDINFO record
111+
S_FRAMEPROC = 0x1012, // extra frame and procedure information
112+
S_REGREL32 = 0x1111, // register-relative address
113+
S_LTHREAD32 = 0x1112, // thread-local static data (local)
114+
S_GTHREAD32 = 0x1113, // thread-local static data (global)
115+
S_LPROC32_ID = 0x1146, // local procedure (type field is an LF_FUNC_ID)
116+
S_GPROC32_ID = 0x1147, // global procedure (type field is an LF_FUNC_ID)
108117
}
109118

110119
// Leaf Indices
@@ -242,4 +251,50 @@ enum
242251
LF_METHOD_V3 = 0x150F,
243252
LF_NESTTYPE_V3 = 0x1510,
244253
LF_ONEMETHOD_V3 = 0x1511,
254+
255+
// Type leaf records used by the ID stream
256+
LF_FUNC_ID = 0x1601, // function id: function type + name
257+
LF_STRING_ID = 0x1605, // interned string -> type index
258+
LF_BUILDINFO = 0x1603, // cwd, tool, source, pdb, args
259+
LF_UDT_SRC_LINE = 0x1606, // source file/line where a UDT is defined
260+
}
261+
262+
// .debug$S subsection kinds
263+
enum
264+
{
265+
DEBUG_S_SYMBOLS = 0xF1,
266+
DEBUG_S_LINES = 0xF2,
267+
DEBUG_S_STRINGTABLE = 0xF3,
268+
DEBUG_S_FILECHKSMS = 0xF4,
269+
}
270+
271+
// Source file checksum kinds
272+
enum
273+
{
274+
CHKSUM_NONE = 0,
275+
CHKSUM_MD5 = 1,
276+
CHKSUM_SHA1 = 2,
277+
CHKSUM_SHA256 = 3,
278+
}
279+
280+
// S_FRAMEPROC flags
281+
enum
282+
{
283+
CV_FRAME_HASALLOCA = 1 << 0, // function uses alloca()
284+
CV_FRAME_HASINLASM = 1 << 3, // function has inline asm
285+
CV_FRAME_HASEH = 1 << 4, // function has exception handling
286+
CV_FRAME_SECURITY = 1 << 8, // function has a stack security cookie
287+
CV_FRAME_OPTSPEED = 1 << 20, // function was optimized for speed
288+
CV_FRAME_LOCALBP_RBP = 2 << 14, // locals addressed relative to RBP/EBP
289+
CV_FRAME_PARAMBP_RBP = 2 << 16, // parameters addressed relative to RBP/EBP
290+
}
291+
292+
// Mark a line-number entry as a statement (not an expression)
293+
enum CV_LINE_STATEMENT = 0x80000000;
294+
295+
// CodeView register encodings for base-pointer-relative records
296+
enum
297+
{
298+
CV_REG_EBP = 22, // x86 EBP
299+
CV_AMD64_RBP = 334, // x64 RBP
245300
}

compiler/src/dmd/backend/cv8.d

Lines changed: 1 addition & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -64,70 +64,6 @@ private bool symbol_iscomdat4(Symbol* s)
6464
// 'fatal error LNK1318: Unexpected PDB error; RPC (23) '(0x000006BA)'
6565
enum CV8_MAX_SYMBOL_LENGTH = 0xffd8;
6666

67-
// Modern CodeView symbol records not declared in cv4.d
68-
enum
69-
{
70-
S_OBJNAME_V3 = 0x1101, // object file name (same value as S_COMPILAND_V3)
71-
S_COMPILE3 = 0x113C, // compile flags, language and compiler version
72-
S_ENVBLOCK = 0x113D, // build environment block
73-
S_BUILDINFO = 0x114C, // reference to an LF_BUILDINFO record
74-
S_FRAMEPROC = 0x1012, // extra frame and procedure information
75-
S_REGREL32 = 0x1111, // register-relative address
76-
S_LTHREAD32 = 0x1112, // thread-local static data (local)
77-
S_GTHREAD32 = 0x1113, // thread-local static data (global)
78-
S_LPROC32_ID = 0x1146, // local procedure (type field is an LF_FUNC_ID)
79-
S_GPROC32_ID = 0x1147, // global procedure (type field is an LF_FUNC_ID)
80-
}
81-
82-
// Type leaf records used by the ID stream
83-
enum
84-
{
85-
LF_FUNC_ID = 0x1601, // function id: function type + name
86-
LF_STRING_ID = 0x1605, // interned string -> type index
87-
LF_BUILDINFO = 0x1603, // cwd, tool, source, pdb, args
88-
LF_UDT_SRC_LINE = 0x1606, // source file/line where a UDT is defined
89-
}
90-
91-
// .debug$S subsection kinds
92-
enum
93-
{
94-
DEBUG_S_SYMBOLS = 0xF1,
95-
DEBUG_S_LINES = 0xF2,
96-
DEBUG_S_STRINGTABLE = 0xF3,
97-
DEBUG_S_FILECHKSMS = 0xF4,
98-
}
99-
100-
// Source file checksum kinds
101-
enum
102-
{
103-
CHKSUM_NONE = 0,
104-
CHKSUM_MD5 = 1,
105-
CHKSUM_SHA1 = 2,
106-
CHKSUM_SHA256 = 3,
107-
}
108-
109-
// S_FRAMEPROC flags
110-
enum
111-
{
112-
CV_FRAME_HASALLOCA = 1 << 0, // function uses alloca()
113-
CV_FRAME_HASINLASM = 1 << 3, // function has inline asm
114-
CV_FRAME_HASEH = 1 << 4, // function has exception handling
115-
CV_FRAME_SECURITY = 1 << 8, // function has a stack security cookie
116-
CV_FRAME_OPTSPEED = 1 << 20, // function was optimized for speed
117-
CV_FRAME_LOCALBP_RBP = 2 << 14, // locals addressed relative to RBP/EBP
118-
CV_FRAME_PARAMBP_RBP = 2 << 16, // parameters addressed relative to RBP/EBP
119-
}
120-
121-
// Mark a line-number entry as a statement (not an expression)
122-
enum CV_LINE_STATEMENT = 0x80000000;
123-
124-
// CodeView register encodings for base-pointer-relative records
125-
enum
126-
{
127-
CV_REG_EBP = 22, // x86 EBP
128-
CV_AMD64_RBP = 334, // x64 RBP
129-
}
130-
13167
// The "F1" section, which is the symbols
13268
private __gshared OutBuffer* F1_buf;
13369

@@ -1059,18 +995,6 @@ idx_t cv8_darray(type* t, idx_t etypidx)
1059995
* }
1060996
*/
1061997

1062-
static if (0)
1063-
{
1064-
d = debtyp_alloc(18);
1065-
TOWORD(d.data.ptr, 0x100F);
1066-
TOWORD(d.data.ptr + 2, OEM);
1067-
TOWORD(d.data.ptr + 4, 1); // 1 = dynamic array
1068-
TOLONG(d.data.ptr + 6, 2); // count of type indices to follow
1069-
TOLONG(d.data.ptr + 10, 0x23); // index type, T_UQUAD
1070-
TOLONG(d.data.ptr + 14, next); // element type
1071-
return cv_debtyp(d);
1072-
}
1073-
1074998
type* tp = type_pointer(t.Tnext);
1075999
idx_t ptridx = cv4_typidx(tp);
10761000
type_free(tp);
@@ -1169,18 +1093,6 @@ idx_t cv8_ddelegate(type* t, idx_t functypidx)
11691093
idx_t ptridx = cv4_typidx(tp);
11701094
type_free(tp);
11711095

1172-
static if (0)
1173-
{
1174-
debtyp_t* d = debtyp_alloc(18);
1175-
TOWORD(d.data.ptr, 0x100F);
1176-
TOWORD(d.data.ptr + 2, OEM);
1177-
TOWORD(d.data.ptr + 4, 3); // 3 = delegate
1178-
TOLONG(d.data.ptr + 6, 2); // count of type indices to follow
1179-
TOLONG(d.data.ptr + 10, key); // void* type
1180-
TOLONG(d.data.ptr + 14, functypidx); // function type
1181-
}
1182-
else
1183-
{
11841096
__gshared const ubyte[38] fl =
11851097
[
11861098
0x03, 0x12, // LF_FIELDLIST_V2
@@ -1220,7 +1132,7 @@ else
12201132
TOWORD(d.data.ptr + 18, 2 * _tysize[TYnptr]); // size
12211133
memcpy(d.data.ptr + 20, id, idlen);
12221134
d.data.ptr[20 + idlen] = 0;
1223-
}
1135+
12241136
return cv_debtyp(d);
12251137
}
12261138

@@ -1243,18 +1155,6 @@ idx_t cv8_daarray(type* t, idx_t keyidx, idx_t validx)
12431155
* }
12441156
*/
12451157

1246-
static if (0)
1247-
{
1248-
debtyp_t* d = debtyp_alloc(18);
1249-
TOWORD(d.data.ptr, 0x100F);
1250-
TOWORD(d.data.ptr + 2, OEM);
1251-
TOWORD(d.data.ptr + 4, 2); // 2 = associative array
1252-
TOLONG(d.data.ptr + 6, 2); // count of type indices to follow
1253-
TOLONG(d.data.ptr + 10, keyidx); // key type
1254-
TOLONG(d.data.ptr + 14, validx); // element type
1255-
}
1256-
else
1257-
{
12581158
type* tv = type_fake(TYnptr);
12591159
tv.Tcount++;
12601160
idx_t pvidx = cv4_typidx(tv);
@@ -1304,7 +1204,6 @@ else
13041204
memcpy(d.data.ptr + 20, id, idlen);
13051205
d.data.ptr[20 + idlen] = 0;
13061206

1307-
}
13081207
return cv_debtyp(d);
13091208
}
13101209

compiler/src/dmd/glue/tocvdebug.d

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ uint cv4_memfunctypidx(FuncDeclaration fd)
110110

111111
debtyp_t* d = debtyp_alloc(26);
112112
ubyte* p = &d.data[0];
113-
TOWORD(p,0x1009);
113+
TOWORD(p,LF_MFUNCTION_V2);
114114
TOLONG(p + 2,cv4_typidx(t.Tnext));
115115
TOLONG(p + 6,cv4_typidx(Type_toCtype(ad.type)));
116116
TOLONG(p + 10,thisidx);
@@ -302,11 +302,8 @@ struct CvFieldList
302302
const uint fieldLenMax;
303303
const uint fieldIndexLen;
304304

305-
const bool canSplitList;
306-
307305
this(uint fields, uint len) scope
308306
{
309-
canSplitList = true; // optlink bails out with LF_INDEX
310307
fieldIndexLen = 2 + 2 + 4;
311308
fieldLenMax = CV8_NAMELENMAX - fieldIndexLen;
312309

@@ -363,8 +360,7 @@ struct CvFieldList
363360
idx_t debtyp()
364361
{
365362
idx_t typidx;
366-
auto numCreate = canSplitList ? fieldLists.length : 1;
367-
for(auto i = numCreate; i > 0; --i)
363+
for(auto i = fieldLists.length; i > 0; --i)
368364
{
369365
auto fld = &fieldLists[i - 1];
370366
if (typidx)

0 commit comments

Comments
 (0)