|
| 1 | +# MemoryView implementation plan |
| 2 | + |
| 3 | +## Scope |
| 4 | +Implement the MemoryView component described in `docs/memory_view.md` with heap |
| 5 | +range virtualization, value highlighting from state panel locals, and basic |
| 6 | +range navigation. |
| 7 | + |
| 8 | +## Milestones |
| 9 | +1) Data contract and backend integration |
| 10 | +- Define a request/response shape for memory range loading (address, length, |
| 11 | + optional step id, optional heap segment id; response includes aligned start, |
| 12 | + length, payload bytes, and state). |
| 13 | +- Add an RPC/IPC endpoint for fetching a range by address and length. |
| 14 | +- Include error and unmapped signaling in the response. |
| 15 | +- Decide on a transport encoding for bytes (base64 string vs. numeric array) |
| 16 | + and mirror it in both Rust and Nim conversions. |
| 17 | +- Add MemoryView request/response types in the shared common types |
| 18 | + (`src/common/common_types/language_features/value.nim`) and ensure they are |
| 19 | + available to the frontend via `src/frontend/types.nim`. |
| 20 | +- Add new `CtEventKind` entries in `src/common/ct_event.nim` (request and |
| 21 | + response kinds) and map them in `src/frontend/dap.nim`: |
| 22 | + - `EVENT_KIND_TO_DAP_MAPPING` |
| 23 | + - `toCtDapResponseEventKind` |
| 24 | + - `commandToCtResponseEventKind` |
| 25 | +- Add custom Codetracer DAP requests for MemoryView and wire send/receive |
| 26 | + plumbing in `src/frontend/middleware.nim` (subscribe + emit). |
| 27 | +- Add a new db-backend DAP server case for the memory query in |
| 28 | + `src/db-backend/src/dap_server.rs` (and in |
| 29 | + `src/db-backend/crates/db-backend-core/src/dap_server.rs` if that path is |
| 30 | + used), define its arguments in `src/db-backend/src/task.rs`, and implement a |
| 31 | + corresponding handler in `src/db-backend/src/handler.rs` to load memory |
| 32 | + ranges. |
| 33 | +- Extend the replay abstraction to support memory reads (e.g. add |
| 34 | + `load_memory_range` to `src/db-backend/src/replay.rs`) and implement it in |
| 35 | + `src/db-backend/src/db.rs` and `src/db-backend/src/rr_dispatcher.rs` |
| 36 | + (returning a clear error for unsupported backends if needed). |
| 37 | + |
| 38 | +2) UI component skeleton |
| 39 | +- Create the MemoryView container with header, range selector, and grid (e.g. |
| 40 | + `src/frontend/ui/memory_view.nim`). |
| 41 | +- Implement the UI-facing `render`/frontend methods in |
| 42 | + `src/frontend/ui/memory_view.nim` to integrate with the existing component |
| 43 | + lifecycle. |
| 44 | +- Add a new `Content.MemoryView` entry in |
| 45 | + `src/common/common_types/codetracer_features/frontend.nim`, then register the |
| 46 | + component in `src/frontend/utils.nim` (`makeComponent` + component mapping). |
| 47 | +- Add a panel entry (menu or command palette) so users can open MemoryView, |
| 48 | + following the existing patterns in `src/frontend/ui_js.nim`. |
| 49 | +- Implement fixed-width address column and grouped byte boxes. |
| 50 | +- Add placeholder rows for unloaded data. |
| 51 | + |
| 52 | +3) Virtualization and cache |
| 53 | +- Implement row virtualization based on viewport height. |
| 54 | +- Add aligned range requests and an LRU cache with a byte budget. |
| 55 | +- Ensure overscan range loads and in-flight de-duplication. |
| 56 | + |
| 57 | +4) Interactions |
| 58 | +- Implement jump-to-address parsing and scroll-to-row. |
| 59 | +- Wire “visualize value” from state panel locals to highlight the memory range: |
| 60 | + add a UI action in `src/frontend/ui/value.nim` (or the state panel row |
| 61 | + renderer) that emits the MemoryView highlight request using the local’s |
| 62 | + `address` and a byte length. If size is not available, default to a single |
| 63 | + byte or pointer-size highlight and document the fallback. |
| 64 | +- Add hover tooltip for address and byte value decoding. |
| 65 | +- Emit MemoryView request events from the view and subscribe to response/update |
| 66 | + events to refresh the grid. |
| 67 | + |
| 68 | +5) Error handling and resilience |
| 69 | +- Render error markers for failed range requests with a retry action. |
| 70 | +- Handle step changes by clearing unsafe caches. |
| 71 | +- Guard against invalid addresses and zero-length ranges. |
| 72 | + |
| 73 | +6) Testing |
| 74 | +- Unit tests for alignment, chunking, and cache eviction. |
| 75 | +- UI tests for scrolling, highlighting, and error states. |
| 76 | + |
| 77 | +## Dependencies |
| 78 | +- State panel locals already expose a stable `address`, but a byte length is not |
| 79 | + currently part of the shared `Variable` type; decide whether to infer size |
| 80 | + from type metadata or add an explicit size field for highlights. |
| 81 | +- Backend must provide memory range access for the active trace step. |
| 82 | + |
| 83 | +## Risks and mitigations |
| 84 | +- Large heap performance: mitigate with strict cache limits and range alignment. |
| 85 | +- Unmapped address density: render sparse rows and avoid repeated requests. |
| 86 | + |
| 87 | +## Deliverables |
| 88 | +- MemoryView UI component and styling. |
| 89 | +- Range loading service with cache and request scheduling. |
| 90 | +- Tests covering virtualized loading and value highlighting. |
0 commit comments