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

Side by Side Diff: src/objects-printer.cc

Issue 2169143003: [debugging] print ranges for consecutive values with %DebugPrint (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 5 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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/objects.h" 5 #include "src/objects.h"
6 6
7 #include <iomanip>
8
7 #include "src/disasm.h" 9 #include "src/disasm.h"
8 #include "src/disassembler.h" 10 #include "src/disassembler.h"
9 #include "src/interpreter/bytecodes.h" 11 #include "src/interpreter/bytecodes.h"
10 #include "src/objects-inl.h" 12 #include "src/objects-inl.h"
11 #include "src/ostreams.h" 13 #include "src/ostreams.h"
12 #include "src/regexp/jsregexp.h" 14 #include "src/regexp/jsregexp.h"
13 15
14 namespace v8 { 16 namespace v8 {
15 namespace internal { 17 namespace internal {
16 18
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 } else if (IsJSGlobalObject()) { 313 } else if (IsJSGlobalObject()) {
312 global_dictionary()->Print(os); 314 global_dictionary()->Print(os);
313 } else { 315 } else {
314 property_dictionary()->Print(os); 316 property_dictionary()->Print(os);
315 } 317 }
316 } 318 }
317 319
318 320
319 template <class T> 321 template <class T>
320 static void DoPrintElements(std::ostream& os, Object* object) { // NOLINT 322 static void DoPrintElements(std::ostream& os, Object* object) { // NOLINT
321 T* p = T::cast(object); 323 T* array = T::cast(object);
322 for (int i = 0; i < p->length(); i++) { 324 if (array->length() == 0) return;
323 os << "\n " << i << ": " << p->get_scalar(i); 325 int previous_index = 0;
326 double previous_value = array->get_scalar(0);
327 double value;
328 int i;
329 for (i = 1; i <= array->length(); i++) {
330 if (i < array->length()) value = array->get_scalar(i);
331 bool values_are_nan = previous_value != previous_value && value != value;
Yang 2016/07/26 13:33:42 isnan()?
332 if ((previous_value == value || values_are_nan) && i != array->length()) {
333 continue;
334 }
335 os << "\n";
336 std::stringstream ss;
337 ss << previous_index;
338 if (previous_index != i - 1) {
339 ss << '-' << (i - 1);
340 }
341 os << std::setw(12) << ss.str() << ": ";
342 if (previous_value == previous_value) {
343 os << previous_value;
344 } else {
345 os << "<the_hole>";
Yang 2016/07/26 13:36:34 as discussed, this could also just be a non-hole n
346 }
347 previous_index = i;
348 previous_value = value;
324 } 349 }
325 } 350 }
326 351
327 352
328 void JSObject::PrintElements(std::ostream& os) { // NOLINT 353 void JSObject::PrintElements(std::ostream& os) { // NOLINT
329 // Don't call GetElementsKind, its validation code can cause the printer to 354 // Don't call GetElementsKind, its validation code can cause the printer to
330 // fail when debugging. 355 // fail when debugging.
356 if (elements()->length() == 0) return;
331 switch (map()->elements_kind()) { 357 switch (map()->elements_kind()) {
332 case FAST_HOLEY_SMI_ELEMENTS: 358 case FAST_HOLEY_SMI_ELEMENTS:
333 case FAST_SMI_ELEMENTS: 359 case FAST_SMI_ELEMENTS:
334 case FAST_HOLEY_ELEMENTS: 360 case FAST_HOLEY_ELEMENTS:
335 case FAST_ELEMENTS: 361 case FAST_ELEMENTS:
336 case FAST_STRING_WRAPPER_ELEMENTS: { 362 case FAST_STRING_WRAPPER_ELEMENTS: {
337 // Print in array notation for non-sparse arrays. 363 // Print in array notation for non-sparse arrays.
338 FixedArray* p = FixedArray::cast(elements()); 364 FixedArray* array = FixedArray::cast(elements());
339 for (int i = 0; i < p->length(); i++) { 365 Object* previous_value = array->get(0);
340 os << "\n " << i << ": " << Brief(p->get(i)); 366 Object* value;
367 int previous_index = 0;
368 int i;
369 for (i = 1; i <= array->length(); i++) {
370 if (i < array->length()) value = array->get(i);
371 if (previous_value == value && i != array->length()) {
372 continue;
373 }
374 os << "\n";
375 std::stringstream ss;
376 ss << previous_index;
377 if (previous_index != i - 1) {
378 ss << '-' << (i - 1);
379 }
380 os << std::setw(12) << ss.str() << ": " << Brief(previous_value);
381 previous_index = i;
382 previous_value = value;
341 } 383 }
342 break; 384 break;
343 } 385 }
344 case FAST_HOLEY_DOUBLE_ELEMENTS: 386 case FAST_HOLEY_DOUBLE_ELEMENTS:
345 case FAST_DOUBLE_ELEMENTS: { 387 case FAST_DOUBLE_ELEMENTS: {
346 // Print in array notation for non-sparse arrays. 388 DoPrintElements<FixedDoubleArray>(os, elements());
347 if (elements()->length() > 0) {
348 FixedDoubleArray* p = FixedDoubleArray::cast(elements());
349 for (int i = 0; i < p->length(); i++) {
350 os << "\n " << i << ": ";
351 if (p->is_the_hole(i)) {
352 os << "<the hole>";
353 } else {
354 os << p->get_scalar(i);
355 }
356 }
357 }
358 break; 389 break;
359 } 390 }
360 391
361 392
362 #define PRINT_ELEMENTS(Kind, Type) \ 393 #define PRINT_ELEMENTS(Kind, Type) \
363 case Kind: { \ 394 case Kind: { \
364 DoPrintElements<Type>(os, elements()); \ 395 DoPrintElements<Type>(os, elements()); \
365 break; \ 396 break; \
366 } 397 }
367 398
(...skipping 1052 matching lines...) Expand 10 before | Expand all | Expand 10 after
1420 void JSObject::PrintTransitions(std::ostream& os) { // NOLINT 1451 void JSObject::PrintTransitions(std::ostream& os) { // NOLINT
1421 Object* transitions = map()->raw_transitions(); 1452 Object* transitions = map()->raw_transitions();
1422 int num_transitions = TransitionArray::NumberOfTransitions(transitions); 1453 int num_transitions = TransitionArray::NumberOfTransitions(transitions);
1423 if (num_transitions == 0) return; 1454 if (num_transitions == 0) return;
1424 os << "\n - transitions"; 1455 os << "\n - transitions";
1425 TransitionArray::PrintTransitions(os, transitions, false); 1456 TransitionArray::PrintTransitions(os, transitions, false);
1426 } 1457 }
1427 #endif // defined(DEBUG) || defined(OBJECT_PRINT) 1458 #endif // defined(DEBUG) || defined(OBJECT_PRINT)
1428 } // namespace internal 1459 } // namespace internal
1429 } // namespace v8 1460 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698