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.
My current workflow is this:
clang -Xclang -ast-dump -fsyntax-only test.ccand get a sense of how the AST tree looks like for code snippets the AST checker is supposed to figure out.
- Write the checker.
- Build the checker and fix syntactic plus other rookie errors when the compiler points out.
- Run the checker
- 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).
- 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.
- Twiddle my thumbs for a while and then email cfe-dev for help.
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 https://clang-analyzer.llvm.org/checker_dev_manual.html). 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.
Copy-pasting an old email response for the same type of question should suffice.