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

kalyan ponnala ponnala.kalyan at gmail.com
Wed Feb 24 16:44:17 PST 2010


 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20100224/f0960862/attachment.html>


More information about the cfe-dev mailing list