Skip to content

Support preliminary brakepoints #30

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

Merged
merged 5 commits into from
Mar 22, 2016
Merged
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
37 changes: 36 additions & 1 deletion adapter/pathTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import * as utils from '../webkit/utilities';
import {DebugProtocol} from 'vscode-debugprotocol';
import * as path from 'path';
import {ISetBreakpointsArgs, IDebugTransformer, ILaunchRequestArgs, IAttachRequestArgs, IStackTraceResponseBody} from '../webkit/WebKitAdapterInterfaces';

interface IPendingBreakpoint {
Expand All @@ -21,10 +22,12 @@ export class PathTransformer implements IDebugTransformer {
private _clientPathToWebkitUrl = new Map<string, string>();
private _webkitUrlToClientPath = new Map<string, string>();
private _pendingBreakpointsByPath = new Map<string, IPendingBreakpoint>();
private inferedDeviceRoot :string = null;

public launch(args: ILaunchRequestArgs): void {
this._webRoot = utils.getAppRoot(args);
this._platform = args.platform;
this.inferedDeviceRoot = (this._platform === 'ios') ? 'file://' : this.inferedDeviceRoot;
}

public attach(args: IAttachRequestArgs): void {
Expand All @@ -51,7 +54,28 @@ export class PathTransformer implements IDebugTransformer {
args.source.path = this._clientPathToWebkitUrl.get(url);
utils.Logger.log(`Paths.setBP: Resolved ${url} to ${args.source.path}`);
resolve();
} else {
}
else if (this.inferedDeviceRoot) {
let inferedUrl = url.replace(this._webRoot, this.inferedDeviceRoot).replace(/\\/g, "/");

//change device path if {N} core module or {N} module
if (inferedUrl.indexOf("/node_modules/tns-core-modules/") != -1)
{
inferedUrl = inferedUrl.replace("/node_modules/tns-core-modules/", "/app/tns_modules/");
}
else if (inferedUrl.indexOf("/node_modules/") != -1)
{
inferedUrl = inferedUrl.replace("/node_modules/", "/app/tns_modules/");
}

//change platform specific paths
inferedUrl = inferedUrl.replace(`.${this._platform}.`, '.');

args.source.path = inferedUrl;
utils.Logger.log(`Paths.setBP: Resolved (by infering) ${url} to ${args.source.path}`);
resolve();
}
else {
utils.Logger.log(`Paths.setBP: No target url cached for client path: ${url}, waiting for target script to be loaded.`);
args.source.path = url;
this._pendingBreakpointsByPath.set(args.source.path, { resolve, reject, args });
Expand All @@ -70,6 +94,17 @@ export class PathTransformer implements IDebugTransformer {

public scriptParsed(event: DebugProtocol.Event): void {
const webkitUrl: string = event.body.scriptUrl;
if (!this.inferedDeviceRoot && this._platform === "android")
{
this.inferedDeviceRoot = utils.inferDeviceRoot(this._webRoot, this._platform, webkitUrl);
utils.Logger.log("\n\n\n ***Inferred device root: " + this.inferedDeviceRoot + "\n\n\n");

if (this.inferedDeviceRoot.indexOf("/data/user/0/") != -1)
{
this.inferedDeviceRoot = this.inferedDeviceRoot.replace("/data/user/0/", "/data/data/");
}
}

const clientPath = utils.webkitUrlToClientPath(this._webRoot, this._platform, webkitUrl);

if (!clientPath) {
Expand Down
54 changes: 33 additions & 21 deletions adapter/sourceMaps/sourceMapTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class SourceMapTransformer implements IDebugTransformer {
*/
public setBreakpoints(args: ISetBreakpointsArgs, requestSeq: number): Promise<void> {
return new Promise<void>((resolve, reject) => {
if (this._sourceMaps && args.source.path) {
if (this._sourceMaps && args.source.path && path.extname(args.source.path) !== ".js") {
const argsPath = args.source.path;
const mappedPath = this._sourceMaps.MapPathFromSource(argsPath);
if (mappedPath) {
Expand Down Expand Up @@ -189,26 +189,8 @@ export class SourceMapTransformer implements IDebugTransformer {

let sourceMapUrlValue = event.body.sourceMapURL;

if (!event.body.sourceMapURL) {

let fileContents = fs.readFileSync(event.body.scriptUrl, 'utf8');

var baseRegex = "\\s*[@#]\\s*sourceMappingURL\\s*=\\s*([^\\s]*)";

// Matches /* ... */ comments
var blockCommentRegex = new RegExp("/\\*" + baseRegex + "\\s*\\*/");

// Matches // .... comments
var commentRegex = new RegExp("//" + baseRegex + "($|\n|\r\n?)");

let match = fileContents.match(commentRegex);
if (!match) {
match = fileContents.match(blockCommentRegex);
}

if (match) {
sourceMapUrlValue = match[1];
}
if (!sourceMapUrlValue) {
sourceMapUrlValue = this._sourceMaps.FindSourceMapUrlInFile(event.body.scriptUrl);
}

if (!sourceMapUrlValue || sourceMapUrlValue === "") {
Expand All @@ -226,6 +208,36 @@ export class SourceMapTransformer implements IDebugTransformer {
}
}

// private getSourceMappingFile(filePathOrSourceMapValue: string): string {

// let result = filePathOrSourceMapValue;

// if (!fs.existsSync(filePathOrSourceMapValue)) {
// return result;
// }

// let fileContents = fs.readFileSync(filePathOrSourceMapValue, 'utf8');

// var baseRegex = "\\s*[@#]\\s*sourceMappingURL\\s*=\\s*([^\\s]*)";

// // Matches /* ... */ comments
// var blockCommentRegex = new RegExp("/\\*" + baseRegex + "\\s*\\*/");

// // Matches // .... comments
// var commentRegex = new RegExp("//" + baseRegex + "($|\n|\r\n?)");

// let match = fileContents.match(commentRegex);
// if (!match) {
// match = fileContents.match(blockCommentRegex);
// }

// if (match) {
// result = match[1];
// }

// return result;
// }

private resolvePendingBreakpoints(sourcePath: string): void {
// If there's a setBreakpoints request waiting on this script, go through setBreakpoints again
if (this._pendingBreakpointsByPath.has(sourcePath)) {
Expand Down
Loading