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

Side by Side Diff: src/d8-debug.cc

Issue 14509: Added command line debugger to D8 shell.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 12 years 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
« no previous file with comments | « src/d8-debug.h ('k') | src/debug-delay.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ native
OLDNEW
(Empty)
1 // Copyright 2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
27
28
29 #include "d8.h"
30 #include "d8-debug.h"
31
32
33 namespace v8 {
34
35
36 void HandleDebugEvent(DebugEvent event,
37 Handle<Object> exec_state,
38 Handle<Object> event_data,
39 Handle<Value> data) {
40 HandleScope scope;
41
42 // Currently only handles break and exception events.
43 if (event != Break && event != Exception) return;
44
45 TryCatch try_catch;
46
47 // Print the event details.
48 Handle<String> details = Shell::DebugEventToText(event_data);
49 String::Utf8Value str(details);
50 printf("%s\n", *str);
51
52 // Get the debug command processor.
53 Local<String> fun_name = String::New("debugCommandProcessor");
54 Local<Function> fun = Function::Cast(*exec_state->Get(fun_name));
55 Local<Object> cmd_processor =
56 Object::Cast(*fun->Call(exec_state, 0, NULL));
57 if (try_catch.HasCaught()) {
58 Shell::ReportException(&try_catch);
59 return;
60 }
61
62 static const int kBufferSize = 256;
63 bool running = false;
64 while (!running) {
65 char command[kBufferSize];
66 printf("dbg> ");
67 char* str = fgets(command, kBufferSize, stdin);
68 if (str == NULL) break;
69
70 // Ignore empty commands.
71 if (strlen(command) == 0) continue;
72
73 TryCatch try_catch;
74
75 // Convert the debugger command to a JSON debugger request.
76 Handle<Value> request =
77 Shell::DebugCommandToJSONRequest(String::New(command));
78 if (try_catch.HasCaught()) {
79 Shell::ReportException(&try_catch);
80 continue;
81 }
82
83 // If undefined is returned the command was handled internally and there is
84 // no JSON to send.
85 if (request->IsUndefined()) {
86 continue;
87 }
88
89 Handle<String> fun_name;
90 Handle<Function> fun;
91 // All the functions used below take one argument.
92 static const int kArgc = 1;
93 Handle<Value> args[kArgc];
94
95 // Invoke the JavaScript to convert the debug command line to a JSON
96 // request, invoke the JSON request and convert the JSON respose to a text
97 // representation.
98 fun_name = String::New("processDebugRequest");
99 fun = Handle<Function>::Cast(cmd_processor->Get(fun_name));
100 args[0] = request;
101 Handle<Value> response_val = fun->Call(cmd_processor, kArgc, args);
102 if (try_catch.HasCaught()) {
103 Shell::ReportException(&try_catch);
104 continue;
105 }
106 Handle<String> response = Handle<String>::Cast(response_val);
107
108 // Convert the debugger response into text details and the running state.
109 Handle<Object> response_details = Shell::DebugResponseDetails(response);
110 if (try_catch.HasCaught()) {
111 Shell::ReportException(&try_catch);
112 continue;
113 }
114 String::Utf8Value text_str(response_details->Get(String::New("text")));
115 if (text_str.length() > 0) {
116 printf("%s\n", *text_str);
117 }
118 running =
119 response_details->Get(String::New("running"))->ToBoolean()->Value();
120 }
121 }
122
123
124 } // namespace v8
OLDNEW
« no previous file with comments | « src/d8-debug.h ('k') | src/debug-delay.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698