360 Secure SkillHub
360 安全技能中心

OpenClaw Debugging Assistant

调试辅助 Skill:解析错误日志、建议断点并追踪函数调用以定位根因,支持 Python 错误模式与可选 C/C++ 分析;文件列表仅含统一入口脚本,SKILL 列出的 error_analyzer.py 和 tracer.py 未出现。

michealxie001
michealxie001
热度 43.75
最近更新 2026-05-11 17:39:22
分类:开发依赖:代码执行 / 读写文件应用场景:调试排错

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add oc-debugging
Metadata
name
debugging
description
Debugging assistant. Analyzes error logs, suggests breakpoints, traces execution flow, and helps identify root causes of issues.

Debugging Assistant

调试助手,分析错误日志、建议断点、追踪执行流程、帮助识别问题根因。

Version: 1.1
Features: 错误分析、断点建议、执行追踪、根因分析、C/C++ 支持 (NEW)


Quick Start

1. 分析错误日志

# 分析 Python 错误
python3 scripts/main.py analyze-error "Traceback (most recent call last):..."

# 从文件分析
python3 scripts/main.py analyze-error --file error.log

2. 建议断点

# 为代码建议断点位置
python3 scripts/main.py suggest-breakpoints --file src/main.py

# 针对特定函数
python3 scripts/main.py suggest-breakpoints --function process_data

3. 追踪执行

# 追踪函数调用
python3 scripts/main.py trace --file src/app.py --function handle_request

Commands

命令 说明 示例
analyze-error 分析错误 analyze-error "Traceback..."
suggest-breakpoints 建议断点 suggest-breakpoints --file src.py
trace 追踪执行 trace --file src.py --function foo

Error Analysis

Python Traceback 分析

$ python3 scripts/main.py analyze-error "Traceback (most recent call last):
  File 'src/auth.py', line 45, in login
    user = db.get_user(username)
  File 'src/db.py', line 23, in get_user
    cursor.execute(query, (username,))
psycopg2.OperationalError: connection closed"

🔍 Error Analysis
=================

Type: Database Connection Error
Severity: 🔴 High

Root Cause:
The database connection was closed before executing the query.

Possible Causes:
1. Connection pool exhaustion
2. Connection timed out
3. Database server restart

Suggested Fixes:
1. Check connection pool settings
2. Implement connection retry logic
3. Add connection health checks

File: src/db.py:23
Function: get_user

常见错误模式

自动识别:

  • ImportError / ModuleNotFoundError - 导入问题
  • AttributeError - 属性访问错误
  • KeyError / IndexError - 数据访问错误
  • TypeError - 类型错误
  • ConnectionError - 网络/连接错误
  • TimeoutError - 超时错误

Breakpoint Suggestions

$ python3 scripts/main.py suggest-breakpoints --file src/payment.py

🔍 Breakpoint Suggestions
=========================

High Priority:
  Line 45: process_payment() - Entry point
  Line 67: validate_card() - Validation logic
  Line 89: charge_customer() - External API call

Medium Priority:
  Line 34: calculate_total() - Business logic
  Line 56: apply_discount() - Conditional logic

Tips:
- Set breakpoints before external API calls
- Watch variables: amount, currency, customer_id

Execution Tracing

$ python3 scripts/main.py trace --file src/api.py --function handle_request

🔍 Execution Trace
==================

Function: handle_request
File: src/api.py:23

Call Graph:
handle_request
├── authenticate_user
│   └── verify_token
├── validate_request
│   └── check_schema
├── process_data
│   ├── fetch_from_db
│   └── cache_result
└── format_response

Potential Issues:
- No error handling in process_data
- External call to fetch_from_db (line 67)

Configuration

.debugging.json:

{
  "breakpoints": {
    "before_external_calls": true,
    "before_conditionals": true,
    "in_error_handlers": true
  },
  "error_patterns": {
    "ignore": ["DeprecationWarning"],
    "highlight": ["SecurityError", "DataLossError"]
  }
}

Examples

场景 1:排查崩溃问题

# 1. 复制错误信息
python3 main.py analyze-error "$(cat error.log)"

# 2. 根据分析设置断点
python3 main.py suggest-breakpoints --file src/crash_point.py

# 3. 追踪相关函数
python3 main.py trace --function problematic_function

场景 2:性能问题排查

# 追踪执行路径
python3 main.py trace --file src/slow_endpoint.py --function handler

# 识别冗余调用

场景 3:API 错误调试

# 分析 API 错误响应
python3 main.py analyze-error "HTTP 500: Internal Server Error"

# 检查 API 处理代码
python3 main.py suggest-breakpoints --file src/api/handlers.py

Files

skills/debugging/
├── SKILL.md                    # 本文件
└── scripts/
    ├── main.py                 # ⭐ 统一入口
    ├── error_analyzer.py       # 错误分析器
    └── tracer.py               # 执行追踪器

Roadmap

  • Python error analysis
  • JavaScript error analysis
  • Interactive debugger integration
  • Log file monitoring