[cfe-dev] Extracting the include tree from a source file

Nico Weber thakis at chromium.org
Mon Nov 15 11:42:00 PST 2010


On Mon, Nov 15, 2010 at 8:33 PM, Bertjan Broeksema <broeksema at kde.org> wrote:
> Hi,
>
> Nico Weber wrote:
>
> Thanks for the quick reply!
>
>> Hi,
>>
>> Call InitializePreprocessor to add defines. To fix the crash, add
>> calls to BeginSourceFile()/EndSourceFile() (see
>> https://github.com/nico/clangtut/blob/master/tut03_pp.cpp ).
>
> Yes, I'm a step closer now, it indeed doesn't crash anymore when an error
> occurs. However, I still have the problem that system includes are not
> found. In this particular case stddef.h. I am somewhat assuming that it
> shouldn't be needed to add paths like:
>
> /usr/include/linux (for stddef.h)
> /usr/lib/gcc/x86_64-pc-linux-gnu/4.4.4/include
>
> clang++ (the command line tool), seems to have these paths available as it
> is able to preprocess the same file I'm testing with, without complaining
> about not finding stddef.h

All these are added in  InitHeaderSearch::AddDefaultCIncludePaths()
and friends in lib/Frontend/InitHeaderSearch.cpp. Maybe step through
that code for your binary and for clang and check which branches are
taken in both cases.

>> Take a look at include/clang/Lex/PPCallbacks.h – you probably want to
>> derive a class from that and set it on the preprocessor to be notified
>> of includes and defines in the code.
>
> Will do, thanks for the pointer.
>
> Bertjan
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>




More information about the cfe-dev mailing list