Git Product home page Git Product logo

Comments (1)

sethfowler avatar sethfowler commented on September 27, 2024

I'll write down the process of debugging this as I do it:

My first approach is to run the executable under lldb to see if the crash is happening in C/C++ code. If it is, this will give me a stack trace and usually the problem is immediately clear.

If the crash is happening in Haskell code, lldb is generally not as useful. In this case I usually add additional print statements to the crashing code to determine exactly where the crash happens. (I could also use ghci for this, but editing the actual source is convenient since you can run it over and over and verify whether the problem is fixed.)

Generally knowing where the crash is tells me the source of the problem immediately. In this case the crash happens in Clang.String.unpack, which means Clang.Cursor.getIncludedFile returned a null value and probably needs to return a Maybe (File s) instead of a File s.

At that point looking at the source of Clang.Cursor.getIncludedFile will tell me the low-level FFI function that it calls - in this case Clang.Internal.FFI.getIncludedFile, which is defined in FFI.gc. I can see from there that the C-level function being called is clang_getIncludedFile. (The mapping between the various names is obvious in this case but sometimes it's less straightforward).

To verify my guess that clang_getIncludedFile may fail and return null, I check its definition at the C level in clang/include/clang-c/Index.h. It seems pretty clear that it's only designed to be called on inclusion directives. At the Haskell level, then, we definitely need it to return a Maybe, since we have no type-level way of restricting the kind of cursor you can pass in.

To fix this, then, I just need to update the definition of getIncludedFile in FFI.gc and the functions that call it. The details of doing that require some knowledge of greencard but it's pretty easy to pick up. In this case we've needed this in several other places and there's already a maybe_file "dis" available, so it's a very simple change.

You can view the referenced commit to see exactly what I did. If you feel comfortable debugging issues like this, we'd love to have the help!

from libclang.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.