This document provides example workflows for common use cases.
Your program crashes and you want to understand why.
- Start the interactive shell:
./compiler-copilot.sh- Analyze the crash:
copilot> analyze crash myprogram --core core.12345
The AI will:
- Load the core dump
- Extract backtrace, registers, and local variables
- Provide an analysis of the likely cause
- Suggest areas to investigate
- Start an interactive debug session:
copilot> debug myprogram --debugger gdb
- Set breakpoints and run:
copilot> breakpoint main
copilot> run
- Ask for help:
copilot> explain what's happening at this breakpoint
You suspect a compiler optimization is causing unexpected behavior.
- Generate IR at different optimization levels:
copilot> generate ir mycode.c --opt O0
copilot> generate ir mycode.c --opt O2
- Identify which pass caused the change:
copilot> identify pass mycode.c
The AI will:
- Compare IR at different optimization levels
- Identify which passes made significant changes
- Explain what each pass did
- Get detailed explanation:
copilot> explain the loop unrolling optimization in my code
A customer reports an issue, and you need to create a minimal test case.
- Describe the issue to the AI:
copilot> generate test for: segmentation fault when accessing array out of bounds in a loop
- The AI generates a test case:
#include <stdio.h>
int main() {
int arr[10];
// This will cause a segfault
for (int i = 0; i <= 10; i++) {
arr[i] = i;
}
return 0;
}- Compile and verify:
copilot> compile test.c with debug info
copilot> debug test
copilot> run
You want to understand what assembly code the compiler generates.
- Generate assembly:
copilot> generate assembly mycode.c --opt O2
- Ask for explanation:
copilot> explain the assembly code for function calculate_sum
- Compare different optimization levels:
copilot> generate assembly mycode.c --opt O0
copilot> generate assembly mycode.c --opt O3
copilot> explain the differences between O0 and O3 assembly
You've identified a bug and want help fixing it.
- Analyze the problematic code:
copilot> suggest fix for buggy_function.c
Describe the issue:
The function crashes when input is NULL
- Review the suggested fix: The AI will:
- Analyze the code
- Identify the root cause
- Suggest a fix with explanation
- Provide the corrected code
- Apply the fix (if you agree):
copilot> apply fix to buggy_function.c
Step-by-step debugging with AI assistance.
- Start debugging:
copilot> debug myprogram --debugger lldb
- Set breakpoints:
copilot> breakpoint process_data
copilot> breakpoint error_handler
- Run and analyze:
copilot> run
copilot> show me the backtrace and explain what's happening
- Inspect variables:
copilot> print all local variables and explain their values
- Step through code:
copilot> step through the next 5 lines and explain each one
Understand why your code isn't being optimized as expected.
- Get optimization remarks:
copilot> analyze optimization remarks for mycode.c at O2
- Generate and compare IR:
copilot> generate ir mycode.c --opt O0
copilot> generate ir mycode.c --opt O2
copilot> explain what optimizations were applied
- Ask specific questions:
copilot> why wasn't my loop vectorized?
copilot> how can I make this code more optimization-friendly?
You can also use natural language:
copilot> I have a segfault in my program, can you help me debug it?
copilot> Show me the LLVM IR for main.c and explain what the optimizer did
copilot> My program is slow, analyze the assembly and suggest improvements
copilot> Create a test case that reproduces a use-after-free bug
copilot> Why is my loop not being unrolled by the compiler?
- Be specific: The more context you provide, the better the AI can help
- Use the status command: Check your current session state with
status - Combine commands: You can chain operations in natural language
- Save important output: The shell maintains history, but save critical findings
- Iterate: Use follow-up questions to dig deeper into issues
You can create scripts with multiple commands:
# debug_script.txt
debug myprogram
breakpoint main
run
backtrace
info locals
continueThen run:
copilot> execute script debug_script.txt
Use Compiler Copilot in automated workflows:
./compiler-copilot.sh --batch << EOF
analyze crash $PROGRAM --core $CORE_FILE
generate report crash_analysis.md
EOF