Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix debug dumping support #227

Open
PathogenDavid opened this issue Dec 2, 2021 · 2 comments
Open

Fix debug dumping support #227

PathogenDavid opened this issue Dec 2, 2021 · 2 comments
Labels
Bug External Issues which represent work which affects Biohazrd but needs to happen outside of Biohazrd

Comments

@PathogenDavid
Copy link
Member

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)
@PathogenDavid PathogenDavid added Bug External Issues which represent work which affects Biohazrd but needs to happen outside of Biohazrd labels Dec 2, 2021
@PathogenDavid
Copy link
Member Author

(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.)

@PathogenDavid
Copy link
Member Author

PathogenDavid commented Dec 2, 2021

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.

PathogenDavid added a commit that referenced this issue Dec 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug External Issues which represent work which affects Biohazrd but needs to happen outside of Biohazrd
Projects
None yet
Development

No branches or pull requests

1 participant