OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/service.h" | 5 #include "vm/service.h" |
6 | 6 |
7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
8 #include "include/dart_native_api.h" | 8 #include "include/dart_native_api.h" |
9 #include "platform/globals.h" | 9 #include "platform/globals.h" |
10 | 10 |
(...skipping 1007 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1018 | 1018 |
1019 | 1019 |
1020 static const MethodParameter* get_stack_params[] = { | 1020 static const MethodParameter* get_stack_params[] = { |
1021 ISOLATE_PARAMETER, | 1021 ISOLATE_PARAMETER, |
1022 new BoolParameter("_full", false), | 1022 new BoolParameter("_full", false), |
1023 NULL, | 1023 NULL, |
1024 }; | 1024 }; |
1025 | 1025 |
1026 | 1026 |
1027 static bool GetStack(Thread* thread, JSONStream* js) { | 1027 static bool GetStack(Thread* thread, JSONStream* js) { |
| 1028 if (!thread->isolate()->compilation_allowed()) { |
| 1029 js->PrintError(kFeatureDisabled, |
| 1030 "Cannot get stack when running a precompiled program."); |
| 1031 return true; |
| 1032 } |
1028 Isolate* isolate = thread->isolate(); | 1033 Isolate* isolate = thread->isolate(); |
1029 DebuggerStackTrace* stack = isolate->debugger()->StackTrace(); | 1034 DebuggerStackTrace* stack = isolate->debugger()->StackTrace(); |
1030 // Do we want the complete script object and complete local variable objects? | 1035 // Do we want the complete script object and complete local variable objects? |
1031 // This is true for dump requests. | 1036 // This is true for dump requests. |
1032 const bool full = BoolParameter::Parse(js->LookupParam("_full"), false); | 1037 const bool full = BoolParameter::Parse(js->LookupParam("_full"), false); |
1033 JSONObject jsobj(js); | 1038 JSONObject jsobj(js); |
1034 jsobj.AddProperty("type", "Stack"); | 1039 jsobj.AddProperty("type", "Stack"); |
1035 { | 1040 { |
1036 JSONArray jsarr(&jsobj, "frames"); | 1041 JSONArray jsarr(&jsobj, "frames"); |
1037 | 1042 |
(...skipping 1006 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2044 const Class& cls, | 2049 const Class& cls, |
2045 const Function& func) const { | 2050 const Function& func) const { |
2046 return func.raw() == func_.raw(); | 2051 return func.raw() == func_.raw(); |
2047 } | 2052 } |
2048 private: | 2053 private: |
2049 const Function& func_; | 2054 const Function& func_; |
2050 }; | 2055 }; |
2051 | 2056 |
2052 | 2057 |
2053 static bool GetHitsOrSites(Thread* thread, JSONStream* js, bool as_sites) { | 2058 static bool GetHitsOrSites(Thread* thread, JSONStream* js, bool as_sites) { |
| 2059 if (!thread->isolate()->compilation_allowed()) { |
| 2060 js->PrintError(kFeatureDisabled, |
| 2061 "Cannot get coverage data when running a precompiled program."); |
| 2062 return true; |
| 2063 } |
2054 if (!js->HasParam("targetId")) { | 2064 if (!js->HasParam("targetId")) { |
2055 CodeCoverage::PrintJSON(thread, js, NULL, as_sites); | 2065 CodeCoverage::PrintJSON(thread, js, NULL, as_sites); |
2056 return true; | 2066 return true; |
2057 } | 2067 } |
2058 const char* target_id = js->LookupParam("targetId"); | 2068 const char* target_id = js->LookupParam("targetId"); |
2059 Object& obj = Object::Handle(LookupHeapObject(thread, target_id, NULL)); | 2069 Object& obj = Object::Handle(LookupHeapObject(thread, target_id, NULL)); |
2060 if (obj.raw() == Object::sentinel().raw()) { | 2070 if (obj.raw() == Object::sentinel().raw()) { |
2061 PrintInvalidParamError(js, "targetId"); | 2071 PrintInvalidParamError(js, "targetId"); |
2062 return true; | 2072 return true; |
2063 } | 2073 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2111 | 2121 |
2112 | 2122 |
2113 static bool GetCallSiteData(Thread* thread, JSONStream* js) { | 2123 static bool GetCallSiteData(Thread* thread, JSONStream* js) { |
2114 return GetHitsOrSites(thread, js, true); | 2124 return GetHitsOrSites(thread, js, true); |
2115 } | 2125 } |
2116 | 2126 |
2117 | 2127 |
2118 static bool AddBreakpointCommon(Thread* thread, | 2128 static bool AddBreakpointCommon(Thread* thread, |
2119 JSONStream* js, | 2129 JSONStream* js, |
2120 const String& script_uri) { | 2130 const String& script_uri) { |
| 2131 if (!thread->isolate()->compilation_allowed()) { |
| 2132 js->PrintError(kFeatureDisabled, |
| 2133 "Cannot use breakpoints when running a precompiled program."); |
| 2134 return true; |
| 2135 } |
2121 const char* line_param = js->LookupParam("line"); | 2136 const char* line_param = js->LookupParam("line"); |
2122 intptr_t line = UIntParameter::Parse(line_param); | 2137 intptr_t line = UIntParameter::Parse(line_param); |
2123 const char* col_param = js->LookupParam("column"); | 2138 const char* col_param = js->LookupParam("column"); |
2124 intptr_t col = -1; | 2139 intptr_t col = -1; |
2125 if (col_param != NULL) { | 2140 if (col_param != NULL) { |
2126 col = UIntParameter::Parse(col_param); | 2141 col = UIntParameter::Parse(col_param); |
2127 if (col == 0) { | 2142 if (col == 0) { |
2128 // Column number is 1-based. | 2143 // Column number is 1-based. |
2129 PrintInvalidParamError(js, "column"); | 2144 PrintInvalidParamError(js, "column"); |
2130 return true; | 2145 return true; |
(...skipping 17 matching lines...) Expand all Loading... |
2148 static const MethodParameter* add_breakpoint_params[] = { | 2163 static const MethodParameter* add_breakpoint_params[] = { |
2149 ISOLATE_PARAMETER, | 2164 ISOLATE_PARAMETER, |
2150 new IdParameter("scriptId", true), | 2165 new IdParameter("scriptId", true), |
2151 new UIntParameter("line", true), | 2166 new UIntParameter("line", true), |
2152 new UIntParameter("column", false), | 2167 new UIntParameter("column", false), |
2153 NULL, | 2168 NULL, |
2154 }; | 2169 }; |
2155 | 2170 |
2156 | 2171 |
2157 static bool AddBreakpoint(Thread* thread, JSONStream* js) { | 2172 static bool AddBreakpoint(Thread* thread, JSONStream* js) { |
| 2173 if (!thread->isolate()->compilation_allowed()) { |
| 2174 js->PrintError(kFeatureDisabled, |
| 2175 "Cannot use breakpoints when running a precompiled program."); |
| 2176 return true; |
| 2177 } |
2158 const char* script_id_param = js->LookupParam("scriptId"); | 2178 const char* script_id_param = js->LookupParam("scriptId"); |
2159 Object& obj = Object::Handle(LookupHeapObject(thread, script_id_param, NULL)); | 2179 Object& obj = Object::Handle(LookupHeapObject(thread, script_id_param, NULL)); |
2160 if (obj.raw() == Object::sentinel().raw() || !obj.IsScript()) { | 2180 if (obj.raw() == Object::sentinel().raw() || !obj.IsScript()) { |
2161 PrintInvalidParamError(js, "scriptId"); | 2181 PrintInvalidParamError(js, "scriptId"); |
2162 return true; | 2182 return true; |
2163 } | 2183 } |
2164 const Script& script = Script::Cast(obj); | 2184 const Script& script = Script::Cast(obj); |
2165 const String& script_uri = String::Handle(script.url()); | 2185 const String& script_uri = String::Handle(script.url()); |
2166 ASSERT(!script_uri.IsNull()); | 2186 ASSERT(!script_uri.IsNull()); |
2167 return AddBreakpointCommon(thread, js, script_uri); | 2187 return AddBreakpointCommon(thread, js, script_uri); |
2168 } | 2188 } |
2169 | 2189 |
2170 | 2190 |
2171 static const MethodParameter* add_breakpoint_with_script_uri_params[] = { | 2191 static const MethodParameter* add_breakpoint_with_script_uri_params[] = { |
2172 ISOLATE_PARAMETER, | 2192 ISOLATE_PARAMETER, |
2173 new IdParameter("scriptUri", true), | 2193 new IdParameter("scriptUri", true), |
2174 new UIntParameter("line", true), | 2194 new UIntParameter("line", true), |
2175 new UIntParameter("column", false), | 2195 new UIntParameter("column", false), |
2176 NULL, | 2196 NULL, |
2177 }; | 2197 }; |
2178 | 2198 |
2179 | 2199 |
2180 static bool AddBreakpointWithScriptUri(Thread* thread, JSONStream* js) { | 2200 static bool AddBreakpointWithScriptUri(Thread* thread, JSONStream* js) { |
| 2201 if (!thread->isolate()->compilation_allowed()) { |
| 2202 js->PrintError(kFeatureDisabled, |
| 2203 "Cannot use breakpoints when running a precompiled program."); |
| 2204 return true; |
| 2205 } |
2181 const char* script_uri_param = js->LookupParam("scriptUri"); | 2206 const char* script_uri_param = js->LookupParam("scriptUri"); |
2182 const String& script_uri = String::Handle(String::New(script_uri_param)); | 2207 const String& script_uri = String::Handle(String::New(script_uri_param)); |
2183 return AddBreakpointCommon(thread, js, script_uri); | 2208 return AddBreakpointCommon(thread, js, script_uri); |
2184 } | 2209 } |
2185 | 2210 |
2186 | 2211 |
2187 static const MethodParameter* add_breakpoint_at_entry_params[] = { | 2212 static const MethodParameter* add_breakpoint_at_entry_params[] = { |
2188 ISOLATE_PARAMETER, | 2213 ISOLATE_PARAMETER, |
2189 new IdParameter("functionId", true), | 2214 new IdParameter("functionId", true), |
2190 NULL, | 2215 NULL, |
2191 }; | 2216 }; |
2192 | 2217 |
2193 | 2218 |
2194 static bool AddBreakpointAtEntry(Thread* thread, JSONStream* js) { | 2219 static bool AddBreakpointAtEntry(Thread* thread, JSONStream* js) { |
| 2220 if (!thread->isolate()->compilation_allowed()) { |
| 2221 js->PrintError(kFeatureDisabled, |
| 2222 "Cannot use breakpoints when running a precompiled program."); |
| 2223 return true; |
| 2224 } |
2195 const char* function_id = js->LookupParam("functionId"); | 2225 const char* function_id = js->LookupParam("functionId"); |
2196 Object& obj = Object::Handle(LookupHeapObject(thread, function_id, NULL)); | 2226 Object& obj = Object::Handle(LookupHeapObject(thread, function_id, NULL)); |
2197 if (obj.raw() == Object::sentinel().raw() || !obj.IsFunction()) { | 2227 if (obj.raw() == Object::sentinel().raw() || !obj.IsFunction()) { |
2198 PrintInvalidParamError(js, "functionId"); | 2228 PrintInvalidParamError(js, "functionId"); |
2199 return true; | 2229 return true; |
2200 } | 2230 } |
2201 const Function& function = Function::Cast(obj); | 2231 const Function& function = Function::Cast(obj); |
2202 Breakpoint* bpt = | 2232 Breakpoint* bpt = |
2203 thread->isolate()->debugger()->SetBreakpointAtEntry(function, false); | 2233 thread->isolate()->debugger()->SetBreakpointAtEntry(function, false); |
2204 if (bpt == NULL) { | 2234 if (bpt == NULL) { |
2205 js->PrintError(kCannotAddBreakpoint, | 2235 js->PrintError(kCannotAddBreakpoint, |
2206 "%s: Cannot add breakpoint at function '%s'", | 2236 "%s: Cannot add breakpoint at function '%s'", |
2207 js->method(), function.ToCString()); | 2237 js->method(), function.ToCString()); |
2208 return true; | 2238 return true; |
2209 } | 2239 } |
2210 bpt->PrintJSON(js); | 2240 bpt->PrintJSON(js); |
2211 return true; | 2241 return true; |
2212 } | 2242 } |
2213 | 2243 |
2214 | 2244 |
2215 static const MethodParameter* add_breakpoint_at_activation_params[] = { | 2245 static const MethodParameter* add_breakpoint_at_activation_params[] = { |
2216 ISOLATE_PARAMETER, | 2246 ISOLATE_PARAMETER, |
2217 new IdParameter("objectId", true), | 2247 new IdParameter("objectId", true), |
2218 NULL, | 2248 NULL, |
2219 }; | 2249 }; |
2220 | 2250 |
2221 | 2251 |
2222 static bool AddBreakpointAtActivation(Thread* thread, JSONStream* js) { | 2252 static bool AddBreakpointAtActivation(Thread* thread, JSONStream* js) { |
| 2253 if (!thread->isolate()->compilation_allowed()) { |
| 2254 js->PrintError(kFeatureDisabled, |
| 2255 "Cannot use breakpoints when running a precompiled program."); |
| 2256 return true; |
| 2257 } |
2223 const char* object_id = js->LookupParam("objectId"); | 2258 const char* object_id = js->LookupParam("objectId"); |
2224 Object& obj = Object::Handle(LookupHeapObject(thread, object_id, NULL)); | 2259 Object& obj = Object::Handle(LookupHeapObject(thread, object_id, NULL)); |
2225 if (obj.raw() == Object::sentinel().raw() || !obj.IsInstance()) { | 2260 if (obj.raw() == Object::sentinel().raw() || !obj.IsInstance()) { |
2226 PrintInvalidParamError(js, "objectId"); | 2261 PrintInvalidParamError(js, "objectId"); |
2227 return true; | 2262 return true; |
2228 } | 2263 } |
2229 const Instance& closure = Instance::Cast(obj); | 2264 const Instance& closure = Instance::Cast(obj); |
2230 Breakpoint* bpt = | 2265 Breakpoint* bpt = |
2231 thread->isolate()->debugger()->SetBreakpointAtActivation(closure); | 2266 thread->isolate()->debugger()->SetBreakpointAtActivation(closure); |
2232 if (bpt == NULL) { | 2267 if (bpt == NULL) { |
2233 js->PrintError(kCannotAddBreakpoint, | 2268 js->PrintError(kCannotAddBreakpoint, |
2234 "%s: Cannot add breakpoint at activation", | 2269 "%s: Cannot add breakpoint at activation", |
2235 js->method()); | 2270 js->method()); |
2236 return true; | 2271 return true; |
2237 } | 2272 } |
2238 bpt->PrintJSON(js); | 2273 bpt->PrintJSON(js); |
2239 return true; | 2274 return true; |
2240 } | 2275 } |
2241 | 2276 |
2242 | 2277 |
2243 static const MethodParameter* remove_breakpoint_params[] = { | 2278 static const MethodParameter* remove_breakpoint_params[] = { |
2244 ISOLATE_PARAMETER, | 2279 ISOLATE_PARAMETER, |
2245 NULL, | 2280 NULL, |
2246 }; | 2281 }; |
2247 | 2282 |
2248 | 2283 |
2249 static bool RemoveBreakpoint(Thread* thread, JSONStream* js) { | 2284 static bool RemoveBreakpoint(Thread* thread, JSONStream* js) { |
| 2285 if (!thread->isolate()->compilation_allowed()) { |
| 2286 js->PrintError(kFeatureDisabled, |
| 2287 "Cannot use breakpoints when running a precompiled program."); |
| 2288 return true; |
| 2289 } |
2250 if (!js->HasParam("breakpointId")) { | 2290 if (!js->HasParam("breakpointId")) { |
2251 PrintMissingParamError(js, "breakpointId"); | 2291 PrintMissingParamError(js, "breakpointId"); |
2252 return true; | 2292 return true; |
2253 } | 2293 } |
2254 const char* bpt_id = js->LookupParam("breakpointId"); | 2294 const char* bpt_id = js->LookupParam("breakpointId"); |
2255 ObjectIdRing::LookupResult lookup_result; | 2295 ObjectIdRing::LookupResult lookup_result; |
2256 Isolate* isolate = thread->isolate(); | 2296 Isolate* isolate = thread->isolate(); |
2257 Breakpoint* bpt = LookupBreakpoint(isolate, bpt_id, &lookup_result); | 2297 Breakpoint* bpt = LookupBreakpoint(isolate, bpt_id, &lookup_result); |
2258 // TODO(turnidge): Should we return a different error for bpts whic | 2298 // TODO(turnidge): Should we return a different error for bpts whic |
2259 // have been already removed? | 2299 // have been already removed? |
(...skipping 984 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3244 | 3284 |
3245 static const MethodParameter* set_trace_class_allocation_params[] = { | 3285 static const MethodParameter* set_trace_class_allocation_params[] = { |
3246 ISOLATE_PARAMETER, | 3286 ISOLATE_PARAMETER, |
3247 new IdParameter("classId", true), | 3287 new IdParameter("classId", true), |
3248 new BoolParameter("enable", true), | 3288 new BoolParameter("enable", true), |
3249 NULL, | 3289 NULL, |
3250 }; | 3290 }; |
3251 | 3291 |
3252 | 3292 |
3253 static bool SetTraceClassAllocation(Thread* thread, JSONStream* js) { | 3293 static bool SetTraceClassAllocation(Thread* thread, JSONStream* js) { |
| 3294 if (!thread->isolate()->compilation_allowed()) { |
| 3295 js->PrintError(kFeatureDisabled, |
| 3296 "Cannot trace allocation when running a precompiled program."); |
| 3297 return true; |
| 3298 } |
3254 const char* class_id = js->LookupParam("classId"); | 3299 const char* class_id = js->LookupParam("classId"); |
3255 const bool enable = BoolParameter::Parse(js->LookupParam("enable")); | 3300 const bool enable = BoolParameter::Parse(js->LookupParam("enable")); |
3256 intptr_t cid = -1; | 3301 intptr_t cid = -1; |
3257 GetPrefixedIntegerId(class_id, "classes/", &cid); | 3302 GetPrefixedIntegerId(class_id, "classes/", &cid); |
3258 Isolate* isolate = thread->isolate(); | 3303 Isolate* isolate = thread->isolate(); |
3259 if (!IsValidClassId(isolate, cid)) { | 3304 if (!IsValidClassId(isolate, cid)) { |
3260 PrintInvalidParamError(js, "classId"); | 3305 PrintInvalidParamError(js, "classId"); |
3261 return true; | 3306 return true; |
3262 } | 3307 } |
3263 const Class& cls = Class::Handle(GetClassForId(isolate, cid)); | 3308 const Class& cls = Class::Handle(GetClassForId(isolate, cid)); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3374 ServiceMethodDescriptor& method = service_methods_[i]; | 3419 ServiceMethodDescriptor& method = service_methods_[i]; |
3375 if (strcmp(method_name, method.name) == 0) { | 3420 if (strcmp(method_name, method.name) == 0) { |
3376 return &method; | 3421 return &method; |
3377 } | 3422 } |
3378 } | 3423 } |
3379 return NULL; | 3424 return NULL; |
3380 } | 3425 } |
3381 | 3426 |
3382 | 3427 |
3383 } // namespace dart | 3428 } // namespace dart |
OLD | NEW |