SuperAPI AI Directory

code-problem-analyzer

Coding & development

View repository

Updated 10-16 07:28

About this skill

Code Problem Analyzer

Prerequisites

When using this skill, the user must provide the following information:

Required Information

  1. Problem Background

    • Expected behavior: what should happen
    • Actual phenomenon: what actually happened
  2. 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

  1. Carefully read the problem background and clarify the difference between the expected behavior and the actual phenomenon
  2. Identify key information: commands, logs, error messages, configuration-related items
  3. 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 grep to search for key functions, parameters, and flags
  • Use read to 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:

  1. Code logic errors: conditional judgments, loops, state transitions, etc.
  2. State management problems: state is not correctly initialized, cleaned up, or synchronized
  3. Configuration problems: wrong configuration source, confused priorities, cache invalidation
  4. Timing problems: asynchronous operations, race conditions, callback order
  5. 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:

  1. Strength of evidence: how much code and logs support this hypothesis
  2. Logical soundness: whether this cause can explain all observed phenomena
  3. Probability of occurrence: whether this type of problem is common in actual development
  4. 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:

  1. Multiple possible root causes: When a unique root cause cannot be determined
  2. Missing key information: More logs or configuration information are needed
  3. 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

  1. Start from key parameters: If the user mentions a parameter or flag, search for it first
  2. Trace the call chain: Start from the entry point and go deeper layer by layer
  3. Focus on state changes: Find where state variables are set, read, and modified
  4. Find conditional checks: Conditional branches are usually the key points of the problem

Code reading techniques

  1. Read the function signature and comments first: Understand the function's inputs, outputs, and purpose
  2. Focus on key logic: Conditional checks, loops, state transitions
  3. Trace the data flow: How variables are passed and modified
  4. Understand the context: In what scenarios the function is called

Build a flowchart

  1. Start from the user command: This is the clearest entry point
  2. Mark key decision points: Conditional checks, state checks
  3. Record state changes: How variable values change
  4. Annotate file locations: Mark the file and line number for each step

Verify assumptions

  1. Check all observed phenomena: Can the assumption explain all phenomena
  2. Look for counterexamples: Is there evidence that contradicts the assumption
  3. Consider edge cases: Does the assumption hold under special circumstances
  4. 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: