Skip to content

Commit c82e588

Browse files
committed
mob
1 parent 9085107 commit c82e588

File tree

7 files changed

+44
-16
lines changed

7 files changed

+44
-16
lines changed

package.json

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@
180180
"required": [
181181
"program",
182182
"workingDir",
183-
"arguments"
183+
"arguments",
184+
"port"
184185
],
185186
"properties": {
186187
"program": {
@@ -197,6 +198,11 @@
197198
"type": "array",
198199
"description": "运行参数",
199200
"default": []
201+
},
202+
"port": {
203+
"type": "number",
204+
"description": "调试端口",
205+
"default": 8172
200206
}
201207
}
202208
}
@@ -208,20 +214,22 @@
208214
"name": "EmmyLua Remote",
209215
"program": "lua.exe",
210216
"workingDir": "${workspaceRoot}",
211-
"arguments": []
217+
"arguments": [],
218+
"port": 8172
212219
}
213220
],
214221
"configurationSnippets": [
215222
{
216-
"label": "%debug.launch.label%",
217-
"description": "%debug.launch.desc%",
223+
"label": "EmmyLua: Remote",
224+
"description": "EmmyLua: Remote",
218225
"body": {
219226
"type": "emmylua_remote",
220227
"request": "launch",
221228
"name": "EmmyLua Remote",
222229
"program": "lua.exe",
223230
"workingDir": "${workspaceRoot}",
224-
"arguments": []
231+
"arguments": [],
232+
"port": 8172
225233
}
226234
}
227235
],

src/debugger/AttachDebugSession.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
LoggingDebugSession, Event, OutputEvent, TerminatedEvent, InitializedEvent,
2+
OutputEvent, TerminatedEvent, InitializedEvent,
33
Breakpoint, StoppedEvent, StackFrame, Source, Thread, Handles
44
} from 'vscode-debugadapter';
55
import { DebugProtocol } from "vscode-debugprotocol";
@@ -15,6 +15,7 @@ import {
1515
import { ByteArray } from './ByteArray';
1616
import * as path from 'path';
1717
import * as fs from 'fs';
18+
import { EmmyDebugSession } from './EmmyDebugSession';
1819

1920
var emmyArchExe:string, emmyLua: string;
2021
var breakpointId:number = 0;
@@ -42,7 +43,7 @@ interface EmmyBreakpoint {
4243
line: number;
4344
}
4445

45-
export class AttachDebugSession extends LoggingDebugSession implements ExprEvaluator, LoadedScriptManager {
46+
export class AttachDebugSession extends EmmyDebugSession implements ExprEvaluator, LoadedScriptManager {
4647

4748
private socket?: net.Socket;
4849
private receiveBuf = new sb.SmartBuffer();
@@ -57,7 +58,7 @@ export class AttachDebugSession extends LoggingDebugSession implements ExprEvalu
5758
private sourcePaths: string[] = [];
5859

5960
public constructor() {
60-
super("emmy_attach.txt");
61+
super();
6162
this.setDebuggerColumnsStartAt1(false);
6263
this.setDebuggerLinesStartAt1(false);
6364
}
@@ -347,10 +348,6 @@ export class AttachDebugSession extends LoggingDebugSession implements ExprEvalu
347348
}
348349
}
349350

350-
private log(obj: any) {
351-
this.sendEvent(new Event("log", obj));
352-
}
353-
354351
public findScriptByIndex(index: number): LoadedScript | undefined {
355352
for (const iterator of this.loadedScripts) {
356353
if (iterator["1"].index === index) {

src/debugger/EmmyDebugSession.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
1-
import { LoggingDebugSession } from "vscode-debugadapter";
1+
import { LoggingDebugSession, Event, OutputEvent } from "vscode-debugadapter";
22

33
export abstract class EmmyDebugSession extends LoggingDebugSession {
44
constructor() {
55
super("emmy.debug.txt");
66
}
7+
8+
log(obj: any) {
9+
this.sendEvent(new Event("log", obj));
10+
}
11+
12+
printConsole(msg: string, newLine: boolean = true) {
13+
if (newLine) {
14+
msg += "\n";
15+
}
16+
this.sendEvent(new OutputEvent(msg));
17+
}
718
}

src/debugger/MobDebugSession.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,12 @@ export class MobDebugSession extends EmmyDebugSession {
2828
private launchServer(port: number): Thenable<net.Server> {
2929
return new Promise(resolve => {
3030
const socket = net.createServer(skt => {
31-
this.client = new MobClient(skt);
31+
this.printConsole("Connected.");
32+
this.client = new MobClient(this, skt);
3233
this.sendEvent(new InitializedEvent());
3334
}).on("listening", () => {
35+
this.printConsole(`Start mobdebug server at port:${port}`);
36+
this.printConsole("Waiting for process connection...");
3437
resolve(socket);
3538
}).listen(port);
3639
this.server = socket;
@@ -44,13 +47,18 @@ export class MobDebugSession extends EmmyDebugSession {
4447

4548
class MobClient {
4649
socket: net.Socket;
47-
constructor(socket: net.Socket) {
50+
session: MobDebugSession;
51+
52+
constructor(session:MobDebugSession, socket: net.Socket) {
4853
this.socket = socket;
54+
this.session = session;
4955
this.init();
5056
}
5157

5258
private init() {
53-
59+
this.socket.on("data", data => {
60+
this.session.printConsole(data.toString());
61+
});
5462
}
5563

5664
close() {

src/debugger/MobDebuggerProvider.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import { MobDebugConfiguration } from './types';
66

77
export class MobDebuggerProvider implements vscode.DebugConfigurationProvider {
88
resolveDebugConfiguration(folder: WorkspaceFolder | undefined, debugConfiguration: MobDebugConfiguration, token?: CancellationToken): ProviderResult<DebugConfiguration> {
9+
if (!debugConfiguration.port) {
10+
debugConfiguration.port = 8172;
11+
}
912
return debugConfiguration;
1013
}
1114

src/debugger/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ export interface MobDebugConfiguration extends EmmyDebugConfiguration {
1818
program?: string;
1919
arguments?: string[];
2020
workingDir?: string;
21+
port?: number;
2122
}

0 commit comments

Comments
 (0)