77
88import gdb
99
10- # pylint: disable=invalid-name,wildcard-import
10+ # pylint: disable=invalid-name,wildcard-import,broad-except
1111try :
1212 # Try to find and load the C++ pretty-printer library.
1313 import glob
1717 sys .path .insert (0 , path )
1818 from libstdcxx .v6 .printers import *
1919 print ("Loaded libstdc++ pretty printers from '%s'" % printers )
20- except ImportError as e :
20+ except Exception as e :
2121 print ("Failed to load the libstdc++ pretty printers: " + str (e ))
2222# pylint: enable=invalid-name,wildcard-import
2323
@@ -151,6 +151,11 @@ def get_boost_optional(optional):
151151 return storage .cast (value_ref_type ).dereference ()
152152
153153
154+ def get_field_names (value ):
155+ """Return a list of all field names on a given GDB value."""
156+ return [typ .name for typ in value .type .fields ()]
157+
158+
154159###################################################################################################
155160#
156161# Commands
@@ -244,7 +249,7 @@ def __init__(self):
244249 """Initialize DumpMongoDSessionCatalog."""
245250 RegisterMongoCommand .register (self , "mongod-dump-sessions" , gdb .COMMAND_DATA )
246251
247- def invoke (self , args , _from_tty ): # pylint: disable=unused-argument,no-self-use,too-many-locals
252+ def invoke (self , args , _from_tty ): # pylint: disable=unused-argument,no-self-use,too-many-locals,too-many-branches
248253 """Invoke DumpMongoDSessionCatalog."""
249254 # See if a particular session id was specified.
250255 argarr = args .split (" " )
@@ -296,7 +301,11 @@ def invoke(self, args, _from_tty): # pylint: disable=unused-argument,no-self-us
296301 print ("SessionId" , "=" , lsid_str )
297302 session_fields_to_print = ['_sessionId' , '_checkoutOpCtx' , '_killsRequested' ]
298303 for field in session_fields_to_print :
299- print (field , "=" , session [field ])
304+ # Skip fields that aren't found on the object.
305+ if field in get_field_names (session ):
306+ print (field , "=" , session [field ])
307+ else :
308+ print ("Could not find field '%s' on the Session object." % field )
300309
301310 # Print the information from a TransactionParticipant if a session has one. Otherwise
302311 # we just print the session's id and nothing else.
@@ -307,7 +316,11 @@ def invoke(self, args, _from_tty): # pylint: disable=unused-argument,no-self-us
307316 fields_to_print = ['_txnState' , '_activeTxnNumber' ]
308317 print ("TransactionParticipant (" + str (txn_part .address ) + "):" )
309318 for field in fields_to_print :
310- print (field , "=" , txn_part [field ])
319+ # Skip fields that aren't found on the object.
320+ if field in get_field_names (txn_part ):
321+ print (field , "=" , txn_part [field ])
322+ else :
323+ print ("Could not find field '%s' on the TransactionParticipant" % field )
311324
312325 # The '_txnResourceStash' field is a boost::optional so we unpack it
313326 # manually if it is non-empty. We are only interested in its Locker object for now.
0 commit comments