runtime: Exception.ToString() throws an exception when it encounters a frame that requires opening a regular PDB
I seem to recall this (or something close to this) was reported for .NET 2.0. I did a quick search on the repo, but didn’t find a duplicate.
The callstack below is for code that called ToString()
on an Exception. It fails on a frame where the method debug information is in a regular PDB.
I’m also interested in just fixing the whole conundrum of not being able to open a regular PDB on CoreCLR (any platform) to give line number information.
coreclr!WinMDInternalImportRO::Release
coreclr!ExceptionTracker::ProcessManagedCallFrame
coreclr!ExceptionTracker::ProcessOSExceptionNotification
coreclr!ProcessCLRException
ntdll!RtlpExecuteHandlerForException
ntdll!RtlDispatchException
ntdll!RtlRaiseException
KERNELBASE!RaiseException
coreclr!RaiseTheExceptionInternalOnly
coreclr!IL_Throw
System.Reflection.Metadata!System.Reflection.Throw.OutOfBounds()$##60000A8
System.Reflection.Metadata!System.Reflection.Metadata.Ecma335.MethodDebugInformationTableReader.GetSequencePoints(System.Reflection.Metadata.MethodDebugInformationHandle)$##6000C23
System.Reflection.Metadata!System.Reflection.Metadata.MethodDebugInformation.get_SequencePointsBlob()$##600083E
System.Diagnostics.StackTrace!System.Diagnostics.StackTraceSymbols.GetSourceLineInfo(System.String, IntPtr, Int32, IntPtr, Int32, Int32, Int32, System.String ByRef, Int32 ByRef, Int32 ByRef)$##6000003
System.Private.CoreLib!System.Diagnostics.StackFrameHelper.InitializeSourceInfo(Int32, Boolean, System.Exception)$##60018CA
System.Private.CoreLib!System.Diagnostics.StackTrace.CaptureStackTrace(Int32, Boolean, System.Threading.Thread, System.Exception)$##60018E3
System.Private.CoreLib!System.Diagnostics.StackTrace..ctor(System.Exception, Boolean)$##60018DD
System.Private.CoreLib!System.Environment.GetStackTrace(System.Exception, Boolean)$##6000711
System.Private.CoreLib!System.Exception.GetStackTrace(Boolean)$##6000399
System.Private.CoreLib!System.Exception.ToString(Boolean, Boolean)$##60003A0
System.Private.CoreLib!System.Text.StringBuilder.AppendFormatHelper(System.IFormatProvider, System.String, System.ParamsArray)$##60034BA
System.Private.CoreLib!System.String.FormatHelper(System.IFormatProvider, System.String, System.ParamsArray)$##600032D```
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 21 (20 by maintainers)
Commits related to this issue
- Managed Windows PDB Reader WIP for https://github.com/dotnet/corefx/issues/29375 — committed to mjsabby/WindowsPdbReader by mjsabby 6 years ago
The original complaint was avoiding an error (exception) when doing ToString() on an exception (which walks its stack. I am assuming there is no pushback on at least no failing. There is an interesting question on exactly what it does do to give the user a hint that their PDB is ‘wrong’. Just giving up on line numbers is not as good as giving a parenthetical diagnostic that the PDB is not a portable PDB).
Of course @mjsabby wants it to ‘just work’. I think we should at least understand the cost-benefit of that. Presumably the idea would be to make it work on Windows only. Note that this is what we do with perfCounters and I am sure other things that are hard to port to Linux. I think the ability to ‘just work’ on windows with Microsoft PDBs is useful (I think @danmosemsft scenario of using windows libraries without recompiling seems interesting, and we should understand how common it is likely to be).
My main concern is that line numbers in the exception trace really does ‘drag’ in a bunch of PDB reading stuff that otherwise the runtime is agnostic to. Ideally the runtime only has the hook, and it is up to other things (like an SDK installer), to wire into the hook (that is install the necessary DLLs).
So, I think it is reasonably to fix the error, and we should gather some data on who is likely to benefit from this (can we describe the scenario where people naturally generated Windows PDBs but want to run on .NET Core?). It seems like our desire to ‘converge’ .NET Core and desktop scenarios suggests that this will be important, but I don’t really have a feel for what we are expecting people to do at build time (if we force them to use new tools (which is sad), then I suppose forcing them to use portable PDBs it not much worse.
But my main suggestion is to fix the uncontroversial part first.
I am confused by this issue. Do I understand it correctly that:
Exception.ToString()
internally throws an exception, which is then caught here. As a consequence, the result ofException.ToString()
doesn’t have line numbers.Exception.ToString()
.To me, this sounds like a reasonable state to be in, especially if adding support for reading non-portable PDBs on Unix would take a lot of effort.
Adding some indication to the output that an exception was thrown seems reasonable to me, assuming it wouldn’t be too noisy.
What I did to see that my understanding is right:
Start on Windows.
dotnet new console
Specify
<DebugType>Full</DebugType>
in csproj to force non-portable PDB and add the following code to Program.cs:dotnet publish
Verify that the PDB does not start with
BSJB
(it starts withMicrosoft C/C++ MSF 7.00
).dotnet .\bin\Debug\netcoreapp2.0\publish\hwapp.dll
prints the line number:Switch to Linux (in my case, WSL Ubuntu), copy the
publish
directory over or use some shared file system.dotnet bin/Debug/netcoreapp2.0/publish/hwapp.dll
doesn’t print the line number: