Commit d61eb044 authored by cbruni's avatar cbruni Committed by Commit bot

Reland of [debugging] print ranges for consecutive values with %DebugPrint...

Reland of [debugging] print ranges for consecutive values with %DebugPrint (patchset #1 id:1 of https://codereview.chromium.org/2181093003/ )

Reason for revert:
Dummy initializing variables to make compilers happy.

Original issue's description:
> Revert of [debugging] print ranges for consecutive values with %DebugPrint (patchset #2 id:20001 of https://codereview.chromium.org/2169143003/ )
>
> Reason for revert:
> breaks android build due to uninitialized variable.
> https://build.chromium.org/p/client.v8.ports/builders/V8%20Arm%20-%20debug%20builder/builds/2034
>
> Original issue's description:
> > [debugging] print ranges for consecutive values with %DebugPrint
> >
> > With this CL repeated values in elements are combined into a single printout with a range.
> >
> > BEFORE:
> > - elements = {
> >   0: <undefined>
> >   1: <undefined>
> >   2: <the_hole>
> > }
> >
> > AFTER:
> >  - elements = {
> >        0-1: <undefined>
> >          2: <the_hole>
> > }
> >
> > BUG=
> >
> > Committed: https://crrev.com/ec4165742088043d8fede38db21a281e16682adb
> > Cr-Commit-Position: refs/heads/master@{#38069}
>
> TBR=yangguo@chromium.org
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=
>
> Committed: https://crrev.com/7b2cd8b988d257f22afc7c03cd2caf8ba2e2b3a3
> Cr-Commit-Position: refs/heads/master@{#38071}

TBR=yangguo@chromium.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=

Review-Url: https://codereview.chromium.org/2182203004
Cr-Commit-Position: refs/heads/master@{#38080}
parent cfe1c594
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "src/objects.h" #include "src/objects.h"
#include <iomanip>
#include <memory> #include <memory>
#include "src/disasm.h" #include "src/disasm.h"
...@@ -317,12 +318,35 @@ void JSObject::PrintProperties(std::ostream& os) { // NOLINT ...@@ -317,12 +318,35 @@ void JSObject::PrintProperties(std::ostream& os) { // NOLINT
} }
} }
template <class T, bool print_the_hole>
template <class T>
static void DoPrintElements(std::ostream& os, Object* object) { // NOLINT static void DoPrintElements(std::ostream& os, Object* object) { // NOLINT
T* p = T::cast(object); T* array = T::cast(object);
for (int i = 0; i < p->length(); i++) { if (array->length() == 0) return;
os << "\n " << i << ": " << p->get_scalar(i); int previous_index = 0;
double previous_value = array->get_scalar(0);
double value = 0.0;
int i;
for (i = 1; i <= array->length(); i++) {
if (i < array->length()) value = array->get_scalar(i);
bool values_are_nan = std::isnan(previous_value) && std::isnan(value);
if ((previous_value == value || values_are_nan) && i != array->length()) {
continue;
}
os << "\n";
std::stringstream ss;
ss << previous_index;
if (previous_index != i - 1) {
ss << '-' << (i - 1);
}
os << std::setw(12) << ss.str() << ": ";
if (print_the_hole &&
FixedDoubleArray::cast(object)->is_the_hole(previous_index)) {
os << "<the_hole>";
} else {
os << previous_value;
}
previous_index = i;
previous_value = value;
} }
} }
...@@ -330,6 +354,7 @@ static void DoPrintElements(std::ostream& os, Object* object) { // NOLINT ...@@ -330,6 +354,7 @@ static void DoPrintElements(std::ostream& os, Object* object) { // NOLINT
void JSObject::PrintElements(std::ostream& os) { // NOLINT void JSObject::PrintElements(std::ostream& os) { // NOLINT
// Don't call GetElementsKind, its validation code can cause the printer to // Don't call GetElementsKind, its validation code can cause the printer to
// fail when debugging. // fail when debugging.
if (elements()->length() == 0) return;
switch (map()->elements_kind()) { switch (map()->elements_kind()) {
case FAST_HOLEY_SMI_ELEMENTS: case FAST_HOLEY_SMI_ELEMENTS:
case FAST_SMI_ELEMENTS: case FAST_SMI_ELEMENTS:
...@@ -337,45 +362,49 @@ void JSObject::PrintElements(std::ostream& os) { // NOLINT ...@@ -337,45 +362,49 @@ void JSObject::PrintElements(std::ostream& os) { // NOLINT
case FAST_ELEMENTS: case FAST_ELEMENTS:
case FAST_STRING_WRAPPER_ELEMENTS: { case FAST_STRING_WRAPPER_ELEMENTS: {
// Print in array notation for non-sparse arrays. // Print in array notation for non-sparse arrays.
FixedArray* p = FixedArray::cast(elements()); FixedArray* array = FixedArray::cast(elements());
for (int i = 0; i < p->length(); i++) { Object* previous_value = array->get(0);
os << "\n " << i << ": " << Brief(p->get(i)); Object* value = nullptr;
int previous_index = 0;
int i;
for (i = 1; i <= array->length(); i++) {
if (i < array->length()) value = array->get(i);
if (previous_value == value && i != array->length()) {
continue;
}
os << "\n";
std::stringstream ss;
ss << previous_index;
if (previous_index != i - 1) {
ss << '-' << (i - 1);
}
os << std::setw(12) << ss.str() << ": " << Brief(previous_value);
previous_index = i;
previous_value = value;
} }
break; break;
} }
case FAST_HOLEY_DOUBLE_ELEMENTS: case FAST_HOLEY_DOUBLE_ELEMENTS:
case FAST_DOUBLE_ELEMENTS: { case FAST_DOUBLE_ELEMENTS: {
// Print in array notation for non-sparse arrays. DoPrintElements<FixedDoubleArray, true>(os, elements());
if (elements()->length() > 0) {
FixedDoubleArray* p = FixedDoubleArray::cast(elements());
for (int i = 0; i < p->length(); i++) {
os << "\n " << i << ": ";
if (p->is_the_hole(i)) {
os << "<the hole>";
} else {
os << p->get_scalar(i);
}
}
}
break; break;
} }
#define PRINT_ELEMENTS(Kind, Type) \
#define PRINT_ELEMENTS(Kind, Type) \ case Kind: { \
case Kind: { \ DoPrintElements<Type, false>(os, elements()); \
DoPrintElements<Type>(os, elements()); \ break; \
break; \
} }
PRINT_ELEMENTS(UINT8_ELEMENTS, FixedUint8Array) PRINT_ELEMENTS(UINT8_ELEMENTS, FixedUint8Array)
PRINT_ELEMENTS(UINT8_CLAMPED_ELEMENTS, FixedUint8ClampedArray) PRINT_ELEMENTS(UINT8_CLAMPED_ELEMENTS, FixedUint8ClampedArray)
PRINT_ELEMENTS(INT8_ELEMENTS, FixedInt8Array) PRINT_ELEMENTS(INT8_ELEMENTS, FixedInt8Array)
PRINT_ELEMENTS(UINT16_ELEMENTS, FixedUint16Array) PRINT_ELEMENTS(UINT16_ELEMENTS, FixedUint16Array)
PRINT_ELEMENTS(INT16_ELEMENTS, FixedInt16Array) PRINT_ELEMENTS(INT16_ELEMENTS, FixedInt16Array)
PRINT_ELEMENTS(UINT32_ELEMENTS, FixedUint32Array) PRINT_ELEMENTS(UINT32_ELEMENTS, FixedUint32Array)
PRINT_ELEMENTS(INT32_ELEMENTS, FixedInt32Array) PRINT_ELEMENTS(INT32_ELEMENTS, FixedInt32Array)
PRINT_ELEMENTS(FLOAT32_ELEMENTS, FixedFloat32Array) PRINT_ELEMENTS(FLOAT32_ELEMENTS, FixedFloat32Array)
PRINT_ELEMENTS(FLOAT64_ELEMENTS, FixedFloat64Array) PRINT_ELEMENTS(FLOAT64_ELEMENTS, FixedFloat64Array)
#undef PRINT_ELEMENTS #undef PRINT_ELEMENTS
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment