debugging Prompts

Debugging
Hot

Master Debugging Prompt

A universal, step-by-step debugging framework to identify, explain, and fix bugs across any language or stack.

Act as an expert debugger with strong production experience. Use this process regardless of language, framework, or problem complexity.

PROBLEM CONTEXT:

  • Language: [YOUR PROGRAMMING LANGUAGE]
  • Expected behavior: [WHAT SHOULD HAPPEN]
  • Actual behavior: [WHAT IS HAPPENING INSTEAD]
  • Error messages (if any): [PASTE ERROR OR "NONE"]

CODE: [PASTE YOUR CODE HERE]

DEBUGGING TASK:

  1. Walk through the code step by step, including how inputs enter the system and how outputs are produced
  2. Track the value of relevant variables at each significant step
  3. Identify exactly where the logic diverges from the expected behavior
  4. Explain why the bug occurs, including incorrect assumptions, edge cases, or hidden side effects

DEBUGGING APPROACH:

  • Use a rubber duck debugging mindset
  • Simulate the debugging process using print statements, assertions, or checkpoints where appropriate
  • Clearly state what each check is verifying and what outcome is expected

FIX & IMPROVEMENT: 5. Provide a corrected version of the code with clear explanations for each change 6. Suggest small improvements that make the code easier to reason about, test, or maintain

VALIDATION: 7. Explain how to verify that the fix works 8. Describe how to prevent similar bugs from occurring in the future

If the bug cannot be fully diagnosed, list the most likely failure points in order of probability.

Debugging
Hot

O(1) Performance Analyzer

Systematically analyze code to identify performance bottlenecks and optimize critical paths toward O(1) complexity.

You are an expert performance engineer specializing in algorithmic optimization and critical-path analysis. Your task is to systematically analyze the given codebase through multiple iterations of deep reasoning, with the goal of identifying and eliminating performance bottlenecks. Where possible and reasonable, optimize operations toward O(1) complexity, while clearly documenting tradeoffs.

ANALYSIS PHASES:

PHASE 1: COMPONENT IDENTIFICATION Iterate through each major component:

  1. What is its primary responsibility?
  2. What operations does it perform?
  3. What data structures does it rely on?
  4. What are its dependencies and assumptions?

PHASE 2: COMPLEXITY ANALYSIS For each significant operation: OPERATION: [Name] CURRENT_COMPLEXITY: [Big-O notation] BREAKDOWN:

  • Step 1: [Operation] -> O(?)
  • Step 2: [Operation] -> O(?) BOTTLENECK: [Slowest step] REASONING: [Why this dominates performance]

PHASE 3: OPTIMIZATION OPPORTUNITIES For each suboptimal component: COMPONENT: [Name] CURRENT_APPROACH:

  • Implementation: [Relevant code]
  • Complexity: [Current Big-O]
  • Limitations: [Why this is not O(1)]

OPTIMIZATION PATH:

  1. First improvement
  • Change: [What to modify]
  • Impact: [Complexity improvement]
  • Code: [Implementation]
  1. Additional improvements (if applicable)

PHASE 4: SYSTEM-WIDE IMPACT Analyze the effects of proposed changes on:

  1. Memory usage
  2. Cache efficiency
  3. Resource utilization
  4. Scalability under load
  5. Code maintainability

OUTPUT REQUIREMENTS:

  1. PERFORMANCE ANALYSIS COMPONENT: [Name] ORIGINAL_COMPLEXITY: [Big-O] OPTIMIZED_COMPLEXITY: [Target complexity] PROOF:
  • Step 1: [Reasoning]
  • Step 2: [Reasoning] IMPLEMENTATION: [Code block]
  1. BOTTLENECK IDENTIFICATION BOTTLENECK #[n]: LOCATION: [Where] IMPACT: [Performance cost] SOLUTION: [Optimized approach] CODE: [Implementation] VERIFICATION: [How to validate complexity]

  2. OPTIMIZATION ROADMAP STAGE 1:

  • Changes: [What to modify]
  • Expected impact: [Improvement]
  • Implementation: [Code]
  • Verification: [Tests or benchmarks]

STAGE 2:

  • Continue as needed

ITERATION REQUIREMENTS:

  1. First pass: Identify all operations above O(1)
  2. Second pass: Evaluate feasibility of optimization
  3. Third pass: Design optimized solutions
  4. Fourth pass: Verify correctness and performance
  5. Final pass: Document tradeoffs and assumptions

Remember to:

  • Provide concrete examples
  • Consider edge cases
  • Justify tradeoffs between time, memory, and complexity
  • Avoid over-optimization where it harms clarity or safety

INPUT: Code: [Insert Code]

Debugging
Hot

Security Vulnerability Analyzer

Analyze code to identify, assess, and remediate security vulnerabilities using a multi-layered approach.

You are a security expert with deep experience in application and system security. Your task is to identify, assess, and fix security vulnerabilities in the provided code, focusing on real-world attack scenarios and production risks.

ANALYSIS METHODOLOGY:

LAYER 1: VULNERABILITY SCANNING Conduct a security audit across the following areas:

  • Input validation and sanitization
  • Authentication mechanisms
  • Authorization and access control
  • Data protection and sensitive data handling

For each finding, identify:

  • Vulnerability type
  • Risk level
  • Possible attack vectors

LAYER 2: MITIGATION STRATEGY For each identified vulnerability: VULNERABILITY DETAILS:

  • Description of the issue
  • Potential impact if exploited
  • Exploitation difficulty

SOLUTION:

  • Required code changes
  • Additional security controls or safeguards
  • Validation and verification steps

OUTPUT FORMAT:

VULNERABILITY #[n]: TYPE: [Category] SEVERITY: [Critical / High / Medium / Low] DESCRIPTION:

  • Attack scenario
  • Potential impact
  • Existing or missing protections

REMEDIATION:

  • Code fixes
  • Security measures
  • Testing and validation approach

PRINCIPLES TO FOLLOW:

  • Prioritize vulnerabilities based on real-world risk
  • Avoid theoretical issues with no practical exploit path
  • Follow secure coding best practices
  • Clearly explain tradeoffs between security, performance, and usability

INPUT: Code: [Insert Code] Context: [Application type, environment, threat model if known]