Skip to content

Commit

Permalink
src: expose ListNode<T>::prev_ on postmortem metadata
Browse files Browse the repository at this point in the history
Make ListNode<T> postmortem easier to find last items in the queue.

PR-URL: #30027
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
  • Loading branch information
legendecas authored and MylesBorins committed Oct 23, 2019
1 parent 13f3d6c commit 8fcc039
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
2 changes: 2 additions & 0 deletions src/node_postmortem_metadata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@
HandleWrap::handle_wrap_queue_) \
V(Environment_HandleWrapQueue, head_, ListNode_HandleWrap, \
Environment::HandleWrapQueue::head_) \
V(ListNode_HandleWrap, prev_, uintptr_t, ListNode<HandleWrap>::prev_) \
V(ListNode_HandleWrap, next_, uintptr_t, ListNode<HandleWrap>::next_) \
V(Environment_ReqWrapQueue, head_, ListNode_ReqWrapQueue, \
Environment::ReqWrapQueue::head_) \
V(ListNode_ReqWrap, prev_, uintptr_t, ListNode<ReqWrapBase>::prev_) \
V(ListNode_ReqWrap, next_, uintptr_t, ListNode<ReqWrapBase>::next_)

extern "C" {
Expand Down
37 changes: 22 additions & 15 deletions test/cctest/test_node_postmortem_metadata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ extern uintptr_t
extern uintptr_t
nodedbg_offset_Environment__req_wrap_queue___Environment_ReqWrapQueue;
extern uintptr_t nodedbg_offset_ExternalString__data__uintptr_t;
extern uintptr_t nodedbg_offset_ListNode_ReqWrap__prev___uintptr_t;
extern uintptr_t nodedbg_offset_ListNode_ReqWrap__next___uintptr_t;
extern uintptr_t nodedbg_offset_ReqWrap__req_wrap_queue___ListNode_ReqWrapQueue;
extern uintptr_t nodedbg_offset_ListNode_HandleWrap__prev___uintptr_t;
extern uintptr_t nodedbg_offset_ListNode_HandleWrap__next___uintptr_t;
extern uintptr_t
nodedbg_offset_Environment_ReqWrapQueue__head___ListNode_ReqWrapQueue;
Expand Down Expand Up @@ -129,6 +131,12 @@ TEST_F(DebugSymbolsTest, HandleWrapList) {
const Argv argv;
Env env{handle_scope, argv};

auto queue = reinterpret_cast<uintptr_t>((*env)->handle_wrap_queue());
auto head = queue +
nodedbg_offset_Environment_HandleWrapQueue__head___ListNode_HandleWrap;
auto tail = head + nodedbg_offset_ListNode_HandleWrap__prev___uintptr_t;
tail = *reinterpret_cast<uintptr_t*>(tail);

uv_tcp_t handle;

auto obj_template = v8::FunctionTemplate::New(isolate_);
Expand All @@ -140,16 +148,12 @@ TEST_F(DebugSymbolsTest, HandleWrapList) {
.ToLocalChecked();
TestHandleWrap obj(*env, object, &handle);

auto queue = reinterpret_cast<uintptr_t>((*env)->handle_wrap_queue());
auto head = queue +
nodedbg_offset_Environment_HandleWrapQueue__head___ListNode_HandleWrap;
auto next =
head + nodedbg_offset_ListNode_HandleWrap__next___uintptr_t;
next = *reinterpret_cast<uintptr_t*>(next);
auto last = tail + nodedbg_offset_ListNode_HandleWrap__next___uintptr_t;
last = *reinterpret_cast<uintptr_t*>(last);

auto expected = reinterpret_cast<uintptr_t>(&obj);
auto calculated = next -
nodedbg_offset_HandleWrap__handle_wrap_queue___ListNode_HandleWrap;
auto calculated =
last - nodedbg_offset_HandleWrap__handle_wrap_queue___ListNode_HandleWrap;
EXPECT_EQ(expected, calculated);

obj.persistent().Reset(); // ~HandleWrap() expects an empty handle.
Expand All @@ -160,6 +164,13 @@ TEST_F(DebugSymbolsTest, ReqWrapList) {
const Argv argv;
Env env{handle_scope, argv};

auto queue = reinterpret_cast<uintptr_t>((*env)->req_wrap_queue());
auto head =
queue +
nodedbg_offset_Environment_ReqWrapQueue__head___ListNode_ReqWrapQueue;
auto tail = head + nodedbg_offset_ListNode_ReqWrap__prev___uintptr_t;
tail = *reinterpret_cast<uintptr_t*>(tail);

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

Expand All @@ -174,16 +185,12 @@ TEST_F(DebugSymbolsTest, ReqWrapList) {
// ARM64 CI machinies.
for (auto it : *(*env)->req_wrap_queue()) (void) &it;

auto queue = reinterpret_cast<uintptr_t>((*env)->req_wrap_queue());
auto head = queue +
nodedbg_offset_Environment_ReqWrapQueue__head___ListNode_ReqWrapQueue;
auto next =
head + nodedbg_offset_ListNode_ReqWrap__next___uintptr_t;
next = *reinterpret_cast<uintptr_t*>(next);
auto last = tail + nodedbg_offset_ListNode_ReqWrap__next___uintptr_t;
last = *reinterpret_cast<uintptr_t*>(last);

auto expected = reinterpret_cast<uintptr_t>(&obj);
auto calculated =
next - nodedbg_offset_ReqWrap__req_wrap_queue___ListNode_ReqWrapQueue;
last - nodedbg_offset_ReqWrap__req_wrap_queue___ListNode_ReqWrapQueue;
EXPECT_EQ(expected, calculated);

obj.Dispatched();
Expand Down

0 comments on commit 8fcc039

Please sign in to comment.