mirror of https://github.com/lukechilds/node.git
Browse Source
Bugs fixed: * v0.12 and later: in-object properties not printing correctly. * 64-bit: not printing external strings correctly (offset was hardcoded for 32-bit). This would happen with "::jsstack -vn0" because the script "node.js" wasn't printed correctly, at least with 0.10 core files. * 64-bit: printing JS source (via "::jsstack -v") emits errors and shows the wrong code. * Several build warnings. * Two-byte strings are unnecessarily truncated. * Could print friendlier note when given obviously bogus function token positions. New features: * ::jsstack prints much cleaner output by default. * ::jsprint keys are now quoted. * ::jsstack -v includes "this" value for each function on the stack. * ::jsstack -v includes more details about each argument (constructor names for each object). * new commands: ::jsconstructor, ::jsfunctions, ::jssource, ::nodebuffer and ::v8internal. * ::findjsobjects and ::jsprint hidden flags for developers to measure and improve test coverage. * internal jsobj_properties() function is much better documented. Reviewed-By: Timothy J Fontaine <tjfontaine@gmail.com>v0.12.0-release
Dave Pacheco
10 years ago
committed by
Julien Gilli
7 changed files with 1524 additions and 220 deletions
File diff suppressed because it is too large
@ -0,0 +1,210 @@ |
|||||
|
// Copyright Joyent, Inc. and other Node contributors.
|
||||
|
//
|
||||
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
|
// copy of this software and associated documentation files (the
|
||||
|
// "Software"), to deal in the Software without restriction, including
|
||||
|
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
|
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
||||
|
// persons to whom the Software is furnished to do so, subject to the
|
||||
|
// following conditions:
|
||||
|
//
|
||||
|
// The above copyright notice and this permission notice shall be included
|
||||
|
// in all copies or substantial portions of the Software.
|
||||
|
//
|
||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
|
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
||||
|
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
|
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
||||
|
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
|
||||
|
var common = require('../common'); |
||||
|
var assert = require('assert'); |
||||
|
var os = require('os'); |
||||
|
var path = require('path'); |
||||
|
var util = require('util'); |
||||
|
|
||||
|
if (os.type() != 'SunOS') { |
||||
|
console.error('Skipping because postmortem debugging not available.'); |
||||
|
process.exit(0); |
||||
|
} |
||||
|
|
||||
|
/* |
||||
|
* We're going to look specifically for this function and buffer in the core |
||||
|
* file. |
||||
|
*/ |
||||
|
function myTestFunction() |
||||
|
{ |
||||
|
[ 1 ].forEach(function myIterFunction(t) {}); |
||||
|
return (new Buffer(bufstr)); |
||||
|
} |
||||
|
|
||||
|
var bufstr, mybuffer; |
||||
|
|
||||
|
/* |
||||
|
* Run myTestFunction() three times to create multiple instances of |
||||
|
* myIterFunction. |
||||
|
*/ |
||||
|
bufstr = 'Hello, test suite!'; |
||||
|
mybuffer = myTestFunction(bufstr); |
||||
|
mybuffer = myTestFunction(bufstr); |
||||
|
mybuffer = myTestFunction(bufstr); |
||||
|
mybuffer.my_buffer = true; |
||||
|
|
||||
|
|
||||
|
/* |
||||
|
* Now we're going to fork ourselves to gcore |
||||
|
*/ |
||||
|
var spawn = require('child_process').spawn; |
||||
|
var prefix = '/var/tmp/node'; |
||||
|
var corefile = prefix + '.' + process.pid; |
||||
|
var tmpfile = '/var/tmp/node-postmortem-func' + '.' + process.pid; |
||||
|
var gcore = spawn('gcore', [ '-o', prefix, process.pid + '' ]); |
||||
|
var output = ''; |
||||
|
var unlinkSync = require('fs').unlinkSync; |
||||
|
var args = [ corefile ]; |
||||
|
var mybuffer; |
||||
|
|
||||
|
if (process.env.MDB_LIBRARY_PATH && process.env.MDB_LIBRARY_PATH != '') |
||||
|
args = args.concat([ '-L', process.env.MDB_LIBRARY_PATH ]); |
||||
|
|
||||
|
gcore.stderr.on('data', function (data) { |
||||
|
console.log('gcore: ' + data); |
||||
|
}); |
||||
|
|
||||
|
gcore.on('exit', function (code) { |
||||
|
if (code != 0) { |
||||
|
console.error('gcore exited with code ' + code); |
||||
|
process.exit(code); |
||||
|
} |
||||
|
|
||||
|
var mdb = spawn('mdb', args, { stdio: 'pipe' }); |
||||
|
|
||||
|
mdb.on('exit', function (code) { |
||||
|
unlinkSync(tmpfile); |
||||
|
var retained = '; core retained as ' + corefile; |
||||
|
|
||||
|
if (code != 0) { |
||||
|
console.error('mdb exited with code ' + util.inspect(code) + retained); |
||||
|
process.exit(code); |
||||
|
} |
||||
|
|
||||
|
var lines = output.split(/\n/); |
||||
|
var current = null, testname = null; |
||||
|
var whichtest = -1; |
||||
|
var i; |
||||
|
|
||||
|
for (i = 0; i < lines.length; i++) { |
||||
|
if (lines[i].indexOf('test: ') === 0) { |
||||
|
if (current !== null) { |
||||
|
console.error('verifying ' + testname + ' using ' + |
||||
|
verifiers[whichtest].name); |
||||
|
verifiers[whichtest](current); |
||||
|
} |
||||
|
whichtest++; |
||||
|
current = []; |
||||
|
testname = lines[i]; |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
if (current !== null) |
||||
|
current.push(lines[i]); |
||||
|
} |
||||
|
|
||||
|
console.error('verifying ' + testname + ' using ' + |
||||
|
verifiers[whichtest].name); |
||||
|
verifiers[whichtest](current); |
||||
|
|
||||
|
unlinkSync(corefile); |
||||
|
process.exit(0); |
||||
|
}); |
||||
|
|
||||
|
mdb.stdout.on('data', function (data) { |
||||
|
output += data; |
||||
|
}); |
||||
|
|
||||
|
mdb.stderr.on('data', function (data) { |
||||
|
console.log('mdb stderr: ' + data); |
||||
|
}); |
||||
|
|
||||
|
var verifiers = []; |
||||
|
var buffer; |
||||
|
verifiers.push(function verifyConstructor(testlines) { |
||||
|
assert.deepEqual(testlines, [ 'Buffer' ]); |
||||
|
}); |
||||
|
verifiers.push(function verifyNodebuffer(testlines) { |
||||
|
assert.equal(testlines.length, 1); |
||||
|
assert.ok(/^[0-9a-fA-F]+$/.test(testlines[0])); |
||||
|
buffer = testlines[0]; |
||||
|
}); |
||||
|
verifiers.push(function verifyBufferContents(testlines) { |
||||
|
assert.equal(testlines.length, 1); |
||||
|
assert.equal(testlines[0], '0x' + buffer + ': Hello'); |
||||
|
}); |
||||
|
verifiers.push(function verifyV8internal(testlines) { |
||||
|
assert.deepEqual(testlines, [ buffer ]); |
||||
|
}); |
||||
|
verifiers.push(function verifyJsfunctionN(testlines) { |
||||
|
assert.equal(testlines.length, 2); |
||||
|
var parts = testlines[1].trim().split(/\s+/); |
||||
|
assert.equal(parts[1], 1); |
||||
|
assert.equal(parts[2], 'myTestFunction'); |
||||
|
assert.ok(parts[3].indexOf('test-postmortem-details.js') != -1); |
||||
|
}); |
||||
|
verifiers.push(function verifyJsfunctionS(testlines) { |
||||
|
var foundtest = false, founditer = false; |
||||
|
assert.ok(testlines.length > 1); |
||||
|
testlines.forEach(function (line) { |
||||
|
var parts = line.trim().split(/\s+/); |
||||
|
if (parts[2] == 'myIterFunction') { |
||||
|
assert.equal(parts[1], '3'); |
||||
|
founditer = true; |
||||
|
} else if (parts[2] == 'myTestFunction') { |
||||
|
foundtest = true; |
||||
|
assert.equal(parts[1], '1'); |
||||
|
} |
||||
|
}); |
||||
|
assert.ok(foundtest); |
||||
|
assert.ok(founditer); |
||||
|
}); |
||||
|
verifiers.push(function verifyJssource(testlines) { |
||||
|
var content = testlines.join('\n'); |
||||
|
assert.ok(testlines[0].indexOf('test-postmortem-details.js') != -1); |
||||
|
assert.ok(content.indexOf('function myTestFunction()\n') != -1); |
||||
|
assert.ok(content.indexOf('return (new Buffer(bufstr));\n') != -1); |
||||
|
}); |
||||
|
|
||||
|
var mod = util.format('::load %s\n', |
||||
|
path.join(__dirname, |
||||
|
'..', |
||||
|
'..', |
||||
|
'out', |
||||
|
'Release', |
||||
|
'mdb_v8.so')); |
||||
|
mdb.stdin.write(mod); |
||||
|
mdb.stdin.write('!echo test: jsconstructor\n'); |
||||
|
mdb.stdin.write('::findjsobjects -p my_buffer | ::findjsobjects | ' + |
||||
|
'::jsprint -b length ! awk -F: \'$2 == ' + bufstr.length + '{ print $1 }\'' + |
||||
|
'| head -1 > ' + tmpfile + '\n'); |
||||
|
mdb.stdin.write('::cat ' + tmpfile + ' | ::jsconstructor\n'); |
||||
|
mdb.stdin.write('!echo test: nodebuffer\n'); |
||||
|
mdb.stdin.write('::cat ' + tmpfile + ' | ::nodebuffer\n'); |
||||
|
mdb.stdin.write('!echo test: nodebuffer contents\n'); |
||||
|
mdb.stdin.write('::cat ' + tmpfile + ' | ::nodebuffer | ::eval "./ccccc"\n'); |
||||
|
|
||||
|
mdb.stdin.write('!echo test: v8internal\n'); |
||||
|
mdb.stdin.write('::cat ' + tmpfile + ' | ::v8print ! awk \'$2 == "elements"{' + |
||||
|
'print $4 }\' > ' + tmpfile + '\n'); |
||||
|
mdb.stdin.write('::cat ' + tmpfile + ' | ::v8internal 0\n'); |
||||
|
|
||||
|
mdb.stdin.write('!echo test: jsfunctions -n\n'); |
||||
|
mdb.stdin.write('::jsfunctions -n myTestFunction ! cat\n'); |
||||
|
mdb.stdin.write('!echo test: jsfunctions -s\n'); |
||||
|
mdb.stdin.write('::jsfunctions -s test-postmortem-details.js ! cat\n'); |
||||
|
mdb.stdin.write('!echo test: jssource\n'); |
||||
|
mdb.stdin.write('::jsfunctions -n myTestFunction ! ' + |
||||
|
'awk \'NR == 2 {print $1}\' | head -1 > ' + tmpfile + '\n'); |
||||
|
mdb.stdin.write('::cat ' + tmpfile + ' | ::jssource -n 0\n'); |
||||
|
mdb.stdin.end(); |
||||
|
}); |
Loading…
Reference in new issue