From 22ef1c95c5f63ae7da8f9d152823bbbb5a4e4750 Mon Sep 17 00:00:00 2001 From: kiyomizumia Date: Wed, 14 Nov 2018 09:53:12 +0900 Subject: [PATCH 1/5] src: added check statements for debugging --- src/base_object-inl.h | 4 ++-- src/stream_base-inl.h | 5 ++--- src/util.h | 23 +++++++++++++++++++++++ 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/base_object-inl.h b/src/base_object-inl.h index 0b8fbb8520c283..f52c6cb81075a4 100644 --- a/src/base_object-inl.h +++ b/src/base_object-inl.h @@ -67,10 +67,10 @@ v8::Local BaseObject::object() const { v8::Local BaseObject::object(v8::Isolate* isolate) const { v8::Local handle = object(); -#ifdef DEBUG + CHECK_EQ(handle->CreationContext()->GetIsolate(), isolate); CHECK_EQ(env_->isolate(), isolate); -#endif + return handle; } diff --git a/src/stream_base-inl.h b/src/stream_base-inl.h index 1d6ec17b802f3b..7e2bbaa1730f2e 100644 --- a/src/stream_base-inl.h +++ b/src/stream_base-inl.h @@ -448,9 +448,8 @@ inline void StreamReq::Done(int status, const char* error_str) { } inline void StreamReq::ResetObject(v8::Local obj) { -#ifdef DEBUG - CHECK_GT(obj->InternalFieldCount(), StreamReq::kStreamReqField); -#endif + DCHECK_GT(obj->InternalFieldCount(), StreamReq::kStreamReqField); + obj->SetAlignedPointerInInternalField(0, nullptr); // BaseObject field. obj->SetAlignedPointerInInternalField(StreamReq::kStreamReqField, nullptr); } diff --git a/src/util.h b/src/util.h index 086e33933e6b5a..f6f980026e38ff 100644 --- a/src/util.h +++ b/src/util.h @@ -128,6 +128,29 @@ void DumpBacktrace(FILE* fp); #define CHECK_NOT_NULL(val) CHECK((val) != nullptr) #define CHECK_IMPLIES(a, b) CHECK(!(a) || (b)) +#ifdef DEBUG +#define DCHECK_EQ(a, b) CHECK((a) == (b)) +#define DCHECK_GE(a, b) CHECK((a) >= (b)) +#define DCHECK_GT(a, b) CHECK((a) > (b)) +#define DCHECK_LE(a, b) CHECK((a) <= (b)) +#define DCHECK_LT(a, b) CHECK((a) < (b)) +#define DCHECK_NE(a, b) CHECK((a) != (b)) +#define DCHECK_NULL(val) CHECK((val) == nullptr) +#define DCHECK_NOT_NULL(val) CHECK((val) != nullptr) +#define DCHECK_IMPLIES(a, b) CHECK(!(a) || (b)) +#else +#define DCHECK_EQ(a, b) +#define DCHECK_GE(a, b) +#define DCHECK_GT(a, b) +#define DCHECK_LE(a, b) +#define DCHECK_LT(a, b) +#define DCHECK_NE(a, b) +#define DCHECK_NULL(val) +#define DCHECK_NOT_NULL(val) +#define DCHECK_IMPLIES(a, b) +#endif + + #define UNREACHABLE() ABORT() // TAILQ-style intrusive list node. From 4f6fdbd31a840356d3f1f9a36396fadd97f1909c Mon Sep 17 00:00:00 2001 From: kiyomizumia Date: Wed, 14 Nov 2018 16:50:53 +0900 Subject: [PATCH 2/5] src: refactored and removed some ifdef debug statements test: fixed order of actual and expected arguments src: ifdef changes src: refactored and removed some ifdef debug statements --- src/base_object-inl.h | 4 ++-- src/env-inl.h | 12 ++++-------- src/env.cc | 4 +--- src/stream_base.cc | 13 ++++++------- src/util.h | 36 ++++++++++++++++++------------------ 5 files changed, 31 insertions(+), 38 deletions(-) diff --git a/src/base_object-inl.h b/src/base_object-inl.h index f52c6cb81075a4..cce872739381cf 100644 --- a/src/base_object-inl.h +++ b/src/base_object-inl.h @@ -68,8 +68,8 @@ v8::Local BaseObject::object() const { v8::Local BaseObject::object(v8::Isolate* isolate) const { v8::Local handle = object(); - CHECK_EQ(handle->CreationContext()->GetIsolate(), isolate); - CHECK_EQ(env_->isolate(), isolate); + DCHECK_EQ(handle->CreationContext()->GetIsolate(), isolate); + DCHECK_EQ(env_->isolate(), isolate); return handle; } diff --git a/src/env-inl.h b/src/env-inl.h index ba5704ed2e9574..db250340f06f99 100644 --- a/src/env-inl.h +++ b/src/env-inl.h @@ -549,20 +549,16 @@ inline void Environment::set_http2_state( } bool Environment::debug_enabled(DebugCategory category) const { -#ifdef DEBUG - CHECK_GE(static_cast(category), 0); - CHECK_LT(static_cast(category), + DCHECK_GE(static_cast(category), 0); + DCHECK_LT(static_cast(category), static_cast(DebugCategory::CATEGORY_COUNT)); -#endif return debug_enabled_[static_cast(category)]; } void Environment::set_debug_enabled(DebugCategory category, bool enabled) { -#ifdef DEBUG - CHECK_GE(static_cast(category), 0); - CHECK_LT(static_cast(category), + DCHECK_GE(static_cast(category), 0); + DCHECK_LT(static_cast(category), static_cast(DebugCategory::CATEGORY_COUNT)); -#endif debug_enabled_[static_cast(category)] = enabled; } diff --git a/src/env.cc b/src/env.cc index 4fdfcafaa142b6..df7b4e827f86bf 100644 --- a/src/env.cc +++ b/src/env.cc @@ -591,9 +591,7 @@ void Environment::RunAndClearNativeImmediates() { }; while (drain_list()) {} -#ifdef DEBUG - CHECK_GE(immediate_info()->count(), count); -#endif + DCHECK_GE(immediate_info()->count(), count); immediate_info()->count_dec(count); immediate_info()->ref_count_dec(ref_count); } diff --git a/src/stream_base.cc b/src/stream_base.cc index 26efa46ba02f83..739964eb85a762 100644 --- a/src/stream_base.cc +++ b/src/stream_base.cc @@ -292,17 +292,16 @@ void StreamBase::CallJSOnreadMethod(ssize_t nread, size_t offset) { Environment* env = env_; -#ifdef DEBUG - CHECK_EQ(static_cast(nread), nread); - CHECK_LE(offset, INT32_MAX); + DCHECK_EQ(static_cast(nread), nread); + DCHECK_LE(offset, INT32_MAX); if (ab.IsEmpty()) { - CHECK_EQ(offset, 0); - CHECK_LE(nread, 0); + DCHECK_EQ(offset, 0); + DCHECK_LE(nread, 0); } else { - CHECK_GE(nread, 0); + DCHECK_GE(nread, 0); } -#endif + env->stream_base_state()[kReadBytesOrError] = nread; env->stream_base_state()[kArrayBufferOffset] = offset; diff --git a/src/util.h b/src/util.h index f6f980026e38ff..04c8807aa6ef7a 100644 --- a/src/util.h +++ b/src/util.h @@ -129,25 +129,25 @@ void DumpBacktrace(FILE* fp); #define CHECK_IMPLIES(a, b) CHECK(!(a) || (b)) #ifdef DEBUG -#define DCHECK_EQ(a, b) CHECK((a) == (b)) -#define DCHECK_GE(a, b) CHECK((a) >= (b)) -#define DCHECK_GT(a, b) CHECK((a) > (b)) -#define DCHECK_LE(a, b) CHECK((a) <= (b)) -#define DCHECK_LT(a, b) CHECK((a) < (b)) -#define DCHECK_NE(a, b) CHECK((a) != (b)) -#define DCHECK_NULL(val) CHECK((val) == nullptr) -#define DCHECK_NOT_NULL(val) CHECK((val) != nullptr) -#define DCHECK_IMPLIES(a, b) CHECK(!(a) || (b)) + #define DCHECK_EQ(a, b) CHECK((a) == (b)) + #define DCHECK_GE(a, b) CHECK((a) >= (b)) + #define DCHECK_GT(a, b) CHECK((a) > (b)) + #define DCHECK_LE(a, b) CHECK((a) <= (b)) + #define DCHECK_LT(a, b) CHECK((a) < (b)) + #define DCHECK_NE(a, b) CHECK((a) != (b)) + #define DCHECK_NULL(val) CHECK((val) == nullptr) + #define DCHECK_NOT_NULL(val) CHECK((val) != nullptr) + #define DCHECK_IMPLIES(a, b) CHECK(!(a) || (b)) #else -#define DCHECK_EQ(a, b) -#define DCHECK_GE(a, b) -#define DCHECK_GT(a, b) -#define DCHECK_LE(a, b) -#define DCHECK_LT(a, b) -#define DCHECK_NE(a, b) -#define DCHECK_NULL(val) -#define DCHECK_NOT_NULL(val) -#define DCHECK_IMPLIES(a, b) + #define DCHECK_EQ(a, b) + #define DCHECK_GE(a, b) + #define DCHECK_GT(a, b) + #define DCHECK_LE(a, b) + #define DCHECK_LT(a, b) + #define DCHECK_NE(a, b) + #define DCHECK_NULL(val) + #define DCHECK_NOT_NULL(val) + #define DCHECK_IMPLIES(a, b) #endif From 799e6d51185fc2836bb67b2417c2959b9a98712f Mon Sep 17 00:00:00 2001 From: kiyomizumia Date: Sat, 24 Nov 2018 16:19:09 +0900 Subject: [PATCH 3/5] src: fixed DCHECK statements --- src/inspector/node_string.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/inspector/node_string.h b/src/inspector/node_string.h index 468aec96b56e79..504798853675a5 100644 --- a/src/inspector/node_string.h +++ b/src/inspector/node_string.h @@ -73,7 +73,4 @@ extern size_t kNotFound; } // namespace inspector } // namespace node -#define DCHECK CHECK -#define DCHECK_LT CHECK_LT - #endif // SRC_INSPECTOR_NODE_STRING_H_ From 2002e03ee6d1fb47b46f7bc8d32e8af59f6ef179 Mon Sep 17 00:00:00 2001 From: kiyomizumia Date: Sat, 24 Nov 2018 16:57:12 +0900 Subject: [PATCH 4/5] src: added ifndef for decheck --- src/inspector/node_string.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/inspector/node_string.h b/src/inspector/node_string.h index 504798853675a5..b5b6a39407a876 100644 --- a/src/inspector/node_string.h +++ b/src/inspector/node_string.h @@ -73,4 +73,7 @@ extern size_t kNotFound; } // namespace inspector } // namespace node +#ifndef DCHECK + #define DCHECK CHECK + #define DCHECK_LT CHECK_LT #endif // SRC_INSPECTOR_NODE_STRING_H_ From 90de2f3776cd8abb3b63e5caacd8f87875c91fe5 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Sat, 8 Dec 2018 00:34:23 +0900 Subject: [PATCH 5/5] Update src/inspector/node_string.h Co-Authored-By: kiyomizumia <42000558+kiyomizumia@users.noreply.github.com> --- src/inspector/node_string.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/inspector/node_string.h b/src/inspector/node_string.h index b5b6a39407a876..4588364ab12196 100644 --- a/src/inspector/node_string.h +++ b/src/inspector/node_string.h @@ -76,4 +76,5 @@ extern size_t kNotFound; #ifndef DCHECK #define DCHECK CHECK #define DCHECK_LT CHECK_LT +#endif // DCHECK #endif // SRC_INSPECTOR_NODE_STRING_H_