Prerequisites
When using this skill, the user must provide the following information:
Required Information
-
Problem Background
- Expected behavior: what should happen
- Actual phenomenon: what actually happened
-
Problem-related information
- Relevant logs (if any)
- Commands executed
- Crash stack or error message
- Configuration information (if relevant)
Analysis Flow
Step 1: Understand the Problem
- Carefully read the problem background and clarify the difference between the expected behavior and the actual phenomenon
- Identify key information: commands, logs, error messages, configuration-related items
- Determine the analysis focus: whether it is an execution flow problem, a state problem, or a configuration problem
Step 2: Code Exploration
Based on the problem type, use the following strategies to explore the code:
Execution Flow Problems:
- Start tracing from the user command or entry point
- Use
grepto search for key functions, parameters, and flags - Use
readto read key files and understand the call chain - Track the passing and modification of key variables
State Management Problems:
- Search for state-related variables and functions (such as
isDebugApp、isStartWithDebug) - Find the locations where state is set and read
- Analyze the lifecycle and cleanup logic of the state
Configuration Problems:
- Find configuration-related code (such as
GetBoolParam、GetApplicationInfo) - Analyze the sources and priorities of the configuration
- Check the caching and update mechanisms of the configuration
Step 3: Build a Flowchart
During the analysis process, build a clear execution flow:
入口点 → 函数A → 函数B → 关键决策点 → 结果
For each key point, record:
- File path and line number
- Function name and key code snippets
- State changes or conditional judgments
Step 4: Identify Possible Root Causes
Based on the flow analysis, list all possible causes of the problem:
- Code logic errors: conditional judgments, loops, state transitions, etc.
- State management problems: state is not correctly initialized, cleaned up, or synchronized
- Configuration problems: wrong configuration source, confused priorities, cache invalidation
- Timing problems: asynchronous operations, race conditions, callback order
- Boundary conditions: null pointers, out-of-bounds, unhandled exceptional cases
Step 5: Determine the Most Likely Root Cause
Rank the possible causes according to the following criteria:
- Strength of evidence: how much code and logs support this hypothesis
- Logical soundness: whether this cause can explain all observed phenomena
- Probability of occurrence: whether this type of problem is common in actual development
- Scope of impact: Does this cause involve all the key points mentioned by the user
Step 6: Pause when user confirmation is needed
If the following situations exist, use the question tool to pause and ask the user:
- Multiple possible root causes: When a unique root cause cannot be determined
- Missing key information: More logs or configuration information are needed
- Need to verify assumptions: The user needs to test or check specific conditions
Example question:
question:
questions:
- question: "我发现了两个可能的原因:[原因1] 和 [原因2]。为了进一步确认,请提供:"
header: "需要更多信息"
options:
- label: "检查配置文件"
description: "查看应用配置文件中的 debug 字段值"
- label: "查看完整日志"
description: "提供应用启动的完整日志"
- label: "检查等待调试列表"
description: "运行 aa appdebug get 命令查看等待调试状态"
Output format
Standard output
## 问题分析结果
### 所有可能的流程
1. **流程1**: [流程描述]
- 文件:file.cpp:行号 - [关键代码片段]
- 文件:file.cpp:行号 - [关键代码片段]
- ...
2. **流程2**: [流程描述]
- 文件:file.cpp:行号 - [关键代码片段]
- ...
### 最有可能的根因
**根因**: [明确的根因描述]
**原因解释**:
- [解释1]
- [解释2]
- [关键代码位置]: file.cpp:行号
**建议的解决方案**:
1. [解决方案1]
2. [解决方案2]
### 需要进一步确认
[如果需要,说明需要用户做什么]
Concise output (if the problem is clear)
## 问题分析结果
### 最有可能的根因
**根因**: [明确的根因描述]
**原因**: [简短解释]
**关键代码位置**: file.cpp:行号
**解决方案**: [具体操作步骤]
Best practices
Code search strategy
- Start from key parameters: If the user mentions a parameter or flag, search for it first
- Trace the call chain: Start from the entry point and go deeper layer by layer
- Focus on state changes: Find where state variables are set, read, and modified
- Find conditional checks: Conditional branches are usually the key points of the problem
Code reading techniques
- Read the function signature and comments first: Understand the function's inputs, outputs, and purpose
- Focus on key logic: Conditional checks, loops, state transitions
- Trace the data flow: How variables are passed and modified
- Understand the context: In what scenarios the function is called
Build a flowchart
- Start from the user command: This is the clearest entry point
- Mark key decision points: Conditional checks, state checks
- Record state changes: How variable values change
- Annotate file locations: Mark the file and line number for each step
Verify assumptions
- Check all observed phenomena: Can the assumption explain all phenomena
- Look for counterexamples: Is there evidence that contradicts the assumption
- Consider edge cases: Does the assumption hold under special circumstances
- Evaluate the scope of impact: Does the assumption involve all the key points mentioned by the user
Common problem patterns
State management issues
- Using state before it is initialized
- State updates are not synchronized to related components
- Incomplete state cleanup causes residue
- Multiple places modify the same state, causing inconsistency
Configuration issues
- Unclear configuration source (command-line arguments vs configuration file vs default values)
- Confusing configuration priority
- Configuration cache is not updated in time
- Missing configuration validation
Timing issues
- Asynchronous operations are not awaited correctly
- Callback function execution order does not match expectations
- Event trigger timing is wrong
- Improper timing for resource release
Reference materials
For a more detailed analysis methodology, please refer to:
- ANALYSIS_METHODOLOGY.md - In-depth code analysis methods
- OUTPUT_FORMAT.md - Output format specifications and examples