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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 // Current debug state. | 96 // Current debug state. |
97 const kNoFrame = -1; | 97 const kNoFrame = -1; |
98 Debug.State = { | 98 Debug.State = { |
99 currentFrame: kNoFrame, | 99 currentFrame: kNoFrame, |
100 currentSourceLine: -1 | 100 currentSourceLine: -1 |
101 } | 101 } |
102 var trace_compile = false; // Tracing all compile events? | 102 var trace_compile = false; // Tracing all compile events? |
103 | 103 |
104 | 104 |
105 function DebugEventToText(event) { | 105 function DebugEventToText(event) { |
106 switch (event.eventType()) { | 106 // Convert the JSON string to an object. |
107 case Debug.DebugEvent.Break: | 107 var response = new ProtocolPackage(event); |
108 // Build the break details. | 108 |
109 var details = ''; | 109 // Build the text. |
110 if (event.breakPointsHit()) { | 110 var body = response.body(); |
| 111 var details = ''; |
| 112 switch (response.event()) { |
| 113 case 'break': |
| 114 if (body.breakpoints) { |
111 details += 'breakpoint'; | 115 details += 'breakpoint'; |
112 if (event.breakPointsHit().length > 1) { | 116 if (body.breakpoints.length > 1) { |
113 details += 's'; | 117 details += 's'; |
114 } | 118 } |
115 details += ' #'; | 119 details += ' #'; |
116 for (var i = 0; i < event.breakPointsHit().length; i++) { | 120 for (var i = 0; i < body.breakpoints.length; i++) { |
117 if (i > 0) { | 121 if (i > 0) { |
118 details += ', #'; | 122 details += ', #'; |
119 } | 123 } |
120 // Find the break point number. For break points originating from a | 124 details += body.breakpoints[i]; |
121 // script break point display the script break point number. | |
122 var break_point = event.breakPointsHit()[i]; | |
123 var script_break_point = break_point.script_break_point(); | |
124 if (script_break_point) { | |
125 details += script_break_point.number(); | |
126 } else { | |
127 details += break_point.number(); | |
128 } | |
129 } | 125 } |
130 } else { | 126 } else { |
131 details += 'break'; | 127 details += 'break'; |
132 } | 128 } |
133 details += ' in '; | 129 details += ' in '; |
134 details += event.executionState().frame(0).invocationText(); | 130 details += body.invocationText; |
135 details += ' at '; | 131 details += ', '; |
136 details += event.executionState().frame(0).sourceAndPositionText(); | 132 details += SourceInfo(body); |
137 details += '\n' | 133 details += '\n'; |
138 if (event.func().script()) { | 134 details += SourceUnderline(body.sourceLineText, body.sourceColumn); |
139 details += FrameSourceUnderline(event.executionState().frame(0)); | 135 Debug.State.currentSourceLine = body.sourceLine; |
140 } | |
141 Debug.State.currentSourceLine = | |
142 event.executionState().frame(0).sourceLine(); | |
143 Debug.State.currentFrame = 0; | 136 Debug.State.currentFrame = 0; |
144 return details; | 137 return details; |
145 | 138 |
146 case Debug.DebugEvent.Exception: | 139 case 'exception': |
147 var details = ''; | 140 if (body.uncaught) { |
148 if (event.uncaught_) { | |
149 details += 'Uncaught: '; | 141 details += 'Uncaught: '; |
150 } else { | 142 } else { |
151 details += 'Exception: '; | 143 details += 'Exception: '; |
152 } | 144 } |
153 | |
154 details += '"'; | 145 details += '"'; |
155 details += event.exception(); | 146 details += body.exception.text; |
156 details += '"'; | 147 details += '"'; |
157 if (event.executionState().frameCount() > 0) { | 148 if (body.sourceLine >= 0) { |
158 details += '"'; | 149 details += ', '; |
159 details += event.exception(); | 150 details += SourceInfo(body); |
160 details += ' at '; | |
161 details += event.executionState().frame(0).sourceAndPositionText(); | |
162 details += '\n'; | 151 details += '\n'; |
163 details += FrameSourceUnderline(event.executionState().frame(0)); | 152 details += SourceUnderline(body.sourceLineText, body.sourceColumn); |
164 Debug.State.currentSourceLine = | 153 Debug.State.currentSourceLine = body.sourceLine; |
165 event.executionState().frame(0).sourceLine(); | |
166 Debug.State.currentFrame = 0; | 154 Debug.State.currentFrame = 0; |
167 } else { | 155 } else { |
168 details += ' (empty stack)'; | 156 details += ' (empty stack)'; |
169 Debug.State.currentSourceLine = -1; | 157 Debug.State.currentSourceLine = -1; |
170 Debug.State.currentFrame = kNoFrame; | 158 Debug.State.currentFrame = kNoFrame; |
171 } | 159 } |
172 return details; | 160 return details; |
173 | 161 |
174 case Debug.DebugEvent.AfterCompile: | 162 case 'exception': |
| 163 if (trace_compile) { |
| 164 details = 'Source ' + body.script.name + ' compiled:\n' |
| 165 } else { |
| 166 return ''; |
| 167 } |
| 168 |
| 169 case 'afterCompile': |
175 if (trace_compile) { | 170 if (trace_compile) { |
176 details = 'Source ' + event.script().name() + ' compiled:\n' | 171 details = 'Source ' + event.script().name() + ' compiled:\n' |
177 var source = event.script().source(); | 172 var source = body.script.source; |
178 if (!(source[source.length - 1] == '\n')) { | 173 if (!(source[source.length - 1] == '\n')) { |
179 details += source; | 174 details += source; |
180 } else { | 175 } else { |
181 details += source.substring(0, source.length - 1); | 176 details += source.substring(0, source.length - 1); |
182 } | 177 } |
183 return details; | 178 return details; |
184 } else { | 179 } else { |
185 return ''; | 180 return ''; |
186 } | 181 } |
187 } | 182 } |
| 183 return 'Unknown debug event ' + response.event(); |
| 184 }; |
188 | 185 |
189 return 'Unknown debug event ' + event.eventType(); | 186 |
190 }; | 187 function SourceInfo(body) { |
| 188 var result = ''; |
| 189 |
| 190 if (body.script) { |
| 191 if (body.script.name) { |
| 192 result += body.script.name; |
| 193 } else { |
| 194 result += '[unnamed]'; |
| 195 } |
| 196 } |
| 197 result += ' line '; |
| 198 result += body.sourceLine + 1; |
| 199 result += ' column '; |
| 200 result += body.sourceColumn + 1; |
| 201 |
| 202 return result; |
| 203 } |
191 | 204 |
192 | 205 |
193 function SourceUnderline(source_text, position) { | 206 function SourceUnderline(source_text, position) { |
194 if (!source_text) { | 207 if (!source_text) { |
195 return; | 208 return; |
196 } | 209 } |
197 | 210 |
198 // Create an underline with a caret pointing to the source position. If the | 211 // Create an underline with a caret pointing to the source position. If the |
199 // source contains a tab character the underline will have a tab character in | 212 // source contains a tab character the underline will have a tab character in |
200 // the same place otherwise the underline will have a space character. | 213 // the same place otherwise the underline will have a space character. |
201 var underline = ''; | 214 var underline = ''; |
202 for (var i = 0; i < position; i++) { | 215 for (var i = 0; i < position; i++) { |
203 if (source_text[i] == '\t') { | 216 if (source_text[i] == '\t') { |
204 underline += '\t'; | 217 underline += '\t'; |
205 } else { | 218 } else { |
206 underline += ' '; | 219 underline += ' '; |
207 } | 220 } |
208 } | 221 } |
209 underline += '^'; | 222 underline += '^'; |
210 | 223 |
211 // Return the source line text with the underline beneath. | 224 // Return the source line text with the underline beneath. |
212 return source_text + '\n' + underline; | 225 return source_text + '\n' + underline; |
213 }; | 226 }; |
214 | 227 |
215 | 228 |
216 function FrameSourceUnderline(frame) { | |
217 var location = frame.sourceLocation(); | |
218 if (location) { | |
219 return SourceUnderline(location.sourceText(), | |
220 location.position - location.start); | |
221 } | |
222 }; | |
223 | |
224 | |
225 // Converts a text command to a JSON request. | 229 // Converts a text command to a JSON request. |
226 function DebugCommandToJSONRequest(cmd_line) { | 230 function DebugCommandToJSONRequest(cmd_line) { |
227 return new DebugRequest(cmd_line).JSONRequest(); | 231 return new DebugRequest(cmd_line).JSONRequest(); |
228 }; | 232 }; |
229 | 233 |
230 | 234 |
231 function DebugRequest(cmd_line) { | 235 function DebugRequest(cmd_line) { |
232 // If the very first character is a { assume that a JSON request have been | 236 // If the very first character is a { assume that a JSON request have been |
233 // entered as a command. Converting that to a JSON request is trivial. | 237 // entered as a command. Converting that to a JSON request is trivial. |
234 if (cmd_line && cmd_line.length > 0 && cmd_line.charAt(0) == '{') { | 238 if (cmd_line && cmd_line.length > 0 && cmd_line.charAt(0) == '{') { |
(...skipping 1145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1380 json += NumberToJSON_(elem); | 1384 json += NumberToJSON_(elem); |
1381 } else if (typeof(elem) === 'string') { | 1385 } else if (typeof(elem) === 'string') { |
1382 json += StringToJSON_(elem); | 1386 json += StringToJSON_(elem); |
1383 } else { | 1387 } else { |
1384 json += elem; | 1388 json += elem; |
1385 } | 1389 } |
1386 } | 1390 } |
1387 json += ']'; | 1391 json += ']'; |
1388 return json; | 1392 return json; |
1389 } | 1393 } |
OLD | NEW |