Vm3 alpha debugger #295

Merged
rodrigorodriguez merged 29 commits from vm3-alpha-debugger into master 2022-11-29 22:05:10 +00:00
2 changed files with 26 additions and 5 deletions
Showing only changes of commit 76c28edaa7 - Show all commits

View file

@ -197,12 +197,13 @@ export class DebuggerService {
GBServer.globals.debuggers[botId] = {}; GBServer.globals.debuggers[botId] = {};
GBServer.globals.debuggers[botId].state = 0; GBServer.globals.debuggers[botId].state = 0;
GBServer.globals.debuggers[botId].breaks = []; GBServer.globals.debuggers[botId].breaks = [];
GBServer.globals.debuggers[botId].stateInfo = "Stopped";
} }
private client; private client;
public async breakpoint({ botId, botApiKey, line }) { public async breakpoint({ botId, botApiKey, line }) {
GBLog.info(`GBDEBUG: Enabled breakpoint for ${botId} on ${line}.`); GBLog.info(`BASIC: Enabled breakpoint for ${botId} on ${line}.`);
GBServer.globals.debuggers[botId].breaks.push(Number.parseInt(line)); GBServer.globals.debuggers[botId].breaks.push(Number.parseInt(line));
} }
@ -211,6 +212,7 @@ export class DebuggerService {
const client = GBServer.globals.debuggers[botId].client; const client = GBServer.globals.debuggers[botId].client;
await client.Debugger.resume(); await client.Debugger.resume();
GBServer.globals.debuggers[botId].state = 1; GBServer.globals.debuggers[botId].state = 1;
GBServer.globals.debuggers[botId].stateInfo = "Running (Debug)";
return {status: 'OK'}; return {status: 'OK'};
} else { } else {
const error = 'Invalid call to resume and state not being debug(2).'; const error = 'Invalid call to resume and state not being debug(2).';
@ -220,6 +222,7 @@ export class DebuggerService {
public async stop({ botId, botApiKey, force }) { public async stop({ botId, botApiKey, force }) {
GBServer.globals.debuggers[botId].state = 0; GBServer.globals.debuggers[botId].state = 0;
GBServer.globals.debuggers[botId].stateInfo = "Stopped";
const client = GBServer.globals.debuggers[botId].client; const client = GBServer.globals.debuggers[botId].client;
await client.Debugger.close(); await client.Debugger.close();
return {status: 'OK'}; return {status: 'OK'};
@ -227,6 +230,7 @@ export class DebuggerService {
public async step({ botId, botApiKey }) { public async step({ botId, botApiKey }) {
if (GBServer.globals.debuggers[botId].state === 2) { if (GBServer.globals.debuggers[botId].state === 2) {
GBServer.globals.debuggers[botId].stateInfo = "Break";
const client = GBServer.globals.debuggers[botId].client; const client = GBServer.globals.debuggers[botId].client;
await client.Debugger.stepOver(); await client.Debugger.stepOver();
return {status: 'OK'}; return {status: 'OK'};
@ -263,8 +267,9 @@ export class DebuggerService {
return { return {
status: 'OK', status: 'OK',
state: GBServer.globals.debuggers[botId].state, state: GBServer.globals.debuggers[botId].state,
messagesText, messages:messagesText,
scope: GBServer.globals.debuggers[botId].scope scope: GBServer.globals.debuggers[botId].scope,
scopeInfo: GBServer.globals.debuggers[botId].stateInfo
}; };
} }
@ -279,8 +284,8 @@ export class DebuggerService {
return {status: 'OK'}; return {status: 'OK'};
} else { } else {
GBLog.info(`BASIC: Running ${botId} in DEBUG mode.`); GBLog.info(`BASIC: Running ${botId} in DEBUG mode.`);
GBServer.globals.debuggers[botId].state = 1; GBServer.globals.debuggers[botId].state = 1;
GBServer.globals.debuggers[botId].stateInfo = "Running (Debug)";
let min: GBMinInstance = GBServer.globals.minInstances.filter(p => p.instance.botId === botId)[0]; let min: GBMinInstance = GBServer.globals.minInstances.filter(p => p.instance.botId === botId)[0];

View file

@ -72,10 +72,14 @@ const createVm2Pool = ({ min, max, ...limits }) => {
if (stderrCache.includes('failed: address already in use')) { if (stderrCache.includes('failed: address already in use')) {
limitError = stderrCache; limitError = stderrCache;
kill(process); kill(process);
GBServer.globals.debuggers[limits.botId].state = 0;
GBServer.globals.debuggers[limits.botId].stateInfo = stderrCache;
} }
if (stderrCache.includes('FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory')) { if (stderrCache.includes('FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory')) {
limitError = 'code execution exceeed allowed memory'; limitError = 'code execution exceeed allowed memory';
kill(process); kill(process);
GBServer.globals.debuggers[limits.botId].state = 0;
GBServer.globals.debuggers[limits.botId].stateInfo = "Fail";
} }
}); });
@ -120,8 +124,9 @@ const createVm2Pool = ({ min, max, ...limits }) => {
GBLog.info(`BASIC: Break at line ${frame.location.lineNumber + 1}`); // (zero-based) GBLog.info(`BASIC: Break at line ${frame.location.lineNumber + 1}`); // (zero-based)
GBServer.globals.debuggers[limits.botId].state = 2; GBServer.globals.debuggers[limits.botId].state = 2;
GBServer.globals.debuggers[limits.botId].stateInfo = "Break";
} else { } else {
GBLog.info(`BASIC: Configuring breakpoints if any for ${limits.botId}`); GBLog.verbose(`BASIC: Configuring breakpoints if any for ${limits.botId}...`);
// Waits for debugger and setup breakpoints. // Waits for debugger and setup breakpoints.
await CollectionUtil.asyncForEach(GBServer.globals.debuggers[limits.botId].breaks, async brk => { await CollectionUtil.asyncForEach(GBServer.globals.debuggers[limits.botId].breaks, async brk => {
@ -149,10 +154,14 @@ const createVm2Pool = ({ min, max, ...limits }) => {
} catch (err) { } catch (err) {
GBLog.error(err); GBLog.error(err);
kill(childProcess); kill(childProcess);
GBServer.globals.debuggers[limits.botId].state = 0;
GBServer.globals.debuggers[limits.botId].stateInfo = "Stopped";
} }
}).on('error', err => { }).on('error', err => {
console.error(err); console.error(err);
kill(childProcess); kill(childProcess);
GBServer.globals.debuggers[limits.botId].state = 0;
GBServer.globals.debuggers[limits.botId].stateInfo = "Stopped";
reject(err); reject(err);
}); });
}); });
@ -163,13 +172,17 @@ const createVm2Pool = ({ min, max, ...limits }) => {
const timer = setTimeout(() => { const timer = setTimeout(() => {
limitError = 'code execution took too long and was killed'; limitError = 'code execution took too long and was killed';
kill(childProcess); kill(childProcess);
GBServer.globals.debuggers[limits.botId].state = 0;
GBServer.globals.debuggers[limits.botId].stateInfo = limitError;
}, limits.time); }, limits.time);
try { try {
let data = await finalStream(socket); let data = await finalStream(socket);
data = JSON.parse(data); data = JSON.parse(data);
if (!data.length) { if (!data.length) {
return null; return null;
} }
@ -182,6 +195,9 @@ const createVm2Pool = ({ min, max, ...limits }) => {
throw new Error(limitError || error); throw new Error(limitError || error);
} finally { } finally {
kill(childProcess); kill(childProcess);
GBServer.globals.debuggers[limits.botId].state = 0;
GBServer.globals.debuggers[limits.botId].stateInfo = 'Stopped';
clearTimeout(timer); clearTimeout(timer);
} }
}; };