Skip to content

Commit 60572f9

Browse files
committed
Fix qWasmLocal to use only function frames as lldb expects
WARDuino also has frames for non-functions, for example blocks in wasm.
1 parent 446fc69 commit 60572f9

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

src/main/java/be/ugent/topl/mio/GdbStub.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import java.net.Socket;
1111
import java.nio.file.Files;
1212
import java.nio.file.Path;
13+
import java.util.ArrayList;
14+
import java.util.List;
1315

1416
import static be.ugent.topl.mio.sourcemap.DwarfSourceMapKt.getDwarfSourcemap;
1517

@@ -189,11 +191,12 @@ else if (pkt.startsWith("qWasmLocal:")) {
189191
int frameIdx = Integer.parseInt(args[0]);
190192
int localIdx = Integer.parseInt(args[1]);
191193
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()));
193196
System.out.println(frame);
194197
System.out.println(getCurrentState().getStack());
195198
int fp = frame.getFp();
196-
long value = getCurrentState().getStack().get(fp + localIdx).getValue();
199+
long value = getCurrentState().getStack().get(fp + localIdx + 1).getValue();
197200
sendPacket(out, toHex(toWasmAddr(value))); // If a pointer on the stack is an address it will be clear it's a wasm memory pointer.
198201
continue;
199202
}
@@ -402,4 +405,15 @@ private String encodeRegs() {
402405
sb.append(String.format("%08x", getCurrentState().getPc()));
403406
return sb.toString();
404407
}
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+
}
405419
}

0 commit comments

Comments
 (0)