Skip to content

Commit a2852ae

Browse files
committed
stack error
1 parent ec57f03 commit a2852ae

File tree

4 files changed

+48
-24
lines changed

4 files changed

+48
-24
lines changed

src/main/java/com/tang/intellij/lua/debugger/remote/commands/DebugCommand.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@
2727
*/
2828
public abstract class DebugCommand {
2929

30-
protected LuaRemoteDebugProcess debugProcess;
30+
LuaRemoteDebugProcess debugProcess;
3131

3232
public void setDebugProcess(LuaRemoteDebugProcess process) {
3333
debugProcess = process;
3434
}
3535

3636
public abstract void write(MobServer writer) throws IOException;
37-
public abstract boolean handle(String data);
37+
public abstract int handle(String data);
3838
public abstract int getRequireRespLines();
39+
public abstract boolean isFinished();
3940
}

src/main/java/com/tang/intellij/lua/debugger/remote/commands/DefaultCommand.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class DefaultCommand extends DebugCommand {
2929

3030
private String commandline;
3131
int requireRespLines;
32-
private int handleLines;
32+
int handleLines;
3333

3434
public DefaultCommand(String commandline) {
3535
this(commandline, 1);
@@ -46,9 +46,17 @@ public void write(MobServer writer) throws IOException {
4646
}
4747

4848
@Override
49-
public final boolean handle(String data) {
50-
handle(handleLines, data);
51-
return requireRespLines == ++handleLines;
49+
public int handle(String data) {
50+
int LB = data.indexOf('\n');
51+
if (LB == -1) return LB;
52+
53+
handle(handleLines++, data);
54+
return data.length();
55+
}
56+
57+
@Override
58+
public boolean isFinished() {
59+
return requireRespLines <= handleLines;
5260
}
5361

5462
@Override

src/main/java/com/tang/intellij/lua/debugger/remote/commands/GetStackCommand.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,38 @@
4040
public class GetStackCommand extends DefaultCommand {
4141

4242
private boolean hasError;
43+
private int errorDataLen;
4344

4445
public GetStackCommand() {
4546
super("STACK", 1);
4647
}
4748

4849
@Override
49-
protected void handle(int index, String data) {
50+
public boolean isFinished() {
51+
return !hasError && super.isFinished();
52+
}
53+
54+
@Override
55+
public int handle(String data) {
5056
if (hasError) {
51-
new DefaultCommand("SUSPEND", 0).exec();
52-
debugProcess.setStack(new LuaExecutionStack(new ArrayList<>()));
53-
return;
57+
hasError = false;
58+
String error = data.substring(0, errorDataLen);
59+
debugProcess.error(error);
60+
debugProcess.runCommand(new DefaultCommand("RUN", 0));
61+
return errorDataLen;
5462
}
63+
return super.handle(data);
64+
}
5565

66+
@Override
67+
protected void handle(int index, String data) {
5668
if (data.startsWith("401")) {
5769
hasError = true;
58-
requireRespLines++;
70+
Pattern pattern = Pattern.compile("(\\d+)([^\\d]+)(\\d+)");
71+
Matcher matcher = pattern.matcher(data);
72+
if (matcher.find()) {
73+
errorDataLen = Integer.parseInt(matcher.group(3));
74+
}
5975
return;
6076
}
6177

src/main/java/com/tang/intellij/lua/debugger/remote/mobdebug/MobServer.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,7 @@ public class MobServer implements Runnable {
4444

4545
class LuaDebugReader extends BaseOutputReader {
4646
LuaDebugReader(@NotNull InputStream inputStream, @Nullable Charset charset) {
47-
super(inputStream, charset, new BaseOutputReader.Options() {
48-
@Override
49-
public boolean sendIncompleteLines() {
50-
return false;
51-
}
52-
53-
@Override
54-
public SleepingPolicy policy() {
55-
return SleepingPolicy.BLOCKING;
56-
}
57-
});
47+
super(inputStream, charset);
5848
start(getClass().getName());
5949
}
6050

@@ -78,6 +68,7 @@ protected Future<?> executeOnPooledThread(@NotNull Runnable runnable) {
7868
private LuaDebugReader debugReader;
7969
private DebugCommand currentCommandWaitForResp;
8070
private OutputStreamWriter streamWriter;
71+
private StringBuffer stringBuffer = new StringBuffer(2048);
8172

8273
public MobServer(LuaRemoteDebugProcess listener) {
8374
this.listener = listener;
@@ -92,8 +83,16 @@ public void start(int port) throws IOException {
9283

9384
private void onResp(String data) {
9485
System.out.println(data);
95-
if (currentCommandWaitForResp != null && currentCommandWaitForResp.handle(data)) {
96-
currentCommandWaitForResp = null;
86+
if (currentCommandWaitForResp != null) {
87+
stringBuffer.append(data);
88+
int eat = currentCommandWaitForResp.handle(stringBuffer.toString());
89+
if (eat > 0) {
90+
stringBuffer.delete(0, eat);
91+
if (currentCommandWaitForResp.isFinished())
92+
currentCommandWaitForResp = null;
93+
}
94+
} else {
95+
stringBuffer.setLength(0);
9796
}
9897

9998
Pattern pattern = Pattern.compile("(\\d+) (\\w+)( (.+))?");

0 commit comments

Comments
 (0)