mirror of
https://github.com/adelphes/android-dev-ext.git
synced 2025-12-22 17:39:19 +00:00
add trace support (#38)
* add basic support for sending console logs to OutputWindow * add trace config setting * standardise logs
This commit is contained in:
@@ -93,6 +93,11 @@
|
|||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "Target Device ID (as indicated by 'adb devices'). Use this to specify which device is used for deployment when multiple devices are connected.",
|
"description": "Target Device ID (as indicated by 'adb devices'). Use this to specify which device is used for deployment when multiple devices are connected.",
|
||||||
"default": ""
|
"default": ""
|
||||||
|
},
|
||||||
|
"trace": {
|
||||||
|
"type": "boolean",
|
||||||
|
"description": "Set to true to output debugging logs for diagnostics",
|
||||||
|
"default": "false"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ const { ADBClient } = require('./adbclient');
|
|||||||
const { Debugger } = require('./debugger');
|
const { Debugger } = require('./debugger');
|
||||||
const $ = require('./jq-promise');
|
const $ = require('./jq-promise');
|
||||||
const { AndroidThread } = require('./threads');
|
const { AndroidThread } = require('./threads');
|
||||||
const { D, isEmptyObject } = require('./util');
|
const { D, onMessagePrint, isEmptyObject } = require('./util');
|
||||||
const { AndroidVariables } = require('./variables');
|
const { AndroidVariables } = require('./variables');
|
||||||
const { evaluate } = require('./expressions');
|
const { evaluate } = require('./expressions');
|
||||||
const ws_proxy = require('./wsproxy').proxy.Server(6037, 5037);
|
const ws_proxy = require('./wsproxy').proxy.Server(6037, 5037);
|
||||||
@@ -73,6 +73,9 @@ class AndroidDebugSession extends DebugSession {
|
|||||||
// flag to distinguish unexpected disconnection events (initiated from the device) vs user-terminated requests
|
// flag to distinguish unexpected disconnection events (initiated from the device) vs user-terminated requests
|
||||||
this._isDisconnecting = false;
|
this._isDisconnecting = false;
|
||||||
|
|
||||||
|
// trace flag for printing diagnostic messages to the client Output Window
|
||||||
|
this.trace = false;
|
||||||
|
|
||||||
// this debugger uses one-based lines and columns
|
// this debugger uses one-based lines and columns
|
||||||
this.setDebuggerLinesStartAt1(true);
|
this.setDebuggerLinesStartAt1(true);
|
||||||
this.setDebuggerColumnsStartAt1(true);
|
this.setDebuggerColumnsStartAt1(true);
|
||||||
@@ -106,14 +109,19 @@ class AndroidDebugSession extends DebugSession {
|
|||||||
}
|
}
|
||||||
|
|
||||||
LOG(msg) {
|
LOG(msg) {
|
||||||
D(msg);
|
if (!this.trace) {
|
||||||
|
D(msg);
|
||||||
|
}
|
||||||
// VSCode no longer auto-newlines output
|
// VSCode no longer auto-newlines output
|
||||||
this.sendEvent(new OutputEvent(msg + os.EOL));
|
this.sendEvent(new OutputEvent(msg + os.EOL));
|
||||||
}
|
}
|
||||||
|
|
||||||
WARN(msg) {
|
WARN(msg) {
|
||||||
D(msg = 'Warning: '+msg);
|
D(msg = 'Warning: '+msg);
|
||||||
this.sendEvent(new OutputEvent(msg + os.EOL));
|
// the message will already be sent if trace is enabled
|
||||||
|
if (!this.trace) {
|
||||||
|
this.sendEvent(new OutputEvent(msg + os.EOL));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
failRequest(msg, response) {
|
failRequest(msg, response) {
|
||||||
@@ -223,6 +231,10 @@ class AndroidDebugSession extends DebugSession {
|
|||||||
}
|
}
|
||||||
|
|
||||||
launchRequest(response/*: DebugProtocol.LaunchResponse*/, args/*: LaunchRequestArguments*/) {
|
launchRequest(response/*: DebugProtocol.LaunchResponse*/, args/*: LaunchRequestArguments*/) {
|
||||||
|
if (args && args.trace) {
|
||||||
|
this.trace = args.trace;
|
||||||
|
onMessagePrint(this.LOG.bind(this));
|
||||||
|
}
|
||||||
|
|
||||||
try { D('Launching: ' + JSON.stringify(args)); } catch(ex) {}
|
try { D('Launching: ' + JSON.stringify(args)); } catch(ex) {}
|
||||||
// app_src_root must end in a path-separator for correct validation of sub-paths
|
// app_src_root must end in a path-separator for correct validation of sub-paths
|
||||||
@@ -360,6 +372,9 @@ class AndroidDebugSession extends DebugSession {
|
|||||||
this.sendResponse(response);
|
this.sendResponse(response);
|
||||||
return this.dbgr.resume();
|
return this.dbgr.resume();
|
||||||
})
|
})
|
||||||
|
.then(() => {
|
||||||
|
this.LOG('Application started');
|
||||||
|
})
|
||||||
.fail(e => {
|
.fail(e => {
|
||||||
// exceptions use message, adbclient uses msg
|
// exceptions use message, adbclient uses msg
|
||||||
this.LOG('Launch failed: '+(e.message||e.msg||'No additional information is available'));
|
this.LOG('Launch failed: '+(e.message||e.msg||'No additional information is available'));
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
const $ = require('./jq-promise');
|
const $ = require('./jq-promise');
|
||||||
const { atob,btoa,D,getutf8bytes,fromutf8bytes,intToHex } = require('./util');
|
const { btoa,D,E,getutf8bytes,fromutf8bytes,intToHex } = require('./util');
|
||||||
/*
|
/*
|
||||||
JDWP - The Java Debug Wire Protocol
|
JDWP - The Java Debug Wire Protocol
|
||||||
*/
|
*/
|
||||||
@@ -96,8 +96,8 @@ function _JDWP() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.errorcode != 0) {
|
if (this.errorcode !== 0) {
|
||||||
console.error("Command failed: error " + this.errorcode, this);
|
E(`JDWP command failed '${this.command.name}'. Error ${this.errorcode}`, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.errorcode && this.command && this.command.replydecodefn) {
|
if (!this.errorcode && this.command && this.command.replydecodefn) {
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ var Deferred = exports.Deferred = function(p, parent) {
|
|||||||
var faildef = $.Deferred(null, this);
|
var faildef = $.Deferred(null, this);
|
||||||
var p = this._promise.catch(function(a) {
|
var p = this._promise.catch(function(a) {
|
||||||
if (a.stack) {
|
if (a.stack) {
|
||||||
console.error(a.stack);
|
util.E(a.stack);
|
||||||
a = [a];
|
a = [a];
|
||||||
}
|
}
|
||||||
if (this.def._context === null && this.def._parent)
|
if (this.def._context === null && this.def._parent)
|
||||||
|
|||||||
11
src/util.js
11
src/util.js
@@ -1,13 +1,18 @@
|
|||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
|
|
||||||
var nofn = function () { };
|
var nofn = function () { };
|
||||||
var D = exports.D = console.log.bind(console);
|
const messagePrintCallbacks = new Set();
|
||||||
var E = exports.E = console.error.bind(console);
|
var D = exports.D = (...args) => (console.log(...args), messagePrintCallbacks.forEach(cb => cb(...args)))
|
||||||
var W = exports.W = console.warn.bind(console);
|
var E = exports.E = (...args) => (console.error(...args), messagePrintCallbacks.forEach(cb => cb(...args)))
|
||||||
|
var W = exports.W = (...args) => (console.warn(...args), messagePrintCallbacks.forEach(cb => cb(...args)))
|
||||||
var DD = nofn, cl = D, printf = D;
|
var DD = nofn, cl = D, printf = D;
|
||||||
var print_jdwp_data = nofn;// _print_jdwp_data;
|
var print_jdwp_data = nofn;// _print_jdwp_data;
|
||||||
var print_packet = nofn;//_print_packet;
|
var print_packet = nofn;//_print_packet;
|
||||||
|
|
||||||
|
exports.onMessagePrint = function(cb) {
|
||||||
|
messagePrintCallbacks.add(cb);
|
||||||
|
}
|
||||||
|
|
||||||
Array.first = function (arr, fn, defaultvalue) {
|
Array.first = function (arr, fn, defaultvalue) {
|
||||||
var idx = Array.indexOfFirst(arr, fn);
|
var idx = Array.indexOfFirst(arr, fn);
|
||||||
return idx < 0 ? defaultvalue : arr[idx];
|
return idx < 0 ? defaultvalue : arr[idx];
|
||||||
|
|||||||
Reference in New Issue
Block a user