Finalize breakpoint patches: edit the buffer to have NOPs by default, and place patch data in the debug breakpoint data tables.
(&mut self)
| 98 | /// default, and place patch data in the debug breakpoint data |
| 99 | /// tables. |
| 100 | fn finalize_breakpoints(&mut self) { |
| 101 | // Traverse debug tags and patchable callsites together. All |
| 102 | // patchable callsites should have debug tags. Given both, we |
| 103 | // can know the Wasm PC and we can emit a breakpoint record. |
| 104 | let mut tags = self.buffer.debug_tags().peekable(); |
| 105 | let mut patchable_callsites = self.buffer.patchable_call_sites().peekable(); |
| 106 | |
| 107 | while let (Some(tag), Some(patchable_callsite)) = (tags.peek(), patchable_callsites.peek()) |
| 108 | { |
| 109 | if tag.offset > patchable_callsite.ret_addr { |
| 110 | patchable_callsites.next(); |
| 111 | continue; |
| 112 | } |
| 113 | if patchable_callsite.ret_addr > tag.offset { |
| 114 | tags.next(); |
| 115 | continue; |
| 116 | } |
| 117 | assert_eq!(tag.offset, patchable_callsite.ret_addr); |
| 118 | |
| 119 | // Tag format used by our Wasm-to-CLIF format is |
| 120 | // (stackslot, wasm_pc, stack_shape). Taking the |
| 121 | // second-to-last tag will get the innermost Wasm PC (if |
| 122 | // there are multiple nested frames due to inlining). |
| 123 | assert!(tag.tags.len() >= 3); |
| 124 | let ir::DebugTag::User(wasm_pc_raw) = tag.tags[tag.tags.len() - 2] else { |
| 125 | panic!("invalid tag") |
| 126 | }; |
| 127 | |
| 128 | let patchable_start = patchable_callsite.ret_addr - patchable_callsite.len; |
| 129 | let patchable_end = patchable_callsite.ret_addr; |
| 130 | |
| 131 | self.breakpoint_patch_points |
| 132 | .push((ModulePC::new(wasm_pc_raw), patchable_start..patchable_end)); |
| 133 | |
| 134 | tags.next(); |
| 135 | patchable_callsites.next(); |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | /// Returns an iterator to the function's relocation information. |
| 140 | pub fn relocations(&self) -> impl Iterator<Item = Relocation> + '_ { |
no test coverage detected