Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private setupLogger(args: LaunchRequestArguments): void {
if (typeof args.trace === 'boolean') {
this.trace = args.trace ? [TRACE_ALL] : undefined;
this.traceAll = args.trace;
} else if (typeof args.trace === 'string') {
this.trace = args.trace.split(',').map(category => category.trim());
this.traceAll = this.trace.indexOf(TRACE_ALL) >= 0;
}
if (this.trace && this.trace.indexOf(TRACE_CATEGORY_PROTOCOL) >= 0) {
// only log debug adapter protocol if 'protocol' tracing flag is set, ignore traceAll here
logger.setup(Logger.LogLevel.Verbose, false);
} else {
logger.setup(Logger.LogLevel.Stop, false);
}
}
import { LoggingDebugSession, Logger, logger, InitializedEvent, TerminatedEvent, StoppedEvent, OutputEvent, Thread, StackFrame, Scope, Source, Handles, DebugSession, Breakpoint } from 'vscode-debugadapter';
import { DebugProtocol } from 'vscode-debugprotocol';
import { Variable, Stack, VariableObject, MIError } from './backend/backend';
import { expandValue } from './backend/gdb_expansion';
import { MI2 } from './backend/flowcpp_runtime';
logger.setup(Logger.LogLevel.Verbose, true);
process.on("unhandledRejection", (error) => {
console.error(error); // This prints error with stack included (as for normal errors)
throw error; // Following best practices re-throw error and let the process exit with error code
});
export interface LaunchRequestArguments extends DebugProtocol.LaunchRequestArguments {
cwd: string;
target: string;
runner_path: string;
env: any;
debugger_args: string;
arguments: string;
autorun: string[];
print_calls: boolean;
showDevDebugOutput: boolean;
private setupLogger(args: LaunchRequestArguments): void {
if (typeof args.trace === 'boolean') {
this.trace = args.trace ? [TRACE_ALL] : undefined;
this.traceAll = args.trace;
} else if (typeof args.trace === 'string') {
this.trace = args.trace.split(',').map(category => category.trim());
this.traceAll = this.trace.indexOf(TRACE_ALL) >= 0;
}
if (this.trace && this.trace.indexOf(TRACE_CATEGORY_PROTOCOL) >= 0) {
// only log debug adapter protocol if 'protocol' tracing flag is set, ignore traceAll here
logger.setup(Logger.LogLevel.Verbose, false);
} else {
logger.setup(Logger.LogLevel.Stop, false);
}
}
protected async launchRequest(
response: DebugProtocol.LaunchResponse,
args: ECALDebugArguments
) {
this.config = args; // Store the configuration
// Setup logging either verbose or just on errors
logger.setup(
args.trace ? Logger.LogLevel.Verbose : Logger.LogLevel.Error,
false
);
await this.wgConfig.wait(); // Wait for configuration sequence to finish
this.extout.appendLine(`Configuration loaded: ${JSON.stringify(args)}`);
await this.client.connect(args.host, args.port);
if (args.executeOnEntry) {
this.client.reload();
}
this.sendResponse(response);
}
protected launchRequest(response: DebugProtocol.LaunchResponse, args: LaunchRequestArguments): void {
if (args.trace) {
logger.setup(Logger.LogLevel.Verbose, /*logToFile=*/ true);
}
// since this debug adapter can accept configuration requests like 'setBreakpoint' at any time,
// we request them early by sending an 'initializeRequest' to the frontend.
// The frontend will end the configuration sequence by calling 'configurationDone' request.
if (!this.connection) {
this.connection = new Connection(this.config);
this.connection
.estabilish()
.then(() => {
this.connection && this.connection
.removeBreakpoints()
.then(() => {
this.sendResponse(response);
await this.sendErrorIfFailed(response, async () => {
// make sure to 'Stop' the buffered logging if 'trace' is not set
// logger.setup enable logs in client
logger.setup(args.trace ? Logger.LogLevel.Verbose : Logger.LogLevel.Stop, false);
// start the program in the runtime
await this._runtime.attach(args.txHash, args.workingDirectory);
await this._runtime.processInitialBreakPoints();
// Events order is important
this.sendEvent(new DebuggerTypes.LaunchedEvent());
this.sendEvent(new StoppedEvent(EVENT_REASONS.breakpoint, MAIN_THREAD.id));
});
}
public setupLogger(args: LaunchRequestArguments): void {
if (typeof args.trace === 'boolean') {
this.trace = args.trace ? [TRACE_ALL] : [];
this.traceAll = args.trace;
} else if (typeof args.trace === 'string') {
this.trace = args.trace.split(',').map(category => category.trim());
this.traceAll = this.trace.indexOf(TRACE_ALL) >= 0;
}
if (this.trace && this.trace.indexOf(TRACE_CATEGORY_PROTOCOL) >= 0) {
logger.setup(Logger.LogLevel.Verbose, false);
} else {
logger.setup(Logger.LogLevel.Stop, false);
}
}
private parseLoggingConfiguration(args: ILaunchRequestArgs | IAttachRequestArgs): LoggingConfiguration {
const traceMapping: { [key: string]: Logger.LogLevel | undefined } = { true: Logger.LogLevel.Warn, verbose: Logger.LogLevel.Verbose };
const traceValue = args.trace && traceMapping[args.trace.toString().toLowerCase()];
return { logLevel: traceValue, logFilePath: args.logFilePath, shouldLogTimestamps: args.logTimestamps };
}