| OLD | NEW |
| 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 Normal: 2 }; | 91 Normal: 2 }; |
| 92 | 92 |
| 93 | 93 |
| 94 // The different types of script compilations matching enum | 94 // The different types of script compilations matching enum |
| 95 // Script::CompilationType in objects.h. | 95 // Script::CompilationType in objects.h. |
| 96 Debug.ScriptCompilationType = { Host: 0, | 96 Debug.ScriptCompilationType = { Host: 0, |
| 97 Eval: 1, | 97 Eval: 1, |
| 98 JSON: 2 }; | 98 JSON: 2 }; |
| 99 | 99 |
| 100 | 100 |
| 101 // The different types of scopes matching constants runtime.cc. |
| 102 Debug.ScopeType = { Global: 0, |
| 103 Local: 1, |
| 104 With: 2, |
| 105 Closure: 3 }; |
| 106 |
| 107 |
| 101 // Current debug state. | 108 // Current debug state. |
| 102 const kNoFrame = -1; | 109 const kNoFrame = -1; |
| 103 Debug.State = { | 110 Debug.State = { |
| 104 currentFrame: kNoFrame, | 111 currentFrame: kNoFrame, |
| 105 currentSourceLine: -1 | 112 currentSourceLine: -1 |
| 106 } | 113 } |
| 107 var trace_compile = false; // Tracing all compile events? | 114 var trace_compile = false; // Tracing all compile events? |
| 108 | 115 |
| 109 | 116 |
| 110 // Process a debugger JSON message into a display text and a running status. | 117 // Process a debugger JSON message into a display text and a running status. |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 case 'backtrace': | 295 case 'backtrace': |
| 289 case 'bt': | 296 case 'bt': |
| 290 this.request_ = this.backtraceCommandToJSONRequest_(args); | 297 this.request_ = this.backtraceCommandToJSONRequest_(args); |
| 291 break; | 298 break; |
| 292 | 299 |
| 293 case 'frame': | 300 case 'frame': |
| 294 case 'f': | 301 case 'f': |
| 295 this.request_ = this.frameCommandToJSONRequest_(args); | 302 this.request_ = this.frameCommandToJSONRequest_(args); |
| 296 break; | 303 break; |
| 297 | 304 |
| 305 case 'scopes': |
| 306 this.request_ = this.scopesCommandToJSONRequest_(args); |
| 307 break; |
| 308 |
| 309 case 'scope': |
| 310 this.request_ = this.scopeCommandToJSONRequest_(args); |
| 311 break; |
| 312 |
| 298 case 'print': | 313 case 'print': |
| 299 case 'p': | 314 case 'p': |
| 300 this.request_ = this.printCommandToJSONRequest_(args); | 315 this.request_ = this.printCommandToJSONRequest_(args); |
| 301 break; | 316 break; |
| 302 | 317 |
| 303 case 'dir': | 318 case 'dir': |
| 304 this.request_ = this.dirCommandToJSONRequest_(args); | 319 this.request_ = this.dirCommandToJSONRequest_(args); |
| 305 break; | 320 break; |
| 306 | 321 |
| 307 case 'references': | 322 case 'references': |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 } | 402 } |
| 388 | 403 |
| 389 | 404 |
| 390 DebugRequest.prototype.createRequest = function(command) { | 405 DebugRequest.prototype.createRequest = function(command) { |
| 391 return new RequestPacket(command); | 406 return new RequestPacket(command); |
| 392 }; | 407 }; |
| 393 | 408 |
| 394 | 409 |
| 395 // Create a JSON request for the evaluation command. | 410 // Create a JSON request for the evaluation command. |
| 396 DebugRequest.prototype.makeEvaluateJSONRequest_ = function(expression) { | 411 DebugRequest.prototype.makeEvaluateJSONRequest_ = function(expression) { |
| 412 // Global varaible used to store whether a handle was requested. |
| 413 lookup_handle = null; |
| 397 // Check if the expression is a handle id in the form #<handle>#. | 414 // Check if the expression is a handle id in the form #<handle>#. |
| 398 var handle_match = expression.match(/^#([0-9]*)#$/); | 415 var handle_match = expression.match(/^#([0-9]*)#$/); |
| 399 if (handle_match) { | 416 if (handle_match) { |
| 417 // Remember the handle requested in a global variable. |
| 418 lookup_handle = parseInt(handle_match[1]); |
| 400 // Build a lookup request. | 419 // Build a lookup request. |
| 401 var request = this.createRequest('lookup'); | 420 var request = this.createRequest('lookup'); |
| 402 request.arguments = {}; | 421 request.arguments = {}; |
| 403 request.arguments.handle = parseInt(handle_match[1]); | 422 request.arguments.handles = [ lookup_handle ]; |
| 404 return request.toJSONProtocol(); | 423 return request.toJSONProtocol(); |
| 405 } else { | 424 } else { |
| 406 // Build an evaluate request. | 425 // Build an evaluate request. |
| 407 var request = this.createRequest('evaluate'); | 426 var request = this.createRequest('evaluate'); |
| 408 request.arguments = {}; | 427 request.arguments = {}; |
| 409 request.arguments.expression = expression; | 428 request.arguments.expression = expression; |
| 410 // Request a global evaluation if there is no current frame. | 429 // Request a global evaluation if there is no current frame. |
| 411 if (Debug.State.currentFrame == kNoFrame) { | 430 if (Debug.State.currentFrame == kNoFrame) { |
| 412 request.arguments.global = true; | 431 request.arguments.global = true; |
| 413 } | 432 } |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 var request = this.createRequest('frame'); | 571 var request = this.createRequest('frame'); |
| 553 args = args.split(/\s*[ ]+\s*/g); | 572 args = args.split(/\s*[ ]+\s*/g); |
| 554 if (args.length > 0 && args[0].length > 0) { | 573 if (args.length > 0 && args[0].length > 0) { |
| 555 request.arguments = {}; | 574 request.arguments = {}; |
| 556 request.arguments.number = args[0]; | 575 request.arguments.number = args[0]; |
| 557 } | 576 } |
| 558 return request.toJSONProtocol(); | 577 return request.toJSONProtocol(); |
| 559 }; | 578 }; |
| 560 | 579 |
| 561 | 580 |
| 581 // Create a JSON request for the scopes command. |
| 582 DebugRequest.prototype.scopesCommandToJSONRequest_ = function(args) { |
| 583 // Build a scopes request from the text command. |
| 584 var request = this.createRequest('scopes'); |
| 585 return request.toJSONProtocol(); |
| 586 }; |
| 587 |
| 588 |
| 589 // Create a JSON request for the scope command. |
| 590 DebugRequest.prototype.scopeCommandToJSONRequest_ = function(args) { |
| 591 // Build a scope request from the text command. |
| 592 var request = this.createRequest('scope'); |
| 593 args = args.split(/\s*[ ]+\s*/g); |
| 594 if (args.length > 0 && args[0].length > 0) { |
| 595 request.arguments = {}; |
| 596 request.arguments.number = args[0]; |
| 597 } |
| 598 return request.toJSONProtocol(); |
| 599 }; |
| 600 |
| 601 |
| 562 // Create a JSON request for the print command. | 602 // Create a JSON request for the print command. |
| 563 DebugRequest.prototype.printCommandToJSONRequest_ = function(args) { | 603 DebugRequest.prototype.printCommandToJSONRequest_ = function(args) { |
| 564 // Build an evaluate request from the text command. | 604 // Build an evaluate request from the text command. |
| 565 if (args.length == 0) { | 605 if (args.length == 0) { |
| 566 throw new Error('Missing expression.'); | 606 throw new Error('Missing expression.'); |
| 567 } | 607 } |
| 568 return this.makeEvaluateJSONRequest_(args); | 608 return this.makeEvaluateJSONRequest_(args); |
| 569 }; | 609 }; |
| 570 | 610 |
| 571 | 611 |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 776 print('warning: arguments to \'help\' are ignored'); | 816 print('warning: arguments to \'help\' are ignored'); |
| 777 } | 817 } |
| 778 | 818 |
| 779 print('break location [condition]'); | 819 print('break location [condition]'); |
| 780 print(' break on named function: location is a function name'); | 820 print(' break on named function: location is a function name'); |
| 781 print(' break on function: location is #<id>#'); | 821 print(' break on function: location is #<id>#'); |
| 782 print(' break on script position: location is name:line[:column]'); | 822 print(' break on script position: location is name:line[:column]'); |
| 783 print('clear <breakpoint #>'); | 823 print('clear <breakpoint #>'); |
| 784 print('backtrace [n] | [-n] | [from to]'); | 824 print('backtrace [n] | [-n] | [from to]'); |
| 785 print('frame <frame #>'); | 825 print('frame <frame #>'); |
| 826 print('scopes'); |
| 827 print('scope <scope #>'); |
| 786 print('step [in | next | out| min [step count]]'); | 828 print('step [in | next | out| min [step count]]'); |
| 787 print('print <expression>'); | 829 print('print <expression>'); |
| 830 print('dir <expression>'); |
| 788 print('source [from line [num lines]]'); | 831 print('source [from line [num lines]]'); |
| 789 print('scripts'); | 832 print('scripts'); |
| 790 print('continue'); | 833 print('continue'); |
| 791 print('trace compile'); | 834 print('trace compile'); |
| 792 print('help'); | 835 print('help'); |
| 793 } | 836 } |
| 794 | 837 |
| 795 | 838 |
| 796 function formatHandleReference_(value) { | 839 function formatHandleReference_(value) { |
| 797 return '#' + value.handle() + '#'; | 840 if (value.handle() >= 0) { |
| 841 return '#' + value.handle() + '#'; |
| 842 } else { |
| 843 return '#Transient#'; |
| 844 } |
| 798 } | 845 } |
| 799 | 846 |
| 800 | 847 |
| 801 function formatObject_(value, include_properties) { | 848 function formatObject_(value, include_properties) { |
| 802 var result = ''; | 849 var result = ''; |
| 803 result += formatHandleReference_(value); | 850 result += formatHandleReference_(value); |
| 804 result += ', type: object' | 851 result += ', type: object' |
| 805 result += ', constructor '; | 852 result += ', constructor '; |
| 806 var ctor = value.constructorFunctionValue(); | 853 var ctor = value.constructorFunctionValue(); |
| 807 result += formatHandleReference_(ctor); | 854 result += formatHandleReference_(ctor); |
| 808 result += ', __proto__ '; | 855 result += ', __proto__ '; |
| 809 var proto = value.protoObjectValue(); | 856 var proto = value.protoObjectValue(); |
| 810 result += formatHandleReference_(proto); | 857 result += formatHandleReference_(proto); |
| 811 result += ', '; | 858 result += ', '; |
| 812 result += value.propertyCount(); | 859 result += value.propertyCount(); |
| 813 result += ' properties.'; | 860 result += ' properties.'; |
| 814 if (include_properties) { | 861 if (include_properties) { |
| 815 result += '\n'; | 862 result += '\n'; |
| 816 for (var i = 0; i < value.propertyCount(); i++) { | 863 for (var i = 0; i < value.propertyCount(); i++) { |
| 817 result += ' '; | 864 result += ' '; |
| 818 result += value.propertyName(i); | 865 result += value.propertyName(i); |
| 819 result += ': '; | 866 result += ': '; |
| 820 var property_value = value.propertyValue(i); | 867 var property_value = value.propertyValue(i); |
| 821 if (property_value && property_value.type()) { | 868 if (property_value instanceof ProtocolReference) { |
| 822 result += property_value.type(); | 869 result += '<no type>'; |
| 823 } else { | 870 } else { |
| 824 result += '<no type>'; | 871 if (property_value && property_value.type()) { |
| 872 result += property_value.type(); |
| 873 } else { |
| 874 result += '<no type>'; |
| 875 } |
| 825 } | 876 } |
| 826 result += ' '; | 877 result += ' '; |
| 827 result += formatHandleReference_(property_value); | 878 result += formatHandleReference_(property_value); |
| 828 result += '\n'; | 879 result += '\n'; |
| 829 } | 880 } |
| 830 } | 881 } |
| 831 return result; | 882 return result; |
| 832 } | 883 } |
| 833 | 884 |
| 834 | 885 |
| 886 function formatScope_(scope) { |
| 887 var result = ''; |
| 888 var index = scope.index; |
| 889 result += '#' + (index <= 9 ? '0' : '') + index; |
| 890 result += ' '; |
| 891 switch (scope.type) { |
| 892 case Debug.ScopeType.Global: |
| 893 result += 'Global, '; |
| 894 result += '#' + scope.object.ref + '#'; |
| 895 break; |
| 896 case Debug.ScopeType.Local: |
| 897 result += 'Local'; |
| 898 break; |
| 899 case Debug.ScopeType.With: |
| 900 result += 'With, '; |
| 901 result += '#' + scope.object.ref + '#'; |
| 902 break; |
| 903 case Debug.ScopeType.Closure: |
| 904 result += 'Closure'; |
| 905 break; |
| 906 default: |
| 907 result += 'UNKNOWN'; |
| 908 } |
| 909 return result; |
| 910 } |
| 911 |
| 912 |
| 835 // Convert a JSON response to text for display in a text based debugger. | 913 // Convert a JSON response to text for display in a text based debugger. |
| 836 function DebugResponseDetails(response) { | 914 function DebugResponseDetails(response) { |
| 837 details = {text:'', running:false} | 915 details = {text:'', running:false} |
| 838 | 916 |
| 839 try { | 917 try { |
| 840 if (!response.success()) { | 918 if (!response.success()) { |
| 841 details.text = response.message(); | 919 details.text = response.message(); |
| 842 return details; | 920 return details; |
| 843 } | 921 } |
| 844 | 922 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 874 details.text = result; | 952 details.text = result; |
| 875 break; | 953 break; |
| 876 | 954 |
| 877 case 'frame': | 955 case 'frame': |
| 878 details.text = SourceUnderline(body.sourceLineText, | 956 details.text = SourceUnderline(body.sourceLineText, |
| 879 body.column); | 957 body.column); |
| 880 Debug.State.currentSourceLine = body.line; | 958 Debug.State.currentSourceLine = body.line; |
| 881 Debug.State.currentFrame = body.index; | 959 Debug.State.currentFrame = body.index; |
| 882 break; | 960 break; |
| 883 | 961 |
| 962 case 'scopes': |
| 963 if (body.totalScopes == 0) { |
| 964 result = '(no scopes)'; |
| 965 } else { |
| 966 result = 'Scopes #' + body.fromScope + ' to #' + |
| 967 (body.toScope - 1) + ' of ' + body.totalScopes + '\n'; |
| 968 for (i = 0; i < body.scopes.length; i++) { |
| 969 if (i != 0) { |
| 970 result += '\n'; |
| 971 } |
| 972 result += formatScope_(body.scopes[i]); |
| 973 } |
| 974 } |
| 975 details.text = result; |
| 976 break; |
| 977 |
| 978 case 'scope': |
| 979 result += formatScope_(body); |
| 980 result += '\n'; |
| 981 var scope_object_value = response.lookup(body.object.ref); |
| 982 result += formatObject_(scope_object_value, true); |
| 983 details.text = result; |
| 984 break; |
| 985 |
| 884 case 'evaluate': | 986 case 'evaluate': |
| 885 case 'lookup': | 987 case 'lookup': |
| 886 if (last_cmd == 'p' || last_cmd == 'print') { | 988 if (last_cmd == 'p' || last_cmd == 'print') { |
| 887 result = body.text; | 989 result = body.text; |
| 888 } else { | 990 } else { |
| 889 var value = response.bodyValue(); | 991 var value; |
| 992 if (lookup_handle) { |
| 993 value = response.bodyValue(lookup_handle); |
| 994 } else { |
| 995 value = response.bodyValue(); |
| 996 } |
| 890 if (value.isObject()) { | 997 if (value.isObject()) { |
| 891 result += formatObject_(value, true); | 998 result += formatObject_(value, true); |
| 892 } else { | 999 } else { |
| 893 result += 'type: '; | 1000 result += 'type: '; |
| 894 result += value.type(); | 1001 result += value.type(); |
| 895 if (!value.isUndefined() && !value.isNull()) { | 1002 if (!value.isUndefined() && !value.isNull()) { |
| 896 result += ', '; | 1003 result += ', '; |
| 897 if (value.isString()) { | 1004 if (value.isString()) { |
| 898 result += '"'; | 1005 result += '"'; |
| 899 } | 1006 } |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1096 return this.packet_.command; | 1203 return this.packet_.command; |
| 1097 } | 1204 } |
| 1098 | 1205 |
| 1099 | 1206 |
| 1100 ProtocolPackage.prototype.body = function() { | 1207 ProtocolPackage.prototype.body = function() { |
| 1101 return this.packet_.body; | 1208 return this.packet_.body; |
| 1102 } | 1209 } |
| 1103 | 1210 |
| 1104 | 1211 |
| 1105 ProtocolPackage.prototype.bodyValue = function(index) { | 1212 ProtocolPackage.prototype.bodyValue = function(index) { |
| 1106 if (index) { | 1213 if (index != null) { |
| 1107 return new ProtocolValue(this.packet_.body[index], this); | 1214 return new ProtocolValue(this.packet_.body[index], this); |
| 1108 } else { | 1215 } else { |
| 1109 return new ProtocolValue(this.packet_.body, this); | 1216 return new ProtocolValue(this.packet_.body, this); |
| 1110 } | 1217 } |
| 1111 } | 1218 } |
| 1112 | 1219 |
| 1113 | 1220 |
| 1114 ProtocolPackage.prototype.body = function() { | 1221 ProtocolPackage.prototype.body = function() { |
| 1115 return this.packet_.body; | 1222 return this.packet_.body; |
| 1116 } | 1223 } |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1504 json += NumberToJSON_(elem); | 1611 json += NumberToJSON_(elem); |
| 1505 } else if (typeof(elem) === 'string') { | 1612 } else if (typeof(elem) === 'string') { |
| 1506 json += StringToJSON_(elem); | 1613 json += StringToJSON_(elem); |
| 1507 } else { | 1614 } else { |
| 1508 json += elem; | 1615 json += elem; |
| 1509 } | 1616 } |
| 1510 } | 1617 } |
| 1511 json += ']'; | 1618 json += ']'; |
| 1512 return json; | 1619 return json; |
| 1513 } | 1620 } |
| OLD | NEW |