Newer
Older
//console.log("sendRaw():", raw); // DUBNERDEBUG
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
if (this.printCalls)
this.log("log", raw);
if (this.isSSH)
this.stream.write(raw + "\n");
else
this.process.stdin.write(raw + "\n");
}
async sendCliCommand(command: string, threadId: number = 0, frameLevel: number = 0) {
// For some reason, somebody, somewhere, is sending a console command "process.pid", which
// just confuses everybody and creates an error message the user can see.
// Let's nip this one in the bud.
if( command == "process.pid" ){
return;
}
let miCommand = "interpreter-exec ";
if (threadId != 0) {
miCommand += `--thread ${threadId} --frame ${frameLevel} `;
}
miCommand += `console "${command.replace(/[\\"']/g, '\\$&')}"`;
await this.sendCommand(miCommand);
}
sendCommand(command: string, suppressFailure: boolean = false): Thenable<MINode> {
const sel = this.currentToken++;
this.recent_variables_request = -1;
return new Promise((resolve, reject) => {
this.handlers[sel] = (node: MINode) => {
if (node && node.resultRecords && node.resultRecords.resultClass === "error") {
if (suppressFailure) {
this.log("stderr", `WARNING: Error executing command '${command}'`);
resolve(node);
} else
reject(new MIError(node.result("msg") || "Internal error", command));
} else
resolve(node);
};
this.sendRaw(sel + "-" + command);
});
}
sendStraightCommand(command: string, suppressFailure: boolean = false): Thenable<MINode> {
const sel = this.currentToken++;
this.recent_variables_request = sel;
return new Promise((resolve, reject) => {
this.handlers[sel] = (node: MINode) => {
if (node && node.resultRecords && node.resultRecords.resultClass === "error") {
if (suppressFailure) {
this.log("stderr", `WARNING: Error executing command '${command}'`);
resolve(node);
} else
reject(new MIError(node.result("msg") || "Internal error", command));
} else
resolve(node);
};
this.sendRaw(sel + command);
});
}
isReady(): boolean {
return this.isSSH ? this.sshReady : !!this.process;
}
prettyPrint: boolean = true;
printCalls: boolean;
debugOutput: boolean;
public procEnv: any;
protected isSSH: boolean;
protected sshReady: boolean;
protected currentToken: number = 1;
protected handlers: { [index: number]: (info: MINode) => any } = {};
protected breakpoints: Map<Breakpoint, Number> = new Map();
protected buffer: string;
protected errbuf: string;
protected process: ChildProcess.ChildProcess;
protected stream;
protected sshConn;
protected recent_variables_request: number; // Most recent MI token for 'p/m ?' variables request