Skip to content

Commit 722c4fb

Browse files
Merge pull request #5 from Tapeline/master
2.0-RC-1
2 parents ef93c36 + e1d3387 commit 722c4fb

94 files changed

Lines changed: 2632 additions & 228 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.idea/artifacts/qdk_jar.xml

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/artifacts/qre_jar.xml

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

QuailDevelopmentKit/src/main/java/me/tapeline/quail/qdk/Main.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package me.tapeline.quail.qdk;
22

3+
import me.tapeline.quail.qdk.debugclient.DebugClient;
4+
import me.tapeline.quail.qdk.debugclient.gui.DebuggerWindow;
35
import me.tapeline.quail.qdk.libconverter.Converter;
46
import me.tapeline.quail.qdk.templater.Templater;
57
import me.tapeline.quailj.lexing.Lexer;
@@ -40,6 +42,12 @@ public static void main(String[] args) throws
4042
args[3]
4143
);
4244
converter.convert();
45+
} else if (args[0].equalsIgnoreCase("debugClient")) {
46+
if (args.length < 3) printUsage();
47+
DebugClient client = new DebugClient(args[1], Short.parseShort(args[2]));
48+
client.run();
49+
} else if (args[0].equalsIgnoreCase("debugClientGui")) {
50+
DebuggerWindow.runGuiDebugger();
4351
}
4452

4553
}
@@ -52,6 +60,10 @@ public static void printUsage() {
5260
System.out.println(" convert <com.pkg.C1;lib.jar:org.xyz.C2...> <package> <prefix> <target folder>");
5361
System.out.println(" | Creates templates for Java-implemented Quail classes and methods based\n" +
5462
" | on given Java classes");
63+
System.out.println(" debugClient <host> <port>");
64+
System.out.println(" | Start a CLI QSDb client");
65+
System.out.println(" debugClientGui");
66+
System.out.println(" | Start a GUI QSDb client");
5567
System.exit(0);
5668
}
5769

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
package me.tapeline.quail.qdk.debugclient;
2+
3+
import java.io.*;
4+
import java.net.Socket;
5+
import java.util.ArrayList;
6+
import java.util.Base64;
7+
import java.util.List;
8+
import java.util.Scanner;
9+
10+
public class DebugClient {
11+
12+
private Socket clientSocket;
13+
private BufferedReader reader;
14+
private BufferedReader socketIn;
15+
private BufferedWriter socketOut;
16+
17+
private boolean isRunning = true;
18+
19+
public DebugClient(String host, short port) throws IOException {
20+
clientSocket = new Socket(host, port);
21+
reader = new BufferedReader(new InputStreamReader(System.in));
22+
socketIn = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
23+
socketOut = new BufferedWriter(new OutputStreamWriter(clientSocket.getOutputStream()));
24+
System.out.println("Connected to remote debug session on " + host + ":" + port);
25+
}
26+
27+
public void run() {
28+
try {
29+
try {
30+
System.out.println("Specify breakpoints in format filename.ext;a;b;c where a,b,c - line numbers.");
31+
System.out.println("When you're done, type end");
32+
Scanner scanner = new Scanner(System.in);
33+
String bp;
34+
List<String> breakpoints = new ArrayList<>();
35+
while (true) {
36+
bp = scanner.nextLine();
37+
if (bp.equalsIgnoreCase("end")) break;
38+
breakpoints.add(bp);
39+
}
40+
for (String breakpoint : breakpoints)
41+
socketOut.write(breakpoint + "\n");
42+
socketOut.write("endheader\n");
43+
socketOut.flush();
44+
while (isRunning) {
45+
String messageType = socketIn.readLine();
46+
if (messageType.equalsIgnoreCase("bp")) {
47+
handleBpInstruction();
48+
} else if (messageType.equalsIgnoreCase("end")) {
49+
System.out.println("Program ended");
50+
isRunning = false;
51+
}
52+
}
53+
} finally {
54+
System.out.println("Client closed");
55+
clientSocket.close();
56+
socketIn.close();
57+
socketOut.close();
58+
}
59+
} catch (IOException e) {
60+
System.err.println(e.toString());
61+
}
62+
}
63+
64+
private void handleBpInstruction() throws IOException {
65+
String message = socketIn.readLine();
66+
String file = message.substring(0, message.indexOf(';'));
67+
int line = Integer.parseInt(message.substring(message.indexOf(';') + 1));
68+
System.out.println("Breakpoint reached at " + file + " line " + line);
69+
while (true) {
70+
System.out.print("qsdb> ");
71+
BufferedReader inputScanner = new BufferedReader(new InputStreamReader(System.in));
72+
while (!inputScanner.ready()) {
73+
if (socketIn.ready()) {
74+
String msg = socketIn.readLine();
75+
if (msg.equalsIgnoreCase("end")) {
76+
System.out.println("Program ended");
77+
isRunning = false;
78+
return;
79+
} else if (msg.equalsIgnoreCase("bpe")) {
80+
return;
81+
}
82+
}
83+
}
84+
String command = inputScanner.readLine();
85+
if (command.equalsIgnoreCase("mem")) {
86+
socketOut.write("mem\n");
87+
socketOut.flush();
88+
String count = socketIn.readLine();
89+
if (count.equalsIgnoreCase("mem not present")) {
90+
System.out.println("Memory is not available at the moment");
91+
continue;
92+
}
93+
int iCount = Integer.parseInt(count);
94+
for (int i = 0; i < iCount; i++) {
95+
try {
96+
String entry = socketIn.readLine();
97+
if (entry.equalsIgnoreCase("endmem"))
98+
break;
99+
String key = new String(Base64.getDecoder().decode(
100+
entry.substring(0, entry.indexOf(';'))));
101+
String value = new String(Base64.getDecoder().decode(
102+
entry.substring(entry.indexOf(';') + 1)));
103+
System.out.println(key + " -> " + value);
104+
} catch (Exception ignored) {}
105+
}
106+
} else if (command.equalsIgnoreCase("c")) {
107+
socketOut.write("continue\n");
108+
socketOut.flush();
109+
} else if (command.equalsIgnoreCase("nl")) {
110+
socketOut.write("next\n");
111+
socketOut.flush();
112+
} else if (command.equalsIgnoreCase("stop")) {
113+
socketOut.write("stop\n");
114+
socketOut.flush();
115+
isRunning = false;
116+
return;
117+
} else if (command.equalsIgnoreCase("eval")) {
118+
System.out.print("eval> ");
119+
String code = inputScanner.readLine();
120+
socketOut.write("eval\n");
121+
socketOut.write(Base64.getEncoder().encodeToString(code.getBytes()) + "\n");
122+
socketOut.flush();
123+
socketIn.readLine();
124+
String result = socketIn.readLine();
125+
System.out.println(" ?= " + result);
126+
}
127+
}
128+
}
129+
130+
}

0 commit comments

Comments
 (0)