<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"><base href="x-msg://3824/"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Hi, Gabor. Yes, Senthil has the right idea here—the trick is that the clang executable is divided into two parts: the "driver" and the compiler proper (sometimes known as "cc1"). The driver's in charge of invoking all the separate steps involved in a compliation command (compile, assemble, compile, assemble, link), whereas "cc1" just does Clang's own work for compiling a single file.</div><div><br></div><div>As Senthil said, you can get the driver to spit out a cc1 invocation line by appending -### to your usual run command. You can then use this output line (which will start with "path/to/clang" and then "-cc1") to launch the cc1-clang in your debugger and catch the assertions.</div><div><br></div><div>It's a good question. I'll try to make sure this ends up in the Checker Developer Manual once Sam has finished revising it.</div><div><br></div><div>Jordan</div><div><br></div><br><div><div>On Apr 29, 2013, at 6:03 , SENTHIL KUMAR THANGAVELU <<a href="mailto:senthil.t@samsung.com">senthil.t@samsung.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="line-height: 1.4; margin: 10px; font-family: Arial, arial; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div style="margin-top: 5px; font-family: Arial, arial; margin-bottom: 5px; font-size: 9pt; "> <br class="webkit-block-placeholder"></div><p style="margin-top: 5px; font-family: Arial, arial; margin-bottom: 5px; font-size: 9pt; ">    I have debugged clang 3.2 static analyzer using following steps, someone might know a better approach. These are the steps I have used for a c++ checker.</p><div style="margin-top: 5px; font-family: Arial, arial; margin-bottom: 5px; font-size: 9pt; "> <br class="webkit-block-placeholder"></div><p style="margin-top: 5px; font-family: Arial, arial; margin-bottom: 5px; font-size: 9pt; ">1) built with CC=gcc & CXX=g++,  might work with CC=clang and CXX=clang++ also I think</p><p style="margin-top: 5px; font-family: Arial, arial; margin-bottom: 5px; font-size: 9pt; ">2) used following command from inside gdb, I remember getting these args either using -v or ### option</p><p style="margin-top: 5px; font-family: Arial, arial; margin-bottom: 5px; font-size: 9pt; "> r "/home/camel/osa/bin/clang++" "-cc1" "-analyze" "-analyzer-checker" "Mychecker" "-internal-isystem" "/usr/lib/gcc/i686-linux-gnu/4.5/../../../../include/c++/4.5" "-internal-isystem" "/usr/lib/gcc/i686-linux-gnu/4.5/../../../../include/c++/4.5/i686-linux-gnu" "-internal-isystem" "/usr/lib/gcc/i686-linux-gnu/4.5/../../../../include/c++/4.5/backward" "-internal-isystem" "/usr/local/include" "-internal-isystem" "/usr/local/bin/../lib/clang/3.1/include" "-internal-isystem" "/usr/lib/gcc/i686-linux-gnu/4.5/../../../gcc/i686-linux-gnu/4.5/include" "-internal-isystem" "/usr/lib/gcc/i686-linux-gnu/4.5/../../../gcc/i686-linux-gnu/4.5/include-fixed" "-internal-externc-isystem" "/include" "-internal-externc-isystem" "/usr/include" testfile.cpp</p><div style="margin-top: 5px; font-family: Arial, arial; margin-bottom: 5px; font-size: 9pt; "> <br class="webkit-block-placeholder"></div><p style="margin-top: 5px; font-family: Arial, arial; margin-bottom: 5px; font-size: 9pt; ">backtrace in gdb always showed segfaults for me incase of checker segfaults.</p><div style="margin-top: 5px; font-family: Arial, arial; margin-bottom: 5px; font-size: 9pt; "> <br class="webkit-block-placeholder"></div><p style="margin-top: 5px; font-family: Arial, arial; margin-bottom: 5px; font-size: 9pt; ">Regards</p><p style="margin-top: 5px; font-family: Arial, arial; margin-bottom: 5px; font-size: 9pt; ">Senthil Kumar</p><div style="margin-top: 5px; font-family: Arial, arial; margin-bottom: 5px; font-size: 9pt; "> <br class="webkit-block-placeholder"></div><p style="margin-top: 5px; font-family: Arial, arial; margin-bottom: 5px; font-size: 9pt; ">-------<span class="Apple-converted-space"> </span><b>Original Message</b><span class="Apple-converted-space"> </span>-------</p><p style="margin-top: 5px; font-family: Arial, arial; margin-bottom: 5px; font-size: 9pt; "><b>Sender</b><span class="Apple-converted-space"> </span>: G�bor Koz�r<<a href="mailto:kozargabor@gmail.com">kozargabor@gmail.com</a>></p><p style="margin-top: 5px; font-family: Arial, arial; margin-bottom: 5px; font-size: 9pt; "><b>Date</b><span class="Apple-converted-space"> </span>: Apr 29, 2013 21:15 (GMT+09:00)</p><p style="margin-top: 5px; font-family: Arial, arial; margin-bottom: 5px; font-size: 9pt; "><b>Title</b><span class="Apple-converted-space"> </span>: [cfe-dev] Debugging Clang Static Analyzer segfault (clang 3.2)</p><div style="margin-top: 5px; font-family: Arial, arial; margin-bottom: 5px; font-size: 9pt; "> <br class="webkit-block-placeholder"></div><div dir="ltr"><div><div><div><div><div><div>Hi,<br><br></div>I wrote a custom checker based on SimpleStreamChecker for the Clang Static Analyzer. I'm using clang version 3.2.<br><br></div>Upon running /.../llvm-3.2/build/bin/clang++ testfile.cpp -std=c++11 -Xclang -analyze -Xclang -analyzer-checker=mychecker, I get the following:<br><br>0  clang-3.2       0x0000000001b8a52c<br>1  clang-3.2       0x0000000001b8a21c<br>2  libpthread.so.0 0x00007f577ad715d0<br>3  clang-3.2       0x000000000291903c<br>4  clang-3.2       0x00000000029193f1<br>5  clang-3.2       0x000000000291ada1<br>6  clang-3.2       0x000000000298b9dc<br>7  clang-3.2       0x0000000002987223<br>8  clang-3.2       0x00000000029894b9<br>9  clang-3.2       0x00000000029872dd clang::ento::CheckerManager::runCheckersForCallEvent(bool, clang::ento::ExplodedNodeSet&, clang::ento::ExplodedNodeSet const&, clang::ento::CallEvent const&, clang::ento::ExprEngine&, bool) + 159<br>10 clang-3.2       0x00000000029c8736<br>11 clang-3.2       0x00000000029cb0db clang::ento::ExprEngine::evalCall(clang::ento::ExplodedNodeSet&, clang::ento::ExplodedNode*, clang::ento::CallEvent const&) + 127<br>12 clang-3.2       0x00000000029cafbd clang::ento::ExprEngine::VisitCallExpr(clang::CallExpr const*, clang::ento::ExplodedNode*, clang::ento::ExplodedNodeSet&) + 397<br>13 clang-3.2       0x00000000029b1163 clang::ento::ExprEngine::Visit(clang::Stmt const*, clang::ento::ExplodedNode*, clang::ento::ExplodedNodeSet&) + 3785<br>14 clang-3.2       0x00000000029af477 clang::ento::ExprEngine::ProcessStmt(clang::CFGStmt, clang::ento::ExplodedNode*) + 523<br>15 clang-3.2       0x00000000029ae9b7 clang::ento::ExprEngine::processCFGElement(clang::CFGElement, clang::ento::ExplodedNode*, unsigned int, clang::ento::NodeBuilderContext*) + 205<br>16 clang-3.2       0x000000000299d85c clang::ento::CoreEngine::HandlePostStmt(clang::CFGBlock const*, unsigned int, clang::ento::ExplodedNode*) + 282<br>17 clang-3.2       0x000000000299cb40 clang::ento::CoreEngine::dispatchWorkItem(clang::ento::ExplodedNode*, clang::ProgramPoint, clang::ento::WorkListUnit const&) + 630<br>18 clang-3.2       0x000000000299c838 clang::ento::CoreEngine::ExecuteWorkList(clang::LocationContext const*, unsigned int, llvm::IntrusiveRefCntPtr<clang::ento::ProgramState const>) + 918<br>19 clang-3.2       0x00000000027fa752<br>20 clang-3.2       0x00000000027d9bd1<br>21 clang-3.2       0x00000000027d9ce2<br>22 clang-3.2       0x00000000027d99c9<br>23 clang-3.2       0x00000000027d8f9a<br>24 clang-3.2       0x00000000027d92b7<br>25 clang-3.2       0x0000000001f08c21 clang::ParseAST(clang::Sema&, bool, bool) + 786<br>26 clang-3.2       0x0000000001e2427c clang::ASTFrontendAction::ExecuteAction() + 298<br>27 clang-3.2       0x0000000001e23e97 clang::FrontendAction::Execute() + 197<br>28 clang-3.2       0x0000000001e00bbb clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 717<br>29 clang-3.2       0x0000000001b8f09d clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 1054<br>30 clang-3.2       0x0000000000d0138c cc1_main(char const**, char const**, char const*, void*) + 678<br>31 clang-3.2       0x0000000000cfb1d3 main + 508<br>32 libc.so.6       0x00007f577a2a9bc6 __libc_start_main + 230<br>33 clang-3.2       0x0000000000cf9879<br>Stack dump:<br>0.    Program arguments: /home/ekozgbo/work/dev/llvm-3.2/build/bin/clang-3.2 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free -main-file-name t2.cpp -mrelocation-model static -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -momit-leaf-frame-pointer -resource-dir /home/ekozgbo/work/dev/llvm-3.2/build/bin/../lib/clang/3.2 -fmodule-cache-path /var/tmp/clang-module-cache -internal-isystem /usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../include/c++/4.3 -internal-isystem /usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../include/c++/4.3/x86_64-suse-linux -internal-isystem /usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../include/c++/4.3/backward -internal-isystem /usr/local/include -internal-isystem /home/ekozgbo/work/dev/llvm-3.2/build/bin/../lib/clang/3.2/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /home/ekozgbo/work/dev/test -ferror-limit 19 -fmessage-length 237 -mstackrealign -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -analyze -analyzer-checker=mychecker -o /tmp/t2-lNeYsr.o -x c++ testfile.cpp<span class="Apple-converted-space"> </span><br>1.    <eof> parser at end of file<br>2.    testfile.cpp:32:2: Error evaluating statement<br>3.    testfile.cpp:32:2: Error evaluating statement<br>clang-3: error: unable to execute command: Segmentation fault<br>clang-3: error: clang frontend command failed due to signal (use -v to see invocation)<br>clang version 3.2 (tags/RELEASE_32/final 180012)<br>Target: x86_64-unknown-linux-gnu<br>Thread model: posix<br>clang-3: note: diagnostic msg: PLEASE submit a bug report to<span class="Apple-converted-space"> </span><a href="http://llvm.org/bugs/">http://llvm.org/bugs/</a><span class="Apple-converted-space"> </span>and include the crash backtrace, preprocessed source, and associated run script.<br>clang-3: error: unable to execute command: Segmentation fault<br>clang-3: note: diagnostic msg: Error generating preprocessed source(s).<br><br></div>I'm fairly certain the issue is in my checker code, but I have no idea how to debug it. Clang seems to handle the segfault on its own, so I can't really do much with gdb.<br>So how can I debug this issue? (Apart from the llvm::errs() or std::cout solution.)<br><br></div>The only changes I made to clang 3.2 is that I compile it with C++11, and of course I added two custom checkers. Oh and I'm also linking the static analyzer with libASTMatchers. So far I haven't had any issues, although the previous checker was much simpler.<br><br></div>Any help would be greatly appreciated.<br></div><br>Gabor<br></div><div style="margin-top: 5px; font-family: Arial, arial; margin-bottom: 5px; font-size: 9pt; "> <br class="webkit-block-placeholder"></div><div style="margin-top: 5px; font-family: Arial, arial; margin-bottom: 5px; font-size: 9pt; "> <br class="webkit-block-placeholder"></div><p style="margin-top: 5px; font-family: Arial, arial; margin-bottom: 5px; font-size: 9pt; ">Regards</p><p style="margin-top: 5px; font-family: Arial, arial; margin-bottom: 5px; font-size: 9pt; ">Senthil Kumar</p><div style="margin-top: 5px; font-family: Arial, arial; margin-bottom: 5px; font-size: 9pt; "> <br class="webkit-block-placeholder"></div><div style="margin-top: 5px; font-family: Arial, arial; margin-bottom: 5px; font-size: 9pt; "> <br class="webkit-block-placeholder"></div><table id="confidentialsignimg"><tbody><tr><td namo_lock="" style="margin-top: 5px; font-family: Arial, arial; margin-bottom: 5px; font-size: 9pt; "><p style="margin-top: 5px; font-family: Arial, arial; margin-bottom: 5px; font-size: 9pt; "><span><201304291837621_QKNMBDIF.gif></span></p></td></tr></tbody></table>_______________________________________________<br>cfe-dev mailing list<br><a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br><a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a></div></blockquote></div><br></body></html>