Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ protected override IList<CodeViewTypeRecord> GetArgumentTypes()
for (int i = 0; i < count; i++)
{
uint typeIndex = reader.ReadUInt32();
if (!_context.ParentImage.TryGetLeafRecord(typeIndex, out CodeViewTypeRecord? t))
var t = _context.ParentImage.GetLeafRecord<CodeViewTypeRecord>(typeIndex);
if (t is null)
{
_context.Parameters.ErrorListener.BadImage(
$"Argument list {TypeIndex:X8} contains an invalid argument type index {typeIndex:X8}.");
// The type index could not be resolved.
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,12 @@ public SerializedArrayTypeRecord(PdbReaderContext context, uint typeIndex, Binar
/// <inheritdoc />
protected override CodeViewTypeRecord? GetElementType()
{
return _context.ParentImage.TryGetLeafRecord(_elementTypeIndex, out CodeViewTypeRecord? type)
? type
: _context.Parameters.ErrorListener.BadImageAndReturn<CodeViewTypeRecord>(
$"Array type {TypeIndex:X8} contains an invalid element type index {_elementTypeIndex:X8}.");
return _context.ParentImage.GetLeafRecord<CodeViewTypeRecord>(_elementTypeIndex);
}

/// <inheritdoc />
protected override CodeViewTypeRecord? GetIndexType()
{
return _context.ParentImage.TryGetLeafRecord(_indexTypeIndex, out CodeViewTypeRecord? type)
? type
: _context.Parameters.ErrorListener.BadImageAndReturn<CodeViewTypeRecord>(
$"Array type {TypeIndex:X8} contains an invalid index type index {_indexTypeIndex:X8}.");
return _context.ParentImage.GetLeafRecord<CodeViewTypeRecord>(_indexTypeIndex);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ public SerializedBaseClassField(PdbReaderContext context, uint typeIndex, ref Bi
/// <inheritdoc />
protected override CodeViewTypeRecord? GetBaseType()
{
return _context.ParentImage.TryGetLeafRecord(_baseTypeIndex, out CodeViewTypeRecord? type)
? type
: _context.Parameters.ErrorListener.BadImageAndReturn<CodeViewTypeRecord>(
$"Base class {TypeIndex:X8} contains an invalid underlying base type index {_baseTypeIndex:X8}.");
return _context.ParentImage.GetLeafRecord<CodeViewTypeRecord>(_baseTypeIndex);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ public SerializedBitFieldTypeRecord(PdbReaderContext context, uint typeIndex, Bi
/// <inheritdoc />
protected override CodeViewTypeRecord? GetBaseType()
{
return _context.ParentImage.TryGetLeafRecord(_baseTypeIndex, out CodeViewTypeRecord? type)
? type
: _context.Parameters.ErrorListener.BadImageAndReturn<CodeViewTypeRecord>(
$"Bit field type {TypeIndex:X8} contains an invalid underlying base type index {_baseTypeIndex:X8}.");
return _context.ParentImage.GetLeafRecord<CodeViewTypeRecord>(_baseTypeIndex);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ public SerializedClassTypeRecord(CodeViewLeafKind kind, PdbReaderContext context
if (_baseTypeIndex == 0)
return null;

return _context.ParentImage.TryGetLeafRecord(_baseTypeIndex, out CodeViewTypeRecord? type)
? type
: _context.Parameters.ErrorListener.BadImageAndReturn<CodeViewTypeRecord>(
$"Class type {TypeIndex:X8} contains an invalid underlying enum type index {_baseTypeIndex:X8}.");
return _context.ParentImage.GetLeafRecord<CodeViewTypeRecord>(_baseTypeIndex);
}

/// <inheritdoc />
Expand All @@ -64,10 +61,7 @@ public SerializedClassTypeRecord(CodeViewLeafKind kind, PdbReaderContext context
if (_fieldIndex == 0)
return null;

return _context.ParentImage.TryGetLeafRecord(_fieldIndex, out SerializedFieldListLeaf? list)
? list
: _context.Parameters.ErrorListener.BadImageAndReturn<FieldListLeaf>(
$"Class type {TypeIndex:X8} contains an invalid field list index {_fieldIndex:X8}.");
return _context.ParentImage.GetLeafRecord<FieldListLeaf>(_fieldIndex);
}

/// <inheritdoc />
Expand All @@ -76,9 +70,6 @@ public SerializedClassTypeRecord(CodeViewLeafKind kind, PdbReaderContext context
if (_vTableShapeIndex == 0)
return null;

return _context.ParentImage.TryGetLeafRecord(_vTableShapeIndex, out VTableShapeLeaf? shape)
? shape
: _context.Parameters.ErrorListener.BadImageAndReturn<VTableShapeLeaf>(
$"Class type {TypeIndex:X8} contains an invalid VTable shape index {_fieldIndex:X8}.");
return _context.ParentImage.GetLeafRecord<VTableShapeLeaf>(_vTableShapeIndex);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ public SerializedEnumTypeRecord(PdbReaderContext context, uint typeIndex, Binary
/// <inheritdoc />
protected override CodeViewTypeRecord? GetBaseType()
{
return _context.ParentImage.TryGetLeafRecord(_underlyingType, out CodeViewTypeRecord? type)
? type
: _context.Parameters.ErrorListener.BadImageAndReturn<CodeViewTypeRecord>(
$"Enum type {TypeIndex:X8} contains an invalid underlying enum type index {_underlyingType:X8}.");
return _context.ParentImage.GetLeafRecord<CodeViewTypeRecord>(_underlyingType);
}

/// <inheritdoc />
Expand All @@ -48,9 +45,6 @@ public SerializedEnumTypeRecord(PdbReaderContext context, uint typeIndex, Binary
if (_fieldIndex == 0)
return null;

return _context.ParentImage.TryGetLeafRecord(_fieldIndex, out FieldListLeaf? list)
? list
: _context.Parameters.ErrorListener.BadImageAndReturn<FieldListLeaf>(
$"Enum type {TypeIndex:X8} contains an invalid field list index {_fieldIndex:X8}.");
return _context.ParentImage.GetLeafRecord<FieldListLeaf>(_fieldIndex);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ public SerializedFunctionIdentifier(PdbReaderContext context, uint typeIndex, Bi
/// <inheritdoc />
protected override CodeViewTypeRecord? GetFunctionType()
{
return _context.ParentImage.TryGetLeafRecord(_typeIndex, out CodeViewTypeRecord? type)
? type
: _context.Parameters.ErrorListener.BadImageAndReturn<CodeViewTypeRecord>(
$"Array type {TypeIndex:X8} contains an invalid element type index {_typeIndex:X8}.");
return _context.ParentImage.GetLeafRecord<CodeViewTypeRecord>(_typeIndex);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ public SerializedInstanceDataField(PdbReaderContext context, uint typeIndex, ref
if (_dataTypeIndex == 0)
return null;

return _context.ParentImage.TryGetLeafRecord(_dataTypeIndex, out CodeViewTypeRecord? type)
? type
: _context.Parameters.ErrorListener.BadImageAndReturn<CodeViewTypeRecord>(
$"Instance data member {TypeIndex:X8} contains an invalid data type index {_dataTypeIndex:X8}.");
return _context.ParentImage.GetLeafRecord<CodeViewTypeRecord>(_dataTypeIndex);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,19 @@ public SerializedMemberFunctionLeaf(PdbReaderContext context, uint typeIndex, Bi
/// <inheritdoc />
protected override CodeViewTypeRecord? GetReturnType()
{
return _context.ParentImage.TryGetLeafRecord(_returnTypeIndex, out CodeViewTypeRecord? type)
? type
: _context.Parameters.ErrorListener.BadImageAndReturn<CodeViewTypeRecord>(
$"Member function {TypeIndex:X8} contains an invalid return type index {_returnTypeIndex:X8}.");
return _context.ParentImage.GetLeafRecord<CodeViewTypeRecord>(_returnTypeIndex);
}

/// <inheritdoc />
protected override CodeViewTypeRecord? GetDeclaringType()
{
return _context.ParentImage.TryGetLeafRecord(_declaringTypeIndex, out CodeViewTypeRecord? type)
? type
: _context.Parameters.ErrorListener.BadImageAndReturn<CodeViewTypeRecord>(
$"Member function {TypeIndex:X8} contains an invalid declaring type index {_declaringTypeIndex:X8}.");
return _context.ParentImage.GetLeafRecord<CodeViewTypeRecord>(_declaringTypeIndex);
}

/// <inheritdoc />
protected override CodeViewTypeRecord? GetThisType()
{
return _context.ParentImage.TryGetLeafRecord(_thisTypeIndex, out CodeViewTypeRecord? type)
? type
: _context.Parameters.ErrorListener.BadImageAndReturn<CodeViewTypeRecord>(
$"Member function {TypeIndex:X8} contains an invalid this-type index {_thisTypeIndex:X8}.");
return _context.ParentImage.GetLeafRecord<CodeViewTypeRecord>(_thisTypeIndex);
}

/// <inheritdoc />
Expand All @@ -67,9 +58,6 @@ public SerializedMemberFunctionLeaf(PdbReaderContext context, uint typeIndex, Bi
if (_argumentListIndex == 0)
return null;

return _context.ParentImage.TryGetLeafRecord(_argumentListIndex, out ArgumentListLeaf? list)
? list
: _context.Parameters.ErrorListener.BadImageAndReturn<ArgumentListLeaf>(
$"Member function {TypeIndex:X8} contains an invalid argument list index {_argumentListIndex:X8}.");
return _context.ParentImage.GetLeafRecord<ArgumentListLeaf>(_argumentListIndex);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ public SerializedMethodListEntry(PdbReaderContext context, ref BinaryStreamReade
/// <inheritdoc />
protected override MemberFunctionLeaf? GetFunction()
{
return _context.ParentImage.TryGetLeafRecord(_functionIndex, out MemberFunctionLeaf? function)
? function
: _context.Parameters.ErrorListener.BadImageAndReturn<MemberFunctionLeaf>(
$"Method list entry contains an invalid function type index {_functionIndex:X8}.");
return _context.ParentImage.GetLeafRecord<MemberFunctionLeaf>(_functionIndex);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ public SerializedModifierTypeRecord(PdbReaderContext context, uint typeIndex, Bi
/// <inheritdoc />
protected override CodeViewTypeRecord? GetBaseType()
{
return _context.ParentImage.TryGetLeafRecord(_baseTypeIndex, out CodeViewTypeRecord? type)
? type
: _context.Parameters.ErrorListener.BadImageAndReturn<CodeViewTypeRecord>(
$"Modifier type {TypeIndex:X8} contains an invalid underlying base type index {_baseTypeIndex:X8}.");
return _context.ParentImage.GetLeafRecord<CodeViewTypeRecord>(_baseTypeIndex);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ public SerializedNestedTypeField(PdbReaderContext context, uint typeIndex, ref B
/// <inheritdoc />
protected override CodeViewTypeRecord? GetNestedType()
{
return _context.ParentImage.TryGetLeafRecord(_typeIndex, out CodeViewTypeRecord? type)
? type
: _context.Parameters.ErrorListener.BadImageAndReturn<CodeViewTypeRecord>(
$"Nested type {TypeIndex:X8} contains an invalid type index {_typeIndex:X8}.");
return _context.ParentImage.GetLeafRecord<CodeViewTypeRecord>(_typeIndex);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ public SerializedNonOverloadedMethod(PdbReaderContext context, uint typeIndex, r
/// <inheritdoc />
protected override MemberFunctionLeaf? GetFunction()
{
return _context.ParentImage.TryGetLeafRecord(_functionIndex, out MemberFunctionLeaf? function)
? function
: _context.Parameters.ErrorListener.BadImageAndReturn<MemberFunctionLeaf>(
$"Method {TypeIndex:X8} contains an invalid function type index {_functionIndex:X8}.");
return _context.ParentImage.GetLeafRecord<MemberFunctionLeaf>(_functionIndex);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ public SerializedOverloadedMethod(PdbReaderContext context, uint typeIndex, ref
if (_methodListIndex == 0)
return null;

return _context.ParentImage.TryGetLeafRecord(_methodListIndex, out MethodListLeaf? list)
? list
: _context.Parameters.ErrorListener.BadImageAndReturn<MethodListLeaf>(
$"Overloaded method {TypeIndex:X8} contains an invalid field list index {_methodListIndex:X8}.");
return _context.ParentImage.GetLeafRecord<MethodListLeaf>(_methodListIndex);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ public SerializedPointerTypeRecord(PdbReaderContext context, uint typeIndex, Bin
/// <inheritdoc />
protected override CodeViewTypeRecord? GetBaseType()
{
return _context.ParentImage.TryGetLeafRecord(_baseTypeIndex, out CodeViewTypeRecord? type)
? type
: _context.Parameters.ErrorListener.BadImageAndReturn<CodeViewTypeRecord>(
$"Pointer {TypeIndex:X8} contains an invalid underlying base type index {_baseTypeIndex:X8}.");

return _context.ParentImage.GetLeafRecord<CodeViewTypeRecord>(_baseTypeIndex);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ public SerializedProcedureTypeRecord(PdbReaderContext context, uint typeIndex, B
/// <inheritdoc />
protected override CodeViewTypeRecord? GetReturnType()
{
return _context.ParentImage.TryGetLeafRecord(_returnTypeIndex, out CodeViewTypeRecord? type)
? type
: _context.Parameters.ErrorListener.BadImageAndReturn<CodeViewTypeRecord>(
$"Procedure type {TypeIndex:X8} contains an invalid return type index {_returnTypeIndex:X8}.");
return _context.ParentImage.GetLeafRecord<CodeViewTypeRecord>(_returnTypeIndex);
}

/// <inheritdoc />
Expand All @@ -44,9 +41,6 @@ public SerializedProcedureTypeRecord(PdbReaderContext context, uint typeIndex, B
if (_argumentListIndex == 0)
return null;

return _context.ParentImage.TryGetLeafRecord(_argumentListIndex, out ArgumentListLeaf? list)
? list
: _context.Parameters.ErrorListener.BadImageAndReturn<ArgumentListLeaf>(
$"Procedure type {TypeIndex:X8} contains an invalid argument list index {_argumentListIndex:X8}.");
return _context.ParentImage.GetLeafRecord<ArgumentListLeaf>(_argumentListIndex);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ public SerializedStaticDataField(PdbReaderContext context, uint typeIndex, ref B
if (_dataTypeIndex == 0)
return null;

return _context.ParentImage.TryGetLeafRecord(_dataTypeIndex, out CodeViewTypeRecord? type)
? type
: _context.Parameters.ErrorListener.BadImageAndReturn<CodeViewTypeRecord>(
$"Static data member {TypeIndex:X8} contains an invalid data type index {_dataTypeIndex:X8}.");
return _context.ParentImage.GetLeafRecord<CodeViewTypeRecord>(_dataTypeIndex);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ public SerializedStringIdentifier(PdbReaderContext context, uint typeIndex, Bina
if (_subStringsIndex == 0)
return null;

return _context.ParentImage.TryGetIdLeafRecord(_subStringsIndex, out SubStringListLeaf? list)
? list
: _context.Parameters.ErrorListener.BadImageAndReturn<SubStringListLeaf>(
$"String ID {TypeIndex:X8} contains an invalid substrings type index {_subStringsIndex:X8}.");
return _context.ParentImage.GetIdLeafRecord<SubStringListLeaf>(_subStringsIndex);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ internal static IList<StringIdentifier> ReadEntries(
for (int i = 0; i < count; i++)
{
uint index = reader.ReadUInt32();
if (!context.ParentImage.TryGetIdLeafRecord(index, out StringIdentifier? entry))
var entry = context.ParentImage.GetIdLeafRecord<StringIdentifier>(index);
if (entry is null)
{
context.Parameters.ErrorListener.BadImage(
$"String List {originIndex:X8} contains an invalid string index {index:X8}.");
// The index could not be resolved.
return result;
}
result.Add(entry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ public SerializedUnionTypeRecord(PdbReaderContext context, uint typeIndex, Binar
if (_fieldIndex == 0)
return null;

return _context.ParentImage.TryGetLeafRecord(_fieldIndex, out SerializedFieldListLeaf? list)
? list
: _context.Parameters.ErrorListener.BadImageAndReturn<FieldListLeaf>(
$"Union type {TypeIndex:X8} contains an invalid field list index {_fieldIndex:X8}.");
return _context.ParentImage.GetLeafRecord<FieldListLeaf>(_fieldIndex);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,12 @@ public SerializedVBaseClassField(
/// <inheritdoc />
protected override CodeViewTypeRecord? GetBaseType()
{
return _context.ParentImage.TryGetLeafRecord(_baseTypeIndex, out CodeViewTypeRecord? type)
? type
: _context.Parameters.ErrorListener.BadImageAndReturn<CodeViewTypeRecord>(
$"Virtual base class {TypeIndex:X8} contains an invalid base type index {_baseTypeIndex:X8}.");
return _context.ParentImage.GetLeafRecord<CodeViewTypeRecord>(_baseTypeIndex);
}

/// <inheritdoc />
protected override CodeViewTypeRecord? GetBasePointerType()
{
return _context.ParentImage.TryGetLeafRecord(_basePointerIndex, out CodeViewTypeRecord? type)
? type
: _context.Parameters.ErrorListener.BadImageAndReturn<CodeViewTypeRecord>(
$"Virtual base class {TypeIndex:X8} contains an invalid base pointer type index {_basePointerIndex:X8}.");
return _context.ParentImage.GetLeafRecord<CodeViewTypeRecord>(_basePointerIndex);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ public SerializedVTableField(PdbReaderContext context, uint typeIndex, ref Binar
/// <inheritdoc />
protected override CodeViewTypeRecord? GetPointerType()
{
return _context.ParentImage.TryGetLeafRecord(_pointerTypeIndex, out CodeViewTypeRecord? type)
? type
: _context.Parameters.ErrorListener.BadImageAndReturn<CodeViewTypeRecord>(
$"Virtual function table type {TypeIndex:X8} contains an invalid pointer type index {_pointerTypeIndex:X8}.");
return _context.ParentImage.GetLeafRecord<CodeViewTypeRecord>(_pointerTypeIndex);
}
}
Loading
Loading