From a26dfb323b1090fe6a003e92f4ecf9efd3498f0f Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Thu, 28 Jan 2021 21:22:09 +0800 Subject: [PATCH] src: expose BaseObject::kInternalFieldCount in post-mortem metadata So that the debugger does not have to hard-code the number of internal fields of BaseObjects. PR-URL: https://github.com/nodejs/node/pull/37111 Refs: https://github.com/nodejs/node/pull/36943 Reviewed-By: Colin Ihrig Reviewed-By: Rich Trott Reviewed-By: James M Snell --- src/node_postmortem_metadata.cc | 3 +++ test/cctest/test_node_postmortem_metadata.cc | 16 +++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/node_postmortem_metadata.cc b/src/node_postmortem_metadata.cc index ccb347e95175c1..2dc534f59bf80a 100644 --- a/src/node_postmortem_metadata.cc +++ b/src/node_postmortem_metadata.cc @@ -36,6 +36,7 @@ extern "C" { int nodedbg_const_ContextEmbedderIndex__kEnvironment__int; +int nodedbg_const_BaseObject__kInternalFieldCount__int; uintptr_t nodedbg_offset_ExternalString__data__uintptr_t; uintptr_t nodedbg_offset_ReqWrap__req_wrap_queue___ListNode_ReqWrapQueue; @@ -50,6 +51,8 @@ namespace node { int GenDebugSymbols() { nodedbg_const_ContextEmbedderIndex__kEnvironment__int = ContextEmbedderIndex::kEnvironment; + nodedbg_const_BaseObject__kInternalFieldCount__int = + BaseObject::kInternalFieldCount; nodedbg_offset_ExternalString__data__uintptr_t = NODE_OFF_EXTSTR_DATA; nodedbg_offset_ReqWrap__req_wrap_queue___ListNode_ReqWrapQueue = diff --git a/test/cctest/test_node_postmortem_metadata.cc b/test/cctest/test_node_postmortem_metadata.cc index 3fb67ecbca265e..4cee7db4c8ee5b 100644 --- a/test/cctest/test_node_postmortem_metadata.cc +++ b/test/cctest/test_node_postmortem_metadata.cc @@ -14,6 +14,7 @@ extern uintptr_t nodedbg_offset_Environment__handle_wrap_queue___Environment_HandleWrapQueue; extern int debug_symbols_generated; extern int nodedbg_const_ContextEmbedderIndex__kEnvironment__int; +extern int nodedbg_const_BaseObject__kInternalFieldCount__int; extern uintptr_t nodedbg_offset_Environment_HandleWrapQueue__head___ListNode_HandleWrap; extern uintptr_t @@ -68,6 +69,12 @@ TEST_F(DebugSymbolsTest, ContextEmbedderEnvironmentIndex) { kEnvironmentIndex); } +TEST_F(DebugSymbolsTest, BaseObjectkInternalFieldCount) { + int kInternalFieldCount = node::BaseObject::kInternalFieldCount; + EXPECT_EQ(nodedbg_const_BaseObject__kInternalFieldCount__int, + kInternalFieldCount); +} + TEST_F(DebugSymbolsTest, ExternalStringDataOffset) { EXPECT_EQ(nodedbg_offset_ExternalString__data__uintptr_t, NODE_OFF_EXTSTR_DATA); @@ -89,7 +96,8 @@ TEST_F(DebugSymbolsTest, BaseObjectPersistentHandle) { Env env{handle_scope, argv}; v8::Local obj_templ = v8::ObjectTemplate::New(isolate_); - obj_templ->SetInternalFieldCount(1); + obj_templ->SetInternalFieldCount( + nodedbg_const_BaseObject__kInternalFieldCount__int); v8::Local object = obj_templ->NewInstance(env.context()).ToLocalChecked(); @@ -139,7 +147,8 @@ TEST_F(DebugSymbolsTest, HandleWrapList) { uv_tcp_t handle; auto obj_template = v8::FunctionTemplate::New(isolate_); - obj_template->InstanceTemplate()->SetInternalFieldCount(1); + obj_template->InstanceTemplate()->SetInternalFieldCount( + nodedbg_const_BaseObject__kInternalFieldCount__int); v8::Local object = obj_template->GetFunction(env.context()) .ToLocalChecked() @@ -171,7 +180,8 @@ TEST_F(DebugSymbolsTest, ReqWrapList) { tail = *reinterpret_cast(tail); auto obj_template = v8::FunctionTemplate::New(isolate_); - obj_template->InstanceTemplate()->SetInternalFieldCount(1); + obj_template->InstanceTemplate()->SetInternalFieldCount( + nodedbg_const_BaseObject__kInternalFieldCount__int); v8::Local object = obj_template->GetFunction(env.context()) .ToLocalChecked()