Skip to content

About

Static analysis for C/C++ codebases with call graphs, pointer analysis, indirect-call resolution, and interprocedural data-flow tracing.

Resources

Code of conduct

Contributing

Stars

11 stars

Watchers

0 watching

Forks

Repository files navigation

trace

trace is a static analysis tool for C and C++ codebases. It runs a custom preprocessor, parses translation units with tree-sitter, performs Andersen-style field-sensitive pointer analysis, and exports call graphs and interprocedural argument-flow facts to SQLite.

Typical uses:

  • Find direct and indirect call targets (function pointers, C++ member pointers, vtables, struct op tables). Member-pointer parsing, const/ref and variadic signatures, and value flow are described in C++ parse-input normalization.
  • Trace argument flow from call-site actuals to callee formals.
  • Query results with trace inspect, ad-hoc SQL, or programmatic C API (trace-capi).

Conditional expressions such as flag ? alpha : beta preserve both alternatives in pointer and callback flow, including across function boundaries. See conditional values for supported forms and type inference, and implementation limitations for precision, model dependencies and coverage boundaries.

Build

# Build CLI binary
cargo build --release
# binary: target/release/trace

# Or build CLI binary with mimalloc allocator for ~20% faster indexing on large workloads
# (source-builds opt-in feature; prebuilt release artifacts use the system allocator;
# measured with mimalloc 0.1 / upstream mimalloc v3):
cargo build -p trace-cli --release --features mimalloc
# binary: target/release/trace

# Or build C API library (staticlib and cdylib)
cargo build -p trace-capi --release
# library: target/release/libtrace_capi.{so,dylib,dll,a}

# Or build cross-repository merger binary
cargo build -p trace-merge --release
# binary: target/release/trace-merge

Ability-runtime benchmark build options and measurements are in the evaluation report. An optional two-stage PGO experiment trains on the pinned real projects and compares ThinLTO/PGO binaries, with optional fat LTO and holdouts: python3 scripts/build_pgo.py --runs 5.

Run the workspace test suite:

cargo test --workspace

Quick start

trace analyze ./tests/fixtures/direct_call -o /tmp/trace.db
trace inspect /tmp/trace.db calls
trace inspect /tmp/trace.db calls --from main
trace inspect /tmp/trace.db calls --from caller --to helper

Analyze a large tree (parallel indexing, minimal SQLite export):

trace analyze /path/to/project -o /tmp/project.db --jobs 8

For call chains across application, framework and service repositories, use separate analysis followed by trace-merge. If an implementation is unavailable, see missing-framework fallbacks.

Editor call hierarchy

Build the separate snapshot language server and point it at an existing database:

cargo build -p trace-lsp --release
trace analyze ./project -o analysis.db
target/release/trace-lsp --db analysis.db

trace-lsp serves standard LSP incoming/outgoing call hierarchy over stdio. Default minimal exports work; no points-to export is needed. It opens schema v7, v8 and v9 read-only and leaves the analyzer and database format unchanged. See LSP configuration and editor example for path mapping, range precision, snapshot behavior, and limitations.

CLI reference

Conditional coverage and GN define evidence

cargo run -p trace-cli --release --example conditional_coverage -- /path/to/project > coverage.tsv

The reporting example records conditional branches and scans BUILD.gn, *.gni and *.gn for direct string entries in defines = [...] and defines += [...]. GN_DEFINE TSV rows retain the macro name, whether a value was supplied, the value, file, entry line, confidence, and enclosing GN conditions. No inferred define is applied. See GN evidence for ranking and limits; scripts/gen_conditional_coverage_report.py renders these candidates in a local report; see conditional coverage reporting.

trace analyze

Analyze every C/C++ file (.c, .cpp, .cc, .cxx) under TARGET and write results to SQLite.

trace analyze [OPTIONS] <TARGET>
Option Description
<TARGET> Root directory to scan recursively for *.c / *.cpp / *.cc / *.cxx files.
-o, --output <PATH> Output database path. Default: trace.db.
--include <PATH> Add a preprocessor #include search path. Repeatable.
-D <NAME> Define preprocessor macro NAME=1. Repeatable.
-D <NAME=VALUE> Define macro with explicit value. Repeatable. Overrides the language predefines (__cplusplus, __STDC_VERSION__, __STDC__) when the name matches.
--compile-commands <PATH> Compilation database to read. Default: auto-discovery at the target root, then build/; otherwise root compile_flags.txt.
--system-includes Query the compiler for its effective system header search paths. Off by default.
--canonical-system-headers Lower the compiler-default standard headers once, as one shared prelude per language, instead of per translation unit (bare-tree only; implies --system-includes). Every unit starts from the prelude's macros and project headers keep the default sharing rules, at close to default-mode cost. One standard-library configuration stands for all units. See design and measurements.
--compiler-predefines Import allowlisted compiler identity and target macros. Off by default; see macro sources and precedence.
--compiler <EXECUTABLE> Explicit fallback driver for sources without a usable compilation command; requires --compiler-predefines or --system-includes.
--compiler-arg <ARG> Repeatable supported fallback compiler configuration option; requires --compiler.
--link-commands <PATH> Link commands database to read, establishing which sources each program links. Default: auto-discovery (link_commands.json at the target root or build/, link entries in the compilation database, or a CMake File API reply). Enables per-program weak-symbol resolution; see link targets and weak symbols.
--jobs <N> Parallel jobs for indexing (parse + lower). Default: logical CPU count.
--timeout-secs <N> Watchdog: abort the process after N seconds (exit 124). Useful when probing hang-prone trees.
--full-export Export full IR detail: all types, all variables, PAG locations. Slower and produces a larger database.
--debug-points-to Retain points-to sets during analysis and export the points_to debug table and the locations it references (requires PAG in memory).
--models <FILE> Load TOML function-behavior summaries (parameter flow, accessor getters, callbacks, IPC) and noise macro lists. Repeatable; later files override earlier entries and built-ins. Project IPC shortcuts such as DataShare OpenFile are opt-in; see missing-framework fallbacks and the model format.
--ignore-macro <NAME> Ignore expansions of the named macro during AST lowering (repeatable). Glob wildcards (*) are supported (e.g. --ignore-macro 'LOG*'). Suppresses boilerplate call sites, temporary variables, and flow constraints.
--ignore-logging Preset flag to ignore common OpenHarmony and standard logging macros (HILOG_*, TAG_LOG*, HIVIEW_LOG*, MEDIA_*_LOG, LOGD, LOGI, LOGW, LOGE, LOGF).
--no-test-partition Disable the bare-tree test partition.
--test-dir <NAME> Replace the partition’s directory names (repeatable). Defaults, validation, and precedence: Declaring-header eligibility.
--dep <PATH> Treat a directory as a dependency root: a tree the target builds against but that is not under analysis (repeatable). Its headers contribute declarations — types, class definitions, inheritance, prototypes, declared return types — while its sources are never translation units. Function bodies and variable initializers are skipped during lowering, so they contribute no call sites or value flow. See the note below.
--explore Enable bounded conditional-variant exploration. Discovers candidate macro definitions from project GN files (BUILD.gn, *.gni), evaluates semantic feasibility of excluded #if/#ifdef/#elif arms, preprocesses and lowers feasible variants independently, and unions their facts into the merged program (preserving body and call facts plus struct fields across configurations; conditional signatures retain the base arity, see limits). Off by default.
--explore-budget <N> Maximum additional configurations per translation unit (default: 4). Budget diagnostics count omitted candidate activation goals, not proven reachable configurations.
--sequencing Record a compact call-order control-flow graph per function body beside the call graph, for call-sequence queries. The call graph, points-to and argument flow are unchanged. Off by default. See call sequencing.
--no-ipc Disable automatic IPC bridge detection and any loaded ipc function models. Bridge edges are synthetic (resolution = 'ipc', call_site_id = NULL). DataShare OpenFile requires an explicit --models file; prefer the source-backed workflow when framework sources are available. See IPC rules. Service IDL and the HDI C++ IPC subset synthesize declarations-only interface/proxy/stub headers; HDI methods may omit a return type. See IDL-generated interfaces for signatures, pairing and dialect limits.
--solve-budget-pops <N> Solver work budget in worklist pops. Default derives from the PAG constraint count (800000 + 6×constraints), so normal trees converge and huge ones finish instead of stopping at a partial result; 0 = unlimited. TRACE_SOLVE_BUDGET_POPS overrides it for experimentation. A truncated run is recorded, not silent: analysis_run.options_json.solver_partial, an analyze-stage diagnostic, and a trace inspect warning.
--solve-budget-secs <N> Solver wall-clock budget in seconds (default: off; 0 = no time limit). Checked periodically, so lead time can overshoot by up to one checkpoint, and the stop point varies with machine load.

OpenHarmony IPC bridging recognizes proxy operations that send through SendTransactCmd helpers as well as direct SendRequest calls, including separately indexed proxy/stub repositories combined with trace-merge. Re-index older proxy-side databases to export the newly recognized senders. See the IPC matching rules and ability-runtime verification.

Epoll event-data flow is modeled by default: registrations through epoll_ctl feed buffers returned by epoll_wait, epoll_pwait and epoll_pwait2, so indirect dispatch and upward value tracing can cross the registration/wait boundary. See Epoll event data for the approximation and configurable wrapper effects.

Progress output (stderr):

discover: 618 TUs, 200 headers under /path
include-graph: 818 files, 1200 include edges
warm: 1/90 /path/foo.h
parse: 0 orphan headers, 618 TUs (jobs=8)
index: 24.2s (618 files, 11442 functions, 48406 flow)
analyze: 0.3s (25478 edges, 3468 indirect)
export: 0.1s
analysis complete: 11442 functions, 25478 call edges, 25803 arg-flow edges -> trace.db

SQLite export builds most secondary indexes after loading rows, before committing and publishing the database, to reduce bulk insertion work.

Without build metadata, indexing spills large preprocessed source text and LineMaps to automatically cleaned temporary files and loads them for parsing. Discovery drops payloads that the settle pass must rebuild. After header lowering, settled TUs can release frozen header expansions and raw source copies before the ordered merge. Parallel parsing reserves estimated source bytes until each unit has merged, with a byte budget and a count safety cap. Small units can run further ahead of a slow unit; workers still wait when either limit fills. Compilation-command indexing retains its previous source-count limit. See Parsing memory limits. Cached header type tables discard lowering-only indexes and layouts once their merge descriptors are ready. Type tables share immutable descriptors across headers and TUs while retaining local IDs. On Linux/glibc, indexing returns freed heap pages at phase boundaries and between ordered TU merge batches. On macOS analyze runs under libmalloc's space-efficient mode, which holds the peak footprint at the live heap size for a few percent of wall time on large trees: it re-executes itself once with MallocSpaceEfficient=1 (same pid and argv[0]). A MallocSpaceEfficient already set to 0 or 1 is respected, so MallocSpaceEfficient=0 trace analyze … keeps the default allocator; an empty or invalid value, which libmalloc warns about on every run, is replaced. inspect never re-executes, nor does a build with the mimalloc feature. The mode in effect is the malloc: line at the start of the progress output. See memory measurements, macOS space-efficient malloc, the memory investigation, and the macOS measurements (scripts/profile_memory_macos.py; on macOS compare phys_footprint, not RSS).

Examples

# HDF-style tree with extra include roots
trace analyze ~/drivers_hdf_core -o /tmp/hdf.db \
  --include ~/drivers_hdf_core/framework/core/common/include \
  -D __LITEOS__ -D CONFIG_XXX=1

# Debug pointer analysis
trace analyze ./my_app -o /tmp/debug.db --debug-points-to --full-export

# Use a compilation database outside the source tree
trace analyze ./my_app --compile-commands ./out/compile_commands.json -o /tmp/app.db

# Include installed compiler system headers as declaration-only dependencies
trace analyze ./my_app --system-includes -o /tmp/app.db
# Lower the standard headers once, as one shared prelude (implies --system-includes)
trace analyze ./my_app --canonical-system-headers -o /tmp/app.db

# Explicit target compiler macros; compiler receives empty input only.
trace analyze ./my_app --compiler-predefines --compiler clang \
  --compiler-arg=--target=aarch64-linux-gnu -o /tmp/app.db

