Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(166)

Side by Side Diff: src/d8.js

Issue 6351007: Adding debugger interface and runtime functions hooks for supporting... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2008 the V8 project authors. All rights reserved. 1 // Copyright 2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 const kNoFrame = -1; 110 const kNoFrame = -1;
111 Debug.State = { 111 Debug.State = {
112 currentFrame: kNoFrame, 112 currentFrame: kNoFrame,
113 displaySourceStartLine: -1, 113 displaySourceStartLine: -1,
114 displaySourceEndLine: -1, 114 displaySourceEndLine: -1,
115 currentSourceLine: -1 115 currentSourceLine: -1
116 } 116 }
117 var trace_compile = false; // Tracing all compile events? 117 var trace_compile = false; // Tracing all compile events?
118 var trace_debug_json = false; // Tracing all debug json packets? 118 var trace_debug_json = false; // Tracing all debug json packets?
119 var last_cmd_line = ''; 119 var last_cmd_line = '';
120 //var lol_is_enabled; // Set to true in d8.cc if LIVE_OBJECT_LIST is defined.
121 var lol_next_dump_index = 0;
122 const kDefaultLolLinesToPrintAtATime = 10;
123 const kMaxLolLinesToPrintAtATime = 1000;
120 var repeat_cmd_line = ''; 124 var repeat_cmd_line = '';
121 var is_running = true; 125 var is_running = true;
122 126
123 // Copied from debug-delay.js. This is needed below: 127 // Copied from debug-delay.js. This is needed below:
124 function ScriptTypeFlag(type) { 128 function ScriptTypeFlag(type) {
125 return (1 << type); 129 return (1 << type);
126 } 130 }
127 131
128 132
129 // Process a debugger JSON message into a display text and a running status. 133 // Process a debugger JSON message into a display text and a running status.
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 this.traceCommand_(args); 492 this.traceCommand_(args);
489 break; 493 break;
490 494
491 case 'help': 495 case 'help':
492 case '?': 496 case '?':
493 this.helpCommand_(args); 497 this.helpCommand_(args);
494 // Return undefined to indicate command handled internally (no JSON). 498 // Return undefined to indicate command handled internally (no JSON).
495 this.request_ = void 0; 499 this.request_ = void 0;
496 break; 500 break;
497 501
502 case 'liveobjectlist':
503 case 'lol':
504 if (lol_is_enabled) {
505 this.request_ = this.lolToJSONRequest_(args, is_repeating);
506 break;
507 }
508
498 default: 509 default:
499 throw new Error('Unknown command "' + cmd + '"'); 510 throw new Error('Unknown command "' + cmd + '"');
500 } 511 }
501 } 512 }
502 513
503 DebugRequest.prototype.JSONRequest = function() { 514 DebugRequest.prototype.JSONRequest = function() {
504 return this.request_; 515 return this.request_;
505 } 516 }
506 517
507 518
(...skipping 24 matching lines...) Expand all
532 json += '}'; 543 json += '}';
533 return json; 544 return json;
534 } 545 }
535 546
536 547
537 DebugRequest.prototype.createRequest = function(command) { 548 DebugRequest.prototype.createRequest = function(command) {
538 return new RequestPacket(command); 549 return new RequestPacket(command);
539 }; 550 };
540 551
541 552
553 // Note: we use detected command repetition as a signal for continuation here.
554 DebugRequest.prototype.createLOLRequest = function(command,
555 start_index,
556 lines_to_dump,
557 is_continuation) {
558 if (is_continuation) {
559 start_index = lol_next_dump_index;
560 }
561
562 if (lines_to_dump) {
563 lines_to_dump = parseInt(lines_to_dump);
564 } else {
565 lines_to_dump = kDefaultLolLinesToPrintAtATime;
566 }
567 if (lines_to_dump > kMaxLolLinesToPrintAtATime) {
568 lines_to_dump = kMaxLolLinesToPrintAtATime;
569 }
570
571 // Save the next start_index to dump from:
572 lol_next_dump_index = start_index + lines_to_dump;
573
574 var request = this.createRequest(command);
575 request.arguments = {};
576 request.arguments.start = start_index;
577 request.arguments.count = lines_to_dump;
578
579 return request;
580 };
581
582
542 // Create a JSON request for the evaluation command. 583 // Create a JSON request for the evaluation command.
543 DebugRequest.prototype.makeEvaluateJSONRequest_ = function(expression) { 584 DebugRequest.prototype.makeEvaluateJSONRequest_ = function(expression) {
544 // Global varaible used to store whether a handle was requested. 585 // Global varaible used to store whether a handle was requested.
545 lookup_handle = null; 586 lookup_handle = null;
587
588 if (lol_is_enabled) {
589 // Check if the expression is a obj id in the form @<obj id>.
590 var obj_id_match = expression.match(/^@([0-9]+)$/);
591 if (obj_id_match) {
592 // Remember the handle requested in a global variable.
Søren Thygesen Gjesse 2011/01/19 08:36:40 Maybe change handle to id here to keep the distinc
marklam 2011/01/19 09:04:02 This comment is a cut-and-paste error from the # c
593 var obj_id = parseInt(obj_id_match[1]);
594 // Build a dump request.
595 var request = this.createRequest('getobj');
596 request.arguments = {};
597 request.arguments.obj_id = obj_id;
598 return request.toJSONProtocol();
599 }
600 }
601
546 // Check if the expression is a handle id in the form #<handle>#. 602 // Check if the expression is a handle id in the form #<handle>#.
547 var handle_match = expression.match(/^#([0-9]*)#$/); 603 var handle_match = expression.match(/^#([0-9]*)#$/);
548 if (handle_match) { 604 if (handle_match) {
549 // Remember the handle requested in a global variable. 605 // Remember the handle requested in a global variable.
550 lookup_handle = parseInt(handle_match[1]); 606 lookup_handle = parseInt(handle_match[1]);
551 // Build a lookup request. 607 // Build a lookup request.
552 var request = this.createRequest('lookup'); 608 var request = this.createRequest('lookup');
553 request.arguments = {}; 609 request.arguments = {};
554 request.arguments.handles = [ lookup_handle ]; 610 request.arguments.handles = [ lookup_handle ];
555 return request.toJSONProtocol(); 611 return request.toJSONProtocol();
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after
1096 request = this.createRequest('listbreakpoints'); 1152 request = this.createRequest('listbreakpoints');
1097 last_cmd = 'info break'; 1153 last_cmd = 'info break';
1098 } else if (args && (args == 'locals' || args == 'lo')) { 1154 } else if (args && (args == 'locals' || args == 'lo')) {
1099 // Build a evaluate request from the text command. 1155 // Build a evaluate request from the text command.
1100 request = this.createRequest('frame'); 1156 request = this.createRequest('frame');
1101 last_cmd = 'info locals'; 1157 last_cmd = 'info locals';
1102 } else if (args && (args == 'args' || args == 'ar')) { 1158 } else if (args && (args == 'args' || args == 'ar')) {
1103 // Build a evaluate request from the text command. 1159 // Build a evaluate request from the text command.
1104 request = this.createRequest('frame'); 1160 request = this.createRequest('frame');
1105 last_cmd = 'info args'; 1161 last_cmd = 'info args';
1162 } else if (lol_is_enabled &&
1163 args && (args == 'liveobjectlist' || args == 'lol')) {
1164 // Build a evaluate request from the text command.
1165 return this.liveObjectListToJSONRequest_(null);
1106 } else { 1166 } else {
1107 throw new Error('Invalid info arguments.'); 1167 throw new Error('Invalid info arguments.');
1108 } 1168 }
1109 1169
1110 return request.toJSONProtocol(); 1170 return request.toJSONProtocol();
1111 }; 1171 };
1112 1172
1113 1173
1114 DebugRequest.prototype.v8FlagsToJSONRequest_ = function(args) { 1174 DebugRequest.prototype.v8FlagsToJSONRequest_ = function(args) {
1115 var request; 1175 var request;
(...skipping 30 matching lines...) Expand all
1146 break; 1206 break;
1147 } 1207 }
1148 // Else fall thru to the default case below to report the error. 1208 // Else fall thru to the default case below to report the error.
1149 default: 1209 default:
1150 throw new Error('Missing arguments after ' + cmd + '.'); 1210 throw new Error('Missing arguments after ' + cmd + '.');
1151 } 1211 }
1152 return request.toJSONProtocol(); 1212 return request.toJSONProtocol();
1153 }; 1213 };
1154 1214
1155 1215
1216 // Args: [v[erbose]] [<N>] [i[ndex] <i>] [t[ype] <type>] [sp[ace] <space>]
1217 DebugRequest.prototype.lolMakeListRequest =
1218 function(cmd, args, first_arg_index, is_repeating) {
1219
1220 var request;
1221 var start_index = 0;
1222 var dump_limit = void 0;
1223 var type_filter = void 0;
1224 var space_filter = void 0;
1225 var prop_filter = void 0;
1226 var is_verbose = false;
1227 var i;
1228
1229 for (i = first_arg_index; i < args.length; i++) {
1230 var arg = args[i];
1231 // Check for [v[erbose]]:
1232 if (arg === 'verbose' || arg === 'v') {
1233 // Nothing to do. This is already implied by args.length > 3.
1234 is_verbose = true;
1235
1236 // Check for [<N>]:
1237 } else if (arg.match(/^[0-9]+$/)) {
1238 dump_limit = arg;
1239 is_verbose = true;
1240
1241 // Check for i[ndex] <i>:
1242 } else if (arg === 'index' || arg === 'i') {
1243 i++;
1244 if (args.length < i) {
1245 throw new Error('Missing index after ' + arg + '.');
1246 }
1247 start_index = parseInt(args[i]);
1248 // The user input start index starts at 1:
1249 if (start_index <= 0) {
1250 throw new Error('Invalid index ' + args[i] + '.');
1251 }
1252 start_index -= 1;
1253 is_verbose = true;
1254
1255 // Check for t[ype] <type>:
1256 } else if (arg === 'type' || arg === 't') {
1257 i++;
1258 if (args.length < i) {
1259 throw new Error('Missing type after ' + arg + '.');
1260 }
1261 type_filter = args[i];
1262
1263 // Check for space <heap space name>:
1264 } else if (arg === 'space' || arg === 'sp') {
1265 i++;
1266 if (args.length < i) {
1267 throw new Error('Missing space name after ' + arg + '.');
1268 }
1269 space_filter = args[i];
1270
1271 // Check for property <prop name>:
1272 } else if (arg === 'property' || arg === 'prop') {
1273 i++;
1274 if (args.length < i) {
1275 throw new Error('Missing property name after ' + arg + '.');
1276 }
1277 prop_filter = args[i];
1278
1279 } else {
1280 throw new Error('Unknown args at ' + arg + '.');
1281 }
1282 }
1283
1284 // Build the verbose request:
1285 if (is_verbose) {
1286 request = this.createLOLRequest('lol-'+cmd,
1287 start_index,
1288 dump_limit,
1289 is_repeating);
1290 request.arguments.verbose = true;
1291 } else {
1292 request = this.createRequest('lol-'+cmd);
1293 request.arguments = {};
1294 }
1295
1296 request.arguments.filter = {};
1297 if (type_filter) {
1298 request.arguments.filter.type = type_filter;
1299 }
1300 if (space_filter) {
1301 request.arguments.filter.space = space_filter;
1302 }
1303 if (prop_filter) {
1304 request.arguments.filter.prop = prop_filter;
1305 }
1306
1307 return request;
1308 }
1309
1310
1311 function extractObjId(args) {
1312 var id = args;
1313 id = id.match(/^@([0-9]+)$/);
1314 if (id) {
1315 id = id[1];
1316 } else {
1317 throw new Error('Invalid obj id ' + args + '.');
1318 }
1319 return parseInt(id);
1320 }
1321
1322
1323 DebugRequest.prototype.lolToJSONRequest_ = function(args, is_repeating) {
1324 var request;
1325 // Use default command if one is not specified:
1326 if (!args) {
1327 args = 'info';
1328 }
1329
1330 var orig_args = args;
1331 var first_arg_index;
1332
1333 var arg, i;
1334 var args = args.split(/\s+/g);
1335 var cmd = args[0];
1336 var id;
1337
1338 // Command: <id> [v[erbose]] ...
1339 if (cmd.match(/^[0-9]+$/)) {
1340 // Convert to the padded list command:
1341 // Command: l[ist] <dummy> <id> [v[erbose]] ...
1342
1343 // Insert the implicit 'list' in front and process as normal:
1344 cmd = 'list';
1345 args.unshift(cmd);
1346 }
1347
1348 switch(cmd) {
1349 // Command: c[apture]
1350 case 'capture':
1351 case 'c':
1352 request = this.createRequest('lol-capture');
1353 break;
1354
1355 // Command: clear|d[elete] <id>|all
1356 case 'clear':
1357 case 'delete':
1358 case 'del': {
1359 if (args.length < 2) {
1360 throw new Error('Missing argument after ' + cmd + '.');
1361 } else if (args.length > 2) {
1362 throw new Error('Too many arguments after ' + cmd + '.');
1363 }
1364 id = args[1];
1365 if (id.match(/^[0-9]+$/)) {
1366 // Delete a specific lol record:
1367 request = this.createRequest('lol-delete');
1368 request.arguments = {};
1369 request.arguments.id = parseInt(id);
1370 } else if (id === 'all') {
1371 // Delete all:
1372 request = this.createRequest('lol-reset');
1373 } else {
1374 throw new Error('Invalid argument after ' + cmd + '.');
1375 }
1376 break;
1377 }
1378
1379 // Command: diff <id1> <id2> [<dump options>]
1380 case 'diff':
1381 first_arg_index = 3;
1382
1383 // Command: list <dummy> <id> [<dump options>]
1384 case 'list':
1385
1386 // Command: ret[ainers] <obj id> [<dump options>]
1387 case 'retainers':
1388 case 'ret':
1389 case 'retaining-paths':
1390 case 'rp': {
1391 if (cmd === 'ret') cmd = 'retainers';
1392 else if (cmd === 'rp') cmd = 'retaining-paths';
1393
1394 if (!first_arg_index) first_arg_index = 2;
1395
1396 if (args.length < first_arg_index) {
1397 throw new Error('Too few arguments after ' + cmd + '.');
1398 }
1399
1400 var request_cmd = (cmd === 'list') ? 'diff':cmd;
1401 request = this.lolMakeListRequest(request_cmd,
1402 args,
1403 first_arg_index,
1404 is_repeating);
1405
1406 if (cmd === 'diff') {
1407 request.arguments.id1 = parseInt(args[1]);
1408 request.arguments.id2 = parseInt(args[2]);
1409 } else if (cmd == 'list') {
1410 request.arguments.id1 = 0;
1411 request.arguments.id2 = parseInt(args[1]);
1412 } else {
1413 request.arguments.id = extractObjId(args[1]);
1414 }
1415 break;
1416 }
1417
1418 // Command: getid
1419 case 'getid': {
1420 request = this.createRequest('lol-getid');
1421 request.arguments = {};
1422 request.arguments.address = args[1];
1423 break;
1424 }
1425
1426 // Command: inf[o] [<N>]
1427 case 'info':
1428 case 'inf': {
1429 if (args.length > 2) {
1430 throw new Error('Too many arguments after ' + cmd + '.');
1431 }
1432 // Built the info request:
1433 request = this.createLOLRequest('lol-info', 0, args[1], is_repeating);
1434 break;
1435 }
1436
1437 // Command: path <obj id 1> <obj id 2>
1438 case 'path': {
1439 request = this.createRequest('lol-path');
1440 request.arguments = {};
1441 if (args.length > 2) {
1442 request.arguments.id1 = extractObjId(args[1]);
1443 request.arguments.id2 = extractObjId(args[2]);
1444 } else {
1445 request.arguments.id1 = 0;
1446 request.arguments.id2 = extractObjId(args[1]);
1447 }
1448 break;
1449 }
1450
1451 // Command: print
1452 case 'print': {
1453 request = this.createRequest('lol-print');
1454 request.arguments = {};
1455 request.arguments.id = extractObjId(args[1]);
1456 break;
1457 }
1458
1459 // Command: reset
1460 case 'reset': {
1461 request = this.createRequest('lol-reset');
1462 break;
1463 }
1464
1465 default:
1466 throw new Error('Invalid arguments.');
1467 }
1468 return request.toJSONProtocol();
1469 };
1470
1471
1156 // Create a JSON request for the threads command. 1472 // Create a JSON request for the threads command.
1157 DebugRequest.prototype.threadsCommandToJSONRequest_ = function(args) { 1473 DebugRequest.prototype.threadsCommandToJSONRequest_ = function(args) {
1158 // Build a threads request from the text command. 1474 // Build a threads request from the text command.
1159 var request = this.createRequest('threads'); 1475 var request = this.createRequest('threads');
1160 return request.toJSONProtocol(); 1476 return request.toJSONProtocol();
1161 }; 1477 };
1162 1478
1163 1479
1164 // Handle the trace command. 1480 // Handle the trace command.
1165 DebugRequest.prototype.traceCommand_ = function(args) { 1481 DebugRequest.prototype.traceCommand_ = function(args) {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1232 print('set <var> = <expression> - executes the specified statement'); 1548 print('set <var> = <expression> - executes the specified statement');
1233 print(''); 1549 print('');
1234 print('l[ist] - list the source code around for the curren t pc'); 1550 print('l[ist] - list the source code around for the curren t pc');
1235 print('l[ist] [- | <start>,<end>] - list the specified range of source code'); 1551 print('l[ist] [- | <start>,<end>] - list the specified range of source code');
1236 print('source [from line [num lines]]'); 1552 print('source [from line [num lines]]');
1237 print('scr[ipts] [native|extensions|all]'); 1553 print('scr[ipts] [native|extensions|all]');
1238 print('scr[ipts] [<filter text>] - list scripts with the specified text in it s description'); 1554 print('scr[ipts] [<filter text>] - list scripts with the specified text in it s description');
1239 print(''); 1555 print('');
1240 print('gc - runs the garbage collector'); 1556 print('gc - runs the garbage collector');
1241 print(''); 1557 print('');
1558
1559 if (lol_is_enabled) {
1560 print('liveobjectlist|lol <command> - live object list tracking.');
1561 print(' where <command> can be:');
1562 print(' c[apture] - captures a LOL list.');
1563 print(' clear|del[ete] <id>|all - clears LOL of id <id>.');
1564 print(' If \'all\' is unspecified instead, will c lear all.');
1565 print(' diff <id1> <id2> [<dump options>]');
1566 print(' - prints the diff between LOLs id1 and id2. ');
1567 print(' - also see <dump options> below.');
1568 print(' getid <address> - gets the obj id for the specified address if available.');
1569 print(' The address must be in hex form prefixed with 0x.');
1570 print(' inf[o] [<N>] - lists summary info of all LOL lists.');
1571 print(' If N is specified, will print N items at a time.');
1572 print(' [l[ist]] <id> [<dump options>]');
1573 print(' - prints the listing of objects in LOL id.' );
1574 print(' - also see <dump options> below.');
1575 print(' reset - clears all LOL lists.');
1576 print(' ret[ainers] <id> [<dump options>]');
1577 print(' - prints the list of retainers of obj id.') ;
1578 print(' - also see <dump options> below.');
1579 print(' path <id1> <id2> - prints the retaining path from obj id1 to id2.');
1580 print(' If only one id is specified, will print t he path from');
1581 print(' roots to the specified object if availabl e.');
1582 print(' print <id> - prints the obj for the specified obj id i f available.');
1583 print('');
1584 print(' <dump options> includes:');
1585 print(' [v[erbose]] - do verbose dump.');
1586 print(' [<N>] - dump N items at a time. Implies verbos e dump.');
1587 print(' If unspecified, N will default to '+
1588 kDefaultLolLinesToPrintAtATime+'. Max N is '+
1589 kMaxLolLinesToPrintAtATime+'.');
1590 print(' [i[ndex] <i>] - start dump from index i. Implies verbo se dump.');
1591 print(' [t[ype] <type>] - filter by type.');
1592 print(' [sp[ace] <space name>] - filter by heap space where <space name> is one of');
1593 print(' { cell, code, lo, map, new, old-data, o ld-pointer }.');
1594 print('');
1595 print(' If the verbose option, or an option that implies a verbose dump' );
1596 print(' is specified, then a verbose dump will requested. Else, a summa ry dump');
1597 print(' will be requested.');
1598 print('');
1599 }
1600
1242 print('trace compile'); 1601 print('trace compile');
1243 // hidden command: trace debug json - toggles tracing of debug json packets 1602 // hidden command: trace debug json - toggles tracing of debug json packets
1244 print(''); 1603 print('');
1245 print('disconnect|exit|quit - disconnects and quits the debugger'); 1604 print('disconnect|exit|quit - disconnects and quits the debugger');
1246 print('help - prints this help information'); 1605 print('help - prints this help information');
1247 } 1606 }
1248 1607
1249 1608
1250 function formatHandleReference_(value) { 1609 function formatHandleReference_(value) {
1251 if (value.handle() >= 0) { 1610 if (value.handle() >= 0) {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1332 result = '"' + value.value() + '"'; 1691 result = '"' + value.value() + '"';
1333 } else if (value.isPrimitive()) { 1692 } else if (value.isPrimitive()) {
1334 result = value.valueString(); 1693 result = value.valueString();
1335 } else if (value.isObject()) { 1694 } else if (value.isObject()) {
1336 result += formatObject_(value, true); 1695 result += formatObject_(value, true);
1337 } 1696 }
1338 return result; 1697 return result;
1339 } 1698 }
1340 1699
1341 1700
1701 function decodeLolCaptureResponse(body) {
1702 var result;
1703 result = 'Captured live object list '+ body.id +
1704 ': count '+ body.count + ' size ' + body.size;
1705 return result;
1706 }
1707
1708
1709 function decodeLolDeleteResponse(body) {
1710 var result;
1711 result = 'Deleted live object list '+ body.id;
1712 return result;
1713 }
1714
1715
1716 function digitsIn(value) {
1717 var digits = 0;
1718 if (value === 0) value = 1;
1719 while (value >= 1) {
1720 digits++;
1721 value /= 10;
1722 }
1723 return digits;
1724 }
1725
1726
1727 function padding(value, max_digits) {
1728 var padding_digits = max_digits - digitsIn(value);
1729 var padding = '';
1730 while (padding_digits > 0) {
1731 padding += ' ';
1732 padding_digits--;
1733 }
1734 return padding;
1735 }
1736
1737
1738 function decodeLolInfoResponse(body) {
1739 var result;
1740 var lists = body.lists;
1741 var length = lists.length;
1742 var first_index = body.first_index + 1;
1743 var has_more = ((first_index + length) <= body.count);
1744 result = 'captured live object lists';
1745 if (has_more || (first_index != 1)) {
1746 result += ' ['+ length +' of '+ body.count +
1747 ': starting from '+ first_index +']';
1748 }
1749 result += ':\n';
1750 var max_digits = digitsIn(body.count);
1751 var last_count = 0;
1752 var last_size = 0;
1753 for (var i = 0; i < length; i++) {
1754 var entry = lists[i];
1755 var count = entry.count;
1756 var size = entry.size;
1757 var index = first_index + i;
1758 result += ' [' + padding(index, max_digits) + index + '] id '+ entry.id +
1759 ': count '+ count;
1760 if (last_count > 0) {
1761 result += '(+' + (count - last_count) + ')';
1762 }
1763 result += ' size '+ size;
1764 if (last_size > 0) {
1765 result += '(+' + (size - last_size) + ')';
1766 }
1767 result += '\n';
1768 last_count = count;
1769 last_size = size;
1770 }
1771 result += ' total: '+length+' lists\n';
1772 if (has_more) {
1773 result += ' -- press <enter> for more --\n';
1774 } else {
1775 repeat_cmd_line = '';
1776 }
1777 if (length === 0) result += ' none\n';
1778
1779 return result;
1780 }
1781
1782
1783 function decodeLolListResponse(body, title) {
1784
1785 var result;
1786 var total_count = body.count;
1787 var total_size = body.size;
1788 var length;
1789 var max_digits;
1790 var i;
1791 var entry;
1792 var index;
1793
1794 var max_count_digits = digitsIn(total_count);
1795 var max_size_digits;
1796
1797 var summary = body.summary;
1798 if (summary) {
1799
1800 var roots_count = 0;
1801 var found_root = body.found_root || 0;
1802 var found_weak_root = body.found_weak_root || 0;
1803
1804 // Print the summary result:
1805 result = 'summary of objects:\n';
1806 length = summary.length;
1807 if (found_root !== 0) {
1808 roots_count++;
1809 }
1810 if (found_weak_root !== 0) {
1811 roots_count++;
1812 }
1813 max_digits = digitsIn(length + roots_count);
1814 max_size_digits = digitsIn(total_size);
1815
1816 index = 1;
1817 if (found_root !== 0) {
1818 result += ' [' + padding(index, max_digits) + index + '] ' +
1819 ' count '+ 1 + padding(0, max_count_digits) +
1820 ' '+ padding(0, max_size_digits+1) +
1821 ' : <root>\n';
1822 index++;
1823 }
1824 if (found_weak_root !== 0) {
1825 result += ' [' + padding(index, max_digits) + index + '] ' +
1826 ' count '+ 1 + padding(0, max_count_digits) +
1827 ' '+ padding(0, max_size_digits+1) +
1828 ' : <weak root>\n';
1829 index++;
1830 }
1831
1832 for (i = 0; i < length; i++) {
1833 entry = summary[i];
1834 var count = entry.count;
1835 var size = entry.size;
1836 result += ' [' + padding(index, max_digits) + index + '] ' +
1837 ' count '+ count + padding(count, max_count_digits) +
1838 ' size '+ size + padding(size, max_size_digits) +
1839 ' : <' + entry.desc + '>\n';
1840 index++;
1841 }
1842 result += '\n total count: '+(total_count+roots_count)+'\n';
1843 if (body.size) {
1844 result += ' total size: '+body.size+'\n';
1845 }
1846
1847 } else {
1848 // Print the full dump result:
1849 var first_index = body.first_index + 1;
1850 var elements = body.elements;
1851 length = elements.length;
1852 var has_more = ((first_index + length) <= total_count);
1853 result = title;
1854 if (has_more || (first_index != 1)) {
1855 result += ' ['+ length +' of '+ total_count +
1856 ': starting from '+ first_index +']';
1857 }
1858 result += ':\n';
1859 if (length === 0) result += ' none\n';
1860 max_digits = digitsIn(length);
1861
1862 var max_id = 0;
1863 var max_size = 0;
1864 for (i = 0; i < length; i++) {
1865 entry = elements[i];
1866 if (entry.id > max_id) max_id = entry.id;
1867 if (entry.size > max_size) max_size = entry.size;
1868 }
1869 var max_id_digits = digitsIn(max_id);
1870 max_size_digits = digitsIn(max_size);
1871
1872 for (i = 0; i < length; i++) {
1873 entry = elements[i];
1874 index = first_index + i;
1875 result += ' ['+ padding(index, max_digits) + index +']';
1876 if (entry.id !== 0) {
1877 result += ' @' + entry.id + padding(entry.id, max_id_digits) +
1878 ': size ' + entry.size + ', ' +
1879 padding(entry.size, max_size_digits) + entry.desc + '\n';
1880 } else {
1881 // Must be a root or weak root:
1882 result += ' ' + entry.desc + '\n';
1883 }
1884 }
1885 if (has_more) {
1886 result += ' -- press <enter> for more --\n';
1887 } else {
1888 repeat_cmd_line = '';
1889 }
1890 if (length === 0) result += ' none\n';
1891 }
1892
1893 return result;
1894 }
1895
1896
1897 function decodeLolDiffResponse(body) {
1898 var title = 'objects';
1899 return decodeLolListResponse(body, title);
1900 }
1901
1902
1903 function decodeLolRetainersResponse(body) {
1904 var title = 'retainers for @' + body.id;
1905 return decodeLolListResponse(body, title);
1906 }
1907
1908
1909 function decodeLolPathResponse(body) {
1910 return body.path;
1911 }
1912
1913
1914 function decodeLolResetResponse(body) {
1915 return 'Reset all live object lists.';
1916 }
1917
1918
1919 function decodeLolGetIdResponse(body) {
1920 if (body.id == 0) {
1921 return 'Address is invalid, or object has been moved or collected';
1922 }
1923 return 'obj id is @' + body.id;
1924 }
1925
1926
1927 function decodeLolPrintResponse(body) {
1928 return body.dump;
1929 }
1930
1931
1342 // Rounds number 'num' to 'length' decimal places. 1932 // Rounds number 'num' to 'length' decimal places.
1343 function roundNumber(num, length) { 1933 function roundNumber(num, length) {
1344 var factor = Math.pow(10, length); 1934 var factor = Math.pow(10, length);
1345 return Math.round(num * factor) / factor; 1935 return Math.round(num * factor) / factor;
1346 } 1936 }
1347 1937
1348 1938
1349 // Convert a JSON response to text for display in a text based debugger. 1939 // Convert a JSON response to text for display in a text based debugger.
1350 function DebugResponseDetails(response) { 1940 function DebugResponseDetails(response) {
1351 details = {text:'', running:false} 1941 details = {text:'', running:false}
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
1503 case 'scope': 2093 case 'scope':
1504 result += formatScope_(body); 2094 result += formatScope_(body);
1505 result += '\n'; 2095 result += '\n';
1506 var scope_object_value = response.lookup(body.object.ref); 2096 var scope_object_value = response.lookup(body.object.ref);
1507 result += formatObject_(scope_object_value, true); 2097 result += formatObject_(scope_object_value, true);
1508 details.text = result; 2098 details.text = result;
1509 break; 2099 break;
1510 2100
1511 case 'evaluate': 2101 case 'evaluate':
1512 case 'lookup': 2102 case 'lookup':
2103 case 'getobj':
1513 if (last_cmd == 'p' || last_cmd == 'print') { 2104 if (last_cmd == 'p' || last_cmd == 'print') {
1514 result = body.text; 2105 result = body.text;
1515 } else { 2106 } else {
1516 var value; 2107 var value;
1517 if (lookup_handle) { 2108 if (lookup_handle) {
1518 value = response.bodyValue(lookup_handle); 2109 value = response.bodyValue(lookup_handle);
1519 } else { 2110 } else {
1520 value = response.bodyValue(); 2111 value = response.bodyValue();
1521 } 2112 }
1522 if (value.isObject()) { 2113 if (value.isObject()) {
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
1664 details.text += 2255 details.text +=
1665 " (" + roundNumber(body.before/(1024*1024), 1) + "M => " + 2256 " (" + roundNumber(body.before/(1024*1024), 1) + "M => " +
1666 roundNumber(body.after/(1024*1024), 1) + "M)"; 2257 roundNumber(body.after/(1024*1024), 1) + "M)";
1667 } else if (body.after > 1024) { 2258 } else if (body.after > 1024) {
1668 details.text += 2259 details.text +=
1669 " (" + roundNumber(body.before/1024, 1) + "K => " + 2260 " (" + roundNumber(body.before/1024, 1) + "K => " +
1670 roundNumber(body.after/1024, 1) + "K)"; 2261 roundNumber(body.after/1024, 1) + "K)";
1671 } 2262 }
1672 break; 2263 break;
1673 2264
2265 case 'lol-capture':
2266 details.text = decodeLolCaptureResponse(body);
2267 break;
2268 case 'lol-delete':
2269 details.text = decodeLolDeleteResponse(body);
2270 break;
2271 case 'lol-diff':
2272 details.text = decodeLolDiffResponse(body);
2273 break;
2274 case 'lol-getid':
2275 details.text = decodeLolGetIdResponse(body);
2276 break;
2277 case 'lol-info':
2278 details.text = decodeLolInfoResponse(body);
2279 break;
2280 case 'lol-print':
2281 details.text = decodeLolPrintResponse(body);
2282 break;
2283 case 'lol-reset':
2284 details.text = decodeLolResetResponse(body);
2285 break;
2286 case 'lol-retainers':
2287 details.text = decodeLolRetainersResponse(body);
2288 break;
2289 case 'lol-path':
2290 details.text = decodeLolPathResponse(body);
2291 break;
2292
1674 default: 2293 default:
1675 details.text = 2294 details.text =
1676 'Response for unknown command \'' + response.command() + '\'' + 2295 'Response for unknown command \'' + response.command() + '\'' +
1677 ' (' + response.raw_json() + ')'; 2296 ' (' + response.raw_json() + ')';
1678 } 2297 }
1679 } catch (e) { 2298 } catch (e) {
1680 details.text = 'Error: "' + e + '" formatting response'; 2299 details.text = 'Error: "' + e + '" formatting response';
1681 } 2300 }
1682 2301
1683 return details; 2302 return details;
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after
2171 json += NumberToJSON_(elem); 2790 json += NumberToJSON_(elem);
2172 } else if (typeof(elem) === 'string') { 2791 } else if (typeof(elem) === 'string') {
2173 json += StringToJSON_(elem); 2792 json += StringToJSON_(elem);
2174 } else { 2793 } else {
2175 json += elem; 2794 json += elem;
2176 } 2795 }
2177 } 2796 }
2178 json += ']'; 2797 json += ']';
2179 return json; 2798 return json;
2180 } 2799 }
OLDNEW
« no previous file with comments | « src/d8.cc ('k') | src/debug-debugger.js » ('j') | src/debug-debugger.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698