Hi, all. Clang is the front end of C/C++ compiler and LLVM plays the role of optimizer and backend. So how do these different stages are connected? Is there any detailed document about this? What's more, the code of LLVM and Clang is so huge that it is hard for me to get started. If I want to make some modifications or just wanna to debug the source code, what should I do? -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140410/baa1cf15/attachment.html>
I use gdb. it was convenient to check call trace as well as variables. a great feature the gdb has but i had not found it in visual studio was, I could call a function at a breakpoint as a gdb command. -- View this message in context: http://llvm.1065342.n5.nabble.com/Questions-about-how-to-debug-LLVM-and-CLang-tp67647p67649.html Sent from the LLVM - Dev mailing list archive at Nabble.com.
On Wed, Apr 9, 2014 at 7:11 PM, 蜡笔小新 <841224078 at qq.com> wrote:> Hi, all. > > Clang is the front end of C/C++ compiler and LLVM plays the role of > optimizer and backend. So how do these different stages are connected?They're connected by API (ie: the clang binary links in the LLVM libraries and calls into them to do optimization/machine code/assembly emission).> Is > there any detailed document about this?Not really> What's more, the code of LLVM and Clang is so huge that it is hard for me to > get started. If I want to make some modifications or just wanna to debug the > source code, what should I do?Depends what it is you want to change. I started by looking at Clang diagnostic (warnings, errors, etc) issues - false positives (cases where warnings are emitted but shouldn't be) were a good place to start because I could find the code that emitted the warning (ultimately breaking on textual printing code - printf/write/whatever basic system call) and then work backwards through the stack trace in a debugger (gdb, etc) to find out what context lead to emitting that warning there and where the missing checks were. One common hurdle to debugging clang is that clang executes another process inside itself. Either use clang -### to get the underlying command and debug that, or in gdb use "set fork-follow-mode child" to make sure the debugger debugs the child process.> > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >
Krzysztof Parzyszek
2014-Apr-10 16:35 UTC
[LLVMdev] Questions about how to debug LLVM and CLang
On 4/9/2014 9:11 PM, 蜡笔小新 wrote:> > What's more, the code of LLVM and Clang is so huge that it is hard for > me to get started. If I want to make some modifications or just wanna to > debug the source code, what should I do?Depends on what you want to do exactly. For LLVM, using -print-after-all will show you the IR after each pass, which can give you an idea of what passes are run and what each pass does. Debugging an individual pass is also fairly straightforward, since the code is usually contained within a single source file. I never use debuggers to debug the compiler itself---I just put a bunch of "dbgs() << ..." in the code to see what I want to see. -Krzysztof -- Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation