microsoft / clrmd

Microsoft.Diagnostics.Runtime is a set of APIs for introspecting processes and dumps.
MIT License
1.05k stars 254 forks source link

DacNameParser.Parse(name) throws System.IndexOutOfRangeException #897

Closed catstrike closed 3 years ago

catstrike commented 3 years ago

I'm enumerating all the types in a dump with ClrMD 2.0 For one of the types, DAC returns the following name: StructureMap.Pipeline.ExpressedInstance`3[[StructureMap.Pipeline.LambdaInstance`2, EnforceHttpsModule],T,TPluginType]

DacNameParser can't parse it and throws System.IndexOutOfRangeException.

Unhandled Exception: System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at System.String.get_Chars(Int32 index)
   at Microsoft.Diagnostics.Runtime.Builders.DACNameParser.DetermineNextStateAndPos(String name, Int32 curPos)in C:\Developer\projects\clrmd2\src\Microsoft.Diagnostics.Runtime\src\Common\DACNameParser.cs:line 630
   at Microsoft.Diagnostics.Runtime.Builders.DACNameParser.Parse(String name) in C:\Developer\projects\clrmd2\src\Microsoft.Diagnostics.Runtime\src\Common\DACNameParser.cs:line 165
   at Microsoft.Diagnostics.Runtime.Builders.RuntimeBuilder.Microsoft.Diagnostics.Runtime.Implementation.ITypeHelpers.GetTypeName(UInt64 mt, String& name) in C:\Developer\projects\clrmd2\src\Microsoft.Diagnostics.Runtime\src\Builders\RuntimeBuilder.cs:line 1465
   at Microsoft.Diagnostics.Runtime.Implementation.ClrmdType.get_Name() in C:\Developer\projects\clrmd2\src\Microsoft.Diagnostics.Runtime\src\Implementation\ClrmdType.cs:line 61
   at Microsoft.Diagnostics.Runtime.Implementation.ClrmdType.DebugOnlyLoadLazyValues() in C:\Developer\projects\clrmd2\src\Microsoft.Diagnostics.Runtime\src\Implementation\ClrmdType.cs:line 120
   at Microsoft.Diagnostics.Runtime.Implementation.ClrmdType..ctor(ClrHeap heap, ClrType baseType, ClrModule module, ITypeData data, String name) in C:\Developer\projects\clrmd2\src\Microsoft.Diagnostics.Runtime\src\Implementation\ClrmdType.cs:line 114
   at Microsoft.Diagnostics.Runtime.Builders.RuntimeBuilder.GetOrCreateType(ClrHeap heap, UInt64 mt, UInt64 obj) in C:\Developer\projects\clrmd2\src\Microsoft.Diagnostics.Runtime\src\Builders\RuntimeBuilder.cs:line 1053
   at Microsoft.Diagnostics.Runtime.Builders.RuntimeBuilder.GetOrCreateType(ClrHeap heap, UInt64 mt, UInt64 obj) in C:\Developer\projects\clrmd2\src\Microsoft.Diagnostics.Runtime\src\Builders\RuntimeBuilder.cs:line 1048
   at Microsoft.Diagnostics.Runtime.Builders.RuntimeBuilder.GetOrCreateType(UInt64 mt, UInt64 obj) in C:\Developer\projects\clrmd2\src\Microsoft.Diagnostics.Runtime\src\Builders\RuntimeBuilder.cs:line 995
   at Microsoft.Diagnostics.Runtime.Implementation.ClrmdRuntime.GetTypeByMethodTable(UInt64 methodTable) in C:\Developer\projects\clrmd2\src\Microsoft.Diagnostics.Runtime\src\Implementation\ClrmdRuntime.cs:line 100
   at ClrMD.Playground.Program.<EnumerateTypes>d__11.MoveNext() in C:\Developer\projects\clrmd2\src\ClrMD.Playground\Program.cs:line 297

CLR version: 4.7.2650.0 Architecture: Amd64

leculver commented 3 years ago

@ryanmolden Do you have some time to take a look? I'll likely put a try catch at the bottom of Parse in the next release either way.

ryanmolden commented 1 year ago

@leculver wow, I never use GitHub (sorry), so I never saw this tag. Anyhow, ironically I am running into the same issue here, the problem is the non-assembly qualified names (T and TPluginType). The parser assumes all generic args will be assembly qualified (i.e. [Foo, Bar]), which clearly is not true. I am working on a fix but as you stated in the fix to add the catch...this area is a massive pain due to the complexity of the DAC name stuff.