CLANG-QUERY(1)
β¨ NAME β¨
okay bestie, gather round π this is clang-query β the manual page for clang-query 15. she's a little tool that lets you poke at clang's AST and ask it questions, and honestly? iconic behavior. no cap.
π DESCRIPTION π
so here's the vibe check, fr fr β this is how you run her:
USAGE: clang-query [options] <source0> [... <sourceN>]
like. you give her options, you give her source files, she does her thing. periodt. π₯
below is the full menu of options, no skips, no skimming, we're reading the whole thing together π
π OPTIONS π
Generic Options
these ones are the universal, everybody-gets-them options β¨
--helpβ shows you all the available options (and if that's not enough,--help-hiddenshows you even more π)--help-listβ shows you a list of all the available options (and yeah,--help-list-hiddengives you the bigger, secret-menu version π)--versionβ prints out what version of this program you're running, in case you need receipts π§Ύ
clang-query options
now THIS is the main character section π the ones that are actually specific to clang-query:
-c <command>β specify a command to run--extra-arg=<string>β an additional argument to append to the compiler command line π«Ά--extra-arg-before=<string>β an additional argument to prepend to the compiler command line (yes bestie, before the others, order matters β¨)-f <file>β read commands from a file-p <string>β build path--preload=<file>β preload commands from a file and then start interactive mode π¦--use-colorβ use colors in the detailed AST output. If it's not set, colors will be used if the terminal connected to standard output supports colors. so like, she checks the vibe of your terminal first π
ποΈ about -p <build-path>
-p <build-path> is the thing you use to read a compile command database.
for example, it can be a CMake build directory in which a file named compile_commands.json exists β and to get that output you use the -DCMAKE_EXPORT_COMPILE_COMMANDS=ON CMake option π. When no build path is specified, a search for compile_commands.json will be attempted through all parent paths of the first input file. See: https://clang.llvm.org/docs/HowToSetupToolingForLLVM.html for an example of setting up Clang Tooling on a source tree.
ngl bestie, that link is your bestie too. go read it. π«Ά
π about <source0> ... <sourceN>
<source0> ... β this is where you specify the paths of your source files. these paths get looked up in the compile command database, okay?
here's the tea tho, and it's kinda strict π:
- If the path of a file is absolute, it needs to point into CMake's source tree.
- If the path is relative, the current working directory needs to be in the CMake source tree, and the file must be in a subdirectory of the current working directory.
"./"prefixes in the relative files will be automatically removed β cute, she does that for you π- but the rest of a relative path must be a suffix of a path in the compile command database. no wiggle room, that's just the rules. periodt.
that's the whole page bestie, you ate it π
signing off with the receipts: this was clang-query 15, dated July 2023, and the manual page is officially known as CLANG-QUERY(1) πβ¨ love u, go query some ASTs πΈ
π¦ where this page comes from
- ubuntu jammy: clang-tools-15 1:15.0.7-0ubuntu0.22.04.3 Β· APACHE-2-LLVM-EXCEPTIONS
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms