Purpose
Generate function-level execution traces that show:- Function entry and exit events
- Call stack depth
- Execution timeline
- Thread-level information
Invocation
Invoked by the crash-analysis-agent as part of the crash analysis workflow. Receives:- Code repository path
- Working directory path
- Crashing example program and build instructions
traces/ subdirectory in working directory
Workflow
Rebuild Target with Instrumentation
Add instrumentation flags to the build:CMake:Makefile:
- Add
-finstrument-functions -gto CFLAGS - Add
-L<path-to-libtrace> -ltrace -ldl -lpthreadto LDFLAGS
Instrumentation Details
The-finstrument-functions flag causes the compiler to insert calls to:
libtrace.so to log:
- Function address
- Timestamp (nanosecond precision)
- Thread ID
- Entry/exit event type
Trace File Format
Raw trace files (trace_<tid>.log) contain:
- [N]: Event sequence number
- [timestamp]: Nanoseconds since start
- Dots: Call depth visualization
- [ENTRY/EXIT]: Event type
- Function name: Resolved from debug symbols
Perfetto Format
The Perfetto JSON format enables visualization at ui.perfetto.dev:Validation
After generating traces, validate: Example validation:Usage in Crash Analysis
The crash-analyzer-agent uses function traces to:- Verify execution path: Confirm hypothesized functions were actually called
- Track control flow: Follow execution from entry to crash
- Identify missing functions: Detect functions that should have been called but weren’t
- Correlate with coverage: Cross-reference with gcov data
Performance Impact
Recommendations:- Use only for crash reproduction, not production
- Limit trace duration to necessary execution
- Consider filtering high-frequency functions if needed
Troubleshooting
No trace files generated
No trace files generated
- Check
LD_LIBRARY_PATHincludes libtrace.so directory - Verify program actually executed (didn’t fail immediately)
- Check write permissions in current directory
Empty or incomplete traces
Empty or incomplete traces
- Program may have crashed before trace buffer flushed
- Increase buffer size in trace_instrument.c
- Add explicit flush before crash-prone code
Function names show as addresses
Function names show as addresses
- Missing debug symbols (-g flag)
- Stripped binary
- Use
addr2lineornmto resolve manually
Trace files too large
Trace files too large
- Filter out high-frequency functions
- Limit tracing to specific code sections
- Use sampling instead of full instrumentation
Output Structure
Related Agents
Crash Analysis
Main crash analysis orchestrator
Coverage Analyzer
Complementary coverage data generation