memory-debugging

Diagnose memory faults and allocation failures in the Breenix kernel.

7|Updated Nov 21, 2015
One-click install
npx skills add https://github.com/ryanbreen/breenix --skill memory-debugging
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: memory-debugging
Source: https://github.com/ryanbreen/breenix/tree/main/breenix-memory-debugging
Command: npx skills add https://github.com/ryanbreen/breenix --skill memory-debugging

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Memory-related bugs like page faults, double faults, and heap corruption are among the most challenging and critical issues in kernel development. This Skill provides a systematic approach to diagnose and resolve these complex memory problems, ensuring kernel stability and preventing system crashes.

Core Features & Use Cases

  • Page Fault Analysis: Decode error codes and identify causes like unmapped memory or protection violations.
  • Double Fault Diagnosis: Pinpoint the root cause of cascading exceptions, often related to stack or page table issues.
  • Allocator Debugging: Troubleshoot frame, heap, and kernel stack allocation failures and leaks.
  • Use Case: Your kernel is experiencing a PAGE FAULT during a system call. Use this Skill to decode the error code, determine if it's a read/write access or a user/kernel mode issue, and systematically investigate the page table mappings and kernel stack configuration to find and fix the underlying memory bug.

Quick Start

Decode a Page Fault error code (e.g., 0x4)

Bit 0 (P): 0 = Page not present

Bit 1 (W): 0 = Read access

Bit 2 (U): 1 = User mode

Diagnosis: Read from unmapped page in user mode

Add checkpoint logging to narrow down

log::debug!("CHECKPOINT: Before page table operation"); page_table.map_to(page, frame, flags, allocator)?; log::debug!("CHECKPOINT: After page table operation");

Frequently Asked Questions about memory-debugging

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I decode a page fault error code to diagnose kernel memory issues?

Page fault error codes are decoded bit-by-bit to identify the access type and memory state. Bit 0 indicates page presence, bit 1 shows read/write access, and bit 2 reveals user/kernel mode. Analyzing these bits pinpoints whether the fault stems from unmapped memory, protection violations, or mode mismatches, guiding your investigation into page table mappings and kernel stack configuration.

What causes double faults in kernel memory management and how do I find the root cause?

Double faults occur when an exception handler itself triggers an exception, often due to stack overflow, invalid page table entries, or corrupted kernel state. Systematic diagnosis requires logging checkpoints around page table operations, stack allocation, and frame allocator calls to isolate which memory subsystem failed and cascade the fault.

Can I debug heap corruption and frame allocation failures in the kernel?

Yes. Heap corruption and frame allocation failures are diagnosed through integrated logging hooks that expose allocator state, track allocation/deallocation patterns, and introspect memory subsystem internals. Checkpoint logging before and after allocator operations narrows down where corruption or exhaustion occurs.

What's the systematic approach to troubleshoot kernel stack overflows and virtual memory mapping errors?

Troubleshooting kernel stack overflows and virtual memory mapping errors requires state introspection of the kernel stack allocator and page table subsystems. Use checkpoint logging to trace memory operations, inspect frame availability, validate virtual-to-physical mappings, and identify protection flag misconfigurations causing faults.

Do I need kernel logging infrastructure to diagnose memory-related bugs effectively?

Integrated logging hooks are essential for effective memory diagnosis. They enable checkpoint logging around critical operations, state introspection of frame allocators and page tables, and actionable diagnostics. Without logging infrastructure, isolating memory defects in page faults, allocator failures, and stack issues becomes significantly harder.

How do I prevent kernel crashes caused by memory bugs like page faults and heap corruption?

Prevention requires proactive diagnosis and remediation of memory defects before they cascade into system crashes. Use this Skill to decode fault conditions, introspect allocator and page table state, and identify root causes of page faults, double faults, and allocation failures. Systematic investigation of early-stage symptoms prevents cascading failures.