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 @@
#include "src/objects.h"
#include <iomanip>
#include <memory>
#include "src/disasm.h"
......@@ -317,12 +318,35 @@ void JSObject::PrintProperties(std::ostream& os) { // NOLINT
}
}
template <class T>
template <class T, bool print_the_hole>
static void DoPrintElements(std::ostream& os, Object* object) { // NOLINT
T* p = T::cast(object);
for (int i = 0; i < p->length(); i++) {
os << "\n " << i << ": " << p->get_scalar(i);
T* array = T::cast(object);
if (array->length() == 0) return;
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
void JSObject::PrintElements(std::ostream& os) { // NOLINT
// Don't call GetElementsKind, its validation code can cause the printer to
// fail when debugging.
if (elements()->length() == 0) return;
switch (map()->elements_kind()) {
case FAST_HOLEY_SMI_ELEMENTS:
case FAST_SMI_ELEMENTS:
......@@ -337,33 +362,37 @@ void JSObject::PrintElements(std::ostream& os) { // NOLINT
case FAST_ELEMENTS:
case FAST_STRING_WRAPPER_ELEMENTS: {
// Print in array notation for non-sparse arrays.
FixedArray* p = FixedArray::cast(elements());
for (int i = 0; i < p->length(); i++) {
os << "\n " << i << ": " << Brief(p->get(i));
FixedArray* array = FixedArray::cast(elements());
Object* previous_value = array->get(0);
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;
}
case FAST_HOLEY_DOUBLE_ELEMENTS:
case FAST_DOUBLE_ELEMENTS: {
// Print in array notation for non-sparse arrays.
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);
}
}
}
DoPrintElements<FixedDoubleArray, true>(os, elements());
break;
}
#define PRINT_ELEMENTS(Kind, Type) \
case Kind: { \
DoPrintElements<Type>(os, elements()); \
DoPrintElements<Type, false>(os, elements()); \
break; \
}
......
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