[cfe-dev] How clang works, whant to learn compiler internals

Serge Pavlov via cfe-dev cfe-dev at lists.llvm.org
Tue Oct 18 01:12:57 PDT 2016


You need to pass argument "-cc1" to the compiler in debug session. In your
case parameters must be:
-cc1 -std=c++1z -Xclang -ast-dump -fsyntax-only test_deb.cpp

Without "-cc1" clang works as driver executing other tools to make job,
with "-cc1" it works as compiler.

Thanks,
--Serge

2016-10-18 14:54 GMT+07:00 Ivan Kush via cfe-dev <cfe-dev at lists.llvm.org>:

> I want to learn clang internals and how it works. But
> llvm::sys::ExecuteAndWait executes in the debugger and that's all, finish,
> console output with my AST (I passes to clang "-ast-dump"). It didn't jump
> in the Lexer.cpp, Sema.cpp, etc. What should I do in the debugger, in order
> to see how Lexer, Sema work?
>
> My steps in the debugger:
>
> 1) compiled debug version of llvm and clang
>
> 2) created a source file "test_deb.cpp" with  the following code
>
> enum class Enum : int
> {
>     kOne,
>     kTwo
> };
>
> int f(int x) {
>   int result = (x / 42);
>   return result;
> }
>
> int main()
> {
>     return f(4);
> }
>
> 3) launch clang-4.0 in in the debugger with the following parameters:
> -std=c++1z -Xclang -ast-dump -fsyntax-only test_deb.cpp
>
> 4)  and begin to learn how all work:
> the "int main" in driver.cpp
>
> in driver.cpp is called "ExecuteCompilation" of "Driver"
>     TheDriver.ExecuteCompilation(*C, FailingCommands);
>
> where called "ExecuteJobs" of "Compilation" (the file Compilation.cpp):
>     C.ExecuteJobs(C.getJobs(), FailingCommands);
>
> in the func ExecuteJobs called ExecuteCommand
>     if (int Res = ExecuteCommand(Job, FailingCommand)) {
>
> that calls "Execute" of "Command" (the file Jobs.cpp):
>
> where called a func "ExecuteAnddWait" of  "llvm::sys"
>
>     return llvm::sys::ExecuteAndWait(Executable, Argv.data(), /*env*/
> nullptr,
>                                      Redirects, /*secondsToWait*/ 0,
>                                      /*memoryLimit*/ 0, ErrMsg,
>                                      ExecutionFailed);
>
> but the "Executable" is "...path/clang-4.0" - the file, that I launched in
> the debugger o__O
>
> 5) so llvm::sys::ExecuteAndWait(Executable,...) is called and that's all,
> finish, console output with my AST. It didn't jump in the Lexer.cpp,
> Sema.cpp, etc.
>
> What should I do in the debugger, in order to see how Lexer, Sema work?
>
> --
> Best wishes,
> Ivan Kush
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20161018/bb5a969a/attachment.html>


More information about the cfe-dev mailing list