debugger
debugger copied to clipboard
Read memory map from backend to fix infinite string search issue
This PR implements comprehensive memory region reading from debug backends to resolve the critical performance issue where string search attempts to read the entire address space (0xffffffff or 0xffffffffffffffff bytes), causing operations to hang indefinitely.
Problem
Currently, the debugger only has limited segment information (binary path and start address) with no knowledge of segment lengths or memory permissions. This causes two major issues:
- Infinite String Search: The
DebuggerFileAccessorreports the entire address space as readable (UINT64_MAX), so string search tries to read all memory addresses, never completing. - Missing Memory Metadata: No information about memory permissions (rwx) or region types (stack, heap, modules).
Solution
Added complete memory region infrastructure with backend-specific implementations:
Core Infrastructure
DebugMemoryRegion: New struct storing start/end addresses, permissions (read/write/execute), region name, and associated moduleGetMemoryRegions(): Virtual method added toDebugAdapterbase classDebuggerMemoryRegions: Management class for caching and validating memory regions- Memory Validation:
DebuggerMemory::ReadBlock()now validates addresses against readable regions before attempting reads
Backend Implementations
- GDB Adapter: Parses
/proc/PID/mapsto extract detailed Linux memory layout with permissions - LLDB Adapter: Uses
SBProcess::GetMemoryRegionInfo()for cross-platform region enumeration - DbgEng Adapter: Leverages
IDebugDataSpaces::QueryVirtual()for Windows memory regions - Fallback Support: Gracefully handles adapters without memory region support
Example Memory Layout (Linux)
0x400000-0x40b000 r-x /bin/ls # Text segment
0x60a000-0x60b000 r-- /bin/ls # Read-only data
0x1c1a000-0x1c3b000 rw- [heap] # Heap region
0x7ffffffde000-0x7ffffffff000 rw- [stack] # Stack region
Performance Impact
Before: String search attempts to scan entire address space
- 32-bit: ~1M blocks (4GB ÷ 4KB blocks)
- 64-bit: Effectively infinite
After: Only scans valid memory regions
- Typical process: ~512 blocks (2MB ÷ 4KB blocks)
- Result: ~2000x performance improvement
Testing
Comprehensive test suite validates:
- Memory region parsing from
/proc/mapsformat - Address validation and boundary conditions
- Permission-based access control
- Edge cases (empty regions, overlaps, invalid ranges)
- Performance optimization verification
The implementation is robust, handles all edge cases, and provides graceful fallback when memory regions aren't available.
Fixes #96.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.