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

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

Issue 14195: 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.cc » ('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 = Shell::DebugCommandToJSONRequest(String::New(command ));
77 if (try_catch.HasCaught()) {
78 Shell::ReportException(&try_catch);
79 continue;
80 }
81
82 // If undefined is returned the command was handled internally and there is
83 // no JSON to send.
84 if (request->IsUndefined()) {
85 continue;
86 }
87
88 Handle<String> fun_name;
89 Handle<Function> fun;
90 // All the functions used below takes one argument.
91 static const int kArgc = 1;
92 Handle<Value> args[kArgc];
93
94 // Invoke the JavaScript to convert the debug command line to a JSON
95 // request, invoke the JSON request and convert the JSON respose to a text
96 // representation.
97 fun_name = String::New("processDebugRequest");
98 fun = Handle<Function>::Cast(cmd_processor->Get(fun_name));
99 args[0] = request;
100 Handle<Value> response_val = fun->Call(cmd_processor, kArgc, args);
101 if (try_catch.HasCaught()) {
102 Shell::ReportException(&try_catch);
103 continue;
104 }
105 Handle<String> response = Handle<String>::Cast(response_val);
106
107 // Convert the debugger response into text details and the running state.
108 Handle<Object> response_details = Shell::DebugResponseDetails(response);
109 if (try_catch.HasCaught()) {
110 Shell::ReportException(&try_catch);
111 continue;
112 }
113 String::Utf8Value text_str(response_details->Get(String::New("text")));
114 if (text_str.length() > 0) {
115 printf("%s\n", *text_str);
116 }
117 running =
118 response_details->Get(String::New("running"))->ToBoolean()->Value();
119 }
120 }
121
122
123 } // namespace v8
OLDNEW
« no previous file with comments | « src/d8-debug.h ('k') | src/debug.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698