[cfe-dev] How to check the flow of the clang compiler with an example

Ted Kremenek kremenek at apple.com
Wed Feb 24 16:55:54 PST 2010

CIndex is not part of the clang executable, but part of a dynamic library which can be used by clients to use some (but not all) of Clang's functionality.

As for your command line, you need to pass the right target options to clang -cc1.  First try:

  clang -fsyntax-only helloworld.c -###

which will print out the 'clang -cc1' line for doing '-fsyntax-only' on 'helloworld.c'.  Then invoke 'clang -cc1' in the debugger with that complete set of arguments.

On Feb 24, 2010, at 4:44 PM, kalyan ponnala wrote:

>  Hi,
> Thanks for the reply. I tried putting breakpoints at CIndex.cpp file in CIndex target near
> Lexer Lex(SourceMgr.getLocForStartOfFile(BeginLocInfo.first),
>             CXXUnit->getASTContext().getLangOptions(),
>             Buffer.first, Buffer.first + BeginLocInfo.second, Buffer.second);
> and another breakpoint at Parser.cpp inside clangparser target.
> bool Parser::ParseTopLevelDecl(DeclGroupPtrTy &Result) {
>   Result = DeclGroupPtrTy();
>   if (Tok.is(tok::eof)) {
>     Actions.ActOnEndOfTranslationUnit();
>     return true;
>   }
> When I tried to run the command clang -cc1 helloworld.c on the command line , it generates 5 diagnostic messages saying error: unknown type __int64 /*64-bit time value*/ and shows me different places inside stdio.h and crtdefs.h.
> The program that I created in visual studio was helloworld.c
> #include<stdio.h>
> int main()
> {
> printf("\n helloworld");
> return 0;
> }
> Could you tell me if the procedure that I used was wrong or is it something with the breakpoints or something else?
> Thanks
> On Wed, Feb 24, 2010 at 5:31 PM, Charles Davis <cdavis at mymail.mines.edu> wrote:
> kalyan ponnala wrote:
> > Hi,
> > I would like to go through the clang compiler (the lexer and the parser)
> > by compiling a small program like helloworld.c . I am using visual
> > studio 2008 solution file for clang/llvm. Can an expert tell me how to
> > proceed and the steps that I need to know to do this.
> > I am not able to figure out what is the starting program that does the
> > lexer and parser stages of the compiler, so that I could put some
> > breakpoints that will be hit when we try to compile a program like
> > helloworld.
> > And I would like to know whats a "cc1". I found it in the code at
> > several places.
> 'cc1' is the actual compiler. It's actually a part of clang.exe, but you
> activate it with the '-cc1' switch. What you want to do is debug
> clang.exe, but pass it the -cc1 so you can debug the compiler itself. If
> you don't pass -cc1, you'll start the driver instead, which spawns the
> compiler. You can get around that by debugging child processes, too, but
> I think it's easier to just run clang -cc1.
> There is a "Lexer" class which is used to read tokens from a source
> file, and a "Parser" class which does the parsing. There's also a
> "Preprocessor" object which handles preprocessor directives.
> The important method in the Lexer class is the Lex() method. It
> retrieves the next token. The parser calls this method every time it
> wants a token.
> The Parser object starts by parsing top-level declarations (i.e. ones at
> global scope), which is initiated with the ParseTopLevelDecl() method.
> If you set breakpoints on these methods, you can step through the Lexer
> and Parser at your leisure.
> Chip
> -- 
> Kalyan Ponnala
> phone: 8163772059
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20100224/bf3686f5/attachment.html>

More information about the cfe-dev mailing list