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

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

Issue 2689493002: [debugger] implement per-function code coverage. (Closed)
Patch Set: one more fix, and rename Created 3 years, 10 months 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
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/runtime/runtime-utils.h" 5 #include "src/runtime/runtime-utils.h"
6 6
7 #include "src/arguments.h" 7 #include "src/arguments.h"
8 #include "src/compiler.h" 8 #include "src/compiler.h"
9 #include "src/debug/debug-coverage.h"
9 #include "src/debug/debug-evaluate.h" 10 #include "src/debug/debug-evaluate.h"
10 #include "src/debug/debug-frames.h" 11 #include "src/debug/debug-frames.h"
11 #include "src/debug/debug-scopes.h" 12 #include "src/debug/debug-scopes.h"
12 #include "src/debug/debug.h" 13 #include "src/debug/debug.h"
13 #include "src/debug/liveedit.h" 14 #include "src/debug/liveedit.h"
14 #include "src/frames-inl.h" 15 #include "src/frames-inl.h"
15 #include "src/globals.h" 16 #include "src/globals.h"
16 #include "src/interpreter/bytecodes.h" 17 #include "src/interpreter/bytecodes.h"
17 #include "src/interpreter/interpreter.h" 18 #include "src/interpreter/interpreter.h"
18 #include "src/isolate-inl.h" 19 #include "src/isolate-inl.h"
(...skipping 1214 matching lines...) Expand 10 before | Expand all | Expand 10 after
1233 CONVERT_ARG_HANDLE_CHECKED(String, source, 1); 1234 CONVERT_ARG_HANDLE_CHECKED(String, source, 1);
1234 1235
1235 RETURN_RESULT_OR_FAILURE(isolate, DebugEvaluate::Global(isolate, source)); 1236 RETURN_RESULT_OR_FAILURE(isolate, DebugEvaluate::Global(isolate, source));
1236 } 1237 }
1237 1238
1238 1239
1239 RUNTIME_FUNCTION(Runtime_DebugGetLoadedScripts) { 1240 RUNTIME_FUNCTION(Runtime_DebugGetLoadedScripts) {
1240 HandleScope scope(isolate); 1241 HandleScope scope(isolate);
1241 DCHECK_EQ(0, args.length()); 1242 DCHECK_EQ(0, args.length());
1242 1243
1243 // This runtime function is used by the debugger to determine whether the
1244 // debugger is active or not. Hence we fail gracefully here and don't crash.
1245 if (!isolate->debug()->is_active()) return isolate->ThrowIllegalOperation();
1246
1247 Handle<FixedArray> instances; 1244 Handle<FixedArray> instances;
1248 { 1245 {
1249 DebugScope debug_scope(isolate->debug()); 1246 DebugScope debug_scope(isolate->debug());
1250 if (debug_scope.failed()) { 1247 if (debug_scope.failed()) {
1251 DCHECK(isolate->has_pending_exception()); 1248 DCHECK(isolate->has_pending_exception());
1252 return isolate->heap()->exception(); 1249 return isolate->heap()->exception();
1253 } 1250 }
1254 // Fill the script objects. 1251 // Fill the script objects.
1255 instances = isolate->debug()->GetLoadedScripts(); 1252 instances = isolate->debug()->GetLoadedScripts();
1256 } 1253 }
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after
1885 SealHandleScope shs(isolate); 1882 SealHandleScope shs(isolate);
1886 return Smi::FromInt(isolate->debug()->is_active()); 1883 return Smi::FromInt(isolate->debug()->is_active());
1887 } 1884 }
1888 1885
1889 1886
1890 RUNTIME_FUNCTION(Runtime_DebugBreakInOptimizedCode) { 1887 RUNTIME_FUNCTION(Runtime_DebugBreakInOptimizedCode) {
1891 UNIMPLEMENTED(); 1888 UNIMPLEMENTED();
1892 return NULL; 1889 return NULL;
1893 } 1890 }
1894 1891
1892 RUNTIME_FUNCTION(Runtime_DebugCollectCoverage) {
1893 HandleScope scope(isolate);
1894 // Collect coverage data.
1895 std::vector<Coverage::ScriptData> scripts = Coverage::Collect(isolate);
1896 Factory* factory = isolate->factory();
1897 // Turn the returned data structure into JavaScript.
1898 // Create an array of scripts.
1899 int num_scripts = static_cast<int>(scripts.size());
1900 // Prepare property keys.
1901 Handle<FixedArray> scripts_array = factory->NewFixedArray(num_scripts);
1902 Handle<String> id_string = factory->NewStringFromStaticChars("script_id");
1903 Handle<String> entries_string = factory->NewStringFromStaticChars("entries");
1904 Handle<String> end_string = factory->NewStringFromStaticChars("end_position");
1905 Handle<String> count_string = factory->NewStringFromStaticChars("count");
1906 for (int i = 0; i < num_scripts; i++) {
1907 // Create an object for each script, containing the script id and entries.
1908 const auto& script = scripts[i];
1909 HandleScope inner_scope(isolate);
1910 int num_entries = static_cast<int>(script.entries.size());
1911 Handle<FixedArray> entries_array = factory->NewFixedArray(num_entries);
1912 for (int j = 0; j < num_entries; j++) {
1913 // Create an object for each entry, containing the end position and count.
1914 const auto& entry = script.entries[j];
1915 Handle<JSObject> entry_obj = factory->NewJSObjectWithNullProto();
1916 JSObject::AddProperty(entry_obj, end_string,
1917 factory->NewNumberFromInt(entry.end_position),
1918 NONE);
1919 JSObject::AddProperty(entry_obj, count_string,
1920 factory->NewNumberFromUint(entry.count), NONE);
1921 entries_array->set(j, *entry_obj);
1922 }
1923 Handle<JSObject> script_obj = factory->NewJSObjectWithNullProto();
1924 JSObject::AddProperty(script_obj, id_string,
1925 factory->NewNumberFromInt(script.script_id), NONE);
1926 JSObject::AddProperty(
1927 script_obj, entries_string,
1928 factory->NewJSArrayWithElements(entries_array, FAST_ELEMENTS), NONE);
1929 scripts_array->set(i, *script_obj);
1930 }
1931 return *factory->NewJSArrayWithElements(scripts_array, FAST_ELEMENTS);
1932 }
1933
1895 } // namespace internal 1934 } // namespace internal
1896 } // namespace v8 1935 } // namespace v8
OLDNEW
« src/debug/debug-coverage.cc ('K') | « src/runtime/runtime.h ('k') | src/v8.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698