본문으로 건너뛰기
cccskills
무료GitHub에 공개

state-snapshot-instrumenter

Instrument programs (Python, C/C++, Java) to capture snapshots of key program states at runtime, including variables, memory, and call stacks. Use when you need to debug complex issues, reproduce test cases, prepare traces for formal verification, or analyze program execution. Supports manual instrumentation points, automatic function/method instrumentation, and conditional triggers. Outputs structured JSON snapshots for debugging, replay, and verification workflows.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

설치 방법 보기

포함된 파일(16)

  • SKILL.md8.7 KB
  • assets/example_c.c445 B
  • assets/example_java.java553 B
  • assets/example_python.py422 B
  • assets/snapshot_schema.json3.0 KB
  • references/instrumentation_guide.md6.2 KB
  • references/snapshot_format.md5.6 KB
  • references/use_cases.md8.1 KB
  • scripts/analyze_snapshots.py6.0 KB
  • scripts/instrument_c.py5.3 KB
  • scripts/instrument_java.py4.9 KB
  • scripts/instrument_python.py5.7 KB
  • scripts/snapshot_runtime.c4.8 KB
  • scripts/snapshot_runtime.h1.3 KB
  • scripts/snapshot_runtime.py4.7 KB
  • scripts/SnapshotRuntime.java7.7 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

State Snapshot Instrumenter

Overview

This skill instruments programs to capture snapshots of key program states at runtime. Snapshots include variable values, memory state, call stacks, and execution context, saved in structured JSON format for analysis, debugging, reproduction, and verification.

Quick Start

Basic Workflow

  1. Add snapshot markers to your code (manual mode) or use automatic instrumentation
  2. Run the instrumenter to generate instrumented code
  3. Execute the instrumented program to capture snapshots
  4. Analyze snapshots to understand program behavior

Example: Python

# 1. Add markers to your code
# def my_function(x):
#     __SNAPSHOT__("my_function:start")
#     result = x * 2
#     __SNAPSHOT__("my_function:end")
#     return result

# 2. Instrument the code
python scripts/instrument_python.py my_program.py --mode manual

# 3. Run instrumented program
python my_program_instrumented.py
# Snapshots saved to snapshots.json

# 4. Analyze snapshots
python scripts/analyze_snapshots.py snapshots.json --list

Example: C/C++

# 1. Add markers to your code
# int main() {
#     __SNAPSHOT__("main:start");
#     int x = 10;
#     __SNAPSHOT__("main:end");
#     return 0;
# }

# 2. Instrument the code
python scripts/instrument_c.py program.c --mode manual

# 3. Compile with runtime
gcc program_instrumented.c scripts/snapshot_runtime.c -o program -rdynamic

# 4. Run and analyze
./program
python scripts/analyze_snapshots.py snapshots.json --list

Example: Java

# 1. Add markers to your code
# public static void main(String[] args) {
#     __SNAPSHOT__("main:start");
#     int x = 10;
#     __SNAPSHOT__("main:end");
# }

# 2. Instrument the code
python scripts/instrument_java.py Program.java --mode manual

# 3. Compile and run
cp scripts/SnapshotRuntime.java snapshot/
javac snapshot/SnapshotRuntime.java
javac Program_instrumented.java
java Program_instrumented

# 4. Analyze
python scripts/analyze_snapshots.py snapshots.json --list

Instrumentation Modes

Manual Mode (Recommended for Targeted Debugging)

Add explicit __SNAPSHOT__("location") markers at specific points in your code.

Python:

def process_data(items):
    __SNAPSHOT__("process_data:entry")

    result = []
    for item in items:
        __SNAPSHOT__("loop_iteration")
        result.append(item * 2)

    __SNAPSHOT__("process_data:exit")
    return result

C/C++:

int calculate(int x, int y) {
    __SNAPSHOT__("calculate:entry");

    int result = x + y;

    __SNAPSHOT__("calculate:exit");
    return result;
}

Java:

public int calculate(int x, int y) {
    __SNAPSHOT__("calculate:entry");

    int result = x + y;

    __SNAPSHOT__("calculate:exit");
    return result;
}

Instrument:

python scripts/instrument_python.py file.py --mode manual
python scripts/instrument_c.py file.c --mode manual
python scripts/instrument_java.py file.java --mode manual

Automatic Mode (Comprehensive Coverage)

Automatically instrument all function/method entry and exit points.

python scripts/instrument_python.py file.py --mode auto
python scripts/instrument_c.py file.c --mode auto
python scripts/instrument_java.py file.java --mode auto

This captures state at every function boundary without manual markers.

Core Operations

1. Instrumentation

Python:

# Manual mode
python scripts/instrument_python.py input.py --mode manual -o output.py

# Automatic mode
python scripts/instrument_python.py input.py --mode auto -o output.py

# In-place modification
python scripts/instrument_python.py input.py --mode manual --inplace

C/C++:

# Instrument
python scripts/instrument_c.py input.c --mode manual -o output.c

# Compile with runtime
gcc output.c scripts/snapshot_runtime.c -o program -rdynamic

# Run with custom output file
SNAPSHOT_OUTPUT=my_snapshots.json ./program

Java:

# Instrument
python scripts/instrument_java.py Input.java --mode manual -o Output.java

# Setup runtime
cp scripts/SnapshotRuntime.java snapshot/
javac snapshot/SnapshotRuntime.java

# Compile and run
javac Output.java
SNAPSHOT_OUTPUT=my_snapshots.json java Output

2. Snapshot Analysis

List all snapshots:

python scripts/analyze_snapshots.py snapshots.json --list

Show detailed snapshot:

python scripts/analyze_snapshots.py snapshots.json --show 5

View execution timeline:

python scripts/analyze_snapshots.py snapshots.json --timeline

Track variable changes:

