Commit 63c4cd96 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[logging] Print const char* as pointer value

When checking {const char*} (or similar) against each other, don't
print them as c strings on failure. Just print the pointer value.
In wasm, where we use byte pointers into wasm wire bytes, this was
sometimes hiding check failures behind segfaults which happened when
trying to output invalid pointers as c strings.
Anyway, it's more useful to see the raw pointer values in these cases.
Other use cases, where we really compare against c string pointers
should be rare in our code base.

R=ishell@chromium.org

Change-Id: I92a13221d18c987a97cf2a29ac8f454178ff2bb5
Reviewed-on: https://chromium-review.googlesource.com/517166
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#45642}
parent 0894b939
......@@ -19,12 +19,6 @@ namespace {
void (*g_print_stack_trace)() = nullptr;
} // namespace
void SetPrintStackTrace(void (*print_stack_trace)()) {
g_print_stack_trace = print_stack_trace;
}
void PrettyPrintChar(std::ostream& os, int ch) {
switch (ch) {
#define CHAR_PRINT_CASE(ch) \
......@@ -54,10 +48,26 @@ void PrettyPrintChar(std::ostream& os, int ch) {
}
}
#define DEFINE_PRINT_CHECK_OPERAND_CHAR(type) \
template <> \
void PrintCheckOperand<type>(std::ostream & os, type ch) { \
PrettyPrintChar(os, ch); \
} // namespace
void SetPrintStackTrace(void (*print_stack_trace)()) {
g_print_stack_trace = print_stack_trace;
}
// Define specialization to pretty print characters (escaping non-printable
// characters) and to print c strings as pointers instead of strings.
#define DEFINE_PRINT_CHECK_OPERAND_CHAR(type) \
template <> \
void PrintCheckOperand<type>(std::ostream & os, type ch) { \
PrettyPrintChar(os, ch); \
} \
template <> \
void PrintCheckOperand<type*>(std::ostream & os, type * cstr) { \
os << static_cast<void*>(cstr); \
} \
template <> \
void PrintCheckOperand<const type*>(std::ostream & os, const type* cstr) { \
os << static_cast<const void*>(cstr); \
}
DEFINE_PRINT_CHECK_OPERAND_CHAR(char)
......@@ -76,7 +86,6 @@ DEFINE_MAKE_CHECK_OP_STRING(long long) // NOLINT(runtime/int)
DEFINE_MAKE_CHECK_OP_STRING(unsigned int)
DEFINE_MAKE_CHECK_OP_STRING(unsigned long) // NOLINT(runtime/int)
DEFINE_MAKE_CHECK_OP_STRING(unsigned long long) // NOLINT(runtime/int)
DEFINE_MAKE_CHECK_OP_STRING(char const*)
DEFINE_MAKE_CHECK_OP_STRING(void const*)
#undef DEFINE_MAKE_CHECK_OP_STRING
......
......@@ -96,11 +96,16 @@ void PrintCheckOperand(std::ostream& os, Op op) {
os << op;
}
void PrettyPrintChar(std::ostream& os, int ch);
#define DEFINE_PRINT_CHECK_OPERAND_CHAR(type) \
template <> \
V8_BASE_EXPORT void PrintCheckOperand<type>(std::ostream & os, type ch);
// Define specializations for character types, defined in logging.cc.
#define DEFINE_PRINT_CHECK_OPERAND_CHAR(type) \
template <> \
V8_BASE_EXPORT void PrintCheckOperand<type>(std::ostream & os, type ch); \
template <> \
V8_BASE_EXPORT void PrintCheckOperand<type*>(std::ostream & os, \
type * cstr); \
template <> \
V8_BASE_EXPORT void PrintCheckOperand<const type*>(std::ostream & os, \
const type* cstr);
DEFINE_PRINT_CHECK_OPERAND_CHAR(char)
DEFINE_PRINT_CHECK_OPERAND_CHAR(signed char)
......@@ -126,20 +131,20 @@ std::string* MakeCheckOpString(typename PassType<Lhs>::type lhs,
// Commonly used instantiations of MakeCheckOpString<>. Explicitly instantiated
// in logging.cc.
#define DEFINE_MAKE_CHECK_OP_STRING(type) \
#define EXPLICIT_CHECK_OP_INSTANTIATION(type) \
extern template V8_BASE_EXPORT std::string* MakeCheckOpString<type, type>( \
type, type, char const*); \
extern template V8_BASE_EXPORT void PrintCheckOperand<type>(std::ostream&, \
type);
DEFINE_MAKE_CHECK_OP_STRING(int)
DEFINE_MAKE_CHECK_OP_STRING(long) // NOLINT(runtime/int)
DEFINE_MAKE_CHECK_OP_STRING(long long) // NOLINT(runtime/int)
DEFINE_MAKE_CHECK_OP_STRING(unsigned int)
DEFINE_MAKE_CHECK_OP_STRING(unsigned long) // NOLINT(runtime/int)
DEFINE_MAKE_CHECK_OP_STRING(unsigned long long) // NOLINT(runtime/int)
DEFINE_MAKE_CHECK_OP_STRING(char const*)
DEFINE_MAKE_CHECK_OP_STRING(void const*)
#undef DEFINE_MAKE_CHECK_OP_STRING
EXPLICIT_CHECK_OP_INSTANTIATION(int)
EXPLICIT_CHECK_OP_INSTANTIATION(long) // NOLINT(runtime/int)
EXPLICIT_CHECK_OP_INSTANTIATION(long long) // NOLINT(runtime/int)
EXPLICIT_CHECK_OP_INSTANTIATION(unsigned int)
EXPLICIT_CHECK_OP_INSTANTIATION(unsigned long) // NOLINT(runtime/int)
EXPLICIT_CHECK_OP_INSTANTIATION(unsigned long long) // NOLINT(runtime/int)
EXPLICIT_CHECK_OP_INSTANTIATION(void const*)
#undef EXPLICIT_CHECK_OP_INSTANTIATION
// comparison_underlying_type provides the underlying integral type of an enum,
// or std::decay<T>::type if T is not an enum.
......
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