<div dir="ltr">Have you tried the binary "clang-query"? It can save you a few steps, particularly 3) , 4) and 5).<div><br></div><div>Cheers,</div><div>Gabor</div></div><br><div class="gmail_quote"><div dir="ltr">On Tue, Jul 3, 2018 at 9:10 AM Thomas Patson via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi all,<div><br></div><div>I'm a Clang newbie. So, I've been trying to write some basic checkers that do AST traversal. Now, one of the difficulties I'm running into is on how to debug when my AST matcher doesn't work as expected.</div><div><br></div><div>My current workflow is this:</div><div>1) `clang -Xclang -ast-dump -fsyntax-only test.cc` and get a sense of how the AST tree looks like for code snippets the AST checker is supposed to figure out.</div><div>2) Write the checker.</div><div>3) Build the checker and fix syntactic plus other rookie errors when the compiler points out.</div><div>4) Run the checker</div><div>5) Notice that it doesn't work as expected, so stare at the checker. Do 1) again and see if I missed anything. If I spot anything, fix the checker and restart from 3).</div><div>6) If ran into 5) and couldn't spot anything in the ast-dump output, then go through ASTMatcher.h and try to see if you have a Eureka moment.</div><div>7) Twiddle my thumbs for a while and then email cfe-dev for help.</div><div><br></div><div>Ideally I want to rely on lldb in this kind of situation, and I suspect the answer lies in the Debug Prints and Tricks section (fromĀ <a href="https://clang-analyzer.llvm.org/checker_dev_manual.html" target="_blank">https://clang-analyzer.llvm.org/checker_dev_manual.html</a>). But I was hoping someone can perhaps go in more detail than what's in the Debug Prints and Tricks section to help a beginner like me. I'll be even more specific: Say there's a DeclStmt which has a VarDecl descendant, and I want to see if DeclRefExpr contains an IntegerLiteral of value 10 in the denominator assuming it's a divide operation. Now assuming that after looking at the ast-dump output, you're still not able to figure out what might be wrong with your matcher. How would you go about this predicament of yours ? I don't want to tell what the specific issue is because I want to go through the debugging process myself to figure out the problem with my matcher.</div><div><br></div><div>Copy-pasting an old email response for the same type of question should suffice.</div><div><br></div><div>Tom</div><div><br></div></div>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</blockquote></div>