[SERVER-76543] The mongod-dump-sessions gdb pretty printer does not work Created: 26/Apr/23  Updated: 29/Oct/23  Resolved: 28/Apr/23

Status: Closed
Project: Core Server
Component/s: Testing Infrastructure
Affects Version/s: None
Fix Version/s: 7.1.0-rc0, 7.0.0-rc1, 6.3.2

Type: Bug Priority: Major - P3
Reporter: Louis Williams Assignee: Max Hirschhorn
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Problem/Incident
is caused by SERVER-62995 Update pretty printers as needed to w... Closed
Related
is related to SERVER-76627 Add gdb pretty printer test for mongo... Open
Assigned Teams:
Server Development Platform
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v7.0, v6.3
Sprint: Sharding NYC 2023-05-01
Participants:
Linked BF Score: 105

 Description   

When I try to open a core dump for this failure, I get these errors when dumping the session catalog:

(gdb) mongod-dump-sessions
Failed to look up decoration type: std::unique_ptr<mongo::transport::(anonymous namespace)::Handle>: No type named std::unique_ptr<mongo::transport::(anonymous namespace)::Handle>.
Failed to look up decoration type: std::unique_ptr<mongo::telemetry::(anonymous namespace)::TelemetryStoreManager>: No type named std::unique_ptr<mongo::telemetry::(anonymous namespace)::TelemetryStoreManager>.
Failed to look up decoration type: std::unique_ptr<mongo::transport::(anonymous namespace)::Handle>: No type named std::unique_ptr<mongo::transport::(anonymous namespace)::Handle>.
Failed to look up decoration type: std::unique_ptr<mongo::telemetry::(anonymous namespace)::TelemetryStoreManager>: No type named std::unique_ptr<mongo::telemetry::(anonymous namespace)::TelemetryStoreManager>.
Dumping 161 Session objects from the SessionCatalog
Traceback (most recent call last):
  File "buildscripts/gdb/mongo.py", line 419, in invoke
    parent_session = session_runtime_info['parentSession']
gdb.error: Attempt to extract a component of a value that is not a struct/class/union.
Error occurred in Python: Attempt to extract a component of a value that is not a struct/class/union.

This specific failure was on the 6.3 branch. I have no idea if the same problem exists on newer branches, but this is preventing me from easily investigating a possible deadlock.



 Comments   
Comment by Githook User [ 28/Apr/23 ]

Author:

{'name': 'Max Hirschhorn', 'email': 'max.hirschhorn@mongodb.com', 'username': 'visemet'}

Message: SERVER-76543 Fix get_unique_ptr() used by GDB pretty printers.

Adds a new get_unique_ptr_bytes() function to retain the specialization
for std::unique_ptr<unsigned char[]>.

(cherry picked from commit e77c5df954dfa8f0aaed5fc6e340180b41d11254)
Branch: v7.0
https://github.com/mongodb/mongo/commit/0f21c7704bc47d98dee64b81a35516280c98d238

Comment by Githook User [ 28/Apr/23 ]

Author:

{'name': 'Max Hirschhorn', 'email': 'max.hirschhorn@mongodb.com', 'username': 'visemet'}

Message: SERVER-76543 Fix get_unique_ptr() used by GDB pretty printers.

Adds a new get_unique_ptr_bytes() function to retain the specialization
for std::unique_ptr<unsigned char[]>.

(cherry picked from commit e77c5df954dfa8f0aaed5fc6e340180b41d11254)
Branch: v6.3
https://github.com/mongodb/mongo/commit/b0bda900c7f42ff1c8e5b1945640cc33694d447c

Comment by Githook User [ 27/Apr/23 ]

Author:

{'name': 'Max Hirschhorn', 'email': 'max.hirschhorn@mongodb.com', 'username': 'visemet'}

Message: SERVER-76543 Fix get_unique_ptr() used by GDB pretty printers.

