From 1a0d2ad97ff1d3eb1df03e5d68c6ca4908802682 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Bla=C5=BEej?= Date: Sun, 29 Mar 2020 13:41:58 +0200 Subject: [PATCH 01/11] Convert tasks.json to version 2.0.0 --- .vscode/launch.json | 6 +++--- .vscode/tasks.json | 44 ++++++++++++++++++++++++++------------------ 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index f4e730f2..07c639b9 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -11,7 +11,7 @@ "stopOnEntry": false, "sourceMaps": true, "outFiles": [ "${workspaceRoot}/out/src/**/*.js" ], - "preLaunchTask": "npm" + "preLaunchTask": "TypeScript Compile" }, { "type": "node", @@ -32,7 +32,7 @@ "stopOnEntry": false, "sourceMaps": true, "outFiles": [ "${workspaceRoot}/out/test/**/*.js" ], - "preLaunchTask": "npm" + "preLaunchTask": "TypeScript Compile" }, { "type": "node", @@ -49,7 +49,7 @@ "sourceMaps": true, "outFiles": [ "${workspaceRoot}/out/test/**/*.js" ], "internalConsoleOptions": "openOnSessionStart", - "preLaunchTask": "npm" + "preLaunchTask": "TypeScript Compile" } ], "compounds": [ diff --git a/.vscode/tasks.json b/.vscode/tasks.json index fb7f662e..293f103e 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -8,23 +8,31 @@ // A task runner that calls a custom npm script that compiles the extension. { - "version": "0.1.0", + "version": "2.0.0", - // we want to run npm - "command": "npm", - - // the command is a shell script - "isShellCommand": true, - - // show the output window only if unrecognized errors occur. - "showOutput": "silent", - - // we run the custom script "compile" as defined in package.json - "args": ["run", "compile", "--loglevel", "silent"], - - // The tsc compiler is started in watching mode - "isWatching": true, - - // use the standard tsc in watch mode problem matcher to find compile problems in the output. - "problemMatcher": "$tsc-watch" + "tasks": [ + { + "label": "TypeScript Compile", + "group": { + "kind": "build", + "isDefault": true + }, + "isBackground": false, + "type": "shell", + "presentation": { + "echo": true, + "reveal": "silent", + "focus": false, + "panel": "shared" + }, + "command": "npm", + "args": [ + "run", + "compile", + "--loglevel", + "silent" + ], + "problemMatcher": "$tsc-watch" + } + ] } \ No newline at end of file From 4284c22606cb318e2399d995065484d79c760bd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Bla=C5=BEej?= Date: Sun, 29 Mar 2020 19:33:10 +0200 Subject: [PATCH 02/11] add sourceFileMap launch property and reduce sourceRoot to single string add sourceFileMap launch.json property as a dictionary for translating local paths to remote --- package.json | 23 +++++++++++---- src/lrdbDebug.ts | 76 +++++++++++++++++++++++++----------------------- 2 files changed, 56 insertions(+), 43 deletions(-) diff --git a/package.json b/package.json index 2c501a2a..06c29f4b 100644 --- a/package.json +++ b/package.json @@ -117,10 +117,17 @@ "default": null }, "sourceRoot": { - "type": ["string", "array"], - "description": "script source root directory. to be used in souce file matching at breakpoints.", + "type": "string", + "description": "script source root directory.", "default": "${workspaceFolder}" }, + "sourceFileMap": { + "type": "object", + "description": "Optional source file mappings passed to the debug engine. Example: '{ \"/original/source/path\":\"/current/source/path\" }'", + "default": { + "": "" + } + }, "stopOnEntry": { "type": "boolean", "description": "Automatically stop after launch.", @@ -145,13 +152,17 @@ "default": 21110 }, "sourceRoot": { - "type": [ - "string", - "array" - ], + "type": "string", "description": "script source root directory.", "default": "${workspaceFolder}" }, + "sourceFileMap": { + "type": "object", + "description": "Optional source file mappings passed to the debug engine. Example: '{ \"/original/source/path\":\"/current/source/path\" }'", + "default": { + "": "" + } + }, "stopOnEntry": { "type": "boolean", "description": "Automatically stop after launch.", diff --git a/src/lrdbDebug.ts b/src/lrdbDebug.ts index c8c13981..8a42d6a0 100644 --- a/src/lrdbDebug.ts +++ b/src/lrdbDebug.ts @@ -10,14 +10,14 @@ import * as net from 'net'; import * as path from 'path'; export interface LaunchRequestArguments extends DebugProtocol.LaunchRequestArguments { - program: string; args: string[]; cwd: string; useInternalLua?: boolean; port: number; - sourceRoot?: string | string[]; + sourceRoot?: string; + sourceFileMap?: object; stopOnEntry?: boolean; } @@ -25,8 +25,8 @@ export interface LaunchRequestArguments extends DebugProtocol.LaunchRequestArgum export interface AttachRequestArguments extends DebugProtocol.AttachRequestArguments { host: string; port: number; - sourceRoot: string | string[]; - + sourceRoot: string; + sourceFileMap?: object; stopOnEntry?: boolean; } @@ -289,7 +289,7 @@ export class LuaDebugSession extends DebugSession { this.sendResponse(response); } - private setupSourceEnv(sourceRoot: string[]) { + private setupSourceEnv(sourceRoot: string, sourceFileMap?: object) { this.convertClientLineToDebugger = (line: number): number => { return line; } @@ -298,35 +298,43 @@ export class LuaDebugSession extends DebugSession { } this.convertClientPathToDebugger = (clientPath: string): string => { - for (let index = 0; index < sourceRoot.length; index++) { - var root = sourceRoot[index]; - var resolvedRoot = path.resolve(root); - var resolvedClient = path.resolve(clientPath); - if (resolvedClient.startsWith(resolvedRoot)) - { - return path.relative(resolvedRoot, resolvedClient); + if (sourceFileMap) { + for (const sourceFileMapSource of Object.keys(sourceFileMap)) { + const sourceFileMapTarget: string = sourceFileMap[sourceFileMapSource]; + const resolvedSource = path.resolve(sourceFileMapSource); + const resolvedClient = path.resolve(clientPath); + + const relativePath = path.relative(resolvedSource, resolvedClient); + if (! relativePath.startsWith("..")) { + // BUG: LRDB doesn't support absolute paths, returning only relative + //return path.join(sourceFileMapTarget, relativePath); + return relativePath; + } } } - return path.relative(sourceRoot[0], clientPath); + + return path.relative(sourceRoot, clientPath); } - this.convertDebuggerPathToClient = (debuggerPath: string): string => { - if (!debuggerPath.startsWith("@")) { return ''; } - const filename: string = debuggerPath.substr(1); - if (path.isAbsolute(filename)) { - return filename; - } - else { + this.convertDebuggerPathToClient = (argDebuggerPath: string): string => { + if (!argDebuggerPath.startsWith("@")) { return ''; } + const debuggerPath = argDebuggerPath.substr(1); + + if (sourceFileMap) { + for (const sourceFileMapSource of Object.keys(sourceFileMap)) { + const sourceFileMapTarget: string = sourceFileMap[sourceFileMapSource]; - if (sourceRoot.length > 1) { - for (let index = 0; index < sourceRoot.length; index++) { - var absolutePath = path.join(sourceRoot[index], filename); - if (existsSync(absolutePath)) { - return absolutePath - } + const relativePath = path.relative(sourceFileMapTarget, debuggerPath); + if (! relativePath.startsWith("..")) { + return path.join(sourceFileMapSource, relativePath); } } - return path.join(sourceRoot[0], filename); + } + + if (path.isAbsolute(debuggerPath)) { + return debuggerPath; + } else { + return path.join(sourceRoot, debuggerPath); } } } @@ -335,12 +343,9 @@ export class LuaDebugSession extends DebugSession { this._stopOnEntry = args.stopOnEntry; const cwd = args.cwd ? args.cwd : process.cwd(); var sourceRoot = args.sourceRoot ? args.sourceRoot : cwd; + var sourceFileMap = args.sourceFileMap; - if (typeof (sourceRoot) === "string") { - sourceRoot = [sourceRoot]; - } - - this.setupSourceEnv(sourceRoot); + this.setupSourceEnv(sourceRoot, sourceFileMap); const programArg = args.args ? args.args : []; const port = args.port ? args.port : 21110; @@ -394,12 +399,9 @@ export class LuaDebugSession extends DebugSession { let args = oargs as AttachRequestArguments; this._stopOnEntry = args.stopOnEntry; var sourceRoot = args.sourceRoot; + var sourceFileMap = args.sourceFileMap; - if (typeof (sourceRoot) === "string") { - sourceRoot = [sourceRoot]; - } - - this.setupSourceEnv(sourceRoot); + this.setupSourceEnv(sourceRoot, sourceFileMap); this._debug_client = new LRDBTCPClient(args.port, args.host); this._debug_client.on_event = (event: DebugServerEvent) => { this.handleServerEvents(event) }; From 7d751dc55a1073e08b974e7185fccc43a449dd21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Bla=C5=BEej?= Date: Sun, 29 Mar 2020 19:57:14 +0200 Subject: [PATCH 03/11] update README.md --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index 62c5a20e..3b061247 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,17 @@ launch.json example: "program": "${file}", "cwd": "${workspaceFolder}", "stopOnEntry": true + }, + { + "type": "lrdb", + "request": "attach", + "host": "192.168.1.28", + "port": 21110, + "name": "attach to remote debugger", + "sourceRoot": "${workspaceFolder}", + "sourceFileMap": { + "${workspaceFolder}": "/mnt/luadb_b/" + } } ] } From 97ad5e20a2d61b473992340f9383815bb9851e45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Bla=C5=BEej?= Date: Thu, 9 Apr 2020 00:02:25 +0200 Subject: [PATCH 04/11] fix vscode ts compiler task --- .vscode/tasks.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 293f103e..2a637630 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -17,7 +17,7 @@ "kind": "build", "isDefault": true }, - "isBackground": false, + "isBackground": true, "type": "shell", "presentation": { "echo": true, From 9d4e278545e324fc302f0b6f37c0c550187df507 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Bla=C5=BEej?= Date: Thu, 9 Apr 2020 00:02:54 +0200 Subject: [PATCH 05/11] add package.lock to .gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 8e5962ee..1294fe26 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ out -node_modules \ No newline at end of file +node_modules +package-lock.json From ed3759b92753401ba734aa2d4c2232a291bd36fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Bla=C5=BEej?= Date: Thu, 9 Apr 2020 00:03:17 +0200 Subject: [PATCH 06/11] make debugger use absolute paths --- src/lrdbDebug.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/lrdbDebug.ts b/src/lrdbDebug.ts index 8a42d6a0..019ec052 100644 --- a/src/lrdbDebug.ts +++ b/src/lrdbDebug.ts @@ -306,9 +306,7 @@ export class LuaDebugSession extends DebugSession { const relativePath = path.relative(resolvedSource, resolvedClient); if (! relativePath.startsWith("..")) { - // BUG: LRDB doesn't support absolute paths, returning only relative - //return path.join(sourceFileMapTarget, relativePath); - return relativePath; + return path.join(sourceFileMapTarget, relativePath); } } } From eb9c1386379a4cd06df6af4667f0e03b3300d893 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Bla=C5=BEej?= Date: Thu, 9 Apr 2020 00:30:46 +0200 Subject: [PATCH 07/11] add comments --- src/lrdbDebug.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lrdbDebug.ts b/src/lrdbDebug.ts index 019ec052..f52e0eaf 100644 --- a/src/lrdbDebug.ts +++ b/src/lrdbDebug.ts @@ -305,7 +305,7 @@ export class LuaDebugSession extends DebugSession { const resolvedClient = path.resolve(clientPath); const relativePath = path.relative(resolvedSource, resolvedClient); - if (! relativePath.startsWith("..")) { + if (! relativePath.startsWith("..")) { // client is child of source return path.join(sourceFileMapTarget, relativePath); } } @@ -323,7 +323,7 @@ export class LuaDebugSession extends DebugSession { const sourceFileMapTarget: string = sourceFileMap[sourceFileMapSource]; const relativePath = path.relative(sourceFileMapTarget, debuggerPath); - if (! relativePath.startsWith("..")) { + if (! relativePath.startsWith("..")) { // debuggerPath is child of target return path.join(sourceFileMapSource, relativePath); } } From bde762e7bfcb01e174e92ae6f99f9c6bd22f6fe7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Bla=C5=BEej?= Date: Thu, 9 Apr 2020 13:06:22 +0200 Subject: [PATCH 08/11] add "build vsix" task --- .gitignore | 1 + .vscode/tasks.json | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/.gitignore b/.gitignore index 1294fe26..e63219de 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ out node_modules package-lock.json +*.vsix diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 2a637630..40568de9 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -33,6 +33,20 @@ "silent" ], "problemMatcher": "$tsc-watch" + }, + { + "label": "Package into VSIX", + "group": "build", + "isBackground": false, + "type": "shell", + "presentation": { + "echo": true, + "reveal": "silent", + "focus": false, + "panel": "shared" + }, + "command": "vsce", + "args": ["package"] } ] } \ No newline at end of file From 3516bd644df5890358bee02e3bae1529fff827d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Bla=C5=BEej?= Date: Thu, 16 Apr 2020 14:22:36 +0200 Subject: [PATCH 09/11] update package task --- .vscode/tasks.json | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 40568de9..cede88ae 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -37,12 +37,9 @@ { "label": "Package into VSIX", "group": "build", - "isBackground": false, "type": "shell", "presentation": { - "echo": true, - "reveal": "silent", - "focus": false, + "reveal": "always", "panel": "shared" }, "command": "vsce", From c8c26fc0ad8d0684e61aa3537ffa519370223423 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Bla=C5=BEej?= Date: Sat, 18 Apr 2020 23:59:56 +0200 Subject: [PATCH 10/11] add remote working directory to LuaDebugSession --- src/lrdbDebug.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/lrdbDebug.ts b/src/lrdbDebug.ts index f52e0eaf..901baaf8 100644 --- a/src/lrdbDebug.ts +++ b/src/lrdbDebug.ts @@ -250,6 +250,8 @@ export class LuaDebugSession extends DebugSession { private _stopOnEntry: boolean; + private _working_directory: string; + /** * Creates a new debug adapter that is used for one debug session. @@ -745,5 +747,8 @@ export class LuaDebugSession extends DebugSession { } else if (event.method == "exit") { } + else if (event.method == "connected") { + this._working_directory = event.params.working_directory; + } } } From ef840fb39cadf5a0c2d175d28958ff12c6357e51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Bla=C5=BEej?= Date: Mon, 18 May 2020 20:09:28 +0200 Subject: [PATCH 11/11] update readme --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 3b061247..d5d9ff67 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,13 @@ # Lua Remote DeBugger for Visual Studio Code +## Fork changes + +This fork is modified to use absolute paths from LRDB debugger instead of relative. +It also defines new `launch.json` property - sourceFileMap for translating +remote paths to local and vice-versa. + +This fork works only with similarly modified LRDB - [kapecp/LRDB](https://github.com/kapecp/lrdb). + ## Introduction This extension is debug Lua programs with Visual Studio Code.