Skip to content
This repository was archived by the owner on Apr 3, 2024. It is now read-only.

Commit 240a748

Browse files
author
Matt Loring
committed
Correct log formatting for non-primitives
We were not correctly resolving non-primitive types for log points. This change prevents a full capture from occuring and gives correct logs for objects and arrays.
1 parent 58006f0 commit 240a748

File tree

3 files changed

+20
-19
lines changed

3 files changed

+20
-19
lines changed

lib/debuglet.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,7 @@ Debuglet.prototype.addBreakpoint_ = function(breakpoint, cb) {
343343
that.logger_.info('Breakpoint hit!: ' + breakpoint.id);
344344
if (breakpoint.action === 'LOG') {
345345
var message = Debuglet.format(breakpoint.logMessageFormat,
346-
breakpoint.evaluatedExpressions.map(function(v) {
347-
return v.value;
348-
}));
346+
breakpoint.evaluatedExpressions.map(JSON.stringify));
349347
console.log(message);
350348
if (!that.completedBreakpointMap_[breakpoint.id]) {
351349
setTimeout(function() {

lib/v8debugapi.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
/** @const */ var state = require('./state.js');
2424
/** @const */ var logModule = require('@google/cloud-diagnostics-common').logger;
2525
/** @const */ var apiclasses = require('./apiclasses.js');
26-
/** @const */ var _ = require('lodash');
2726
/** @const */ var StatusMessage = apiclasses.StatusMessage;
2827

2928
/** @const */ var messages = {
@@ -485,18 +484,22 @@ module.exports.create = function(logger_, config_, fileStats_) {
485484
}
486485
}
487486
}
488-
var localConfig;
489487
if (breakpoint.action === 'LOG') {
490-
localConfig = { capture: { maxFrames: 0 } };
491-
_.defaultsDeep(localConfig, config);
488+
// TODO: This doesn't work with compiled languages if there is an error
489+
// compiling one of the expressions in the loop above.
490+
var frame = execState.frame(0);
491+
var evaluatedExpressions = breakpoint.expressions.map(function(exp) {
492+
var result = state.evaluate(exp, frame);
493+
return result.error ? result.error : result.mirror.value();
494+
});
495+
breakpoint.evaluatedExpressions = evaluatedExpressions;
492496
} else {
493-
localConfig = config;
497+
var captured = state.capture(execState, breakpoint.expressions, config);
498+
breakpoint.stackFrames = captured.stackFrames;
499+
breakpoint.variableTable = captured.variableTable;
500+
breakpoint.evaluatedExpressions =
501+
expressionErrors.concat(captured.evaluatedExpressions);
494502
}
495-
var captured = state.capture(execState, breakpoint.expressions, localConfig);
496-
breakpoint.stackFrames = captured.stackFrames;
497-
breakpoint.variableTable = captured.variableTable;
498-
breakpoint.evaluatedExpressions =
499-
expressionErrors.concat(captured.evaluatedExpressions);
500503
}
501504

502505
/**

test/e2e/test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/* KEEP THIS CODE AT THE TOP SO THAT THE BREAKPOINT LINE NUMBERS DON'T CHANGE */
22
'use strict';
33
function fib(n) {
4-
if (n < 2) { return n; }
5-
return fib(n - 1) + fib(n - 2);
4+
if (n < 2) { return n; } var o = { a: [1, 'hi', true] };
5+
return fib(n - 1, o) + fib(n - 2, o); // adding o to appease linter.
66
}
77
/**
88
* Copyright 2015 Google Inc. All Rights Reserved.
@@ -140,8 +140,8 @@ function runTest() {
140140
location: {path: 'test.js', line: 5},
141141
condition: 'n === 10',
142142
action: 'LOG',
143-
expressions: ['n'],
144-
log_message_format: 'n is: $0'
143+
expressions: ['o'],
144+
log_message_format: 'o is: $0'
145145
});
146146
// I don't know what I am doing. There is a better way to write the
147147
// following using promises.
@@ -167,7 +167,7 @@ function runTest() {
167167
return Q.delay(10 * 1000).then(function() { return result; });
168168
})
169169
.then(function(result) {
170-
assert(transcript.indexOf('n is: 10') !== -1);
170+
assert(transcript.indexOf('o is: {"a":[1,"hi",true]}') !== -1);
171171
deleteBreakpoint(result.debuggee, result.breakpoint).then();
172172
return result.debuggee;
173173
})
@@ -225,7 +225,7 @@ function runTest() {
225225
assert.ok(arg, 'should find the n argument');
226226
assert.strictEqual(arg.value, '10');
227227
console.log('-- checking log point was hit again');
228-
assert.ok(transcript.split('n is: 10').length > 4);
228+
assert.ok(transcript.split('o is: {"a":[1,"hi",true]}').length > 4);
229229
console.log('Test passed');
230230
process.exit(0);
231231
})

0 commit comments

Comments
 (0)