|
10 | 10 | import java.net.Socket; |
11 | 11 | import java.nio.file.Files; |
12 | 12 | import java.nio.file.Path; |
| 13 | +import java.util.ArrayList; |
| 14 | +import java.util.List; |
13 | 15 |
|
14 | 16 | import static be.ugent.topl.mio.sourcemap.DwarfSourceMapKt.getDwarfSourcemap; |
15 | 17 |
|
@@ -189,11 +191,12 @@ else if (pkt.startsWith("qWasmLocal:")) { |
189 | 191 | int frameIdx = Integer.parseInt(args[0]); |
190 | 192 | int localIdx = Integer.parseInt(args[1]); |
191 | 193 | log("Reading local " + localIdx + " from frame " + frameIdx); |
192 | | - Frame frame = getCurrentState().getCallstack().get(getCurrentState().getCallstack().size() - frameIdx - 1); |
| 194 | + Frame frame = getCallStack(getCurrentState()).get(frameIdx); |
| 195 | + System.out.println(getCallStack(getCurrentState())); |
193 | 196 | System.out.println(frame); |
194 | 197 | System.out.println(getCurrentState().getStack()); |
195 | 198 | int fp = frame.getFp(); |
196 | | - long value = getCurrentState().getStack().get(fp + localIdx).getValue(); |
| 199 | + long value = getCurrentState().getStack().get(fp + localIdx + 1).getValue(); |
197 | 200 | sendPacket(out, toHex(toWasmAddr(value))); // If a pointer on the stack is an address it will be clear it's a wasm memory pointer. |
198 | 201 | continue; |
199 | 202 | } |
@@ -402,4 +405,15 @@ private String encodeRegs() { |
402 | 405 | sb.append(String.format("%08x", getCurrentState().getPc())); |
403 | 406 | return sb.toString(); |
404 | 407 | } |
| 408 | + |
| 409 | + private List<Frame> getCallStack(WOODDumpResponse state) { |
| 410 | + List<Frame> callStack = new ArrayList<Frame>(); |
| 411 | + for (int i = state.getCallstack().size() - 1; i >= 0; i--) { |
| 412 | + Frame f = state.getCallstack().get(i); |
| 413 | + if (f.getType() == 0) { |
| 414 | + callStack.add(state.getCallstack().get(i)); |
| 415 | + } |
| 416 | + } |
| 417 | + return callStack; |
| 418 | + } |
405 | 419 | } |
0 commit comments