Skip to content

Commit

Permalink
fix Issue 4372, 982 - CodeView: type of enumerator values reduced to …
Browse files Browse the repository at this point in the history
…base type in debug info

write a forward reference to the enum definition, it is emitted elsewhere
  • Loading branch information
rainers committed Aug 22, 2019
1 parent 0f6c2e2 commit f4e4b7e
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 3 deletions.
45 changes: 44 additions & 1 deletion src/dmd/backend/dcgcv.d
Expand Up @@ -1736,7 +1736,50 @@ static if (SYMDEB_TDB)
}

}
else
{
private uint cv4_fwdenum(type* t)
{
Symbol* s = t.Ttag;

if (s.Stypidx) // if reference already generated
return s.Stypidx; // use already existing reference

// write a forward reference enum record that is enough for the linker to
// fold with original definition from EnumDeclaration
uint bty = dttab4[tybasic(t.Tnext.Tty)];
const id = prettyident(s);
uint len = config.fulltypes == CV8 ? 14 : 10;
debtyp_t* d = debtyp_alloc(len + cv_stringbytes(id));
switch (config.fulltypes)
{
case CV8:
TOWORD(d.data.ptr, LF_ENUM_V3);
TOLONG(d.data.ptr + 2, 0); // count
TOWORD(d.data.ptr + 4, 0x80); // property : forward reference
TOLONG(d.data.ptr + 6, bty); // memtype
TOLONG(d.data.ptr + 10, 0); // fieldlist
break;

case CV4:
TOWORD(d.data.ptr,LF_ENUM);
TOWORD(d.data.ptr + 2, 0); // count
TOWORD(d.data.ptr + 4, bty); // memtype
TOLONG(d.data.ptr + 6, 0); // fieldlist
TOWORD(d.data.ptr + 8, 0x80); // property : forward reference
break;

default:
assert(0);
}
len += cv_namestring(d.data.ptr + len, id);
d.length = 0; // so cv_debtyp() will allocate new
s.Stypidx = cv_debtyp(d);
d.length = cast(ushort)len; // restore length
return s.Stypidx;
}

}
/************************************************
* Return 'calling convention' type of function.
*/
Expand Down Expand Up @@ -2261,7 +2304,7 @@ version (SCPP)
}
}
else
typidx = dttab4[tybasic(t.Tnext.Tty)];
typidx = cv4_fwdenum(t);
break;

version (SCPP)
Expand Down
32 changes: 30 additions & 2 deletions test/runnable/testpdb.d
Expand Up @@ -44,9 +44,11 @@ void main(string[] args)
S18984 s = test18984(session, globals);

test19307(session, globals);

test19318(session, globals);

testE982(session, globals);

source.Release();
session.Release();
globals.Release();
Expand Down Expand Up @@ -222,7 +224,7 @@ int foo19307()
return nested()();
}

string toUTF8(wstring ws)
string toUTF8(const(wchar)[] ws)
{
string s;
foreach(dchar c; ws)
Expand Down Expand Up @@ -333,6 +335,32 @@ void test19318(IDiaSession session, IDiaSymbol globals)
assert(off == C19318_px - C19318_capture);
}

///////////////////////////////////////////////
enum E982
{
E1, E2, E3
}

void testE982(IDiaSession session, IDiaSymbol globals)
{
E982 ee = E982.E1;

IDiaSymbol funcSym = searchSymbol(globals, "testpdb.testE982");
funcSym || assert(false, "testpdb.testE982 not found");

string varName = "testpdb.testE982.ee";
IDiaSymbol varSym = searchSymbol(funcSym, "ee");
varSym || assert(false, varName ~ " not found");

IDiaSymbol varType;
varSym.get_type(&varType) == S_OK || assert(false, varName ~ ": no type");
BSTR typename;
varType.get_name(&typename) == S_OK || assert(false, varName ~ ": no type name");
scope(exit) SysFreeString(typename);
wchar[] wtypename = typename[0..wcslen(typename)];
wcscmp(typename, "testpdb.E982") == 0 || assert(false, varName ~ ": unexpected type name " ~ toUTF8(wtypename));
}

///////////////////////////////////////////////
import core.stdc.stdio;
import core.stdc.wchar_;
Expand Down

0 comments on commit f4e4b7e

Please sign in to comment.