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 |
11 // with the distribution. | 11 // with the distribution. |
12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
15 // | 15 // |
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 // Flags: --expose-debug-as debug | |
29 // Get the Debug object exposed from the debug context global object. | |
30 Debug = debug.Debug | 28 Debug = debug.Debug |
31 | 29 |
32 // Simple function which stores the last debug event. | 30 // Simple function which stores the last debug event. |
33 var listenerComplete = false; | 31 var listenerComplete = false; |
34 var exception = false; | 32 var exception = false; |
35 var f_script_id = 0; | 33 var f_script_id = 0; |
36 var g_script_id = 0; | 34 var g_script_id = 0; |
37 var h_script_id = 0; | 35 var h_script_id = 0; |
38 var f_line = 0; | 36 var f_line = 0; |
39 var g_line = 0; | 37 var g_line = 0; |
40 var h_line = 0; | 38 var h_line = 0; |
41 | 39 |
42 function listener(event, exec_state, event_data, data) { | 40 function listener(event, exec_state, event_data, data) { |
43 try { | 41 try { |
44 if (event == Debug.DebugEvent.Break) { | 42 if (event == Debug.DebugEvent.Break) { |
45 Debug.setBreakPoint(exec_state.evaluateGlobal("f").value()); | 43 if (listenerComplete) return; |
46 Debug.setBreakPoint(exec_state.evaluateGlobal("h").value()); | |
47 Debug.setBreakPoint(exec_state.evaluateGlobal("f").value(), 1); | |
48 Debug.setBreakPoint(exec_state.evaluateGlobal("f").value(), 1); | |
49 Debug.setBreakPoint(exec_state.evaluateGlobal("f").value(), | |
50 undefined, undefined, "i == 1"); | |
51 | 44 |
52 Debug.setScriptBreakPointByName("test"); | 45 Debug.setScriptBreakPointById(f_script_id, f_line); |
53 Debug.setScriptBreakPointByName("test", 1); | 46 Debug.setScriptBreakPointById(g_script_id, g_line); |
54 Debug.setScriptBreakPointByName("test", 1, 1); | 47 Debug.setScriptBreakPointById(h_script_id, h_line); |
55 | |
56 Debug.setScriptBreakPointByName(f_script_id, f_line); | |
57 Debug.setScriptBreakPointByName(g_script_id, g_line); | |
58 Debug.setScriptBreakPointByName(h_script_id, h_line); | |
59 | 48 |
60 // Indicate that all was processed. | 49 // Indicate that all was processed. |
61 listenerComplete = true; | 50 listenerComplete = true; |
62 } | 51 } |
63 } catch (e) { | 52 } catch (e) { |
64 exception = e | 53 exception = e |
| 54 print(e) |
65 }; | 55 }; |
66 }; | 56 }; |
67 | 57 |
68 // Add the debug event listener. | 58 // Add the debug event listener. |
69 Debug.setListener(listener); | 59 Debug.setListener(listener); |
70 | 60 |
71 function f() { | 61 function f() { |
72 a=1 | 62 a=1; |
73 }; | 63 }; |
74 | 64 |
75 function g() { | 65 function g() { |
76 // Comment. | 66 // Comment. |
77 f(); | 67 f(); |
78 }; | 68 }; |
79 | 69 |
80 eval('function h(){}'); | 70 eval('function h(){}'); |
81 eval('function sourceUrlFunc() { a = 2; }\n//# sourceURL=sourceUrlScript'); | 71 eval('function sourceUrlFunc() { a = 2; }\n//# sourceURL=sourceUrlScript'); |
82 | 72 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 assertTrue(!!i_script, "invalid script for i1"); | 131 assertTrue(!!i_script, "invalid script for i1"); |
142 Debug.setScriptBreakPoint(Debug.ScriptBreakPointType.ScriptId, | 132 Debug.setScriptBreakPoint(Debug.ScriptBreakPointType.ScriptId, |
143 i_script.id, 4); | 133 i_script.id, 4); |
144 } | 134 } |
145 | 135 |
146 // Creates the eval script and tries to set the breakpoint. | 136 // Creates the eval script and tries to set the breakpoint. |
147 // The tricky part is that the script function must be strongly reachable at the | 137 // The tricky part is that the script function must be strongly reachable at the |
148 // moment. Since there's no way of simply getting the pointer to the function, | 138 // moment. Since there's no way of simply getting the pointer to the function, |
149 // we run this code while the script function is being activated on stack. | 139 // we run this code while the script function is being activated on stack. |
150 eval('SetBreakpointInI1Script()\nfunction i1(){}\n\n\n\nfunction i2(){}\n'); | 140 eval('SetBreakpointInI1Script()\nfunction i1(){}\n\n\n\nfunction i2(){}\n'); |
OLD | NEW |