Skip to content

Commit d4ae94b

Browse files
committed
Seems like we just don't need the code section and the offset
1 parent 7e10450 commit d4ae94b

File tree

1 file changed

+3
-40
lines changed

1 file changed

+3
-40
lines changed

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

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import java.net.Socket;
1212
import java.nio.file.Files;
1313
import java.nio.file.Path;
14-
import java.util.Arrays;
1514

1615
import static be.ugent.topl.mio.sourcemap.DwarfSourceMapKt.getDwarfSourcemap;
1716

@@ -81,36 +80,6 @@ private long stripAddrType(long addr) {
8180
return addr & Long.MAX_VALUE;
8281
}
8382

84-
record CodeSection(byte[] data, int offset) {}
85-
86-
private CodeSection getCodeSection(String filename) throws IOException {
87-
byte[] wasmBytes = Files.readAllBytes(Path.of(filename));
88-
int i = 8; // skip header
89-
90-
while (i < wasmBytes.length) {
91-
int sectionId = wasmBytes[i++] & 0xFF;
92-
93-
// LEB128 section size
94-
int size = 0;
95-
int shift = 0;
96-
int b;
97-
do {
98-
b = wasmBytes[i++] & 0xFF;
99-
size |= (b & 0x7F) << shift;
100-
shift += 7;
101-
} while ((b & 0x80) != 0);
102-
103-
if (sectionId == 10) { // code section
104-
System.out.println("Found code section at address " + i);
105-
//return new CodeSection(Arrays.copyOfRange(wasmBytes, i, i + size), i);
106-
return new CodeSection(wasmBytes, i);
107-
}
108-
109-
i += size;
110-
}
111-
return null;
112-
}
113-
11483
private String getTriple(String s) {
11584
String hex = s.chars()
11685
.mapToObj(c -> String.format("%02x", c))
@@ -125,11 +94,9 @@ public WOODDumpResponse getCurrentState() {
12594
}
12695

12796
public void start() throws IOException {
128-
//System.out.println(stripAddrType(0x800000000000fffcL)); // 65532
12997
debugger.pause();
13098

131-
System.out.println(toHex(4508));
132-
CodeSection codeSection = getCodeSection(binaryLocation);
99+
byte[] wasmData = Files.readAllBytes(Path.of(binaryLocation));
133100

134101
for (int i = 0; i < regs.length; i++) {
135102
regs[i] = 0x11111111 * (i + 1);
@@ -167,7 +134,7 @@ public void start() throws IOException {
167134
continue;
168135
}*/
169136

170-
byte[] memory = codeSection.data;
137+
byte[] memory = wasmData;
171138
if (addrType == 1) {
172139
log("Reading from wasm linear memory");
173140
memory = getCurrentState().getMemory().getBytes();
@@ -215,11 +182,7 @@ else if (pkt.startsWith("qXfer:libraries:read")) {
215182
// +--------------------+--------------------+
216183
// <----- 32 bit -----> <----- 32 bit ----->
217184
// Offset 0, module id 0
218-
// toHex(codeSection.offset, 4)
219-
//"0x00044444"
220-
//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()));
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()));
185+
sendPacket(out, String.format("l<library-list><library name=\"%s\"><section address=\"0x00000000\"/></library></library-list>", new File(binaryLocation).getAbsolutePath()));
223186
continue;
224187
}
225188
// TODO: We can probably remove this:

0 commit comments

Comments
 (0)