Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add sourceFileMap launch property #13

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
out
node_modules
node_modules
package-lock.json
*.vsix
6 changes: 3 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"stopOnEntry": false,
"sourceMaps": true,
"outFiles": [ "${workspaceRoot}/out/src/**/*.js" ],
"preLaunchTask": "npm"
"preLaunchTask": "TypeScript Compile"
},
{
"type": "node",
Expand All @@ -32,7 +32,7 @@
"stopOnEntry": false,
"sourceMaps": true,
"outFiles": [ "${workspaceRoot}/out/test/**/*.js" ],
"preLaunchTask": "npm"
"preLaunchTask": "TypeScript Compile"
},
{
"type": "node",
Expand All @@ -49,7 +49,7 @@
"sourceMaps": true,
"outFiles": [ "${workspaceRoot}/out/test/**/*.js" ],
"internalConsoleOptions": "openOnSessionStart",
"preLaunchTask": "npm"
"preLaunchTask": "TypeScript Compile"
}
],
"compounds": [
Expand Down
55 changes: 37 additions & 18 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,42 @@

// 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": true,
"type": "shell",
"presentation": {
"echo": true,
"reveal": "silent",
"focus": false,
"panel": "shared"
},
"command": "npm",
"args": [
"run",
"compile",
"--loglevel",
"silent"
],
"problemMatcher": "$tsc-watch"
},
{
"label": "Package into VSIX",
"group": "build",
"type": "shell",
"presentation": {
"reveal": "always",
"panel": "shared"
},
"command": "vsce",
"args": ["package"]
}
]
}
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -35,6 +43,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/"
}
}
]
}
Expand Down
23 changes: 17 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
"<source-path>": "<target-path>"
}
},
"stopOnEntry": {
"type": "boolean",
"description": "Automatically stop after launch.",
Expand All @@ -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": {
"<source-path>": "<target-path>"
}
},
"stopOnEntry": {
"type": "boolean",
"description": "Automatically stop after launch.",
Expand Down
79 changes: 42 additions & 37 deletions src/lrdbDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ 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;
}


export interface AttachRequestArguments extends DebugProtocol.AttachRequestArguments {
host: string;
port: number;
sourceRoot: string | string[];

sourceRoot: string;
sourceFileMap?: object;
stopOnEntry?: boolean;
}

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -289,7 +291,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;
}
Expand All @@ -298,35 +300,41 @@ 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("..")) { // client is child of source
return path.join(sourceFileMapTarget, 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("..")) { // debuggerPath is child of target
return path.join(sourceFileMapSource, relativePath);
}
}
return path.join(sourceRoot[0], filename);
}

if (path.isAbsolute(debuggerPath)) {
return debuggerPath;
} else {
return path.join(sourceRoot, debuggerPath);
}
}
}
Expand All @@ -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;
Expand Down Expand Up @@ -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) };
Expand Down Expand Up @@ -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;
}
}
}