dash/contrib/auto_gdb/used_size.py
Konstantin Akimov 097a8e7196
non-scripted-diff: bump copyright year to 2023
that's a result of:
contrib/devtools/copyright_header.py update ./

it is not scripted diff, because it works differentlly on my localhost and in CI:
CI doesn't want to use git commit date which is mocked to 30th Dec of 2023
2024-02-24 11:05:37 -06:00

48 lines
1.3 KiB
Python

#!/usr/bin/env python3
# Copyright (c) 2018-2023 The Dash Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
#
try:
import gdb
except ImportError as e:
raise ImportError("This script must be run in GDB: ", str(e))
import traceback
import sys
import os
import common_helpers
sys.path.append(os.getcwd())
class UsedSizeCommand (gdb.Command):
"""calc size of the memory used by the object"""
def __init__ (self):
super (UsedSizeCommand, self).__init__ ("usedsize", gdb.COMMAND_USER)
@classmethod
def assign_value(cls, obj_name, value):
gdb.execute("set " + obj_name + " = " + str(value))
@classmethod
def get_type(cls, obj_name):
return gdb.parse_and_eval(obj_name).type
def invoke(self, arg, _from_tty):
try:
args = gdb.string_to_argv(arg)
obj = gdb.parse_and_eval(args[1])
obj_type = obj.type
print (args[1] + " is " + str(obj_type))
size = common_helpers.get_instance_size(obj)
UsedSizeCommand.assign_value(args[0], size)
print (size)
except Exception as e:
print(traceback.format_exc())
raise e
UsedSizeCommand()