Skip to content

Commit 29f0253

Browse files
authored
Merge pull request #37 from nberth/log-to-channel
Move debug logs to a VSCode-managed channel
2 parents 50b0ee8 + fca3206 commit 29f0253

File tree

4 files changed

+108
-114
lines changed

4 files changed

+108
-114
lines changed

src/gdb.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import * as path from "path";
1919
import {MI2} from './mi2';
2020
import {CoverageStatus} from './coverage';
2121
import {DebuggerSettings} from './settings';
22+
import * as log from './log';
2223

2324
const STACK_HANDLES_START = 1000;
2425
const VAR_HANDLES_START = 512 * 256 + 1000;
@@ -42,7 +43,7 @@ export interface LaunchRequestArguments extends DebugProtocol.LaunchRequestArgum
4243
sourceDirs: string[];
4344
}
4445

45-
export interface AttachRequestArguments extends DebugProtocol.LaunchRequestArguments {
46+
export interface AttachRequestArguments extends DebugProtocol.AttachRequestArguments {
4647
cwd: string | null;
4748
target: string;
4849
arguments: string;
@@ -57,6 +58,14 @@ export interface AttachRequestArguments extends DebugProtocol.LaunchRequestArgum
5758

5859
const settings = new DebuggerSettings();
5960

61+
function initLogLevel(verbose: boolean) {
62+
if (verbose) {
63+
log.setLevel(log.Level.Debug);
64+
} else {
65+
log.setLevel(log.Level.Info);
66+
}
67+
}
68+
6069
export class GDBDebugSession extends DebugSession {
6170
protected variableHandles = new Handles<string | VariableObject | ExtendedVariable>(VAR_HANDLES_START);
6271
protected variableHandlesReverse: { [id: string]: number } = {};
@@ -78,11 +87,13 @@ export class GDBDebugSession extends DebugSession {
7887
}
7988

8089
protected launchRequest(response: DebugProtocol.LaunchResponse, args: LaunchRequestArguments): void {
90+
initLogLevel(args.verbose);
91+
8192
this.showCoverage = args.coverage;
8293
this.started = false;
8394
this.attached = false;
8495

85-
this.miDebugger = new MI2(settings.gdbPath, args.gdbargs, args.env, args.verbose, args.noDebug, args.gdbtty, settings.cobcrunPath, args.useCobcrun, args.sourceDirs);
96+
this.miDebugger = new MI2(settings.gdbPath, args.gdbargs, args.env, args.noDebug, args.gdbtty, settings.cobcrunPath, args.useCobcrun, args.sourceDirs);
8697
this.miDebugger.on("launcherror", (err: Error) => this.launchError(err));
8798
this.miDebugger.on("quit", () => this.quitEvent());
8899
this.miDebugger.on("exited-normally", () => this.quitEvent());
@@ -123,6 +134,8 @@ export class GDBDebugSession extends DebugSession {
123134
}
124135

125136
protected attachRequest(response: DebugProtocol.AttachResponse, args: AttachRequestArguments): void {
137+
initLogLevel(args.verbose);
138+
126139
if (!args.pid && !args.remoteDebugger) {
127140
this.sendErrorResponse(
128141
response,
@@ -136,7 +149,7 @@ export class GDBDebugSession extends DebugSession {
136149
this.attached = true;
137150
this.started = false;
138151

139-
this.miDebugger = new MI2(settings.gdbPath, args.gdbargs, args.env, args.verbose, false, false, "", false, args.sourceDirs);
152+
this.miDebugger = new MI2(settings.gdbPath, args.gdbargs, args.env, false, false, "", false, args.sourceDirs);
140153
this.miDebugger.on("launcherror", (err: Error) => this.launchError(err));
141154
this.miDebugger.on("quit", () => this.quitEvent());
142155
this.miDebugger.on("exited-normally", () => this.quitEvent());

src/log.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import * as vscode from "vscode";
2+
3+
export enum Level { Debug, Info };
4+
export let level = Level.Info;
5+
export function setLevel (l: Level): void {
6+
level = l;
7+
}
8+
9+
const channel = vscode.window.createOutputChannel("SuperBOL Debugger");
10+
11+
export function emit(...msg: (string | (() => (string | string[])))[]) {
12+
channel.appendLine(msg.flatMap(f => {
13+
if (typeof (f) == "string") {
14+
return [f];
15+
} else {
16+
const r = f();
17+
return (typeof (r) == "string") ? [r] : r;
18+
}
19+
}).join(' '));
20+
}
21+
22+
export const info = emit;
23+
24+
export function debug(...msg: (string | (() => (string | string[])))[]) {
25+
if (level == Level.Debug) {
26+
emit(...msg);
27+
}
28+
}
29+
30+
export function error(...msg) {
31+
emit(...msg);
32+
channel.show();
33+
}

0 commit comments

Comments
 (0)