Skip to content

Commit

Permalink
src: expose BaseObject::kInternalFieldCount in post-mortem metadata
Browse files Browse the repository at this point in the history
So that the debugger does not have to hard-code the number of
internal fields of BaseObjects.

PR-URL: #37111
Refs: #36943
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
joyeecheung authored and targos committed May 1, 2021
1 parent 35cf86c commit 1ecdb66
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/node_postmortem_metadata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 =
Expand Down
16 changes: 13 additions & 3 deletions test/cctest/test_node_postmortem_metadata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -89,7 +96,8 @@ TEST_F(DebugSymbolsTest, BaseObjectPersistentHandle) {
Env env{handle_scope, argv};

v8::Local<v8::ObjectTemplate> obj_templ = v8::ObjectTemplate::New(isolate_);
obj_templ->SetInternalFieldCount(1);
obj_templ->SetInternalFieldCount(
nodedbg_const_BaseObject__kInternalFieldCount__int);

v8::Local<v8::Object> object =
obj_templ->NewInstance(env.context()).ToLocalChecked();
Expand Down Expand Up @@ -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<v8::Object> object = obj_template->GetFunction(env.context())
.ToLocalChecked()
Expand Down Expand Up @@ -171,7 +180,8 @@ TEST_F(DebugSymbolsTest, ReqWrapList) {
tail = *reinterpret_cast<uintptr_t*>(tail);

auto obj_template = v8::FunctionTemplate::New(isolate_);
obj_template->InstanceTemplate()->SetInternalFieldCount(1);
obj_template->InstanceTemplate()->SetInternalFieldCount(
nodedbg_const_BaseObject__kInternalFieldCount__int);

v8::Local<v8::Object> object = obj_template->GetFunction(env.context())
.ToLocalChecked()
Expand Down

0 comments on commit 1ecdb66

Please sign in to comment.