From 8241219a269e7e4722ad92362263d555cc02d8bd Mon Sep 17 00:00:00 2001 From: eddylin83 Date: Fri, 20 Dec 2019 22:53:25 +0800 Subject: [PATCH] custom debug configuration support --- package.json | 19 ++++++++- src/config.ts | 8 ++++ src/debugger.ts | 107 +++++++++++++++++++++++++++++------------------- 3 files changed, 90 insertions(+), 44 deletions(-) diff --git a/package.json b/package.json index 879e49d..39b1ad7 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "xmake-vscode", "displayName": "XMake", "description": "Extended XMake support in Visual Studio Code", - "version": "1.2.3", + "version": "1.2.4", "publisher": "tboox", "icon": "res/logo256.png", "repository": { @@ -325,6 +325,23 @@ "default": [] }, "description": "The Debugging Targets Arguments, .e.g {\"targetName\": [\"args\", \"...\"]}" + }, + "xmake.debugConfigType": { + "type": "string", + "default": "default", + "enum": [ + "default", + "codelldb", + "custom" + ], + "description": "The Debugging Configuration Type, .e.g default|codelldb|custom" + }, + "xmake.customDebugConfig": { + "type": "object", + "default": { + "type": "cppdbg" + }, + "description": "The Custom Debugging Configurations when xmake.debugConfigType is custom" } } } diff --git a/src/config.ts b/src/config.ts index 070b574..6844676 100644 --- a/src/config.ts +++ b/src/config.ts @@ -71,6 +71,14 @@ export class Config { get debuggingTargetsArguments(): {} { return this.get<{}>("debuggingTargetsArguments"); } + + get debugConfigType(): string { + return utils.replaceVars(this.get("debugConfigType")); + } + + get customDebugConfig(): {} { + return this.get<{}>("customDebugConfig"); + } } // init the global config diff --git a/src/debugger.ts b/src/debugger.ts index 548f5b7..0a9da72 100644 --- a/src/debugger.ts +++ b/src/debugger.ts @@ -6,8 +6,8 @@ import * as fs from 'fs'; import * as path from 'path'; import * as os from 'os'; import * as encoding from 'encoding'; -import {log} from './log'; -import {config} from './config'; +import { log } from './log'; +import { config } from './config'; // the debugger class export class Debugger implements vscode.Disposable { @@ -28,7 +28,7 @@ export class Debugger implements vscode.Disposable { // no target program? if (!targetProgram) { - return ; + return; } // no target name? get it from target program @@ -42,57 +42,78 @@ export class Debugger implements vscode.Disposable { args = config.debuggingTargetsArguments[targetName]; else if ("default" in config.debuggingTargetsArguments) args = config.debuggingTargetsArguments["default"]; - + // init debug configuration var debugConfig: vscode.DebugConfiguration = null - if (os.platform() == "darwin") { - debugConfig = { - name: `launch: ${targetName}`, - type: 'cppdbg', - request: 'launch', - program: targetProgram, - args: args, - stopAtEntry: true, - cwd: path.dirname(targetProgram), - environment: [], - externalConsole: true, - MIMode: "lldb", - miDebuggerPath: "" - }; - } else if (os.platform() == "linux") { + if (config.debugConfigType == "codelldb") { debugConfig = { name: `launch: ${targetName}`, - type: 'cppdbg', + type: 'lldb', request: 'launch', program: targetProgram, args: args, stopAtEntry: true, cwd: path.dirname(targetProgram), environment: [], - externalConsole: true, - MIMode: "gdb", - miDebuggerPath: "", - description: "Enable pretty-printing for gdb", - text: "-enable-pretty-printing", - ignoreFailures: true - }; - } else if (os.platform() == "win32") { - debugConfig = { - name: `launch: ${targetName}`, - type: 'cppvsdbg', - request: 'launch', - program: targetProgram, - args: [], - stopAtEntry: true, - cwd: path.dirname(targetProgram), - environment: [], - externalConsole: true, - MIMode: "gdb", - miDebuggerPath: "", - description: "Enable pretty-printing for gdb", - text: "-enable-pretty-printing", - ignoreFailures: true + externalConsole: false, }; + } else { + if (os.platform() == "darwin") { + debugConfig = { + name: `launch: ${targetName}`, + type: 'cppdbg', + request: 'launch', + program: targetProgram, + args: args, + stopAtEntry: true, + cwd: path.dirname(targetProgram), + environment: [], + externalConsole: true, + MIMode: "lldb", + miDebuggerPath: "" + }; + } else if (os.platform() == "linux") { + debugConfig = { + name: `launch: ${targetName}`, + type: 'cppdbg', + request: 'launch', + program: targetProgram, + args: args, + stopAtEntry: true, + cwd: path.dirname(targetProgram), + environment: [], + externalConsole: true, + MIMode: "gdb", + miDebuggerPath: "", + description: "Enable pretty-printing for gdb", + text: "-enable-pretty-printing", + ignoreFailures: true + }; + } else if (os.platform() == "win32") { + debugConfig = { + name: `launch: ${targetName}`, + type: 'cppvsdbg', + request: 'launch', + program: targetProgram, + args: [], + stopAtEntry: true, + cwd: path.dirname(targetProgram), + environment: [], + externalConsole: true, + MIMode: "gdb", + miDebuggerPath: "", + description: "Enable pretty-printing for gdb", + text: "-enable-pretty-printing", + ignoreFailures: true + }; + } + + if (config.debugConfigType == "custom") { + var customcfg = config.customDebugConfig; + for (let key in customcfg) { + debugConfig[key] = customcfg[key]; + } + } } // start debugging