python scripts/analyze_snapshots.py snapshots.json --track-var "user_id"

Compare two snapshots:

python scripts/analyze_snapshots.py snapshots.json --compare 10 20

Filter snapshots:

# By location
python scripts/analyze_snapshots.py snapshots.json --filter-location "main"

# By type
python scripts/analyze_snapshots.py snapshots.json --filter-type "function_entry"

3. Runtime Control

Python:

import snapshot_runtime

# Disable snapshots temporarily
snapshot_runtime.disable()
# ... performance-critical code ...
snapshot_runtime.enable()

# Set custom output file
snapshot_runtime.set_output_file("custom.json")

# Manually save snapshots
snapshot_runtime.save_snapshots()

C/C++:

#include "snapshot_runtime.h"

snapshot_disable();
// ... performance-critical code ...
snapshot_enable();

snapshot_finalize();  // Manually save

Java:

import snapshot.SnapshotRuntime;

SnapshotRuntime.disable();
// ... performance-critical code ...
SnapshotRuntime.enable();

SnapshotRuntime.setOutputFile("custom.json");
SnapshotRuntime.saveSnapshots();

Use Cases

Bug Debugging

Capture comprehensive state to understand complex bugs:

  1. Instrument with automatic mode for full coverage
  2. Run to reproduce the bug
  3. Analyze snapshots to identify failure point
  4. Track variable changes to understand root cause

See references/use_cases.md for detailed debugging workflows.

Test Case Reproduction

Extract exact inputs and state to reproduce failures:

  1. Instrument with manual snapshots at key points
  2. Capture failing execution
  3. Extract input dependencies from snapshots
  4. Reconstruct minimal test case

See references/use_cases.md for reproduction workflows.

Formal Verification

Generate execution traces for verification tools:

  1. Instrument function boundaries
  2. Collect execution traces
  3. Extract invariants and contracts
  4. Feed to verification tools

See references/use_cases.md for verification workflows.

Reference Documentation

  • references/instrumentation_guide.md - Comprehensive guide on instrumenting programs, including language-specific instructions, best practices, and troubleshooting
  • references/snapshot_format.md - Complete specification of the JSON snapshot format, including language-specific variations and serialization rules
  • references/use_cases.md - Detailed workflows for debugging, reproduction, verification, performance analysis, and concurrency debugging

Example Programs

Example instrumented programs are provided in assets/:

  • example_python.py - Python example with manual snapshots
  • example_c.c - C example with manual snapshots
  • example_java.java - Java example with manual snapshots

Output Format

All snapshots are saved in unified JSON format:

{
  "format_version": "1.0",
  "language": "python",
  "total_snapshots": 5,
  "snapshots": [
    {
      "snapshot_id": 1,
      "timestamp": "2026-02-17T19:30:45",
      "location": "main:start",
      "type": "manual",
      "call_stack": [...],
      "local_variables": {...}
    }
  ]
}

See assets/snapshot_schema.json for the complete JSON schema.

Tips

  • Use manual mode for targeted debugging to minimize overhead
  • Use automatic mode for comprehensive execution understanding
  • Disable snapshots in performance-critical sections
  • Use descriptive location names (e.g., "function:entry", "after_operation")
  • Set custom output files with SNAPSHOT_OUTPUT environment variable
  • Analyze snapshots incrementally as you debug
  • Compare snapshots to identify when state becomes incorrect
  • Track key variables through execution to understand data flow

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

Applies abstract interpretation using different abstract domains (intervals, octagons, polyhedra, sign, congruence) to statically analyze program variables and infer invariants, value ranges, and relationships. Use when analyzing program properties, inferring loop invariants, detecting potential errors, or understanding variable relationships through static analysis.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

ArabelaTso/Skills-4-SE2582026년 8월 21일 업데이트

Uses abstract interpretation to automatically infer loop invariants, function preconditions, and postconditions for formal verification. Generates invariants that capture program behavior and support correctness proofs in Dafny, Isabelle, Coq, and other verification systems. Use when adding formal specifications to code, generating verification conditions, inferring contracts for functions, or discovering loop invariants for proofs.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

ArabelaTso/Skills-4-SE2582026년 8월 21일 업데이트

Performs abstract interpretation over source code to infer possible program states, variable ranges, and data properties without executing the program. Reports potential runtime errors including out-of-bounds accesses, null dereferences, type inconsistencies, division by zero, and integer overflows. Use when analyzing code for potential runtime errors, performing static analysis, checking safety properties, or verifying program behavior without execution.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

ArabelaTso/Skills-4-SE2582026년 8월 21일 업데이트

Performs abstract interpretation to produce summarized execution traces and high-level program behavior representations. Highlights key control flow paths, variable relationships, loop invariants, function summaries, and potential runtime states using abstract domains (intervals, signs, nullness, etc.). Use when analyzing program behavior, understanding execution paths, computing loop invariants, tracking variable ranges, detecting potential runtime errors, or generating program summaries without concrete execution.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

ArabelaTso/Skills-4-SE2582026년 8월 21일 업데이트

Create ACSL (ANSI/ISO C Specification Language) formal annotations for C/C++ programs. Use this skill when working with formal verification, adding function contracts (requires/ensures), loop invariants, assertions, memory safety annotations, or any ACSL specifications. Supports Frama-C verification and generates comprehensive formal specifications for C/C++ code.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

ArabelaTso/Skills-4-SE2582026년 8월 21일 업데이트

CLI-based browser automation with persistent page state using ref-based element interaction. Use when users ask to navigate websites, interact with web pages, fill forms, take screenshots, test web applications, or extract information from web pages.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

ArabelaTso/Skills-4-SE2582026년 8월 21일 업데이트

ArabelaTso의 스킬 모두 보기

이 스킬의 문제 신고