Skip to content

Commit 7e10450

Browse files
committed
Allow reading outside of code section (needs refactor, since the code section is now just the full module)
I also am unsure if LLDB actually cares about the section address, seems to not really matter much?
1 parent f7ad125 commit 7e10450

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ private CodeSection getCodeSection(String filename) throws IOException {
102102

103103
if (sectionId == 10) { // code section
104104
System.out.println("Found code section at address " + i);
105-
return new CodeSection(Arrays.copyOfRange(wasmBytes, i, i + size), i);
105+
//return new CodeSection(Arrays.copyOfRange(wasmBytes, i, i + size), i);
106+
return new CodeSection(wasmBytes, i);
106107
}
107108

108109
i += size;
@@ -161,20 +162,23 @@ public void start() throws IOException {
161162

162163
// TODO: Hack to temporarily prevent lldb from using breakpoints when stepping
163164
// https://github.com/llvm/llvm-project/issues/189960
164-
if (addrType == 0) {
165+
/*if (addrType == 0) {
165166
sendPacket(out, "E01");
166167
continue;
167-
}
168+
}*/
168169

169170
byte[] memory = codeSection.data;
170171
if (addrType == 1) {
171172
log("Reading from wasm linear memory");
172173
memory = getCurrentState().getMemory().getBytes();
173174
}
175+
else {
176+
//pos -= codeSection.offset;
177+
}
174178

175179
// The reply may contain fewer addressable memory units than requested if the server was reading from a trace frame memory and was able to read only part of the region of memory.
176-
if (pos >= memory.length) {
177-
System.out.println("Out of bounds for length " + memory.length);
180+
if (pos >= memory.length || pos < 0) {
181+
System.out.println("Pos " + pos + " out of bounds for length " + memory.length);
178182
sendPacket(out, "E01");
179183
continue;
180184
}
@@ -214,7 +218,8 @@ else if (pkt.startsWith("qXfer:libraries:read")) {
214218
// toHex(codeSection.offset, 4)
215219
//"0x00044444"
216220
//sendPacket(out, String.format("l<library-list><library name=\"%s\"><section address=\"0x" + toHex(codeSection.offset, 4, false) + "\"/></library></library-list>", new File(binaryLocation).getAbsolutePath()));
217-
sendPacket(out, String.format("l<library-list><library name=\"%s\"><section address=\"" + "0x00000000" + "\"/></library></library-list>", new File(binaryLocation).getAbsolutePath()));
221+
sendPacket(out, String.format("l<library-list><library name=\"%s\"><section address=\"" + codeSection.offset + "\"/></library></library-list>", new File(binaryLocation).getAbsolutePath()));
222+
//sendPacket(out, String.format("l<library-list><library name=\"%s\"><section address=\"" + "0x00000000" + "\"/></library></library-list>", new File(binaryLocation).getAbsolutePath()));
218223
continue;
219224
}
220225
// TODO: We can probably remove this:

0 commit comments

Comments
 (0)