diff options
author | Ivan Povazan <55002338+ivanpovazan@users.noreply.github.com> | 2020-12-20 05:49:04 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-20 05:49:04 +0300 |
commit | 0b58771eb88ebde13f5b9e4e86845d509207c05b (patch) | |
tree | 55345057a69072f49dc4ae946cd38f7df28650a8 /src/coreclr/ilasm | |
parent | d7e90d449496f48061d0a59918c42f43f9ec84b4 (diff) |
Fix for ilasm generation of malformed PDB files due to empty body methods (#46250)
* Fix malformed portable PDB generation for methods with empty body (#46124)
* Adding a test case for ilasm which verifies that the MethodDef and MethodDebugInformation tables have the same number of rows (#46124)
Diffstat (limited to 'src/coreclr/ilasm')
-rw-r--r-- | src/coreclr/ilasm/assem.cpp | 18 | ||||
-rw-r--r-- | src/coreclr/ilasm/portable_pdb.cpp | 6 |
2 files changed, 13 insertions, 11 deletions
diff --git a/src/coreclr/ilasm/assem.cpp b/src/coreclr/ilasm/assem.cpp index c8ef2691445..473ec42cda9 100644 --- a/src/coreclr/ilasm/assem.cpp +++ b/src/coreclr/ilasm/assem.cpp @@ -512,15 +512,6 @@ BOOL Assembler::EmitMethodBody(Method* pMethod, BinStr* pbsOut) pFH = (COR_ILMETHOD_FAT*)(pMethod->m_pbsBody->ptr()); pFH->SetLocalVarSigTok(pMethod->m_LocalsSig); } - //-------------------------------------------------------------------------------- - if(m_fGeneratePDB) - { - if (FAILED(m_pPortablePdbWriter->DefineSequencePoints(pMethod))) - return FALSE; - if (FAILED(m_pPortablePdbWriter->DefineLocalScope(pMethod))) - return FALSE; - } // end if(fIncludeDebugInfo) - //----------------------------------------------------- if(m_fFoldCode) { @@ -597,6 +588,15 @@ BOOL Assembler::EmitMethodBody(Method* pMethod, BinStr* pbsOut) } m_pEmitter->SetRVA(pMethod->m_Tok,pMethod->m_headerOffset); } + + if (m_fGeneratePDB) + { + if (FAILED(m_pPortablePdbWriter->DefineSequencePoints(pMethod))) + return FALSE; + if (FAILED(m_pPortablePdbWriter->DefineLocalScope(pMethod))) + return FALSE; + } + return TRUE; } else return FALSE; diff --git a/src/coreclr/ilasm/portable_pdb.cpp b/src/coreclr/ilasm/portable_pdb.cpp index c7077d21c42..47a6111078e 100644 --- a/src/coreclr/ilasm/portable_pdb.cpp +++ b/src/coreclr/ilasm/portable_pdb.cpp @@ -223,6 +223,7 @@ HRESULT PortablePdbWriter::DefineSequencePoints(Method* method) LinePC* prevNonHiddenSeqPoint = NULL; LinePC* nextSeqPoint = NULL; BOOL isValid = TRUE; + BOOL hasEmptyMethodBody = method->m_LinePCList.COUNT() == 0; for (UINT32 i = 0; i < method->m_LinePCList.COUNT(); i++) { @@ -304,9 +305,10 @@ HRESULT PortablePdbWriter::DefineSequencePoints(Method* method) } // finally define sequence points for the method - if (isValid && currSeqPoint != NULL) + if ((isValid && currSeqPoint != NULL) || hasEmptyMethodBody) { - ULONG documentRid = RidFromToken(currSeqPoint->pOwnerDocument->GetToken()); + mdDocument document = hasEmptyMethodBody ? m_currentDocument->GetToken() : currSeqPoint->pOwnerDocument->GetToken(); + ULONG documentRid = RidFromToken(document); hr = m_pdbEmitter->DefineSequencePoints(documentRid, blob->ptr(), blob->length()); } |