Adds a new get_unique_ptr_bytes() function to retain the specialization
for std::unique_ptr<unsigned char[]>.
Branch: master
https://github.com/mongodb/mongo/commit/e77c5df954dfa8f0aaed5fc6e340180b41d11254

Comment by Daniel Moody [ 27/Apr/23 ]

Thanks for looking into it max.hirschhorn@mongodb.com , the changes seem reasonable to me. We should implement them along with a pretty printer test for mongo-dump-sessions which uses or replicates the stack in the core dump.

Comment by Max Hirschhorn [ 27/Apr/23 ]

I looked into this issue and don't believe the problem would be specific to mongod-dump-sessions. The changes from fb23430 as part of SERVER-62995 changed the definition of get_unique_ptr() such that the returned gdb.Value has its type casted to an unsigned char*. While get_decoration() and get_decorations() will do their own cast, the other callers of get_unique_ptr() are expecting a gdb.Value which is the true underlying type. CC daniel.moody@mongodb.com, alexander.neben@mongodb.com

session_runtime_info.type=unsigned char

The following changes enable the mongod-dump-sessions command to work for me. I found the current definition of get_unique_ptr() is still needed by get_decoration() and get_decorations() to avoid GDB errors about the type being incomplete at the time of the cast.

diff --git a/buildscripts/gdb/mongo.py b/buildscripts/gdb/mongo.py
index 317c52acf5c..fa9c0b88e08 100644
--- a/buildscripts/gdb/mongo.py
+++ b/buildscripts/gdb/mongo.py
@@ -14,7 +14,7 @@ import gdb
 
 if not gdb:
     sys.path.insert(0, str(Path(os.path.abspath(__file__)).parent.parent.parent))
-    from buildscripts.gdb.mongo_printers import absl_get_nodes, get_unique_ptr
+    from buildscripts.gdb.mongo_printers import absl_get_nodes, get_unique_ptr, get_unique_ptr_bytes
 
 
 def detect_toolchain(progspace):
@@ -249,7 +249,7 @@ def get_decorations(obj):
         type_name = type_name[0:type_name.rindex(">")]
         type_name = type_name[type_name.index("constructAt<"):].replace("constructAt<", "")
         # get_unique_ptr should be loaded from 'mongo_printers.py'.
-        decoration_data = get_unique_ptr(decorable["_decorations"]["_decorationData"])
+        decoration_data = get_unique_ptr_bytes(decorable["_decorations"]["_decorationData"])
 
         if type_name.endswith('*'):
             type_name = type_name[0:len(type_name) - 1]
diff --git a/buildscripts/gdb/mongo_printers.py b/buildscripts/gdb/mongo_printers.py
index f54f131db76..e429b757992 100644
--- a/buildscripts/gdb/mongo_printers.py
+++ b/buildscripts/gdb/mongo_printers.py
@@ -33,11 +33,16 @@ if sys.version_info[0] < 3:
         "MongoDB gdb extensions only support Python 3. Your GDB was compiled against Python 2")
 
 
-def get_unique_ptr(obj):
+def get_unique_ptr_bytes(obj):
     """Read the value of a libstdc++ std::unique_ptr."""
     return obj.cast(gdb.lookup_type('std::_Head_base<0, unsigned char*, false>'))['_M_head_impl']
 
 
+def get_unique_ptr(obj):
+    """Read the value of a libstdc++ std::unique_ptr."""
+    return get_unique_ptr_bytes(obj).cast(obj.type.template_argument(0).pointer())
+
+
 ###################################################################################################
 #
 # Pretty-Printers

Comment by Wenbin Zhu [ 26/Apr/23 ]

This specific failure was on the 6.3 branch. I have no idea if the same problem exists on newer branches,

Confirming that this also happens on 7.0 (BF-28535).

cc cheahuychou.mao@mongodb.com

Generated at Thu Feb 08 06:32:57 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.