Notes

  • .c and .cpp-family files are indexed as translation units. Headers are pulled in via #include during preprocessing, not analyzed as standalone TUs. A C++ unit is preprocessed with __cplusplus (201703L) and __STDC__ predefined, a C unit with __STDC__ and __STDC_VERSION__ (201710L), so #ifdef __cplusplus takes the C++ arm in .cpp units and the C arm in .c units, headers included. C++ support is a pragmatic first step — see C++ support for scope and imprecision.
  • Line numbers in the database refer to original files on disk (resolved through the preprocessor's LineMap); call sites inside macro expansions attribute to the expansion site.
  • C++ parser adaptation — GNU visibility attributes before extern "C" are recovered during indexing, preserving source positions and external function identity. See C++ parse-input normalization for recognized spellings and limits. Re-analyze existing databases to apply the fix.
  • Compilation database — automatically reads compile_commands.json at the target root, then build/compile_commands.json, or an explicit --compile-commands PATH. Each entry supplies its working directory, ordered -I/-iquote/-isystem paths, ordered -D/-U, -include, and -x/-std. MSVC cl/clang-cl preprocessing switches (/I, /D, /U, /FI, /TC, /TP, /Tc, /Tp, /std:) are also supported. All applicable commands for a source contribute facts, even without --explore; link-object membership restricts them to their target. CLI --include paths precede database -I paths and CLI -D values override database macros. When no JSON database is selected, root compile_flags.txt supplies shared flags to every discovered source (the parent directory for a single-file analysis). It contains one literal argument per line, preserving spaces; relative paths use its directory. The formats are never combined. Unreadable or malformed flags produce configuration diagnostics and fall back to inferred configuration. Files without a usable entry retain inferred configuration; a database is never required. See compilation database support.
  • Compiler predefines — --compiler-predefines imports a documented allowlist from the compilation-command driver, or an explicit --compiler fallback. Missing or unsupported compiler context produces configuration warnings without guessing a host compiler. See macro sources, supported drivers and precedence.
  • System headers — --system-includes queries the compilation command's compiler for its effective search paths, with results cached by compiler and configuration. Sources lacking a usable compilation command or explicit compiler share one project fallback compiler: GCC first, then Clang. With --compiler-predefines, this implicit fallback supplies header paths only; macro discovery still requires compiler context. Reached system headers contribute declarations and macros as dependencies. Explicit -isystem, -idirafter, and library-supplied system paths continue to work without the flag. See compiler include discovery. Bare-tree indexing shares compatible expansions, lowered declaration units and recurring assembled header preambles, including extensionless standard headers; its cache contract describes context-sensitive fallbacks. Indexing also shares raw tokens, compacts temporary source maps, and reuses parsed syntax. See post-review system-header measurements.
  • Unresolved headers — analysis prints a bounded summary with file/line examples and target SDK, compiler, dependency and include-path guidance. Matching indexed files provide search-path evidence; other files' availability remains unknown. Original warnings remain in the database. --apply-include-candidates applies the proposed include roots and repeats indexing, retaining the final diagnostics. See missing-header guidance.
  • GN target inference — automatic bare-tree target discovery follows the target inference contract.
  • Link targets and weak symbols — --link-commands PATH, auto-discovered link_commands.json, mixed compilation/link databases, and CMake File API replies establish target scopes. Strong definitions override weak fallbacks only in targets that contain them; shared sources retain separate bindings per target. See resolution rules and limitations.
  • static functions (internal linkage) and file-scope static variables are resolved within the defining translation unit. static locals inside functions are tracked as fn_static storage.
  • Dependency roots (--dep <PATH>) separate what the target uses from what it is. A dependency's headers are reached and merged for their declarations — smart-pointer wrappers such as sptr<T>, base classes, external interfaces — so a wrapper-typed receiver resolves on the wrapped class rather than producing an edge on the wrapper. Its sources are never translation units, its unreached headers are never indexed as standalone units, and a body written in a dependency header merges as a declaration (is_defined = 0) with no call sites, locals, value flow or return flow. Files and functions from a dependency root export with is_dep = 1; trace inspect calls --exclude-deps drops the edges that touch them. A dependency root nested inside the analysis root is fine; one that contains or equals it is rejected at startup, since every source would become a dependency and nothing would be left to analyze.

static storage support

Context IR / export Call / flow resolution
File-scope static function linkage = internal Direct calls and CallReturn via scope-aware name lookup (file + name)
File-scope static variable kind = file_static Persistent PAG location; name lookup scoped to its file and the files including it
Function-local static variable kind = fn_static Persistent PAG location within enclosing function
External (non-static) symbols linkage = external Global fn_by_name / global_by_name tables

Same identifier in different .c files (each static) gets distinct IR ids; resolution uses the call site's file.

trace inspect

Query an existing analysis database.

trace inspect <DB> calls [--from FN] [--to FN] [--file SUBSTR] [--exclude-deps]

Edges print as `caller (file:line) -> callee [deffile] (resolution)` — the
`[deffile]` bracket distinguishes same-name (e.g. `static`) functions defined
in different files; `--file` filters ordinary edges by call-site or callee
file. A synthetic edge has no call site, so its caller definition file is used
instead.
Option Description
<DB> Path to SQLite file produced by trace analyze.
--from <FN> Filter edges where the caller name equals FN or ends with ::FN (C++ qualified methods). _ and % in FN are literal, not LIKE wildcards.
--to <FN> Filter edges where the callee name equals FN or ends with ::FN. Same escaping as --from.
--file <SUBSTR> Filter ordinary edges by call-site or callee file; synthetic edges by caller or callee definition file. / and \ are interchangeable.
--callgraph-filter <FILE> JSON file listing regex patterns over function names; edges whose caller and callee both fail to match are hidden.
--exclude-deps Hide call edges whose caller or callee comes from a dependency root (is_dep = 1). Requires a v4 or later database.

Both filters may be combined. Output format:

CallerFn -> CalleeFn (direct|indirect|ambiguous) at line N

Only call_edges are listed. Unresolved indirect call sites appear in call_sites but produce no line here unless an edge exists.

Examples

trace inspect /tmp/hdf.db calls --from NetIfSetAddr
trace inspect /tmp/hdf.db calls --from HdfSbufReadBuffer
trace inspect /tmp/hdf.db calls --to LiteNetSetIpAddr

When the full call graph is too large but you only care about a handful of functions (e.g. memory-related ones), pass a filter config and only edges whose caller or callee matches are printed. The database and analysis stay untouched; the filter is purely a display adapter.

{ "functions": ["malloc", "free", "calloc", "realloc", "memcpy", "memset"] }
trace inspect /tmp/hdf.db calls --callgraph-filter mem.json

For unresolved indirect calls, query SQL directly (see below).

trace inspect callgraph

Print the transitive callees or callers of the function containing a line.

trace inspect <DB> callgraph --file SUBSTR --line N [--depth N] [--direction down|up]
Option Description
--file <SUBSTR> File path substring to disambiguate same-name functions. / and \ are interchangeable.
--line <N> A line inside the function of interest.
--depth <N> Maximum BFS depth (default 3).
--show-lambdas Inspect the complete graph, including lambda intermediates.
--direction down = callees (default), up = callers.
--format Output format: text (default), json, graphviz, or mermaid.
--callgraph-filter <FILE> JSON file listing regex patterns over function names; edges whose caller and callee both fail to match are hidden, nodes left without any surviving edge are pruned. The start function (the root) is always kept even when it does not match, so the query anchor stays visible.

The start function is chosen among definitions whose [line_start, line_end] contains --line. Edges are labeled with their resolution (direct, indirect, external, ambiguous) and call-site locations; repeated callees print (see above; also file:line).

Downward callgraphs also show call sites without a resolved target as unresolved leaves labeled by their callee expression. These retain the call's source position and count separately from functions; they do not assert a callee identity. They are available from existing databases that retained the unresolved sites, without re-analysis.

Re-analyze existing databases to apply the C++ chained-call position and enclosing-scope lookup fixes. These preserve repeated methods in a chain and recover implicit calls whose class header is unavailable.

Examples

trace inspect /tmp/hdf.db callgraph --file devsvc_manager.c --line 120 --depth 2
trace inspect /tmp/hdf.db callgraph --file hdf_service_record.c --line 20 --direction up
trace inspect /tmp/hdf.db callgraph --file allocator.c --line 44 --callgraph-filter mem.json

trace inspect callchain

New v9 databases count a path such as ScheduleAbilityTransaction → lambda → HandleAbilityTransaction as one visible hop by default:

trace inspect graph.db callchain --from ScheduleAbilityTransaction --to HandleAbilityTransaction --depth 1

Use --show-lambdas to inspect the complete graph. Both callchain and callgraph support it in either direction and every output format. The existing public tables and views keep their master column layouts and expose the lambda-free graph; raw_* relations retain the complete analysis. Lambda-owned variables and flow ownership move to the enclosing non-lambda function. See the projection contract for provenance, execution contexts, and raw merging. Existing v7/v8 databases retain their stored graph; re-export or re-merge to obtain the lambda-free public interface.

Find all simple call paths (chains) between two functions no longer than --depth.

trace inspect <DB> callchain [--from FN|FILE:LINE] [--to FN|FILE:LINE] [--depth N] [--limit N]
Option Description
--from <FN> Start function name, C++ qualified suffix, or FILE:LINE (e.g. main or main.c:10).
--to <FN> Target function name, C++ qualified suffix, or FILE:LINE (e.g. target or worker.c:25).
--from-file <SUBSTR>, --from-line <N> File and line locating the start function.
--to-file <SUBSTR>, --to-line <N> File and line locating the target function.
--depth <N> Maximum path length in call hops (default 5).
--direction down = callers -> callees (default), up = callees -> callers.
--limit <N> Maximum number of chains to return (default 100, 0 for unlimited).
--format Output format: text (default), json, graphviz, or mermaid.
--callgraph-filter Path to JSON filter config file ({"functions": ["regex", ...]}).

Examples

trace inspect /tmp/trace.db callchain --from main --to target --depth 3
trace inspect /tmp/trace.db callchain --from main.c:10 --to target.c:20
trace inspect /tmp/trace.db callchain --from caller --to helper --format mermaid

trace inspect sequence

A bounded call sequence rebuilt from the call-order graphs a trace analyze --sequencing database records: one function body (every configuration variant side by side), the part of a body reachable from one call, or the blocks on paths between two calls together with their relation (sequenced_before, guaranteed_before, may_precede, may_follow, may_both, exclusive, unordered or unknown, with the conditions each claims). Callees are inlined up to --depth, each call returning to the event that made it; loops stay back edges. Unknown callees, bodies without a graph (dependency, declaration only), recursion, thread and task starts and IPC bridges are shown as boundaries, and a budget that cuts something leaves a truncated marker. A database analysed without --sequencing is rejected with an error naming the flag. Semantics and limits: Call sequencing.

trace inspect <DB> sequence (--function FN | --file SUBSTR --line N [--col C] [--callee NAME])
    [--to-file SUBSTR --to-line N [--to-col C] [--to-callee NAME]]
    [--depth N] [--max-events N] [--max-frames N] [--max-targets N] [--inline-contexts]
    [--format text|json|graphviz|mermaid]
Option Description
--function <FN> Function name, C++ qualified suffix, or FILE:LINE; --file narrows a name, and shows only the bodies compiled from or written in that file (/ and \ are interchangeable).
--file <SUBSTR>, --line <N> Position of the starting call: its spelling or its macro invocation. A call several configuration variants compile is one call, followed in each of them.
--col <C>, --callee <NAME> Pick one call when the line holds several (NAME or a ::NAME suffix).
--to-file, --to-line, --to-col, --to-callee The second call: show the paths between the two and report their relation.
--depth <N> Call levels inlined below the starting function (default 1).
--max-events <N> Events shown across all inlined bodies (default 200).
--max-frames <N> Function graphs shown, the starting ones included (default 32).
--max-targets <N> Targets of one call considered for inlining (default 4).
--inline-contexts Also inline the callbacks thread and task starts run; they stay unordered against the starter.
--format text (default), json, graphviz or mermaid.

In the text view, calls whose order the language leaves unspecified are grouped as { g(), h() } (order unspecified); ↺ marks a back edge or a recursive call, ?? an unknown callee and ⊘ an omitted body.

Examples

trace analyze tests/fixtures/call_sequence --sequencing -o /tmp/seq.db
trace inspect /tmp/seq.db sequence --function for_loop
trace inspect /tmp/seq.db sequence --file branches.c --line 10 \
    --to-file branches.c --to-line 12        # relation: exclusive
trace inspect /tmp/seq.db sequence --function args --format mermaid

trace inspect diagnostics

Read diagnostics saved during analysis without rerunning it or writing SQL. Both minimal and full exports include these records. When diagnostics exist, analyze prints their count and the command to inspect them.

trace inspect /tmp/trace.db diagnostics
trace inspect /tmp/trace.db diagnostics --stage preprocess --severity warning
trace inspect /tmp/trace.db diagnostics --file main.cpp --format json

Text output includes severity, pipeline stage, message, and the original source path and line when available. --stage and --severity match exactly; --file matches a literal path substring; / and \ are interchangeable, and on Windows an absolute existing spelling is canonicalized (8.3 short names expand to the stored long path). Filters combine, and records retain export order. Diagnostics for the whole run (such as a solver budget limit) have no source path and are omitted when filtering by file. JSON output is an array of objects with severity, file (nullable), line, message, and stage; no matches produce [] (text: No matching diagnostics.).

Some existing parse, IDL, and build-metadata diagnostics store their source path only inside the message. Use --stage to find these: --file matches the structured source path and therefore excludes them. See the corpus evaluation and root-cause investigation.

trace inspect dataflow

Show possible value flows from a source variable declaration, grouped by canonical function and global/file scope.

trace inspect <DB> dataflow --file SUBSTR --line N --col C [--depth N] [--direction down|up]
Option Description
--file <SUBSTR> File path substring; / and \ are interchangeable.
--line <N>, --col <C> Position near a source variable declaration. Synthetic intermediates are excluded.
--depth <N> Maximum visible transitions after collapsing technical nodes (default 3).
--direction down = where values flow (default), up = where they come from.
--format text (default), json, graphviz, or mermaid.

All formats retain numeric identities and omit call-site IDs. Text function headers list parameter positions, names, types, and variable IDs. Argument edges qualify cross-function parameters as dispatch::payload and identify the callee in pass argument [fn#29, argument 2]. Operations identify assignments, argument positions, returns, field access, pointer reads and writes, and indirect calls. Macro calls emphasize the invocation; text and diagrams retain the macro-body spelling. Text uses fixed indentation; diagrams group by scope. All formats use the same source-level graph. Text shows every transition selected by --depth and lists every possible callee once per call occurrence. Inspection loads the requested visible neighborhood and its supporting metadata on demand. Field labels identify abstract storage paths; call targets appear in separate lists.

These are context-insensitive possible flows. Separate call sites identify argument-to-parameter wiring; they do not represent separate executions or preserve correlations between argument pairs. Existing default-argument facts are not supplemented: omitted defaults currently can have no parameter flow, while explicit C++ nullptr arguments appear as null pointer values without points-to targets. Each query shows only the graph reachable from its selected variable: use a receiver downstream or its formal upstream to inspect receiver passing, and a nullable formal upstream to inspect null arguments. See the authoritative Source-level dataflow presentation for identity, traversal, provenance, and compatibility rules. The walk stays on the constraint edges; the memory edges that join a store to the loads of the same cell are followed by trace inspect slice.

Dataflow JSON contains title, direction (down or up), depth, truncated, scopes, nodes, and edges. The four scope description arrays (functions, globals, statics, values) are always present, unique, and sorted by numeric ID. Nodes and edges use typed scope references or null for unknown ownership. Every possible callee has a function description. Each operation has kind, expression, and location, plus its own callee_id when known. Null callee IDs are omitted; edges omit callee_id entirely. Argument operations include their original zero-based arg_index; null indices are omitted. Collapsed edges preserve their distinct recorded operations and callees. This changes the JSON contract: internal fields and the edge-level argument index are omitted. See Source-level dataflow presentation for field definitions, reference rules, and compatibility.

A dataflow edge in --format json:

{
  "from": 701,
  "to": 702,
  "scope": { "kind": "function", "id": 31 },
  "expression": "dispatch(message)",
  "location": { "path": "/project/main.cpp", "line": 38, "col": 5 },
  "operations": [
    {
      "kind": "pass argument",
      "expression": "dispatch(message)",
      "location": { "path": "/project/main.cpp", "line": 38, "col": 5 },
      "callee_id": 32,
      "arg_index": 0
    }
  ]
}

Examples

trace inspect /tmp/hdf.db dataflow --file can_test.c --line 33 --col 31
trace inspect /tmp/hdf.db dataflow --file usb_raw_io.c --line 331 --col 23 --depth 4

trace inspect slice

A bounded value slice from a variable or field access: up to where the value comes from, then down to where it goes. Each node lists the execution contexts that reach it, and edges where the value may change hands between threads, tasks or IPC requests are flagged as cross-context. A flag is a hint, not a proven race. Rules, output fields and limits: Value slice.

trace inspect <DB> slice --file SUBSTR --line N --col C [--name IDENT]
    [--up-depth N] [--down-depth N] [--format text|json]
Option Description
--file <SUBSTR>, --line <N>, --col <C> Position of a variable (declaration, use, or a call's argument: p in sink(p);) or of a field access (cb_ in cb_ = cb;; p after -> in s->p = p;, the other p being the variable). --file is a literal substring of the recorded path (% and _ are not wildcards; / and \ are interchangeable; on Windows an absolute existing spelling is canonicalized). The column is inside the identifier.
--name <IDENT> The identifier at the position, when the recorded source file cannot be read from here or the line moves several values.
--up-depth <N> Stage 1 limit: edges followed backwards to the sources.
--down-depth <N> Stage 2 limit: edges followed forwards from each source.
--format text (default, for people) or json (for tools).

Examples

trace analyze tests/fixtures/value_slice -o /tmp/slice.db
# `callback_` in `ICallback *cb = callback_;`: written by an IPC handler, read by a thread
trace inspect /tmp/slice.db slice --file value_slice/main.cpp --line 59 --col 25
trace inspect /tmp/slice.db slice --file value_slice/main.cpp --line 59 --col 25 --format json

Graph output formats

Both callgraph and dataflow accept --format text|json|graphviz|mermaid (text is the default). text is the indented view shown above; the other formats emit machine-readable graphs of the same traversal — same nodes, same edges, same depth limit and truncation semantics. Dataflow text shows every transition and every possible callee in the graph selected by --depth. trace inspect dataflow prints its candidate/fallback note: hints on stderr in every format.

All examples below run the same query on /tmp/hpp.db (tests/fixtures/hpp_designated_dispatch):

trace inspect /tmp/hpp.db callgraph --file hpp_designated_dispatch/launch.cpp --line 5 --depth 3

--format text (default)

callgraph from launch (launch.cpp:5-5) (callees, depth 3):
* launch (launch.cpp:5)
  -indirect-> DispatchToMessage (target.cpp:1) (launch.cpp:5)
2 functions, 1 edges

--format json — a single JSON document with title, direction, depth, truncated, summary, nodes, and edges:

{
  "title": "callgraph from launch (launch.cpp:5-5) (callees, depth 3):",
  "direction": "callees",
  "depth": 3,
  "truncated": false,
  "summary": "2 functions, 1 edges",
  "nodes": [
    {
      "id": 0,
      "depth": 0,
      "label": "launch (launch.cpp:5)",
      "detail": "launch.cpp:5"
    },
    {
      "id": 1,
      "depth": 1,
      "label": "DispatchToMessage (target.cpp:1)",
      "detail": "target.cpp:1"
    }
  ],
  "edges": [
    {
      "from": 0,
      "to": 1,
      "label": "indirect",
      "site": "launch.cpp:5"
    }
  ]
}

--format graphviz — a DOT digraph renderable with dot:

trace inspect /tmp/hpp.db callgraph --file hpp_designated_dispatch/launch.cpp --line 5 --depth 3 --format graphviz > call.dot
dot -Tsvg call.dot -o call.svg
digraph "callgraph from launch (launch.cpp:5-5) (callees, depth 3):" {
  rankdir="TB";
  node [shape=box];
  n0 [label="launch (launch.cpp:5)"];
  n1 [label="DispatchToMessage (target.cpp:1)"];
  n0 -> n1 [label="indirect (launch.cpp:5)"];
}

--format mermaid — a Mermaid flowchart for GitHub/Markdown or mmdc:

```mermaid
flowchart TD
  %% callgraph from launch (launch.cpp:5-5) (callees, depth 3):
  n0["launch (launch.cpp:5)"]
  n1["DispatchToMessage (target.cpp:1)"]
  n0 -->|"indirect (launch.cpp:5)"| n1
```

The same flag applies to dataflow:

trace inspect /tmp/hpp.db dataflow --file hpp_designated_dispatch/launch.cpp --line 5 --col 12 --format mermaid

Every format escapes special characters (quote/backslash for DOT, HTML entities for Mermaid, JSON via serde_json), so arbitrary C++ names and file paths stay valid input.

Analysis pipeline

discover .c/.cpp → preprocess → parse → lower IR → build PAG → solve → export SQLite
Stage What happens
Index Discover .c / .cpp files, preprocess TUs (custom preprocessor), parse with tree-sitter (C or C++ grammar per TU), lower to IR (functions, variables, flow constraints, call sites).
Analyze Build pointer assignment graph (PAG), run Andersen-style solver, resolve direct calls by name (including file-local static functions), indirect calls via points-to to function locations.
Export Write SQLite (minimal by default).

Analysis is may-analysis (sound over-approximation): if a call target is possible, it may appear as an edge.

Header-function identity and visibility follow the shared header function rules. Measured changes are recorded in the evaluation report.

Export modes

Mode Flags Database contents
Minimal (default) (none) analysis_run, files, functions, filtered call_sites, call_edges, arg_flow_edges, execution_contexts, PAG-referenced variables, flow graph (flow_nodes / flow_edges / flow_memory_access), diagnostics.
Full IR --full-export Minimal plus all types, all variables, PAG locations.
Points-to debug --debug-points-to Adds points_to and locations tables (and retains PAG during analysis). Use with --full-export for complete debug dumps.
Call sequencing --sequencing Adds the call-order graphs (cfg_* tables) to either mode above; without the flag those tables are empty. See call sequencing tables.

The flow-graph tables are always exported because trace inspect dataflow queries them directly.

Call site export filter

call_sites rows are written when any of the following holds:

  • The site has at least one call_edge.
  • The site has at least one arg_flow_edge.
  • The site is an indirect call (is_direct = 0), including unresolved function-pointer calls.
  • A call-order event names the site (--sequencing only), so every site trace inspect sequence shows can be joined.

So unresolved indirect sites (e.g. sbuf->impl->readBuffer before a fix) still appear in call_sites even with zero call_edges.

trace-merge

Merge multiple per-repository SQLite databases into a unified database, reconstructing the cross-repository callgraph without running static analysis or dataflow solvers during the merge stage.

trace-merge [OPTIONS] <INPUT_DBS>... [-o <OUTPUT_DB>]
Option Description
<INPUT_DBS>... Paths to per-repository SQLite databases generated by trace analyze.
-o, --output <PATH> Target unified SQLite database path. Default: unified.db.
-v, --verbose Print detailed diagnostics for all unresolved external functions and weak overrides. By default, collision warnings and summary counts are printed.

How it works:

  • Ingests and remaps files, link targets, functions, call sites, call edges, and execution contexts across input databases (an input exported before execution_contexts existed contributes none and is named in a MissingExecutionContexts diagnostic).
  • Keeps call_edges.id stable when unchanged input databases are added or reordered. IDs are nonnegative 63-bit integers; the first merge with this version replaces previous sequential IDs. Merger-only metadata preserves original target, function and call-site identities through later merges. Overlapping inputs such as A + merge(A, B) unify those rows before deduplicating edges, preserving call chains, execution contexts and sequencing. Other row IDs remain local to each output; see the identity contract and scope and metadata schema.
  • Identifies input snapshots by a SHA-256 content digest stored in database_identity, computing it read-only for older databases. Moving, renaming or copying a database preserves its merged edge IDs; copies with the same identity contribute once. See database identity.
  • Carries the call-order graphs of inputs analysed with --sequencing, remapped; a shared header body keeps one graph per distinct body, as trace analyze keeps configuration variants. options_json.call_sequencing is true when every input was sequenced, false when none was and "partial" otherwise, which trace inspect sequence reports; see the merger schema contract.
  • Shared header declarations deduplicate across link images; definitions retain each image's ownership and outgoing calls. Project-file ownership (is_dep = 0 in any input) propagates to all copies; see database merger header copies.
  • Re-links external call edges (functions.is_defined = 0 or call_edges.resolution = 'external') against matching exported definitions (is_defined = 1, linkage = 'external') from other repositories, updating edge resolution to direct or ambiguous, while preserving original non-direct resolutions (indirect and ipc).
  • May-analysis over-approximation: External calls retain edges to every selected definition, including each image's copy of a shared header body. Distinct source origins make the call ambiguous; shared-origin copies retain a resolved classification. Deduplicates call edges per call site to eliminate duplicate edges.
  • Keeps internal-linkage (static) functions file-scoped and preserves resolved definitions in known link images; see merge linking rules for weak-symbol precedence and ambiguous matches.
  • Uses normalized parameter signatures in functions.signature (name(type1, type2)) to disambiguate C++ overloads and avoid false collisions; falls back to all same-name candidates if exact signature matching misses.
  • Prevents accidental overwriting of any input database when specifying -o.
  • Opens inputs read-only and publishes through a unique temporary file beside the output. Failed merges clean up staging files and preserve the existing destination.
  • Merger output supports call graphs, call chains, and editor call hierarchy. It omits variables, arg-flow, points-to, and all PAG/provenance tables; call-site variable bindings remain NULL. Dataflow inspection requires an original analysis database or a new analysis of the combined source tree; see the merger schema contract.
  • The completion summary reports reconstructed IPC bridges and member calls. Even a single-input merge can recover inherited member calls absent from the source analysis; see merge linking rules.
  • Existing indirect and IPC edges are retained. New exports carry deduplicated declaration facts so the merger can recover cross-repository virtual overrides and IPC proxy/stub pairs without running pointer analysis. Names, type shapes and dispatch queries are shared through relational linking tables. Version-3 facts also preserve provider-specific final boundaries and guessed parameter types; version-1 JSON and version-2 tables remain readable. Inputs without linking facts produce an incomplete-reconstruction diagnostic; merged outputs retain facts for later merges. See merge linking rules and the optional metadata schema. New targets that require cross-project pointer propagation remain outside the merge contract.
  • Identifies and reports merge problems:
    • Collisions: Multiple strong definitions of the same symbol and signature from distinct source origins across different repositories (MultipleDefinitions).
    • Unresolved externals: External function calls that remain unresolved in all merged repositories (UnresolvedExternal).
    • Weak symbol overrides: Weak definitions superseded by strong definitions across repositories (WeakOverride, scoped to cross-repository overrides).
    • Inputs without execution contexts: Inputs that have no execution_contexts table (MissingExecutionContexts).
    • Inputs without call sequencing: Inputs analysed without --sequencing when another input was (MissingSequencing).

Cross-project analysis with framework sources

Prefer separate indexing and trace-merge when the framework/service implementation is available. Each repository contributes its function bodies, and the combined declaration facts recover possible cross-project member and IPC paths. The DataShare OpenFile rule is opt-in and is unnecessary for this workflow. Analyze these inputs without that fallback: merging retains summary edges already present in an input database.

For example, with media-library and DataShare source checkouts:

cargo build --release -p trace-cli -p trace-merge

# Index each repository's implementations, without the DataShare summary.
target/release/trace analyze /path/to/multimedia_media_library \
  --jobs 8 --ignore-logging -o /tmp/media.db
target/release/trace analyze /path/to/distributeddatamgr_data_share \
  --jobs 8 --ignore-logging -o /tmp/datashare.db

# Reconstruct calls and IPC bridges from the combined source facts.
target/release/trace-merge /tmp/media.db /tmp/datashare.db -o /tmp/combined.db

# Include enough depth for the helper/controller/proxy/stub route.
target/release/trace inspect /tmp/combined.db callchain \
  --from 'OHOS::Media::MediaLibraryManager::OpenAsset' \
  --to 'OHOS::AbilityRuntime::MediaDataShareExtAbility::OpenFile' --depth 10 --limit 1

These commands work on bare checkouts. Supply each project's matching --compile-commands and --include paths when available to improve declaration and receiver resolution. Add further projects by analyzing them into their own databases and passing those databases to trace-merge too.

A framework whose implementation you want to navigate needs its own analysis database. --dep supplies declarations from external headers; its function bodies and source files are excluded from that analysis. Merged databases support call-graph navigation; keep the original analysis databases for argument/value-flow queries. See the merge contract.

Missing-framework fallbacks

When only SDK/dependency headers are available, use --include and --dep to supply type, inheritance and function declarations. When an unavailable implementation has known behavior, an explicit --models file can summarize memory operations, callbacks, accessor getters or an IPC boundary. Built-in libc and callback models load automatically; the DataShare OpenFile shortcut does not.

For a bodyless framework accessor such as ops_t *get_ops(Driver *d), use return_field to connect the result to the named member of each caller's object. The same model handles a getter that returns &d->ops when the member is an ops_t and a getter that loads d->ops when the member is an ops_t *.

[[model]]
name = "get_ops"
effects = [ { kind = "return_field", param = 0, field = "ops" } ]

The getter must declare a pointer-like return type. An indexed body suppresses the model, and a null literal in the modeled argument contributes no field flow. For argument numbering and member lookup, see the modeling recipes.

For a media-only analysis with indexed provider implementations, save this optional fallback as datashare-fallback.toml:

[[model]]
name = "OHOS::DataShare::DataShareHelper::OpenFile"
effects = [
  { kind = "ipc", target = "OHOS::DataShare::DataShareStub::OpenFile" }
]
target/release/trace analyze /path/to/multimedia_media_library \
  --models datashare-fallback.toml --jobs 8 --ignore-logging -o /tmp/media.db

This connects a bodyless helper to eligible stub implementations already indexed in the media project. It conservatively retains possible providers and overloads; URI routing and parcel/value flow remain unmodeled. Use the source-backed workflow when the framework can be indexed. Re-analyze previously modeled inputs without the DataShare fallback to obtain that source-backed view.

Matching, body/override precedence and disabling rules are specified in DataShare sources and fallbacks.

SQLite database schema

A callable constructed by std::bind can appear as a Bound location in debug exports. Its argument-flow rows are attached to the call site that invokes it. See Bound callables.

Minimal and full databases record indirect callee and return-destination variable IDs in call_sites.callee_var and call_sites.return_dst. Export uses indexed SQLite joins for indirect-return provenance, building the required indexes before that export phase. See the call-site schema for bindings and index rules.

SQLite export also builds a function-range index for operation ownership lookup during source-level dataflow inspection; see the inspection index rules.

Schema version: v9; readers also support v7 and v8. Public relations are lambda-free, with complete analysis retained in raw_*; see the projection contract. Repeated names, call and operation expressions, and graph text are stored once in a shared dictionary; the existing query columns are exposed through read-only views (see compact text storage). Each version is an additive compatibility family. Readers check required structures and database origin rather than infer available capabilities from the number alone; see the version and capability contract. Optional flow_call_origins and flow_call_expressions metadata improves exact occurrence attribution and call text; older v7 analysis exports retain fallback behavior. Re-analysis supplies new metadata and selective-query indexes. trace-merge accepts v7, v8 and v9 inputs with the required call-graph columns, rejects v6 or missing required structures before writing output, and produces a call-graph database without PAG/provenance data. Foreign keys are declared in DDL; exports temporarily disable FK enforcement for bulk load speed. Macro-body calls use their definition spelling in call_sites.file_id/line/col; nullable expansion_file_id/expansion_line/expansion_col retain the outermost invocation. flow_nodes stores empty labels/details for variable nodes to save space; the flow_nodes_text view reconstructs them for direct queries. flow_edges rows carry no position: flow_origins records where each edge's operation is written (original file, line and column, one row per statement), and the enclosing function follows from that position (see Where a value moves). flow_memory_access records which memory cells each load and store reaches (its sites are that load's or store's flow_origins rows), or that none are recorded (Memory access edges); an earlier v7 export has no such table and trace-merge output leaves it empty. execution_contexts lists where threads, tasks and IPC requests start running code — one row per resolved callback of an invoke model that starts one (not std::bind or std::packaged_task, which only wrap a callable; pthread_create, std::thread, ffrt::submit, EventHandler::PostTask, HdfWorkInit, ...), with the model's name and the receiver variable it was submitted on when named, and one per entry no call site starts (an override of Thread::Run, EventHandler::ProcessEvent or DeathRecipient::OnRemoteDied; an IPC stub handler) — with its kind (thread, pool_task, serial_task, ipc_handler, unknown) and multi-instance evidence (loop, cycle, parent, unknown; see Execution contexts); an earlier v7 export has no such table. The cfg_* tables hold the per-function call-order graphs trace analyze --sequencing records (empty otherwise; analysis_run.options_json.call_sequencing says which), read by trace inspect sequence; see call sequencing tables.

Entity relationship (overview)

analysis_run
link_targets ─┬─ target_sources → files
              └─ target_dependencies → link_targets
files ─┬─ functions ─┬─ call_sites ─ arg_flow_edges → variables
       │             │  (target_id → link_targets)
       │             ├─ call_edges → functions (caller and callee)
       │             ├─ execution_contexts → functions, call_sites, variables
       │             └─ cfg_functions ─ cfg_blocks ─ cfg_events ─ cfg_event_sites → call_sites
       │                (--sequencing; cfg_edges, cfg_event_order, cfg_gaps)
       └─ variables ─ flow_nodes ─ flow_edges → flow_nodes
                    (fn_id → functions, type_id → types,
                     target_id → link_targets)
types
locations (full export / debug)
points_to (debug only)
diagnostics

Table reference

Every table, column and index is documented once, in docs/SQLITE_SCHEMA.md — including which tables each export mode writes, and the is_weak / target_id columns and link_targets tables added in v5. It is the canonical description; this file keeps only the overview above so the two cannot drift.

Example SQL queries

Callees of a function

SELECT callee.name, ce.resolution, cs.line, cs.callee_text
FROM call_edges ce
LEFT JOIN call_sites cs ON cs.id = ce.call_site_id
JOIN functions caller ON caller.id = ce.caller_fn_id
JOIN functions callee ON callee.id = ce.callee_fn_id
WHERE caller.name = 'HdfSbufReadBuffer';

Unresolved indirect call sites

SELECT caller.name, cs.line, cs.callee_text
FROM call_sites cs
JOIN functions caller ON caller.id = cs.caller_fn_id
LEFT JOIN call_edges ce ON ce.call_site_id = cs.id
WHERE cs.is_direct = 0 AND ce.id IS NULL
ORDER BY caller.name, cs.line;

All indirect resolutions for a call expression pattern

SELECT caller.name, callee.name, cs.line
FROM call_edges ce
JOIN call_sites cs ON cs.id = ce.call_site_id
JOIN functions caller ON caller.id = ce.caller_fn_id
JOIN functions callee ON callee.id = ce.callee_fn_id
WHERE ce.resolution = 'indirect'
  AND cs.callee_text LIKE '%readBuffer%';

Callers of a function

SELECT caller.name, ce.resolution, cs.line
FROM call_edges ce
LEFT JOIN call_sites cs ON cs.id = ce.call_site_id
JOIN functions caller ON caller.id = ce.caller_fn_id
JOIN functions callee ON callee.id = ce.callee_fn_id
WHERE callee.name = 'LiteNetSetIpAddr';

Argument flow at a call site (variable actuals)

SELECT cs.line, af.arg_index, av.name AS actual, fv.name AS formal
FROM arg_flow_edges af
JOIN call_sites cs ON cs.id = af.call_site_id
JOIN variables av ON av.id = af.actual_var_id
JOIN variables fv ON fv.id = af.formal_var_id
WHERE af.actual_var_id IS NOT NULL;

Argument flow (function-pointer actuals)

SELECT cs.line, af.arg_index, f.name AS actual_fn, fv.name AS formal
FROM arg_flow_edges af
JOIN call_sites cs ON cs.id = af.call_site_id
JOIN functions f ON f.id = af.actual_fn_id
JOIN variables fv ON fv.id = af.formal_var_id
WHERE af.actual_fn_id IS NOT NULL;

Where threads and tasks start

SELECT e.kind, entry.name AS entry, e.model, caller.name AS started_in, cs.line,
       queue.name AS submitted_on, e.multi_instance, e.self_concurrent
FROM execution_contexts e
JOIN functions entry ON entry.id = e.entry_fn_id
LEFT JOIN call_sites cs ON cs.id = e.call_site_id
LEFT JOIN functions caller ON caller.id = cs.caller_fn_id
LEFT JOIN variables queue ON queue.id = e.receiver_var_id
ORDER BY e.kind, entry.name;

Project layout

crates/
  trace-preproc/   Custom C preprocessor (#include, #define, conditionals)
  trace-parse/     tree-sitter parsing, IR lowering, TU merge
  trace-ir/        Shared IR (types, symbols, flow constraints)
  trace-analysis/  PAG construction, Andersen solver, call graph
  trace-db/        SQLite schema and export
  trace-capi/      C ABI wrapper library (`libtrace_capi`) and C header (`trace.h`)
  trace-cli/       `trace` binary (`analyze`, `inspect`)
  trace-merge/     Cross-repository database merger & callgraph reconstruction (`trace-merge`)
docs/              Design docs (architecture, analysis, preprocessor, schema)
tests/fixtures/    Integration test C corpora

Limitations

  • C++ first step — namespaces (qualified variables and static data members included; see Canonical variable identity), overloads (arity), classes/virtual dispatch (including virtual bases), final class/method devirtualization, ctors/dtors (constructors also for objects built by std::make_shared / std::make_unique / sptr<T>::MakeSptr; see Factory construction; member-initializer construction retains aggregate subobjects, constant and unknown array bounds, default initialization after inherited construction, cv/ref constructor distinctions and implicit copy/move subobject calls, following constructor declarations and reference-binding rules under Ctors / dtors), implicit this->method(), smart-pointer unwrap through a declared operator-> (shared_ptr, and OHOS sptr/RefPtr or HDI AutoPtr alike, the wrapper keeping its own members for .) or, for a wrapper whose body is not in the tree, through its single class argument, bodyless std::shared_ptr<T>::get() / std::unique_ptr<T>::get() pointee aliases (see Smart-pointer unwrap), auto locals typed from declared return types and smart-pointer factories (including parenthesized single-expression initializers such as auto self(shared_from_this());, see C++ parse-input normalization), and callables (std::function, lambdas, operator()) are modeled; type-based overload ranking and templates beyond name-stripping are not (see C++ support). Next slices from hiview: docs/CPP_ROADMAP.md.
  • May-analysis — indirect calls can list multiple targets; absence of an edge does not prove unreachability.
  • IDL subset — service IDL and HDI omitted-return methods are supported for C++ IPC declarations. Imported type layouts and generator options are not reconstructed; unsupported syntax and generated-header collisions remain visible as diagnostics. See IDL-generated interfaces for the supported mappings and limits.
  • No path sensitivity — all branches and paths are merged.
  • Preprocessor subset — not gcc/clang compatible for all extensions. Vendor macros such as __GNUC__ / __clang__ require opt-in --compiler-predefines; --system-includes imports only selected target and hosted-mode macros from the compiler. Without either discovery flag, only the language's own __cplusplus / __STDC__ / __STDC_VERSION__ are predefined; see docs/PREPROCESSOR.md.
  • Build environment — with --system-includes, compiler probing locates installed standard-library headers and selected target macros, but does not supply missing SDK or generated headers. Supply additional roots with --dep / --include as needed. Other compiler-specific builtins and response files are not modeled.
  • Canonical system headers — --canonical-system-headers preprocesses the tree's standard includes once, in one bare-tree configuration, lowers them to one prelude per language and merges it into the final program once. Every preprocessing run starts from the prelude's macros, and an include of a header the prelude read contributes nothing, so translation units never hold standard text and project headers keep the default sharing rules. Conditional variants and per-unit standard declarations may differ from full system-header indexing, and standard-library typing is not available while a translation unit is lowered. On ability_ability_runtime it takes about 3.5% longer than default indexing, with the same peak memory; see the canonical system-header prelude and measurements. Ignored with configured indexing.
  • Configuration coverage — without database entries or --explore, indexing uses one inferred configuration. A name no -D or reached #define binds resolves to 0 in #if; use conditional coverage reporting to measure exclusions in a selected configuration. Explicit database commands are all merged; exploratory configurations remain bounded by --explore-budget.
  • Original line attribution — entities use original source positions through the preprocessor's LineMap. See Call source locations for macro-body spelling and invocation positions, and Shared header functions for header identity and ownership.

Further reading

Contributing

See CONTRIBUTING.md for development setup, testing, and pull-request guidelines, and CODE_OF_CONDUCT.md for our community standards.

License

This project is licensed under the MIT License.

About

Static analysis for C/C++ codebases with call graphs, pointer analysis, indirect-call resolution, and interprocedural data-flow tracing.

Resources

Code of conduct

Contributing

Stars

11 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages