Biohazrd
Biohazrd copied to clipboard
Fix debug dumping support
At some point Clang cursor detail dumping broke, probably when we upgraded from Clang 10. Attempting to use ClangSharpInfoDumper
or enabling dumping in the C# output via CSharpGenerationOptions.DumpClangInfo
will result in an access violation:
Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Repeat 2 times:
--------------------------------
at ClangSharp.Interop.clangsharp.Cursor_getDeclKind(ClangSharp.Interop.CXCursor)
--------------------------------
at ClangSharp.Decl.Create(ClangSharp.Interop.CXCursor)
at ClangSharp.Cursor.Create(ClangSharp.Interop.CXCursor)
at ClangSharp.TranslationUnit.GetOrCreate[[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](ClangSharp.Interop.CXCursor)
at ClangSharp.Decl.<.ctor>b__13_0()
at System.Lazy`1[[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].ViaFactory(System.Threading.LazyThreadSafetyMode)
at System.Lazy`1[[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].ExecutionAndPublication(System.LazyHelper, Boolean)
at System.Lazy`1[[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].CreateValue()
at ClangSharp.Decl.get_AsFunction()
at System.RuntimeMethodHandle.InvokeMethod(System.Object, System.Span`1<System.Object> ByRef, System.Signature, Boolean, Boolean)
at System.Reflection.RuntimeMethodInfo.Invoke(System.Object, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo)
at System.Reflection.RuntimePropertyInfo.GetValue(System.Object, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo)
at System.Reflection.RuntimePropertyInfo.GetValue(System.Object, System.Object[])
at ClangSharp.Pathogen.InfoDumperSupport.ReflectionDumper+<Dump>d__4.MoveNext()
at System.Collections.Generic.List`1[[ClangSharp.Pathogen.InfoDumperSupport.InfoRow, ClangSharp.Pathogen, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]].InsertRange(Int32, System.Collections.Generic.IEnumerable`1<ClangSharp.Pathogen.InfoDumperSupport.InfoRow>)
at System.Collections.Generic.List`1[[ClangSharp.Pathogen.InfoDumperSupport.InfoRow, ClangSharp.Pathogen, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]].AddRange(System.Collections.Generic.IEnumerable`1<ClangSharp.Pathogen.InfoDumperSupport.InfoRow>)
at ClangSharp.Pathogen.ClangSharpInfoDumper.EnumerateRows(System.Collections.Generic.List`1<ClangSharp.Pathogen.InfoDumperSupport.InfoRow>, System.Type, System.Type, System.Object, Options)
at ClangSharp.Pathogen.ClangSharpInfoDumper.EnumerateRows(System.Collections.Generic.List`1<ClangSharp.Pathogen.InfoDumperSupport.InfoRow>, System.Type, System.Type, System.Object, Options)
at ClangSharp.Pathogen.ClangSharpInfoDumper.EnumerateRows(System.Collections.Generic.List`1<ClangSharp.Pathogen.InfoDumperSupport.InfoRow>, System.Type, System.Type, System.Object, Options)
at ClangSharp.Pathogen.ClangSharpInfoDumper.EnumerateRows(System.Collections.Generic.List`1<ClangSharp.Pathogen.InfoDumperSupport.InfoRow>, System.Type, System.Type, System.Object, Options)
at ClangSharp.Pathogen.ClangSharpInfoDumper.EnumerateRows(System.Collections.Generic.List`1<ClangSharp.Pathogen.InfoDumperSupport.InfoRow>, System.Type, System.Type, System.Object, Options)
at ClangSharp.Pathogen.ClangSharpInfoDumper.Dump(System.IO.TextWriter, ClangSharp.Cursor, Options)
at ClangSharp.Pathogen.ClangSharpInfoDumper.Dump(System.IO.TextWriter, ClangSharp.Cursor)
(Very low prioritization because this only really affects me. You should generally only need this if you're working on low level functionality of Biohazrd. Marked external because it's technically ClangSharp.Pathogen
which is broken.)
This is going to be quite a pain. Lots of new stuff has been added to ClangSharp.Decl
which is only valid to access in the correct context. (AsFunction
, Body
, and DescribedTemplate
to name a few.)
This will likely require a more sophisticated dumper than we have today. The info dumper has not been super important for quite some time (it was originally added when I was developing the original Biohazrd prototype to help me explore the ClangSharp API), I may never create an updated version which matches its fidelity and settle for something simpler built into Dr. Mochi. (Alternatively I might just use SEH to prevent the AVs from tanking the process.)
For now I'm going to mark the APIs that activate the info dumper functionality as obsolete.